Commit 23c4a9e94d77e08909f59bde82ef1ef3041232fc
Exists in
master
Merge branch 'master' of https://bitbucket.org/youngdesk/ydapp
Showing
6 changed files
Show diff stats
client/stylesheets/custom.css
1 | body | 1 | body |
2 | { | 2 | { |
3 | background: -webkit-linear-gradient(#00b395, #00b395); | 3 | background: -webkit-linear-gradient(#00b395, #00b395); |
4 | background: -o-linear-gradient(#00b395, #00b395); | 4 | background: -o-linear-gradient(#00b395, #00b395); |
5 | background: linear-gradient(#00b395, #00b395); | 5 | background: linear-gradient(#00b395, #00b395); |
6 | } | 6 | } |
7 | |||
8 | table .dropdown span{ | ||
9 | color: #000000; | ||
10 | } | ||
11 | table .dropdown-toggle{ | ||
12 | cursor: pointer; | ||
13 | } | ||
14 | table .dropdown .fa{ | ||
15 | display: inline; | ||
16 | margin: 6px 6px; | ||
17 | } | ||
18 | table .dropdown-menu { | ||
19 | min-width: 134px; | ||
20 | } | ||
21 | table .dropdown-menu > li { | ||
22 | cursor: pointer; | ||
23 | } | ||
24 | table .dropdown-menu > li:hover{ | ||
25 | text-decoration: none; | ||
26 | color: #333333; | ||
27 | background-color: #f5f5f5; | ||
28 | } | ||
29 | table .dropdown-menu > li > span{ | ||
30 | padding: 6px 16px; | ||
31 | display: block; | ||
32 | } | ||
33 | .panel-body{ | ||
34 | max-height: 550px; | ||
35 | overflow-y: scroll; | ||
36 | } | ||
7 | 37 |
imports/client/views/org/admin/students/view/StudentRow.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, | 6 | import { FormGroup, |
7 | FormControl,Glyphicon,Button } from 'react-bootstrap'; | 7 | FormControl,Glyphicon,Button } from 'react-bootstrap'; |
8 | 8 | ||
9 | 9 | ||
10 | export class StudentRow extends Component { | 10 | export class StudentRow extends Component { |
11 | 11 | ||
12 | constructor(props) { | 12 | constructor(props) { |
13 | super(props); | 13 | super(props); |
14 | this.state = { | 14 | this.state = { |
15 | 15 | editOpen: false, | |
16 | }; | 16 | }; |
17 | this.onUpdate = this.onUpdate.bind(this); | 17 | this.onUpdate = this.onUpdate.bind(this); |
18 | this.toggleEditOpen = this.toggleEditOpen.bind(this); | ||
19 | this.deleteStudent = this.deleteStudent.bind(this); | ||
18 | }; | 20 | }; |
19 | 21 | ||
20 | onUpdate(key, value) { | 22 | onUpdate(key, value) { |
21 | this.setState({[key]: value}); | 23 | this.setState({[key]: value}); |
22 | }; | 24 | }; |
23 | 25 | toggleEditOpen(){ | |
26 | this.setState({ | ||
27 | editOpen : !this.state.editOpen | ||
28 | }) | ||
29 | } | ||
30 | deleteStudent(){ | ||
31 | console.log("Delete"); | ||
32 | console.log(this.props.student._id); | ||
33 | } | ||
24 | render() { | 34 | render() { |
25 | const {student} = this.props; | 35 | const {student} = this.props; |
26 | if(student.firstName){ | 36 | if(student.firstName){ |
27 | return ( | 37 | return ( |
28 | <tr> | 38 | <tr> |
29 | <td>{student.firstName}</td> | 39 | <td>{student.firstName}</td> |
30 | <td>{student.lastName}</td> | 40 | <td>{student.lastName}</td> |
31 | <td>{student.class}</td> | 41 | <td>{student.class}</td> |
32 | <td>{student.dob? moment(student.dob).format("LL") : <span></span>}</td> | 42 | <td>{student.dob? moment(student.dob).format("LL") : <span></span>}</td> |
33 | <td><span className="label label-success">Active</span></td> | 43 | <td><span className="label label-success">Active</span></td> |
34 | <td className="text-center"> | 44 | <td className="text-center"> |
35 | <ul className="icons-list"> | 45 | <ul className="icons-list"> |
36 | <li className="dropdown"> | 46 | <li className={this.state.editOpen? "dropdown open": "dropdown" }> |
37 | <a href="#" className="dropdown-toggle" data-toggle="dropdown"> | 47 | <span className="dropdown-toggle" onClick={this.toggleEditOpen}> |
38 | <i className="icon-menu9"></i> | 48 | <i className="icon-menu9"></i> |
39 | </a> | 49 | </span> |
40 | <ul className="dropdown-menu dropdown-menu-right"> | 50 | <ul className="dropdown-menu dropdown-menu-right"> |
41 | <li><a href="#"><i className="icon-file-pdf"></i> Export to .pdf</a></li> | 51 | <li onClick={this.viewStudent}><Link to={`/student/${student._id}`}><span><i className="fa fa-binoculars"></i>View </span></Link></li> |
42 | <li><a href="#"><i className="icon-file-excel"></i> Export to .csv</a></li> | 52 | <li onClick={this.editStudent}><span><i className="fa fa-pencil-square"></i> Edit </span></li> |
43 | <li><a href="#"><i className="icon-file-word"></i> Export to .doc</a></li> | 53 | <li onClick={this.deleteStudent}><span><i className="fa fa-exclamation-triangle"></i> Delete</span></li> |
44 | </ul> | 54 | </ul> |
45 | </li> | 55 | </li> |
46 | </ul> | 56 | </ul> |
47 | </td> | 57 | </td> |
48 | </tr> | 58 | </tr> |
49 | ); | 59 | ); |
50 | }else { | 60 | }else { |
51 | return null; | 61 | return null; |
52 | } | 62 | } |
53 | 63 | ||
54 | }; | 64 | }; |
55 | 65 | ||
56 | }; | 66 | }; |
57 | 67 |
imports/client/views/org/admin/students/view/StudentTable.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, | 7 | ButtonToolbar,Modal, |
8 | FormControl,Glyphicon,Button } from 'react-bootstrap'; | 8 | FormControl,Glyphicon,Button, } from 'react-bootstrap'; |
9 | import {moment} from 'meteor/momentjs:moment' | 9 | import {moment} from 'meteor/momentjs:moment' |
10 | import {StudentRow} from './StudentRow' | 10 | import {StudentRow} from './StudentRow' |
11 | 11 | ||
12 | export class StudentTable extends Component { | 12 | export class StudentTable extends Component { |
13 | 13 | ||
14 | constructor(props) { | 14 | constructor(props) { |
15 | super(props); | 15 | super(props); |
16 | this.state = { | 16 | this.state = { |
17 | show: false | 17 | show: false, |
18 | panleOpen: true, | ||
18 | }; | 19 | }; |
19 | this.onUpdate = this.onUpdate.bind(this); | 20 | this.onUpdate = this.onUpdate.bind(this); |
21 | this.togglePanel = this.togglePanel.bind(this); | ||
20 | }; | 22 | }; |
21 | onUpdate(key, value) { | 23 | onUpdate(key, value) { |
22 | this.setState({[key]: value}); | 24 | this.setState({[key]: value}); |
23 | }; | 25 | }; |
24 | 26 | togglePanel(){ | |
27 | this.setState({panleOpen: !this.state.panleOpen}); | ||
28 | } | ||
25 | render() { | 29 | render() { |
26 | return ( | 30 | return ( |
27 | <div className="panel panel-flat"> | 31 | <div className="panel panel-flat"> |
28 | <div className="panel-heading"> | 32 | <div className="panel-heading"> |
29 | <h5 className="panel-title">Student Details</h5> | 33 | <h5 className="panel-title">Student Details</h5> |
30 | <div className="heading-elements"> | 34 | <div className="heading-elements"> |
31 | <ul className="icons-list"> | 35 | <ul className="icons-list"> |
32 | <li><a data-action="collapse"></a></li> | 36 | <li onClick={this.togglePanel}><a data-action="collapse" className={this.state.panleOpen?"rotate-180":null}></a></li> |
33 | <li><a data-action="reload"></a></li> | ||
34 | </ul> | 37 | </ul> |
35 | </div> | 38 | </div> |
36 | </div> | 39 | </div> |
37 | <Table striped bordered condensed hover> | 40 | <Panel collapsible expanded={this.state.panleOpen}> |
38 | <thead> | 41 | <Table striped bordered condensed hover> |
39 | <tr> | 42 | <thead> |
40 | <th>First Name</th> | 43 | <tr> |
41 | <th>Last Name</th> | 44 | <th>First Name</th> |
42 | <th>Class</th> | 45 | <th>Last Name</th> |
43 | <th>DOB</th> | 46 | <th>Class</th> |
44 | <th>Status</th> | 47 | <th>DOB</th> |
45 | <th className="text-center">Actions</th> | 48 | <th>Status</th> |
46 | </tr> | 49 | <th className="text-center">Actions</th> |
47 | </thead> | 50 | </tr> |
48 | <tbody> | 51 | </thead> |
49 | { | 52 | <tbody> |
50 | this.props.students.map(function(student, i) | 53 | { |
51 | { | 54 | this.props.students.map(function(student, i) |
52 | return( | 55 | { |
53 | <StudentRow | 56 | return( |
54 | student = {student} | 57 | <StudentRow |
55 | /> | 58 | key = { i } |
56 | ) | 59 | student = {student} |
57 | }) | 60 | /> |
58 | } | 61 | ) |
59 | </tbody> | 62 | }) |
60 | </Table> | 63 | } |
64 | </tbody> | ||
65 | </Table> | ||
66 | </Panel> | ||
61 | </div> | 67 | </div> |
62 | ); | 68 | ); |
63 | }; | 69 | }; |
64 | 70 | ||
65 | }; | 71 | }; |
imports/collections/staff/methods.js
1 | // import {Parents } from '/imports/collections/parents/methods' | 1 | // import {Parents } from '/imports/collections/parents/methods' |
2 | import _ from 'lodash'; | 2 | import _ from 'lodash'; |
3 | import { Meteor } from 'meteor/meteor'; | 3 | import { Meteor } from 'meteor/meteor'; |
4 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; | 4 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; |
5 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | 5 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; |
6 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; | 6 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; |
7 | import { Bert } from 'meteor/themeteorchef:bert'; | 7 | import { Bert } from 'meteor/themeteorchef:bert'; |
8 | import { Users } from '/imports/collections/users/index'; | 8 | import { Users } from '/imports/collections/users/index'; |
9 | import { Staffs } from '/imports/collections/staff/index'; | 9 | import { Staffs } from '/imports/collections/staff/index'; |
10 | import { Orgs } from '/imports/collections/orgs/index'; | 10 | import { Orgs } from '/imports/collections/orgs/index'; |
11 | export const staffMethods = new ValidatedMethod({ | 11 | export const staffMethods = new ValidatedMethod({ |
12 | name: 'staff.method', | 12 | name: 'staff.method', |
13 | 13 | ||
14 | validate: new SimpleSchema({ | 14 | validate: new SimpleSchema({ |
15 | itemId: { type: String }, | 15 | itemId: { type: String }, |
16 | }).validator(), | 16 | }).validator(), |
17 | 17 | ||
18 | run({itemId}) { | 18 | run({itemId}) { |
19 | return {}; | 19 | return {}; |
20 | }, | 20 | }, |
21 | 21 | ||
22 | }); | 22 | }); |
23 | 23 | ||
24 | export const staffAddNew = new ValidatedMethod({ | 24 | export const staffAddNew = new ValidatedMethod({ |
25 | name: 'staff.addNew', | 25 | name: 'staff.addNew', |
26 | 26 | ||
27 | validate: new SimpleSchema({ | 27 | validate: new SimpleSchema({ |
28 | employeeId: { type: String }, | 28 | employeeId: { type: String }, |
29 | firstName: { type: String }, | 29 | firstName: { type: String }, |
30 | lastName: { type: String }, | 30 | lastName: { type: String }, |
31 | martialStatus: { type: String }, | 31 | martialStatus: { type: String }, |
32 | gender: { type: String }, | 32 | gender: { type: String }, |
33 | dob: { type: String }, | 33 | dob: { type: String }, |
34 | email: { type: String }, | 34 | email: { type: String }, |
35 | phone: { type: String }, | 35 | phone: { type: String }, |
36 | address: { type: String }, | 36 | address: { type: String }, |
37 | type: { type: String }, | 37 | type: { type: String }, |
38 | doj: { type: String }, | 38 | doj: { type: String }, |
39 | teaching: { type: String }, | 39 | teaching: { type: String }, |
40 | qualifaication: { type: String }, | 40 | qualifaication: { type: String }, |
41 | specialization: { type: String }, | 41 | specialization: { type: String }, |
42 | university: { type: String }, | 42 | university: { type: String }, |
43 | degreeFrom: { type: String }, | 43 | degreeFrom: { type: String }, |
44 | degreeEnded: { type: String }, | 44 | degreeEnded: { type: String }, |
45 | }).validator(), | 45 | }).validator(), |
46 | 46 | ||
47 | run(data) { | 47 | run(data) { |
48 | const user = Users.findOne({_id: Meteor.userId()}); | 48 | const user = Users.findOne({_id: Meteor.userId()}); |
49 | if(!user) return false; | 49 | if(!user) return false; |
50 | const org = Orgs.findOne({_id: user.orgId}); | 50 | const org = Orgs.findOne({_id: user.orgId}); |
51 | if(!org) return false; | 51 | if(!org) return false; |
52 | // console.log(data);return true; | 52 | // console.log(data);return true; |
53 | orgId = user.orgId; | 53 | orgId = user.orgId; |
54 | newUserId = Users.insert({ | 54 | newUserId = Users.insert({ |
55 | emails: [{address:data.email, verified: false}], | 55 | emails: [{address:data.email, verified: false}], |
56 | phones: [{number:data.phone, verified: false}], | 56 | phones: [{number:data.phone, verified: false}], |
57 | firstName: data.firstName, | 57 | firstName: data.firstName, |
58 | lastName: data.lastName, | 58 | lastName: data.lastName, |
59 | address: data.address, | 59 | address: data.address, |
60 | orgId: orgId, | 60 | orgId: orgId, |
61 | role: 'STAFF' | 61 | role: 'STAFF' |
62 | }); | 62 | }); |
63 | console.log("newUserId"); | 63 | console.log("newUserId"); |
64 | console.log(newUserId); | 64 | console.log(newUserId); |
65 | if(newUserId){ | 65 | if(newUserId){ |
66 | newStaffId = Staffs.insert({ | 66 | newStaffId = Staffs.insert({ |
67 | userId: newUserId, | 67 | userId: newUserId, |
68 | orgId: orgId, | 68 | orgId: orgId, |
69 | employeeId: data.employeeId, | 69 | employeeId: data.employeeId, |
70 | martialStatus:data.martialStatus, | 70 | martialStatus:data.martialStatus, |
71 | gender: data.gender, | 71 | gender: data.gender, |
72 | dob: data.dob, | 72 | dob: data.dob, |
73 | teaching: data.teaching, | 73 | teaching: data.teaching, |
74 | type: data.type, | 74 | type: data.type, |
75 | qualifaication: data.qualifaication, | 75 | qualifaication: data.qualifaication, |
76 | specialization: data.specialization, | 76 | specialization: data.specialization, |
77 | university: data.university, | 77 | university: data.university, |
78 | degreeFrom: data.degreeFrom, | 78 | degreeFrom: data.degreeFrom, |
79 | degreeEnded: data.degreeEnded | 79 | degreeEnded: data.degreeEnded, |
80 | doj: data.doj | ||
80 | }); | 81 | }); |
81 | } | 82 | } |
82 | console.log("newStaffId"); | 83 | console.log("newStaffId"); |
83 | console.log(newStaffId); | 84 | console.log(newStaffId); |
84 | return {}; | 85 | return {}; |
85 | }, | 86 | }, |
86 | 87 | ||
87 | }); | 88 | }); |
88 | 89 |
imports/collections/students/index.js
1 | // import {Students } from '/imports/collections/students/index' | 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 ,unique: 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 | religion: { type: String, optional: true }, | 82 | religion: { type: String, optional: true }, |
83 | permanentAddress: { | 83 | permanentAddress: { |
84 | type: new SimpleSchema({ | 84 | type: new SimpleSchema({ |
85 | home: { type: String, optional: true }, | 85 | home: { type: String, optional: true }, |
86 | street: { type: String, optional: true }, | 86 | street: { type: String, optional: true }, |
87 | town: { type: String, optional: true }, | 87 | town: { type: String, optional: true }, |
88 | city: { type: String, optional: true }, | 88 | city: { type: String, optional: true }, |
89 | state: { type: String, optional: true }, | 89 | state: { type: String, optional: true }, |
90 | zip: { type: String, optional: true }, | 90 | zip: { type: String, optional: true }, |
91 | }), | 91 | }), |
92 | optional: true | 92 | optional: true |
93 | }, | 93 | }, |
94 | parent: { | 94 | parent: { |
95 | type: [new SimpleSchema({ | 95 | type: [new SimpleSchema({ |
96 | id: { type: String, }, | 96 | id: { type: String, }, |
97 | relatinship: { type: String, }, | 97 | relatinship: { type: String, }, |
98 | })], | 98 | })], |
99 | optional: true | 99 | optional: true |
100 | }, | 100 | }, |
101 | prevInstitute: { | 101 | prevInstitute: { |
102 | type: [new SimpleSchema({ | 102 | type: [new SimpleSchema({ |
103 | name: { type: String, }, | 103 | name: { type: String, }, |
104 | fromYear: { type: String, }, | 104 | fromYear: { type: String, }, |
105 | toYear: { type: String, }, | 105 | toYear: { type: String, }, |
106 | fromClass: { type: String, }, | 106 | fromClass: { type: String, }, |
107 | toClass: { type: String, }, | 107 | toClass: { 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
1 | // import { } from '/imports/collections/orgs/methods'; | 1 | // import { } from '/imports/collections/orgs/methods'; |
2 | import _ from 'lodash'; | 2 | import _ from 'lodash'; |
3 | import { Meteor } from 'meteor/meteor'; | 3 | import { Meteor } from 'meteor/meteor'; |
4 | import Papa from 'meteor/harrison:papa-parse' | 4 | import Papa from 'meteor/harrison:papa-parse' |
5 | import csv from 'csv2json-convertor' | 5 | import csv from 'csv2json-convertor' |
6 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; | 6 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; |
7 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | 7 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; |
8 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; | 8 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; |
9 | import { Bert } from 'meteor/themeteorchef:bert'; | 9 | import { Bert } from 'meteor/themeteorchef:bert'; |
10 | import { Users } from '/imports/collections/users/index'; | 10 | import { Users } from '/imports/collections/users/index'; |
11 | import { Orgs } from '/imports/collections/orgs/index'; | 11 | import { Orgs } from '/imports/collections/orgs/index'; |
12 | import { Students } from '/imports/collections/students/index' | 12 | import { Students } from '/imports/collections/students/index' |
13 | import { Parents } from '/imports/collections/parents/index'; | 13 | import { Parents } from '/imports/collections/parents/index'; |
14 | import csv1 from 'csv2json-convertor' | 14 | import csv1 from 'csv2json-convertor' |
15 | import json2csv from 'json2csv' | 15 | import json2csv from 'json2csv' |
16 | import fs from 'fs' | 16 | import fs from 'fs' |
17 | import Validation from '/imports/validation/validationMethods'; | 17 | import Validation from '/imports/validation/validationMethods'; |
18 | import Constants from '/imports/constants/constants' | 18 | import Constants from '/imports/constants/constants' |
19 | 19 | ||
20 | export const studenCsvtMethod = new ValidatedMethod({ | 20 | export const studenCsvtMethod = new ValidatedMethod({ |
21 | name: 'student.csvMethod', | 21 | name: 'student.csvMethod', |
22 | 22 | ||
23 | validate: new SimpleSchema({ | 23 | validate: new SimpleSchema({ |
24 | itemId: { type: String }, | 24 | itemId: { type: String }, |
25 | }).validator(), | 25 | }).validator(), |
26 | 26 | ||
27 | run({itemId}) { | 27 | run({itemId}) { |
28 | return {}; | 28 | return {}; |
29 | }, | 29 | }, |
30 | 30 | ||
31 | }); | 31 | }); |
32 | 32 | ||
33 | export const save_csv_data = new ValidatedMethod({ | 33 | export const save_csv_data = new ValidatedMethod({ |
34 | name: 'save_csv_data', | 34 | name: 'save_csv_data', |
35 | 35 | ||
36 | validate: null, | 36 | validate: null, |
37 | 37 | ||
38 | run({item,filename,csv_fiels}) { | 38 | run({item,filename,csv_fiels}) { |
39 | 39 | ||
40 | if ((item.length)) | 40 | if ((item.length)) |
41 | { console.log("++++++++++++++++++"+item.length) | 41 | { console.log("++++++++++++++++++"+item.length) |
42 | var csv = json2csv({ | 42 | var csv = json2csv({ |
43 | data: item, | 43 | data: item, |
44 | fields: csv_fiels | 44 | fields: csv_fiels |
45 | }); | 45 | }); |
46 | fs.writeFile(filename, csv,function(err) { | 46 | fs.writeFile(filename, csv,function(err) { |
47 | if (err) throw err; | 47 | if (err) throw err; |
48 | }); | 48 | }); |
49 | 49 | ||
50 | } | 50 | } |
51 | }, | 51 | }, |
52 | }); | 52 | }); |
53 | 53 | ||
54 | export const addStudentCSV= new ValidatedMethod({ | 54 | export const addStudentCSV= new ValidatedMethod({ |
55 | name: 'student.addCSV', | 55 | name: 'student.addCSV', |
56 | 56 | ||
57 | validate: null, | 57 | validate: null, |
58 | 58 | ||
59 | run(item){ | 59 | run(item){ |
60 | data = item ; | 60 | data = item ; |
61 | console.log("data"); | 61 | console.log("data"); |
62 | console.log(data); | 62 | console.log(data); |
63 | // return true; | 63 | // return true; |
64 | const user = Users.findOne({_id: this.userId}); | 64 | const user = Users.findOne({_id: this.userId}); |
65 | orgId = user.orgId; | 65 | orgId = user.orgId; |
66 | newStudentId = Users.insert({ | 66 | newStudentId = Users.insert({ |
67 | // emails: [{address:data.email, verified: false}], | 67 | // emails: [{address:data.email, verified: false}], |
68 | //username: data["First Name*"], | 68 | //username: data["First Name*"], |
69 | firstName: data["First Name*"], | 69 | firstName: data["First Name*"], |
70 | lastName: data['Last Name*'], | 70 | lastName: data['Last Name*'], |
71 | orgId: orgId, | 71 | orgId: orgId, |
72 | role: 'STUDENT' | 72 | role: 'STUDENT' |
73 | }); | 73 | }); |
74 | newParentUserId = Users.insert({ | 74 | newParentUserId = Users.insert({ |
75 | //emails: [{address:data.parentEmail, verified: false}], | 75 | //emails: [{address:data.parentEmail, verified: false}], |
76 | //3: data['Parent Name*'], | 76 | //3: data['Parent Name*'], |
77 | firstName: data['Parent Name*'], | 77 | firstName: data['Parent Name*'], |
78 | orgId: orgId, | 78 | orgId: orgId, |
79 | role: 'PARENT' | 79 | role: 'PARENT' |
80 | }); | 80 | }); |
81 | if(newParentUserId){ | 81 | if(newParentUserId){ |
82 | newParentId = Parents.insert({ | 82 | newParentId = Parents.insert({ |
83 | userId: newParentUserId, | 83 | userId: newParentUserId, |
84 | orgId: orgId, | 84 | orgId: orgId, |
85 | profession: data['Parent Profession'] | 85 | profession: data['Parent Profession'] |
86 | 86 | ||
87 | }); | 87 | }); |
88 | console.log("newParentUserId"); | 88 | console.log("newParentUserId"); |
89 | console.log(newParentUserId); | 89 | console.log(newParentUserId); |
90 | } | 90 | } |
91 | console.log("newUserId"); | 91 | console.log("newUserId"); |
92 | console.log(newStudentId); | 92 | console.log(newStudentId); |
93 | if(newStudentId){ | 93 | if(newStudentId){ |
94 | Students.insert({ | 94 | Students.insert({ |
95 | userId: newStudentId, | 95 | userId: newStudentId, |
96 | orgId: orgId, | 96 | orgId: orgId, |
97 | admissionId: data['Student Admission ID*'], | 97 | admissionId: data['Student Admission ID*'], |
98 | enrollmentDate: data['Enrollment Date(YYYY-MM-DD)*'], | 98 | enrollmentDate: data['Enrollment Date(YYYY-MM-DD)*'], |
99 | gender: data['Gender(male/female)*'], | 99 | gender: data['Gender(male/female)*'], |
100 | dob: data['Birthday(YYYY-MM-DD)*'], | 100 | dob: data['Birthday(YYYY-MM-DD)*'], |
101 | bloodGroup: data['Blood Group*'], | 101 | bloodGroup: data['Blood Group*'], |
102 | nationality: data['Nationality*'], | 102 | nationality: data['Nationality*'], |
103 | motherTongue: data['Mother Tongue*'], | 103 | motherTongue: data['Mother Tongue*'], |
104 | religion: data['Religion*'], | 104 | religion: data['Religion*'], |
105 | community: data['Community'], | 105 | community: data['Community'], |
106 | 106 | ||
107 | rollNo: data['Student Roll*'], | 107 | rollNo: data['Student Roll*'], |
108 | class: data['Student Class Name*'], | 108 | class: data['Student Class Name*'], |
109 | section: data['Student Section Name*'], | 109 | section: data['Student Section Name*'], |
110 | 110 | ||
111 | prevInstitute: [{ name: data['Previous Institution Name'], | 111 | prevInstitute: [{ name: data['Previous Institution Name'], |
112 | fromYear: data['Class-From'], | 112 | fromYear: data['Class-From'], |
113 | toYear: data['Class-To'], | 113 | toYear: data['Class-To'], |
114 | fromClass: data['From-Year'], | 114 | fromClass: data['From-Year'], |
115 | toClass: data['To-Year'] | 115 | toClass: data['To-Year'] |
116 | }], | 116 | }], |
117 | permanentAddress: { street: data['Student Line Adress*'], | 117 | permanentAddress: { street: data['Student Line Adress*'], |
118 | city: data['Student City*'], | 118 | city: data['Student City*'], |
119 | state: data['Student State*'], | 119 | state: data['Student State*'], |
120 | zip: data['Student Zip Code*'] | 120 | zip: data['Student Zip Code*'] |
121 | }, | 121 | }, |
122 | parent: [{id: newParentUserId, relatinship: data['Parent Relation*']}] | 122 | parent: [{id: newParentUserId, relatinship: data['Parent Relation*']}] |
123 | }); | 123 | }); |
124 | } | 124 | } |
125 | return {newStudentId}; | 125 | return {newStudentId}; |
126 | }, | 126 | }, |
127 | 127 | ||
128 | }); | 128 | }); |
129 | 129 | ||
130 | export const studentUploadCsv = new ValidatedMethod({ | 130 | export const studentUploadCsv = new ValidatedMethod({ |
131 | name: 'student.uploadCsv', | 131 | name: 'student.uploadCsv', |
132 | 132 | ||
133 | validate: null, | 133 | validate: null, |
134 | 134 | ||
135 | run({data}) { | 135 | run({data}) { |
136 | let validation = new Validation(); | 136 | let validation = new Validation(); |
137 | let constants = new Constants(); | 137 | let constants = new Constants(); |
138 | //console.log("++++++++++++++++++++++++"+constants.csv_students_data()); | 138 | //console.log("++++++++++++++++++++++++"+constants.csv_students_data()); |
139 | temp = constants.csv_students_data(); | 139 | temp = constants.csv_students_data(); |
140 | // | 140 | // |
141 | console.log(temp); | 141 | console.log(temp); |
142 | // var data_1=csv1.csvtojson(("/Users/satheeshnagaraj/Downloads/11.csv")); //csvtojson is function that accepts csv filenames and returns JSON object | 142 | // var data_1=csv1.csvtojson(("/Users/satheeshnagaraj/Downloads/11.csv")); //csvtojson is function that accepts csv filenames and returns JSON object |
143 | //console.log(data);'' | 143 | //console.log(data);'' |
144 | // Stores = new Mongo.Collection('stores'); | 144 | // Stores = new Mongo.Collection('stores'); |
145 | // data = data_1; | 145 | // data = data_1; |
146 | 146 | ||
147 | var CSV_valid_buffer = []; | 147 | var CSV_valid_buffer = []; |
148 | var CSV_invalid_buffer = []; | 148 | var CSV_invalid_buffer = []; |
149 | var filename = "Student" + new Date().getTime().toString(); | 149 | var filename = "Student" + new Date().getTime().toString(); |
150 | var csv_filepath = '/Users/satheeshnagaraj/Documents/Workspace/Meteor/Youngdesk/ydapp/CSV_Files/'; | 150 | var csv_filepath = '/Users/deepak/dev/yd/csv'; |
151 | 151 | ||
152 | 152 | ||
153 | 153 | ||
154 | for (let i = 0; i < data.length; i++) | 154 | for (let i = 0; i < data.length; i++) |
155 | { | 155 | { |
156 | 156 | ||
157 | //let item= {Errors:""}; | 157 | //let item= {Errors:""}; |
158 | let item = data[i]; | 158 | let item = data[i]; |
159 | delete item['Errors']; | 159 | delete item['Errors']; |
160 | var formate_validation = 1; | 160 | var formate_validation = 1; |
161 | var is_not_null = 1; | 161 | var is_not_null = 1; |
162 | var errors = []; | 162 | var errors = []; |
163 | for (var key in item) | 163 | for (var key in item) |
164 | { | 164 | { |
165 | var value = item[key]; | 165 | var value = item[key]; |
166 | var n = key.indexOf("*"); | 166 | var n = key.indexOf("*"); |
167 | if(n!=-1) { | 167 | if(n!=-1) { |
168 | if(!(validation.notNull(value))) | 168 | if(!(validation.notNull(value))) |
169 | { | 169 | { |
170 | errors.push(key+"is Empty"); | 170 | errors.push(key+"is Empty"); |
171 | } | 171 | } |
172 | is_not_null = is_not_null && validation.notNull(value); | 172 | is_not_null = is_not_null && validation.notNull(value); |
173 | } | 173 | } |
174 | } | 174 | } |
175 | //console.log(validation.mobileNumber(item["Parent Mobile*"])); | 175 | //console.log(validation.mobileNumber(item["Parent Mobile*"])); |
176 | 176 | ||
177 | 177 | ||
178 | 178 | ||
179 | 179 | ||
180 | var formate_validation = validation.validateEmail(item["Parent Email*"]) && validation.mobileNumber(item["Parent Mobile*"]) ; //&& validation.validateEmail(item["Parent Mobile"]) ); | 180 | var formate_validation = validation.validateEmail(item["Parent Email*"]) && validation.mobileNumber(item["Parent Mobile*"]) ; //&& validation.validateEmail(item["Parent Mobile"]) ); |
181 | 181 | ||
182 | if (!(validation.validateEmail(item["Parent Email*"]))) | 182 | if (!(validation.validateEmail(item["Parent Email*"]))) |
183 | { | 183 | { |
184 | errors.push('Parent Email is invalid'); | 184 | errors.push('Parent Email is invalid'); |
185 | } | 185 | } |
186 | if (!(validation.mobileNumber(item["Parent Mobile*"]))) | 186 | if (!(validation.mobileNumber(item["Parent Mobile*"]))) |
187 | { | 187 | { |
188 | errors.push('Parent Mobile is invalid'); | 188 | errors.push('Parent Mobile is invalid'); |
189 | } | 189 | } |
190 | 190 | ||
191 | var is_valid = formate_validation && is_not_null ; | 191 | var is_valid = formate_validation && is_not_null ; |
192 | 192 | ||
193 | // console.log(formate_validation); | 193 | // console.log(formate_validation); |
194 | if (is_valid) | 194 | if (is_valid) |
195 | { | 195 | { |
196 | CSV_valid_buffer.push(item); | 196 | CSV_valid_buffer.push(item); |
197 | console.log("----------------------------------------1"); | 197 | console.log("----------------------------------------1"); |
198 | console.log("----------------------------------------item"); | ||
199 | console.log(item); | ||
200 | console.log (Users.findOne({"firstName": item["First Name*"],"lastName": item["Last Name*"]})); | ||
201 | |||
198 | Meteor.call('student.addCSV',item); | 202 | Meteor.call('student.addCSV',item); |
199 | console.log("----------------------------------------2"); | 203 | console.log("----------------------------------------2"); |
200 | 204 | ||
201 | // exists = Stores.findOne({ | 205 | // exists = Stores.findOne({ |
202 | // "Student 'Admission' ID*": item["Student Admission ID*"] | 206 | // "Student 'Admission' ID*": item["Student Admission ID*"] |
203 | // }); | 207 | // }); |
204 | // if (!exists) | 208 | // if (!exists) |
205 | // { | 209 | // { |
206 | // Stores.insert(item); | 210 | // Stores.insert(item); |
207 | // } | 211 | // } |
208 | // else | 212 | // else |
209 | // { | 213 | // { |
210 | // console.warn('Rejected. This item already exists.'); | 214 | // console.warn('Rejected. This item already exists.'); |
211 | // } | 215 | // } |
212 | } | 216 | } |
213 | else | 217 | else |
214 | { | 218 | { |
215 | var str = errors.toString(); | 219 | var str = errors.toString(); |
216 | item.Errors = str; | 220 | item.Errors = str; |
217 | CSV_invalid_buffer.push(item); | 221 | CSV_invalid_buffer.push(item); |
218 | //console.log(str); | 222 | //console.log(str); |
219 | // console.log(CSV_invalid_buffer); | 223 | // console.log(CSV_invalid_buffer); |
220 | } | 224 | } |
221 | } | 225 | } |
222 | Meteor.call('save_csv_data',{ item : CSV_invalid_buffer, filename: csv_filepath+filename+"_CSV_invalid_data"+".csv",csv_fiels :constants.csv_students_data()}); | 226 | Meteor.call('save_csv_data',{ item : CSV_invalid_buffer, filename: csv_filepath+filename+"_CSV_invalid_data"+".csv",csv_fiels :constants.csv_students_data()}); |
223 | Meteor.call('save_csv_data',{ item : CSV_valid_buffer,filename: csv_filepath+filename+"_CSV_valid_data"+".csv",csv_fiels :constants.csv_students_data()}); | 227 | Meteor.call('save_csv_data',{ item : CSV_valid_buffer,filename: csv_filepath+filename+"_CSV_valid_data"+".csv",csv_fiels :constants.csv_students_data()}); |
224 | return {}; | 228 | return {}; |
225 | }, | 229 | }, |
226 | 230 | ||
227 | }); | 231 | }); |
228 | 232 |