Commit d0a93cc6d1cf5b12fb3583acecb7aec3cd27ed16
1 parent
9508f883a0
Exists in
master
csv file
Showing
3 changed files
with
46 additions
and
2 deletions
Show diff stats
imports/client/views/org/admin/students/UploadCsv.js
1 | import _ from 'lodash'; | 1 | import _ from 'lodash'; |
2 | import { Meteor } from 'meteor/meteor'; | 2 | import { Meteor } from 'meteor/meteor'; |
3 | 3 | ||
4 | import React, { Component } from 'react'; | 4 | import React, { Component } from 'react'; |
5 | import { Link,browserHistory } from 'react-router'; | 5 | import { Link,browserHistory } from 'react-router'; |
6 | import { FormGroup,Panel,Table, | 6 | import { FormGroup,Panel,Table, |
7 | ButtonToolbar,Modal,ControlLabel,HelpBlock, | 7 | ButtonToolbar,Modal,ControlLabel,HelpBlock, |
8 | FormControl,Glyphicon,Button } from 'react-bootstrap'; | 8 | FormControl,Glyphicon,Button } from 'react-bootstrap'; |
9 | // import { AddStudentForm } from './addStudentForm'; | 9 | // import { AddStudentForm } from './addStudentForm'; |
10 | 10 | ||
11 | const style = { | 11 | const style = { |
12 | margin: 12, | 12 | margin: 12, |
13 | }; | 13 | }; |
14 | function FieldGroup({ id, label, help, ...props }) { | 14 | function FieldGroup({ id, label, help, ...props }) { |
15 | return ( | 15 | return ( |
16 | <FormGroup controlId={id}> | 16 | <FormGroup controlId={id}> |
17 | <ControlLabel>{label}</ControlLabel> | 17 | <ControlLabel>{label}</ControlLabel> |
18 | <FormControl {...props} /> | 18 | <FormControl {...props} /> |
19 | {help && <HelpBlock>{help}</HelpBlock>} | 19 | {help && <HelpBlock>{help}</HelpBlock>} |
20 | </FormGroup> | 20 | </FormGroup> |
21 | ); | 21 | ); |
22 | } | 22 | } |
23 | export class UploadCsv extends Component { | 23 | export class UploadCsv extends Component { |
24 | constructor(props) { | 24 | constructor(props) { |
25 | super(props); | 25 | super(props); |
26 | this.state = { | 26 | this.state = { |
27 | show: false | 27 | show: false |
28 | }; | 28 | }; |
29 | this.showModal = this.showModal.bind(this); | 29 | this.showModal = this.showModal.bind(this); |
30 | this.hideModal = this.hideModal.bind(this); | 30 | this.hideModal = this.hideModal.bind(this); |
31 | this.onUpdate = this.onUpdate.bind(this); | 31 | this.onUpdate = this.onUpdate.bind(this); |
32 | }; | 32 | }; |
33 | 33 | ||
34 | showModal() { | 34 | showModal() { |
35 | this.setState({show: true}); | 35 | this.setState({show: true}); |
36 | } | 36 | } |
37 | 37 | ||
38 | hideModal() { | 38 | hideModal() { |
39 | this.setState({show: false}); | 39 | this.setState({show: false}); |
40 | } | 40 | } |
41 | onUpdate(key, value) { | 41 | onUpdate(key, value) { |
42 | this.setState({[key]: value}); | 42 | this.setState({[key]: value}); |
43 | }; | 43 | }; |
44 | uploadStudentCsv(e){ | ||
45 | e.preventDefault(); | ||
46 | e.persist(); | ||
47 | csvData = ""; | ||
48 | Meteor.call('student.uploadCsv', csvData, function (error, result) { | ||
49 | |||
50 | }) | ||
51 | } | ||
44 | 52 | ||
45 | render() { | 53 | render() { |
46 | console.log(this.props); | 54 | console.log(this.props); |
47 | return ( | 55 | return ( |
48 | <ButtonToolbar> | 56 | <ButtonToolbar> |
49 | <Button bsStyle="primary" onClick={this.showModal}> | 57 | <Button bsStyle="primary" onClick={this.showModal}> |
50 | Upload CSV | 58 | Upload CSV |
51 | </Button> | 59 | </Button> |
52 | <Modal | 60 | <Modal |
53 | {...this.props} | 61 | {...this.props} |
54 | show={this.state.show} | 62 | show={this.state.show} |
55 | onHide={this.hideModal} | 63 | onHide={this.hideModal} |
56 | dialogClassName="custom-modal" | 64 | dialogClassName="custom-modal" |
57 | > | 65 | > |
58 | <Modal.Header closeButton> | 66 | <Modal.Header closeButton> |
59 | <Modal.Title id="contained-modal-title-lg">New Student</Modal.Title> | 67 | <Modal.Title id="contained-modal-title-lg">New Student</Modal.Title> |
60 | </Modal.Header> | 68 | </Modal.Header> |
61 | <Modal.Body> | 69 | <Modal.Body> |
62 | <form> | 70 | <form onSubmit={ (e) => this.uploadStudentCsv(e) } > |
63 | <FieldGroup | 71 | <FieldGroup |
64 | id="formControlsFile" | 72 | id="formControlsFile" |
65 | type="file" | 73 | type="file" |
66 | label="File" | 74 | label="File" |
67 | help="Upload you CSV here." | 75 | help="Upload you CSV here." |
68 | /> | 76 | /> |
77 | <Button type="submit" bsStyle="default">Upload File</Button> | ||
69 | </form> | 78 | </form> |
70 | </Modal.Body> | 79 | </Modal.Body> |
71 | <Modal.Footer> | 80 | <Modal.Footer> |
72 | <Button onClick={this.hideModal}>Close</Button> | 81 | <Button onClick={this.hideModal}>Close</Button> |
73 | </Modal.Footer> | 82 | </Modal.Footer> |
74 | </Modal> | 83 | </Modal> |
75 | </ButtonToolbar> | 84 | </ButtonToolbar> |
76 | ); | 85 | ); |
77 | }; | 86 | }; |
78 | 87 | ||
79 | }; | 88 | }; |
80 | 89 |
imports/collections/students/index.js
1 | // import {Students } from '/imports/collections/students/methods' | 1 | // import {Students } from '/imports/collections/students/index' |
2 | 2 | ||
3 | import _ from 'lodash'; | 3 | import _ from 'lodash'; |
4 | import { Meteor } from 'meteor/meteor'; | 4 | import { Meteor } from 'meteor/meteor'; |
5 | import { Mongo } from 'meteor/mongo'; | 5 | import { Mongo } from 'meteor/mongo'; |
6 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | 6 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; |
7 | 7 | ||
8 | import { Orgs } from '/imports/collections/orgs/index'; | 8 | import { Orgs } from '/imports/collections/orgs/index'; |
9 | import { Users } from '/imports/collections/users/index'; | 9 | import { Users } from '/imports/collections/users/index'; |
10 | 10 | ||
11 | class Student { | 11 | class Student { |
12 | constructor(doc) { | 12 | constructor(doc) { |
13 | _.assign(this, doc); | 13 | _.assign(this, doc); |
14 | }; | 14 | }; |
15 | 15 | ||
16 | getUserIds() { | 16 | getUserIds() { |
17 | return _.filter(_.map(this.users, 'userId')); | 17 | return _.filter(_.map(this.users, 'userId')); |
18 | }; | 18 | }; |
19 | }; | 19 | }; |
20 | export { Student }; | 20 | export { Student }; |
21 | 21 | ||
22 | class StudentsCollection extends Mongo.Collection { | 22 | class StudentsCollection extends Mongo.Collection { |
23 | insert(item, callback) { | 23 | insert(item, callback) { |
24 | _.assign(item, { | 24 | _.assign(item, { |
25 | createdAt: new Date().getTime(), | 25 | createdAt: new Date().getTime(), |
26 | }); | 26 | }); |
27 | return super.insert(item, callback); | 27 | return super.insert(item, callback); |
28 | }; | 28 | }; |
29 | }; | 29 | }; |
30 | 30 | ||
31 | export const Students = new StudentsCollection('Students', { | 31 | export const Students = new StudentsCollection('Students', { |
32 | transform: (item) => { | 32 | transform: (item) => { |
33 | return new Student(item); | 33 | return new Student(item); |
34 | }, | 34 | }, |
35 | }); | 35 | }); |
36 | 36 | ||
37 | _.assign(Students, { | 37 | _.assign(Students, { |
38 | allStudents: () => { | 38 | allStudents: () => { |
39 | const user = Users.current(); | 39 | const user = Users.current(); |
40 | if(!user) return null; | 40 | if(!user) return null; |
41 | return Orgs.find({'users.userId': user._id}); | 41 | return Orgs.find({'users.userId': user._id}); |
42 | }, | 42 | }, |
43 | current: () => { | 43 | current: () => { |
44 | const user = Users.current(); | 44 | const user = Users.current(); |
45 | if(!user) return null; | 45 | if(!user) return null; |
46 | return Orgs.findOne({_id: user.orgId}); | 46 | return Orgs.findOne({_id: user.orgId}); |
47 | }, | 47 | }, |
48 | currentOrgUsers: () => { | 48 | currentOrgUsers: () => { |
49 | const OrgsArr = Orgs.current(); | 49 | const OrgsArr = Orgs.current(); |
50 | if(!OrgsArr) return null; | 50 | if(!OrgsArr) return null; |
51 | return OrgsArr.users; | 51 | return OrgsArr.users; |
52 | }, | 52 | }, |
53 | 53 | ||
54 | }); | 54 | }); |
55 | 55 | ||
56 | Students.deny({ | 56 | Students.deny({ |
57 | insert() { return true; }, | 57 | insert() { return true; }, |
58 | update() { return true; }, | 58 | update() { return true; }, |
59 | remove() { return true; }, | 59 | remove() { return true; }, |
60 | }); | 60 | }); |
61 | 61 | ||
62 | 62 | ||
63 | Students.schema = new SimpleSchema({ | 63 | Students.schema = new SimpleSchema({ |
64 | userId: { type: String }, | 64 | userId: { type: String }, |
65 | orgId: { type: String }, | 65 | orgId: { type: String }, |
66 | admissionId: { type: String, optional: true }, | 66 | admissionId: { type: String, optional: true }, |
67 | enrollmentDate: { type: String, optional: true }, | 67 | enrollmentDate: { type: String, optional: true }, |
68 | address: { type: String, optional: true }, | 68 | address: { type: String, optional: true }, |
69 | prefix: { type: String, optional: true }, | 69 | prefix: { type: String, optional: true }, |
70 | firstName: { type: String, optional: true }, | 70 | firstName: { type: String, optional: true }, |
71 | middlename: { type: String, optional: true }, | 71 | middlename: { type: String, optional: true }, |
72 | lastName: { type: String, optional: true }, | 72 | lastName: { type: String, optional: true }, |
73 | gender: { type: String, optional: true }, | 73 | gender: { type: String, optional: true }, |
74 | dob: { type: String, optional: true }, | 74 | dob: { type: String, optional: true }, |
75 | rollNo: { type: String, optional: true }, | 75 | rollNo: { type: String, optional: true }, |
76 | class: { type: String, optional: true }, | 76 | class: { type: String, optional: true }, |
77 | section: { type: String, optional: true }, | 77 | section: { type: String, optional: true }, |
78 | bloodGroup: { type: String, optional: true }, | 78 | bloodGroup: { type: String, optional: true }, |
79 | community: { type: String, optional: true }, | 79 | community: { type: String, optional: true }, |
80 | nationality: { type: String, optional: true }, | 80 | nationality: { type: String, optional: true }, |
81 | motherTongue: { type: String, optional: true }, | 81 | motherTongue: { type: String, optional: true }, |
82 | motherTongue: { type: String, optional: true }, | 82 | motherTongue: { type: String, optional: true }, |
83 | religion: { type: String, optional: true }, | 83 | religion: { type: String, optional: true }, |
84 | permanentAddress: { | 84 | permanentAddress: { |
85 | type: new SimpleSchema({ | 85 | type: new SimpleSchema({ |
86 | home: { type: String, optional: true }, | 86 | home: { type: String, optional: true }, |
87 | street: { type: String, optional: true }, | 87 | street: { type: String, optional: true }, |
88 | town: { type: String, optional: true }, | 88 | town: { type: String, optional: true }, |
89 | city: { type: String, optional: true }, | 89 | city: { type: String, optional: true }, |
90 | state: { type: String, optional: true }, | 90 | state: { type: String, optional: true }, |
91 | zip: { type: String, optional: true }, | 91 | zip: { type: String, optional: true }, |
92 | }), | 92 | }), |
93 | optional: true | 93 | optional: true |
94 | }, | 94 | }, |
95 | parent: { | 95 | parent: { |
96 | type: [new SimpleSchema({ | 96 | type: [new SimpleSchema({ |
97 | id: { type: String, }, | 97 | id: { type: String, }, |
98 | relatinship: { type: String, }, | 98 | relatinship: { type: String, }, |
99 | })], | 99 | })], |
100 | optional: true | 100 | optional: true |
101 | }, | 101 | }, |
102 | prevInstitute: { | 102 | prevInstitute: { |
103 | type: [new SimpleSchema({ | 103 | type: [new SimpleSchema({ |
104 | name: { type: String, }, | 104 | name: { type: String, }, |
105 | fromYear: { type: String, }, | 105 | fromYear: { type: String, }, |
106 | toYear: { type: String, }, | 106 | toYear: { type: String, }, |
107 | ydId: { type: String, }, | 107 | ydId: { type: String, }, |
108 | })], | 108 | })], |
109 | optional: true | 109 | optional: true |
110 | }, | 110 | }, |
111 | 111 | ||
112 | services: { | 112 | services: { |
113 | type: Object, | 113 | type: Object, |
114 | optional: true, | 114 | optional: true, |
115 | blackbox: true, | 115 | blackbox: true, |
116 | }, | 116 | }, |
117 | 117 | ||
118 | isMetaUser: { type: Boolean, optional: true }, | 118 | isMetaUser: { type: Boolean, optional: true }, |
119 | 119 | ||
120 | createdAt: { type: Date, autoValue: function(){return new Date();}} | 120 | createdAt: { type: Date, autoValue: function(){return new Date();}} |
121 | 121 | ||
122 | }); | 122 | }); |
123 | 123 | ||
124 | Students.attachSchema(Students.schema); | 124 | Students.attachSchema(Students.schema); |
125 | 125 | ||
126 | Students.privateFields = { | 126 | Students.privateFields = { |
127 | orgId: 1, | 127 | orgId: 1, |
128 | address: 1, | 128 | address: 1, |
129 | 129 | ||
130 | firstName: 1, | 130 | firstName: 1, |
131 | lastName: 1, | 131 | lastName: 1, |
132 | emails: 1, | 132 | emails: 1, |
133 | phones: 1, | 133 | phones: 1, |
134 | 134 | ||
135 | isMetaUser: 1, | 135 | isMetaUser: 1, |
136 | createdAt: 1, | 136 | createdAt: 1, |
137 | }; | 137 | }; |
138 | 138 | ||
139 | Students.publicFields = { | 139 | Students.publicFields = { |
140 | firstName: 1, | 140 | firstName: 1, |
141 | lastName: 1, | 141 | lastName: 1, |
142 | emails: 1, | 142 | emails: 1, |
143 | 143 | ||
144 | createdAt: 1, | 144 | createdAt: 1, |
145 | }; | 145 | }; |
146 | 146 |
imports/collections/students/serverCsvUpload.js
File was created | 1 | // import { } from '/imports/collections/orgs/methods'; | |
2 | import _ from 'lodash'; | ||
3 | import { Meteor } from 'meteor/meteor'; | ||
4 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; | ||
5 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | ||
6 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; | ||
7 | import { Bert } from 'meteor/themeteorchef:bert'; | ||
8 | import { Users } from '/imports/collections/users/index'; | ||
9 | import { Orgs } from '/imports/collections/orgs/index'; | ||
10 | import {Students } from '/imports/collections/students/index' | ||
11 | export const orgMethod = new ValidatedMethod({ | ||
12 | name: 'org.method', | ||
13 | |||
14 | validate: new SimpleSchema({ | ||
15 | itemId: { type: String }, | ||
16 | }).validator(), | ||
17 | |||
18 | run({itemId}) { | ||
19 | return {}; | ||
20 | }, | ||
21 | |||
22 | }); | ||
23 | |||
24 | export const studentUploadCsv = new ValidatedMethod({ | ||
25 | name: 'student.uploadCsv', | ||
26 | |||
27 | validate: new SimpleSchema({ | ||
28 | itemId: { type: String }, | ||
29 | }).validator(), | ||
30 | |||
31 | run({itemId}) { | ||
32 | return {}; | ||
33 | }, | ||
34 | |||
35 | }); | ||
36 |