Commit 5d043355e349d2d4ef04781104b1cf9f8c7b42cb
1 parent
c32092e5ea
Exists in
master
fixed bug and added csv file functionality
Showing
10 changed files
with
171 additions
and
138 deletions
Show diff stats
imports/client/views/core/DatePicker.js
imports/client/views/org/admin/students/StudentTable.js
... | ... | @@ -1,83 +0,0 @@ |
1 | -import _ from 'lodash'; | |
2 | -import { Meteor } from 'meteor/meteor'; | |
3 | - | |
4 | -import React, { Component } from 'react'; | |
5 | -import { Link,browserHistory } from 'react-router'; | |
6 | -import { FormGroup,Panel,Table, | |
7 | - ButtonToolbar,Modal, | |
8 | - FormControl,Glyphicon,Button } from 'react-bootstrap'; | |
9 | - import { AddStudentForm } from './addStudentForm'; | |
10 | -import {moment} from 'meteor/momentjs:moment' | |
11 | - | |
12 | -export class StudentTable extends Component { | |
13 | - | |
14 | - constructor(props) { | |
15 | - super(props); | |
16 | - this.state = { | |
17 | - show: false | |
18 | - }; | |
19 | - this.onUpdate = this.onUpdate.bind(this); | |
20 | - }; | |
21 | - onUpdate(key, value) { | |
22 | - this.setState({[key]: value}); | |
23 | - }; | |
24 | - | |
25 | - render() { | |
26 | - return ( | |
27 | - <div className="panel panel-flat"> | |
28 | - <div className="panel-heading"> | |
29 | - <h5 className="panel-title">Student Details</h5> | |
30 | - <div className="heading-elements"> | |
31 | - <ul className="icons-list"> | |
32 | - <li><a data-action="collapse"></a></li> | |
33 | - <li><a data-action="reload"></a></li> | |
34 | - </ul> | |
35 | - </div> | |
36 | - </div> | |
37 | - <Table striped bordered condensed hover> | |
38 | - <thead> | |
39 | - <tr> | |
40 | - <th>First Name</th> | |
41 | - <th>Last Name</th> | |
42 | - <th>Class</th> | |
43 | - <th>DOB</th> | |
44 | - <th>Status</th> | |
45 | - <th className="text-center">Actions</th> | |
46 | - </tr> | |
47 | - </thead> | |
48 | - <tbody> | |
49 | - { | |
50 | - this.props.students.map(function(student, i) | |
51 | - { | |
52 | - return( | |
53 | - <tr key={i}> | |
54 | - <td>{student.firstName}</td> | |
55 | - <td>{student.lastName}</td> | |
56 | - <td>{student.class}</td> | |
57 | - <td>{student.dob? moment(student.dob).format("LL") : <span></span>}</td> | |
58 | - <td><span className="label label-success">Active</span></td> | |
59 | - <td className="text-center"> | |
60 | - <ul className="icons-list"> | |
61 | - <li className="dropdown"> | |
62 | - <a href="#" className="dropdown-toggle" data-toggle="dropdown"> | |
63 | - <i className="icon-menu9"></i> | |
64 | - </a> | |
65 | - <ul className="dropdown-menu dropdown-menu-right"> | |
66 | - <li><a href="#"><i className="icon-file-pdf"></i> Export to .pdf</a></li> | |
67 | - <li><a href="#"><i className="icon-file-excel"></i> Export to .csv</a></li> | |
68 | - <li><a href="#"><i className="icon-file-word"></i> Export to .doc</a></li> | |
69 | - </ul> | |
70 | - </li> | |
71 | - </ul> | |
72 | - </td> | |
73 | - </tr> | |
74 | - ) | |
75 | - }) | |
76 | - } | |
77 | - </tbody> | |
78 | - </Table> | |
79 | - </div> | |
80 | - ); | |
81 | - }; | |
82 | - | |
83 | -}; |
imports/client/views/org/admin/students/StudentView.js
... | ... | @@ -9,7 +9,7 @@ import { Navbar,Modal, Nav, NavItem, |
9 | 9 | NavLink, DropdownItem, DropdownToggle, DropdownMenu, |
10 | 10 | NavDropdown, MenuItem, Breadcrumb, Button } from 'react-bootstrap'; |
11 | 11 | import { AddStudent } from './addStudent'; |
12 | -import { StudentTable } from './StudentTable'; | |
12 | +import { StudentTable } from './view/StudentTable'; | |
13 | 13 | import { Header } from './Header'; |
14 | 14 | import { FabMenuView } from './FabMenu'; |
15 | 15 | import { UploadCsv } from './UploadCsv'; |
... | ... | @@ -46,7 +46,9 @@ export class StudentView extends Component { |
46 | 46 | firstNameSearch = this.state.firstNameSearch; |
47 | 47 | lastNameSearch = this.state.lastNameSearch; |
48 | 48 | var students =_.filter(this.props.data.students,function(item){ |
49 | - return _.includes(item.firstName.toLowerCase(),firstNameSearch.toLowerCase()); | |
49 | + if(item.firstName){ | |
50 | + return _.includes(item.firstName.toLowerCase(),firstNameSearch.toLowerCase()); | |
51 | + } | |
50 | 52 | }); |
51 | 53 | return ( |
52 | 54 | <div className="appLayout-box"> |
... | ... | @@ -132,7 +134,7 @@ export class StudentView extends Component { |
132 | 134 | </div> |
133 | 135 | </div> |
134 | 136 | {/*content*/} |
135 | - | |
137 | + | |
136 | 138 | <div className="content has-detached-left"> |
137 | 139 | <div className="container-detached"> |
138 | 140 | <div className="content-detached"> | ... | ... |
imports/client/views/org/admin/students/UploadCsv.js
1 | +// import {UploadCsv } from '/imports/collections/students/UploadCsv' | |
1 | 2 | import _ from 'lodash'; |
2 | 3 | import { Meteor } from 'meteor/meteor'; |
3 | 4 | |
... | ... | @@ -48,10 +49,16 @@ export class UploadCsv extends Component { |
48 | 49 | e.persist(); |
49 | 50 | var file = $('input[type="file"]').prop("files")[0]; |
50 | 51 | Papa.parse(file, { |
51 | - complete: function(results) { | |
52 | - if(results){ | |
52 | + header: true, | |
53 | + complete: function(csvData) { | |
54 | + console.log("csvData"); | |
55 | + console.log(csvData); | |
56 | + if(csvData){ | |
53 | 57 | Meteor.call('student.uploadCsv', csvData, function (error, result) { |
54 | - | |
58 | + console.log("error"); | |
59 | + console.log(error); | |
60 | + console.log("result"); | |
61 | + console.log(result); | |
55 | 62 | }) |
56 | 63 | } |
57 | 64 | } | ... | ... |
imports/client/views/org/admin/students/view/StudentRow.js
... | ... | @@ -0,0 +1,56 @@ |
1 | +import _ from 'lodash'; | |
2 | +import { Meteor } from 'meteor/meteor'; | |
3 | + | |
4 | +import React, { Component } from 'react'; | |
5 | +import { Link,browserHistory } from 'react-router'; | |
6 | +import { FormGroup, | |
7 | + FormControl,Glyphicon,Button } from 'react-bootstrap'; | |
8 | + | |
9 | + | |
10 | +export class StudentRow extends Component { | |
11 | + | |
12 | + constructor(props) { | |
13 | + super(props); | |
14 | + this.state = { | |
15 | + | |
16 | + }; | |
17 | + this.onUpdate = this.onUpdate.bind(this); | |
18 | + }; | |
19 | + | |
20 | + onUpdate(key, value) { | |
21 | + this.setState({[key]: value}); | |
22 | + }; | |
23 | + | |
24 | + render() { | |
25 | + const {student} = this.props; | |
26 | + if(student.firstName){ | |
27 | + return ( | |
28 | + <tr> | |
29 | + <td>{student.firstName}</td> | |
30 | + <td>{student.lastName}</td> | |
31 | + <td>{student.class}</td> | |
32 | + <td>{student.dob? moment(student.dob).format("LL") : <span></span>}</td> | |
33 | + <td><span className="label label-success">Active</span></td> | |
34 | + <td className="text-center"> | |
35 | + <ul className="icons-list"> | |
36 | + <li className="dropdown"> | |
37 | + <a href="#" className="dropdown-toggle" data-toggle="dropdown"> | |
38 | + <i className="icon-menu9"></i> | |
39 | + </a> | |
40 | + <ul className="dropdown-menu dropdown-menu-right"> | |
41 | + <li><a href="#"><i className="icon-file-pdf"></i> Export to .pdf</a></li> | |
42 | + <li><a href="#"><i className="icon-file-excel"></i> Export to .csv</a></li> | |
43 | + <li><a href="#"><i className="icon-file-word"></i> Export to .doc</a></li> | |
44 | + </ul> | |
45 | + </li> | |
46 | + </ul> | |
47 | + </td> | |
48 | + </tr> | |
49 | + ); | |
50 | + }else { | |
51 | + return null; | |
52 | + } | |
53 | + | |
54 | + }; | |
55 | + | |
56 | +}; | ... | ... |
imports/client/views/org/admin/students/view/StudentTable.js
... | ... | @@ -0,0 +1,66 @@ |
1 | +import _ from 'lodash'; | |
2 | +import { Meteor } from 'meteor/meteor'; | |
3 | + | |
4 | +import React, { Component } from 'react'; | |
5 | +import { Link,browserHistory } from 'react-router'; | |
6 | +import { FormGroup,Panel,Table, | |
7 | + ButtonToolbar,Modal, | |
8 | + FormControl,Glyphicon,Button } from 'react-bootstrap'; | |
9 | + import { AddStudentForm } from '../addStudentForm'; | |
10 | +import {moment} from 'meteor/momentjs:moment' | |
11 | +import {StudentRow} from './StudentRow' | |
12 | + | |
13 | +export class StudentTable extends Component { | |
14 | + | |
15 | + constructor(props) { | |
16 | + super(props); | |
17 | + this.state = { | |
18 | + show: false | |
19 | + }; | |
20 | + this.onUpdate = this.onUpdate.bind(this); | |
21 | + }; | |
22 | + onUpdate(key, value) { | |
23 | + this.setState({[key]: value}); | |
24 | + }; | |
25 | + | |
26 | + render() { | |
27 | + return ( | |
28 | + <div className="panel panel-flat"> | |
29 | + <div className="panel-heading"> | |
30 | + <h5 className="panel-title">Student Details</h5> | |
31 | + <div className="heading-elements"> | |
32 | + <ul className="icons-list"> | |
33 | + <li><a data-action="collapse"></a></li> | |
34 | + <li><a data-action="reload"></a></li> | |
35 | + </ul> | |
36 | + </div> | |
37 | + </div> | |
38 | + <Table striped bordered condensed hover> | |
39 | + <thead> | |
40 | + <tr> | |
41 | + <th>First Name</th> | |
42 | + <th>Last Name</th> | |
43 | + <th>Class</th> | |
44 | + <th>DOB</th> | |
45 | + <th>Status</th> | |
46 | + <th className="text-center">Actions</th> | |
47 | + </tr> | |
48 | + </thead> | |
49 | + <tbody> | |
50 | + { | |
51 | + this.props.students.map(function(student, i) | |
52 | + { | |
53 | + return( | |
54 | + <StudentRow | |
55 | + student = {student} | |
56 | + /> | |
57 | + ) | |
58 | + }) | |
59 | + } | |
60 | + </tbody> | |
61 | + </Table> | |
62 | + </div> | |
63 | + ); | |
64 | + }; | |
65 | + | |
66 | +}; | ... | ... |
imports/collections/orgs/methods.js
... | ... | @@ -51,19 +51,3 @@ export const checkEmailInOrg = new ValidatedMethod({ |
51 | 51 | } |
52 | 52 | }, |
53 | 53 | }); |
54 | - | |
55 | -export const save_csv_data = new ValidatedMethod({ | |
56 | - name: 'save_csv_data', | |
57 | - | |
58 | - validate: null, | |
59 | - | |
60 | - run(item,filename) { | |
61 | - var csv = json2csv({ | |
62 | - data: item, | |
63 | - fields: csv_students_fields | |
64 | - }); | |
65 | - fs.writeFile(filename, csv,function(err) { | |
66 | - if (err) throw err; | |
67 | - }); | |
68 | - }, | |
69 | -}); | ... | ... |
imports/collections/students/serverCsvUpload.js
... | ... | @@ -13,7 +13,7 @@ import { Students } from '/imports/collections/students/in |
13 | 13 | import { Parents } from '/imports/collections/parents/index'; |
14 | 14 | import csv1 from 'csv2json-convertor' |
15 | 15 | import json2csv from 'json2csv' |
16 | -import fs from 'fs' | |
16 | +import fs from 'fs' | |
17 | 17 | import Validation from '/imports/validation/validationMethods'; |
18 | 18 | import Constants from '/imports/constants/constants' |
19 | 19 | |
... | ... | @@ -50,19 +50,19 @@ export const addStudentCSV= new ValidatedMethod({ |
50 | 50 | name: 'student.addCSV', |
51 | 51 | |
52 | 52 | validate: null, |
53 | - | |
53 | + | |
54 | 54 | run(item){ |
55 | 55 | data = item ; |
56 | 56 | console.log("data"); |
57 | 57 | console.log(data); |
58 | + return true; | |
58 | 59 | const user = Users.findOne({_id: this.userId}); |
59 | 60 | orgId = user.orgId; |
60 | 61 | newStudentId = Users.insert({ |
61 | 62 | // emails: [{address:data.email, verified: false}], |
62 | - username: data["first Name*"], | |
63 | - firstName: data.firstName, | |
64 | - middleName: data.middleName, | |
65 | - lastName: data.lastName, | |
63 | + username: data["First Name*"], | |
64 | + firstName: data["First Name*"], | |
65 | + lastName: data['Last Name*'], | |
66 | 66 | orgId: orgId, |
67 | 67 | role: 'STUDENT' |
68 | 68 | }); |
... | ... | @@ -95,10 +95,10 @@ export const addStudentCSV= new ValidatedMethod({ |
95 | 95 | Students.insert({ |
96 | 96 | userId: newStudentId, |
97 | 97 | orgId: orgId, |
98 | - admissionId: data.admissionId, | |
99 | - address: data.address, | |
100 | - gender: data.gender, | |
101 | - dob: data.dob, | |
98 | + admissionId: data['Student Admission ID*'], | |
99 | + address: data['Student Admission ID*'], | |
100 | + gender: data['Gender(male/female)*'], | |
101 | + dob: data['Birthday(YYYY-MM-DD)*'], | |
102 | 102 | rollNo: data.rollNo, |
103 | 103 | class: data.studentclass, |
104 | 104 | section: data.section, |
... | ... | @@ -115,9 +115,7 @@ export const addStudentCSV= new ValidatedMethod({ |
115 | 115 | export const studentUploadCsv = new ValidatedMethod({ |
116 | 116 | name: 'student.uploadCsv', |
117 | 117 | |
118 | - validate: new SimpleSchema({ | |
119 | - data: { type: [Object] }, | |
120 | - }).validator(), | |
118 | + validate: null, | |
121 | 119 | |
122 | 120 | run({data}) { |
123 | 121 | let validation = new Validation(); |
... | ... | @@ -126,19 +124,19 @@ export const studentUploadCsv = new ValidatedMethod({ |
126 | 124 | temp = constants.csv_students_data(); |
127 | 125 | // |
128 | 126 | console.log(temp); |
129 | - var data_1=csv1.csvtojson(("/Users/satheeshnagaraj/Downloads/11.csv")); //csvtojson is function that accepts csv filenames and returns JSON object | |
127 | + // var data_1=csv1.csvtojson(("/Users/satheeshnagaraj/Downloads/11.csv")); //csvtojson is function that accepts csv filenames and returns JSON object | |
130 | 128 | //console.log(data);'' |
131 | 129 | Stores = new Mongo.Collection('stores'); |
132 | - data = data_1; | |
130 | + // data = data_1; | |
133 | 131 | |
134 | 132 | var CSV_valid_buffer = []; |
135 | 133 | var CSV_invalid_buffer = []; |
136 | 134 | var filename = new Date().getTime().toString(); |
137 | 135 | var csv_filepath = '/Users/satheeshnagaraj/Documents/Workspace/Meteor/ydapp/CSV_Files/'; |
138 | - | |
139 | - | |
140 | - for (let i = 0; i < data.length; i++) | |
141 | - { | |
136 | + | |
137 | + | |
138 | + for (let i = 0; i < data.length; i++) | |
139 | + { | |
142 | 140 | |
143 | 141 | //let item= {Errors:""}; |
144 | 142 | let item = data[i]; |
... | ... | @@ -147,15 +145,15 @@ export const studentUploadCsv = new ValidatedMethod({ |
147 | 145 | var is_not_null = 1; |
148 | 146 | var errors = []; |
149 | 147 | for (var key in item) |
150 | - { | |
148 | + { | |
151 | 149 | var value = item[key]; |
152 | 150 | var n = key.indexOf("*"); |
153 | 151 | if(n!=-1) { |
154 | - if(!(validation.notNull(value))) | |
152 | + if(!(validation.notNull(value))) | |
155 | 153 | { |
156 | 154 | errors.push(key+"is Empty"); |
157 | 155 | } |
158 | - is_not_null = is_not_null && validation.notNull(value); | |
156 | + is_not_null = is_not_null && validation.notNull(value); | |
159 | 157 | } |
160 | 158 | } |
161 | 159 | //console.log(validation.mobileNumber(item["Parent Mobile*"])); |
... | ... | @@ -167,36 +165,36 @@ export const studentUploadCsv = new ValidatedMethod({ |
167 | 165 | |
168 | 166 | if (!(validation.validateEmail(item["Parent Email*"]))) |
169 | 167 | { |
170 | - errors.push('Parent Email is invalid'); | |
168 | + errors.push('Parent Email is invalid'); | |
171 | 169 | } |
172 | 170 | if (!(validation.mobileNumber(item["Parent Mobile*"]))) |
173 | 171 | { |
174 | - errors.push('Parent Mobile is invalid'); | |
172 | + errors.push('Parent Mobile is invalid'); | |
175 | 173 | } |
176 | 174 | |
177 | 175 | var is_valid = formate_validation && is_not_null ; |
178 | - | |
176 | + | |
179 | 177 | // console.log(formate_validation); |
180 | 178 | if (is_valid) |
181 | - { | |
179 | + { | |
182 | 180 | CSV_valid_buffer.push(item); |
183 | 181 | console.log("----------------------------------------1"); |
184 | 182 | Meteor.call('student.addCSV',item); |
185 | 183 | console.log("----------------------------------------2"); |
186 | - | |
184 | + | |
187 | 185 | // exists = Stores.findOne({ |
188 | - // "Student 'Admission' ID*": item["Student Admission ID*"] | |
186 | + // "Student 'Admission' ID*": item["Student Admission ID*"] | |
189 | 187 | // }); |
190 | - // if (!exists) | |
188 | + // if (!exists) | |
191 | 189 | // { |
192 | 190 | // Stores.insert(item); |
193 | 191 | // } |
194 | - // else | |
192 | + // else | |
195 | 193 | // { |
196 | 194 | // console.warn('Rejected. This item already exists.'); |
197 | 195 | // } |
198 | - } | |
199 | - else | |
196 | + } | |
197 | + else | |
200 | 198 | { |
201 | 199 | var str = errors.toString(); |
202 | 200 | item.Errors = str; | ... | ... |
imports/server/collections.js
package.json
... | ... | @@ -66,11 +66,13 @@ |
66 | 66 | "babyparse": "^0.4.6", |
67 | 67 | "bcrypt": "^0.8.7", |
68 | 68 | "bootstrap": "^4.0.0-alpha.6", |
69 | + "csv2json-convertor": "^1.2.0", | |
69 | 70 | "csvtojson": "^1.1.4", |
70 | 71 | "fs": "0.0.1-security", |
71 | 72 | "jquery": "^2.2.4", |
72 | 73 | "jquery-ui": "^1.12.1", |
73 | 74 | "jquery-validation": "^1.15.1", |
75 | + "json2csv": "^3.7.3", | |
74 | 76 | "lodash": "^4.17.4", |
75 | 77 | "material-fabmenu": "0.0.1", |
76 | 78 | "material-ui": "^0.17.1", | ... | ... |