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
1 | import React, { Component, PropTypes } from 'react' | 1 | import React, { Component, PropTypes } from 'react' |
2 | import $ from 'jquery' | 2 | import $ from 'jquery' |
3 | import 'jquery-ui/ui/widgets/datepicker' | 3 | import 'jquery-ui/ui/widgets/datepicker' |
4 | 4 | ||
5 | class DatePicker extends Component { | 5 | class DatePicker extends Component { |
6 | componentDidMount() { | 6 | componentDidMount() { |
7 | $('.datepicker').datepicker({ | 7 | $('.datepicker').datepicker({ |
8 | changeMonth: true, | 8 | changeMonth: true, |
9 | changeYear: true, | 9 | changeYear: true, |
10 | showButtonPanel: true, | 10 | showButtonPanel: true, |
11 | yearRange: '-116:+34', | 11 | yearRange: '-116:-1', |
12 | dateFormat: 'dd/mm/yy' | 12 | dateFormat: 'dd/mm/yy' |
13 | }); | 13 | }); |
14 | } | 14 | } |
15 | 15 | ||
16 | render() { | 16 | render() { |
17 | return ( | 17 | return ( |
18 | <input | 18 | <input |
19 | type="text" | 19 | type="text" |
20 | className="datepicker form-control" | 20 | className="datepicker form-control" |
21 | placeholder="DD-MM-YYYY" | 21 | placeholder="DD-MM-YYYY" |
22 | onChange={this.props.onChange} | 22 | onChange={this.props.onChange} |
23 | value={this.props.value} | 23 | value={this.props.value} |
24 | /> | 24 | /> |
25 | ) | 25 | ) |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | DatePicker.propTypes = { | 29 | DatePicker.propTypes = { |
30 | value: PropTypes.string.isRequired, | 30 | value: PropTypes.string.isRequired, |
31 | onChange: PropTypes.func.isRequired, | 31 | onChange: PropTypes.func.isRequired, |
32 | } | 32 | } |
33 | 33 | ||
34 | export default DatePicker | 34 | export default DatePicker |
35 | 35 |
imports/client/views/org/admin/students/StudentTable.js
1 | import _ from 'lodash'; | File was deleted | |
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 | }; | ||
84 | 1 | import _ from 'lodash'; |
imports/client/views/org/admin/students/StudentView.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 { Navbar,Modal, Nav, NavItem, | 6 | import { Navbar,Modal, Nav, NavItem, |
7 | Glyphicon, Collapse, FormGroup, FormControl, Panel, | 7 | Glyphicon, Collapse, FormGroup, FormControl, Panel, |
8 | NavbarToggler, NavbarBrand, Table, ButtonToolbar, | 8 | NavbarToggler, NavbarBrand, Table, ButtonToolbar, |
9 | NavLink, DropdownItem, DropdownToggle, DropdownMenu, | 9 | NavLink, DropdownItem, DropdownToggle, DropdownMenu, |
10 | NavDropdown, MenuItem, Breadcrumb, Button } from 'react-bootstrap'; | 10 | NavDropdown, MenuItem, Breadcrumb, Button } from 'react-bootstrap'; |
11 | import { AddStudent } from './addStudent'; | 11 | import { AddStudent } from './addStudent'; |
12 | import { StudentTable } from './StudentTable'; | 12 | import { StudentTable } from './view/StudentTable'; |
13 | import { Header } from './Header'; | 13 | import { Header } from './Header'; |
14 | import { FabMenuView } from './FabMenu'; | 14 | import { FabMenuView } from './FabMenu'; |
15 | import { UploadCsv } from './UploadCsv'; | 15 | import { UploadCsv } from './UploadCsv'; |
16 | import { Students } from '/imports/collections/students/index'; | 16 | import { Students } from '/imports/collections/students/index'; |
17 | 17 | ||
18 | 18 | ||
19 | export class StudentView extends Component { | 19 | export class StudentView extends Component { |
20 | 20 | ||
21 | constructor(props) { | 21 | constructor(props) { |
22 | super(props); | 22 | super(props); |
23 | this.state = { | 23 | this.state = { |
24 | show: false, | 24 | show: false, |
25 | firstNameSearch: "", | 25 | firstNameSearch: "", |
26 | lastNameSearch: "", | 26 | lastNameSearch: "", |
27 | }; | 27 | }; |
28 | this.showModal = this.showModal.bind(this); | 28 | this.showModal = this.showModal.bind(this); |
29 | this.hideModal = this.hideModal.bind(this); | 29 | this.hideModal = this.hideModal.bind(this); |
30 | this.onUpdate = this.onUpdate.bind(this); | 30 | this.onUpdate = this.onUpdate.bind(this); |
31 | }; | 31 | }; |
32 | 32 | ||
33 | showModal() { | 33 | showModal() { |
34 | this.setState({show: true}); | 34 | this.setState({show: true}); |
35 | } | 35 | } |
36 | 36 | ||
37 | hideModal() { | 37 | hideModal() { |
38 | this.setState({show: false}); | 38 | this.setState({show: false}); |
39 | } | 39 | } |
40 | onUpdate(key, value) { | 40 | onUpdate(key, value) { |
41 | this.setState({[key]: value}); | 41 | this.setState({[key]: value}); |
42 | }; | 42 | }; |
43 | 43 | ||
44 | render() { | 44 | render() { |
45 | console.log(this.props); | 45 | console.log(this.props); |
46 | firstNameSearch = this.state.firstNameSearch; | 46 | firstNameSearch = this.state.firstNameSearch; |
47 | lastNameSearch = this.state.lastNameSearch; | 47 | lastNameSearch = this.state.lastNameSearch; |
48 | var students =_.filter(this.props.data.students,function(item){ | 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 | return ( | 53 | return ( |
52 | <div className="appLayout-box"> | 54 | <div className="appLayout-box"> |
53 | <div className="page-container"> | 55 | <div className="page-container"> |
54 | <div className="page-content"> | 56 | <div className="page-content"> |
55 | <div className="sidebar sidebar-main sidebar-default"> | 57 | <div className="sidebar sidebar-main sidebar-default"> |
56 | <div className="sidebar-content"> | 58 | <div className="sidebar-content"> |
57 | 59 | ||
58 | <div className="sidebar-category sidebar-category-visible"> | 60 | <div className="sidebar-category sidebar-category-visible"> |
59 | <div className="category-content no-padding"> | 61 | <div className="category-content no-padding"> |
60 | <Nav className="navigation navigation-main navigation-accordion"> | 62 | <Nav className="navigation navigation-main navigation-accordion"> |
61 | <NavItem className="navigation-header"><span>#schoolname</span> <i className="icon-menu" title="Main pages"></i></NavItem> | 63 | <NavItem className="navigation-header"><span>#schoolname</span> <i className="icon-menu" title="Main pages"></i></NavItem> |
62 | <NavItem className="active" eventKey={1} href="#"><i className="icon-home4"></i> <span>Dashboard</span></NavItem> | 64 | <NavItem className="active" eventKey={1} href="#"><i className="icon-home4"></i> <span>Dashboard</span></NavItem> |
63 | 65 | ||
64 | <NavDropdown eventKey={2} title="Settings" name="Settings" id="setting"> | 66 | <NavDropdown eventKey={2} title="Settings" name="Settings" id="setting"> |
65 | <MenuItem eventKey={2.1}>Information</MenuItem> | 67 | <MenuItem eventKey={2.1}>Information</MenuItem> |
66 | <MenuItem eventKey={2.2}>Infrastructure</MenuItem> | 68 | <MenuItem eventKey={2.2}>Infrastructure</MenuItem> |
67 | <MenuItem eventKey={2.3}>Users</MenuItem> | 69 | <MenuItem eventKey={2.3}>Users</MenuItem> |
68 | <MenuItem eventKey={2.4}>Academic Settings</MenuItem> | 70 | <MenuItem eventKey={2.4}>Academic Settings</MenuItem> |
69 | <MenuItem eventKey={2.5}>Account Configuration</MenuItem> | 71 | <MenuItem eventKey={2.5}>Account Configuration</MenuItem> |
70 | </NavDropdown> | 72 | </NavDropdown> |
71 | <NavDropdown eventKey={3} title="Academic" name="Academic" id="academic"> | 73 | <NavDropdown eventKey={3} title="Academic" name="Academic" id="academic"> |
72 | <MenuItem eventKey={3.1}>Layout 1</MenuItem> | 74 | <MenuItem eventKey={3.1}>Layout 1</MenuItem> |
73 | <MenuItem eventKey={3.2}>Layout 2</MenuItem> | 75 | <MenuItem eventKey={3.2}>Layout 2</MenuItem> |
74 | <MenuItem eventKey={3.3}>Layout 3</MenuItem> | 76 | <MenuItem eventKey={3.3}>Layout 3</MenuItem> |
75 | <MenuItem eventKey={3.4}>Layout 4</MenuItem> | 77 | <MenuItem eventKey={3.4}>Layout 4</MenuItem> |
76 | <MenuItem eventKey={3.5}>Layout 5</MenuItem> | 78 | <MenuItem eventKey={3.5}>Layout 5</MenuItem> |
77 | </NavDropdown> | 79 | </NavDropdown> |
78 | <NavDropdown eventKey={4} title="Communication" name="Communication" id="communication"> | 80 | <NavDropdown eventKey={4} title="Communication" name="Communication" id="communication"> |
79 | <MenuItem eventKey={4.1}>Primary palett</MenuItem> | 81 | <MenuItem eventKey={4.1}>Primary palett</MenuItem> |
80 | <MenuItem eventKey={4.2}>Danger palett</MenuItem> | 82 | <MenuItem eventKey={4.2}>Danger palett</MenuItem> |
81 | <MenuItem eventKey={4.3}>Success palett</MenuItem> | 83 | <MenuItem eventKey={4.3}>Success palett</MenuItem> |
82 | <MenuItem eventKey={4.4}>Warning palett</MenuItem> | 84 | <MenuItem eventKey={4.4}>Warning palett</MenuItem> |
83 | <MenuItem divider /> | 85 | <MenuItem divider /> |
84 | <MenuItem eventKey={4.5}>Info palett</MenuItem> | 86 | <MenuItem eventKey={4.5}>Info palett</MenuItem> |
85 | <MenuItem eventKey={4.6}>Info palett</MenuItem> | 87 | <MenuItem eventKey={4.6}>Info palett</MenuItem> |
86 | <MenuItem eventKey={4.7}>Info palett</MenuItem> | 88 | <MenuItem eventKey={4.7}>Info palett</MenuItem> |
87 | <MenuItem eventKey={4.8}>Info palett</MenuItem> | 89 | <MenuItem eventKey={4.8}>Info palett</MenuItem> |
88 | </NavDropdown> | 90 | </NavDropdown> |
89 | <NavDropdown eventKey={5} title="Finance" name="Finance" id="finance"> | 91 | <NavDropdown eventKey={5} title="Finance" name="Finance" id="finance"> |
90 | <MenuItem eventKey={5.1}>Primary palett</MenuItem> | 92 | <MenuItem eventKey={5.1}>Primary palett</MenuItem> |
91 | <MenuItem eventKey={5.2}>Danger palett</MenuItem> | 93 | <MenuItem eventKey={5.2}>Danger palett</MenuItem> |
92 | <MenuItem eventKey={5.3}>Success palett</MenuItem> | 94 | <MenuItem eventKey={5.3}>Success palett</MenuItem> |
93 | <MenuItem eventKey={5.4}>Warning palett</MenuItem> | 95 | <MenuItem eventKey={5.4}>Warning palett</MenuItem> |
94 | <NavDropdown eventKey={5.5} title="Calumns" id="calumns"> | 96 | <NavDropdown eventKey={5.5} title="Calumns" id="calumns"> |
95 | <MenuItem>Success palett</MenuItem> | 97 | <MenuItem>Success palett</MenuItem> |
96 | <MenuItem>Warning palett</MenuItem> | 98 | <MenuItem>Warning palett</MenuItem> |
97 | </NavDropdown> | 99 | </NavDropdown> |
98 | </NavDropdown> | 100 | </NavDropdown> |
99 | 101 | ||
100 | <NavItem eventKey={6} href="#"><i className="icon-file-stats"></i><span> Reports </span></NavItem> | 102 | <NavItem eventKey={6} href="#"><i className="icon-file-stats"></i><span> Reports </span></NavItem> |
101 | <NavItem eventKey={7} href="#"><i className="icon-design"></i> <span>Examinations</span></NavItem> | 103 | <NavItem eventKey={7} href="#"><i className="icon-design"></i> <span>Examinations</span></NavItem> |
102 | 104 | ||
103 | </Nav> | 105 | </Nav> |
104 | </div> | 106 | </div> |
105 | </div> | 107 | </div> |
106 | </div> | 108 | </div> |
107 | </div> | 109 | </div> |
108 | {/*end sidebar*/} | 110 | {/*end sidebar*/} |
109 | <div className="content-wrapper"> | 111 | <div className="content-wrapper"> |
110 | <div className="page-header page-header-default"> | 112 | <div className="page-header page-header-default"> |
111 | <div className="breadcrumb-line"> | 113 | <div className="breadcrumb-line"> |
112 | <Breadcrumb> | 114 | <Breadcrumb> |
113 | <Breadcrumb.Item href="#"> | 115 | <Breadcrumb.Item href="#"> |
114 | <i className="icon-home2 position-left"></i> Users | 116 | <i className="icon-home2 position-left"></i> Users |
115 | </Breadcrumb.Item> | 117 | </Breadcrumb.Item> |
116 | <Breadcrumb.Item active href="#"> | 118 | <Breadcrumb.Item active href="#"> |
117 | Setup | 119 | Setup |
118 | </Breadcrumb.Item> | 120 | </Breadcrumb.Item> |
119 | </Breadcrumb> | 121 | </Breadcrumb> |
120 | 122 | ||
121 | <ul className="breadcrumb-elements"> | 123 | <ul className="breadcrumb-elements"> |
122 | <NavItem href="#"><i className="icon-comment-discussion position-left"></i> Support</NavItem> | 124 | <NavItem href="#"><i className="icon-comment-discussion position-left"></i> Support</NavItem> |
123 | <NavDropdown title="Settings" id="setting"> | 125 | <NavDropdown title="Settings" id="setting"> |
124 | <MenuItem><i className="icon-user-lock"></i> Account security</MenuItem> | 126 | <MenuItem><i className="icon-user-lock"></i> Account security</MenuItem> |
125 | <MenuItem><i className="icon-statistics"></i> Analytics</MenuItem> | 127 | <MenuItem><i className="icon-statistics"></i> Analytics</MenuItem> |
126 | <MenuItem><i className="icon-accessibility"></i> Accessibility</MenuItem> | 128 | <MenuItem><i className="icon-accessibility"></i> Accessibility</MenuItem> |
127 | <MenuItem divider/> | 129 | <MenuItem divider/> |
128 | <MenuItem><i className="icon-gear"></i> All settings</MenuItem> | 130 | <MenuItem><i className="icon-gear"></i> All settings</MenuItem> |
129 | </NavDropdown> | 131 | </NavDropdown> |
130 | 132 | ||
131 | </ul> | 133 | </ul> |
132 | </div> | 134 | </div> |
133 | </div> | 135 | </div> |
134 | {/*content*/} | 136 | {/*content*/} |
135 | 137 | ||
136 | <div className="content has-detached-left"> | 138 | <div className="content has-detached-left"> |
137 | <div className="container-detached"> | 139 | <div className="container-detached"> |
138 | <div className="content-detached"> | 140 | <div className="content-detached"> |
139 | <Header/> | 141 | <Header/> |
140 | <StudentTable | 142 | <StudentTable |
141 | data = {this.props.data} | 143 | data = {this.props.data} |
142 | students = {students} | 144 | students = {students} |
143 | /> | 145 | /> |
144 | <AddStudent/> | 146 | <AddStudent/> |
145 | <UploadCsv /> | 147 | <UploadCsv /> |
146 | </div> | 148 | </div> |
147 | </div> | 149 | </div> |
148 | <div className="sidebar-detached affix-top"> | 150 | <div className="sidebar-detached affix-top"> |
149 | <div className="sidebar sidebar-default"> | 151 | <div className="sidebar sidebar-default"> |
150 | <div className="sidebar-content"> | 152 | <div className="sidebar-content"> |
151 | 153 | ||
152 | <div className="sidebar-category"> | 154 | <div className="sidebar-category"> |
153 | <div className="category-title"> | 155 | <div className="category-title"> |
154 | <span>Advanced Search</span> | 156 | <span>Advanced Search</span> |
155 | <ul className="icons-list"> | 157 | <ul className="icons-list"> |
156 | <li><a href="#" data-action="collapse"></a></li> | 158 | <li><a href="#" data-action="collapse"></a></li> |
157 | </ul> | 159 | </ul> |
158 | </div> | 160 | </div> |
159 | 161 | ||
160 | <div className="category-content"> | 162 | <div className="category-content"> |
161 | <form action="#"> | 163 | <form action="#"> |
162 | <div className="has-feedback has-feedback-left"> | 164 | <div className="has-feedback has-feedback-left"> |
163 | <input type="search" className="form-control" | 165 | <input type="search" className="form-control" |
164 | value={this.state.firstNameSearch} | 166 | value={this.state.firstNameSearch} |
165 | onChange={e=>this.onUpdate('firstNameSearch',e.target.value)} | 167 | onChange={e=>this.onUpdate('firstNameSearch',e.target.value)} |
166 | placeholder="First Name" | 168 | placeholder="First Name" |
167 | /> | 169 | /> |
168 | <div className="form-control-feedback"> | 170 | <div className="form-control-feedback"> |
169 | <i className="icon-search4 text-size-base text-muted"></i> | 171 | <i className="icon-search4 text-size-base text-muted"></i> |
170 | </div> | 172 | </div> |
171 | </div> | 173 | </div> |
172 | </form> | 174 | </form> |
173 | </div> | 175 | </div> |
174 | <div className="category-content"> | 176 | <div className="category-content"> |
175 | <form action="#"> | 177 | <form action="#"> |
176 | <div className="has-feedback has-feedback-left"> | 178 | <div className="has-feedback has-feedback-left"> |
177 | <input type="search" className="form-control" | 179 | <input type="search" className="form-control" |
178 | value={this.state.lastNameSearch} | 180 | value={this.state.lastNameSearch} |
179 | onChange={e=>this.onUpdate('lastNameSearch',e.target.value)} | 181 | onChange={e=>this.onUpdate('lastNameSearch',e.target.value)} |
180 | placeholder="Last Name" /> | 182 | placeholder="Last Name" /> |
181 | <div className="form-control-feedback"> | 183 | <div className="form-control-feedback"> |
182 | <i className="icon-search4 text-size-base text-muted"></i> | 184 | <i className="icon-search4 text-size-base text-muted"></i> |
183 | </div> | 185 | </div> |
184 | </div> | 186 | </div> |
185 | </form> | 187 | </form> |
186 | </div> | 188 | </div> |
187 | </div> | 189 | </div> |
188 | </div> | 190 | </div> |
189 | </div> | 191 | </div> |
190 | </div> | 192 | </div> |
191 | </div> | 193 | </div> |
192 | </div> | 194 | </div> |
193 | </div> | 195 | </div> |
194 | </div> | 196 | </div> |
195 | </div> | 197 | </div> |
196 | ); | 198 | ); |
197 | }; | 199 | }; |
198 | 200 | ||
199 | }; | 201 | }; |
200 | 202 |
imports/client/views/org/admin/students/UploadCsv.js
1 | // import {UploadCsv } from '/imports/collections/students/UploadCsv' | ||
1 | import _ from 'lodash'; | 2 | import _ from 'lodash'; |
2 | import { Meteor } from 'meteor/meteor'; | 3 | import { Meteor } from 'meteor/meteor'; |
3 | 4 | ||
4 | import React, { Component } from 'react'; | 5 | import React, { Component } from 'react'; |
5 | import { Link,browserHistory } from 'react-router'; | 6 | import { Link,browserHistory } from 'react-router'; |
6 | import { FormGroup,Panel,Table, | 7 | import { FormGroup,Panel,Table, |
7 | ButtonToolbar,Modal,ControlLabel,HelpBlock, | 8 | ButtonToolbar,Modal,ControlLabel,HelpBlock, |
8 | FormControl,Glyphicon,Button } from 'react-bootstrap'; | 9 | FormControl,Glyphicon,Button } from 'react-bootstrap'; |
9 | // import { AddStudentForm } from './addStudentForm'; | 10 | // import { AddStudentForm } from './addStudentForm'; |
10 | import { FilesCollection } from 'meteor/ostrio:files'; | 11 | import { FilesCollection } from 'meteor/ostrio:files'; |
11 | const Papa = this.Papa; | 12 | const Papa = this.Papa; |
12 | // console.log(this); | 13 | // console.log(this); |
13 | const style = { | 14 | const style = { |
14 | margin: 12, | 15 | margin: 12, |
15 | }; | 16 | }; |
16 | function FieldGroup({ id, label, help, ...props }) { | 17 | function FieldGroup({ id, label, help, ...props }) { |
17 | return ( | 18 | return ( |
18 | <FormGroup controlId={id}> | 19 | <FormGroup controlId={id}> |
19 | <ControlLabel>{label}</ControlLabel> | 20 | <ControlLabel>{label}</ControlLabel> |
20 | <FormControl {...props} /> | 21 | <FormControl {...props} /> |
21 | {help && <HelpBlock>{help}</HelpBlock>} | 22 | {help && <HelpBlock>{help}</HelpBlock>} |
22 | </FormGroup> | 23 | </FormGroup> |
23 | ); | 24 | ); |
24 | } | 25 | } |
25 | export class UploadCsv extends Component { | 26 | export class UploadCsv extends Component { |
26 | constructor(props) { | 27 | constructor(props) { |
27 | super(props); | 28 | super(props); |
28 | this.state = { | 29 | this.state = { |
29 | show: false | 30 | show: false |
30 | }; | 31 | }; |
31 | this.showModal = this.showModal.bind(this); | 32 | this.showModal = this.showModal.bind(this); |
32 | this.hideModal = this.hideModal.bind(this); | 33 | this.hideModal = this.hideModal.bind(this); |
33 | this.onUpdate = this.onUpdate.bind(this); | 34 | this.onUpdate = this.onUpdate.bind(this); |
34 | }; | 35 | }; |
35 | 36 | ||
36 | showModal() { | 37 | showModal() { |
37 | this.setState({show: true}); | 38 | this.setState({show: true}); |
38 | } | 39 | } |
39 | 40 | ||
40 | hideModal() { | 41 | hideModal() { |
41 | this.setState({show: false}); | 42 | this.setState({show: false}); |
42 | } | 43 | } |
43 | onUpdate(key, value) { | 44 | onUpdate(key, value) { |
44 | this.setState({[key]: value}); | 45 | this.setState({[key]: value}); |
45 | }; | 46 | }; |
46 | uploadStudentCsv(e){ | 47 | uploadStudentCsv(e){ |
47 | e.preventDefault(); | 48 | e.preventDefault(); |
48 | e.persist(); | 49 | e.persist(); |
49 | var file = $('input[type="file"]').prop("files")[0]; | 50 | var file = $('input[type="file"]').prop("files")[0]; |
50 | Papa.parse(file, { | 51 | Papa.parse(file, { |
51 | complete: function(results) { | 52 | header: true, |
52 | if(results){ | 53 | complete: function(csvData) { |
54 | console.log("csvData"); | ||
55 | console.log(csvData); | ||
56 | if(csvData){ | ||
53 | Meteor.call('student.uploadCsv', csvData, function (error, result) { | 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 | } |
58 | }); | 65 | }); |
59 | } | 66 | } |
60 | 67 | ||
61 | render() { | 68 | render() { |
62 | console.log(this.props); | 69 | console.log(this.props); |
63 | return ( | 70 | return ( |
64 | <ButtonToolbar> | 71 | <ButtonToolbar> |
65 | <Button bsStyle="primary" onClick={this.showModal}> | 72 | <Button bsStyle="primary" onClick={this.showModal}> |
66 | Upload CSV | 73 | Upload CSV |
67 | </Button> | 74 | </Button> |
68 | <Modal | 75 | <Modal |
69 | {...this.props} | 76 | {...this.props} |
70 | show={this.state.show} | 77 | show={this.state.show} |
71 | onHide={this.hideModal} | 78 | onHide={this.hideModal} |
72 | dialogClassName="custom-modal" | 79 | dialogClassName="custom-modal" |
73 | > | 80 | > |
74 | <Modal.Header closeButton> | 81 | <Modal.Header closeButton> |
75 | <Modal.Title id="contained-modal-title-lg">New Student</Modal.Title> | 82 | <Modal.Title id="contained-modal-title-lg">New Student</Modal.Title> |
76 | </Modal.Header> | 83 | </Modal.Header> |
77 | <Modal.Body> | 84 | <Modal.Body> |
78 | <form onSubmit={ (e) => this.uploadStudentCsv(e) } > | 85 | <form onSubmit={ (e) => this.uploadStudentCsv(e) } > |
79 | <FieldGroup | 86 | <FieldGroup |
80 | id="formControlsFile" | 87 | id="formControlsFile" |
81 | type="file" | 88 | type="file" |
82 | label="File" | 89 | label="File" |
83 | help="Upload you CSV here." | 90 | help="Upload you CSV here." |
84 | /> | 91 | /> |
85 | <Button type="submit" bsStyle="default">Upload File</Button> | 92 | <Button type="submit" bsStyle="default">Upload File</Button> |
86 | </form> | 93 | </form> |
87 | </Modal.Body> | 94 | </Modal.Body> |
88 | <Modal.Footer> | 95 | <Modal.Footer> |
89 | <Button onClick={this.hideModal}>Close</Button> | 96 | <Button onClick={this.hideModal}>Close</Button> |
90 | </Modal.Footer> | 97 | </Modal.Footer> |
91 | </Modal> | 98 | </Modal> |
92 | </ButtonToolbar> | 99 | </ButtonToolbar> |
93 | ); | 100 | ); |
94 | }; | 101 | }; |
95 | 102 | ||
96 | }; | 103 | }; |
97 | 104 |
imports/client/views/org/admin/students/view/StudentRow.js
File was created | 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 | }; | ||
57 |
imports/client/views/org/admin/students/view/StudentTable.js
File was created | 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 | }; | ||
67 |
imports/collections/orgs/methods.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 { 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 { Orgs } from '/imports/collections/orgs/index'; | 9 | import { Orgs } from '/imports/collections/orgs/index'; |
10 | // import { sendNotificationAPN } from '/imports/server/push/methods'; | 10 | // import { sendNotificationAPN } from '/imports/server/push/methods'; |
11 | export const orgMethod = new ValidatedMethod({ | 11 | export const orgMethod = new ValidatedMethod({ |
12 | name: 'org.method', | 12 | name: 'org.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 checkExistingOrg = new ValidatedMethod({ | 24 | export const checkExistingOrg = new ValidatedMethod({ |
25 | name: 'checkExistingOrg', | 25 | name: 'checkExistingOrg', |
26 | validate: new SimpleSchema({ | 26 | validate: new SimpleSchema({ |
27 | slug: { type: String }, | 27 | slug: { type: String }, |
28 | }).validator(), | 28 | }).validator(), |
29 | 29 | ||
30 | run({slug}) { | 30 | run({slug}) { |
31 | org = Orgs.findOne({slug:slug}); | 31 | org = Orgs.findOne({slug:slug}); |
32 | return org; | 32 | return org; |
33 | }, | 33 | }, |
34 | }); | 34 | }); |
35 | 35 | ||
36 | export const checkEmailInOrg = new ValidatedMethod({ | 36 | export const checkEmailInOrg = new ValidatedMethod({ |
37 | name: 'checkEmailInOrg', | 37 | name: 'checkEmailInOrg', |
38 | 38 | ||
39 | validate: new SimpleSchema({ | 39 | validate: new SimpleSchema({ |
40 | email: { type: String }, | 40 | email: { type: String }, |
41 | orgId: { type: String }, | 41 | orgId: { type: String }, |
42 | }).validator(), | 42 | }).validator(), |
43 | 43 | ||
44 | run({email, orgId}) { | 44 | run({email, orgId}) { |
45 | console.log(orgId); | 45 | console.log(orgId); |
46 | user = Users.findOne({"orgId":orgId, "emails.address":email}); | 46 | user = Users.findOne({"orgId":orgId, "emails.address":email}); |
47 | if(user){ | 47 | if(user){ |
48 | return {success:true} | 48 | return {success:true} |
49 | }else{ | 49 | }else{ |
50 | return {success:false} | 50 | return {success:false} |
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 | }); | ||
70 | 54 |
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 | var csv = json2csv({ | 39 | var csv = json2csv({ |
40 | data: item, | 40 | data: item, |
41 | fields: csv_fiels | 41 | fields: csv_fiels |
42 | }); | 42 | }); |
43 | fs.writeFile(filename, csv,function(err) { | 43 | fs.writeFile(filename, csv,function(err) { |
44 | if (err) throw err; | 44 | if (err) throw err; |
45 | }); | 45 | }); |
46 | }, | 46 | }, |
47 | }); | 47 | }); |
48 | 48 | ||
49 | export const addStudentCSV= new ValidatedMethod({ | 49 | export const addStudentCSV= new ValidatedMethod({ |
50 | name: 'student.addCSV', | 50 | name: 'student.addCSV', |
51 | 51 | ||
52 | validate: null, | 52 | validate: null, |
53 | 53 | ||
54 | run(item){ | 54 | run(item){ |
55 | data = item ; | 55 | data = item ; |
56 | console.log("data"); | 56 | console.log("data"); |
57 | console.log(data); | 57 | console.log(data); |
58 | return true; | ||
58 | const user = Users.findOne({_id: this.userId}); | 59 | const user = Users.findOne({_id: this.userId}); |
59 | orgId = user.orgId; | 60 | orgId = user.orgId; |
60 | newStudentId = Users.insert({ | 61 | newStudentId = Users.insert({ |
61 | // emails: [{address:data.email, verified: false}], | 62 | // emails: [{address:data.email, verified: false}], |
62 | username: data["first Name*"], | 63 | username: data["First Name*"], |
63 | firstName: data.firstName, | 64 | firstName: data["First Name*"], |
64 | middleName: data.middleName, | 65 | lastName: data['Last Name*'], |
65 | lastName: data.lastName, | ||
66 | orgId: orgId, | 66 | orgId: orgId, |
67 | role: 'STUDENT' | 67 | role: 'STUDENT' |
68 | }); | 68 | }); |
69 | newParentUserId = Users.insert({ | 69 | newParentUserId = Users.insert({ |
70 | //emails: [{address:data.parentEmail, verified: false}], | 70 | //emails: [{address:data.parentEmail, verified: false}], |
71 | username: data.parentName, | 71 | username: data.parentName, |
72 | firstName: data.parentName, | 72 | firstName: data.parentName, |
73 | orgId: orgId, | 73 | orgId: orgId, |
74 | role: 'PARENT' | 74 | role: 'PARENT' |
75 | }); | 75 | }); |
76 | if(newParentUserId){ | 76 | if(newParentUserId){ |
77 | newParentId = Parents.insert({ | 77 | newParentId = Parents.insert({ |
78 | userId: newParentUserId, | 78 | userId: newParentUserId, |
79 | orgId: orgId, | 79 | orgId: orgId, |
80 | address: data.address, | 80 | address: data.address, |
81 | gender: data.gender, | 81 | gender: data.gender, |
82 | dob: data.dob, | 82 | dob: data.dob, |
83 | rollNo: data.rollNo, | 83 | rollNo: data.rollNo, |
84 | class: data.studentclass, | 84 | class: data.studentclass, |
85 | section: data.section, | 85 | section: data.section, |
86 | bloodGroup: data.bloodGroup, | 86 | bloodGroup: data.bloodGroup, |
87 | community: data.community, | 87 | community: data.community, |
88 | }); | 88 | }); |
89 | console.log("newParentUserId"); | 89 | console.log("newParentUserId"); |
90 | console.log(newParentUserId); | 90 | console.log(newParentUserId); |
91 | } | 91 | } |
92 | console.log("newUserId"); | 92 | console.log("newUserId"); |
93 | console.log(newStudentId); | 93 | console.log(newStudentId); |
94 | if(newStudentId){ | 94 | if(newStudentId){ |
95 | Students.insert({ | 95 | Students.insert({ |
96 | userId: newStudentId, | 96 | userId: newStudentId, |
97 | orgId: orgId, | 97 | orgId: orgId, |
98 | admissionId: data.admissionId, | 98 | admissionId: data['Student Admission ID*'], |
99 | address: data.address, | 99 | address: data['Student Admission ID*'], |
100 | gender: data.gender, | 100 | gender: data['Gender(male/female)*'], |
101 | dob: data.dob, | 101 | dob: data['Birthday(YYYY-MM-DD)*'], |
102 | rollNo: data.rollNo, | 102 | rollNo: data.rollNo, |
103 | class: data.studentclass, | 103 | class: data.studentclass, |
104 | section: data.section, | 104 | section: data.section, |
105 | bloodGroup: data.bloodGroup, | 105 | bloodGroup: data.bloodGroup, |
106 | community: data.community, | 106 | community: data.community, |
107 | parent: [{id: newParentUserId, relatinship: data.relation}] | 107 | parent: [{id: newParentUserId, relatinship: data.relation}] |
108 | }); | 108 | }); |
109 | } | 109 | } |
110 | return {newStudentId}; | 110 | return {newStudentId}; |
111 | }, | 111 | }, |
112 | 112 | ||
113 | }); | 113 | }); |
114 | 114 | ||
115 | export const studentUploadCsv = new ValidatedMethod({ | 115 | export const studentUploadCsv = new ValidatedMethod({ |
116 | name: 'student.uploadCsv', | 116 | name: 'student.uploadCsv', |
117 | 117 | ||
118 | validate: new SimpleSchema({ | 118 | validate: null, |
119 | data: { type: [Object] }, | ||
120 | }).validator(), | ||
121 | 119 | ||
122 | run({data}) { | 120 | run({data}) { |
123 | let validation = new Validation(); | 121 | let validation = new Validation(); |
124 | let constants = new Constants(); | 122 | let constants = new Constants(); |
125 | //console.log("++++++++++++++++++++++++"+constants.csv_students_data()); | 123 | //console.log("++++++++++++++++++++++++"+constants.csv_students_data()); |
126 | temp = constants.csv_students_data(); | 124 | temp = constants.csv_students_data(); |
127 | // | 125 | // |
128 | console.log(temp); | 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 | //console.log(data);'' | 128 | //console.log(data);'' |
131 | Stores = new Mongo.Collection('stores'); | 129 | Stores = new Mongo.Collection('stores'); |
132 | data = data_1; | 130 | // data = data_1; |
133 | 131 | ||
134 | var CSV_valid_buffer = []; | 132 | var CSV_valid_buffer = []; |
135 | var CSV_invalid_buffer = []; | 133 | var CSV_invalid_buffer = []; |
136 | var filename = new Date().getTime().toString(); | 134 | var filename = new Date().getTime().toString(); |
137 | var csv_filepath = '/Users/satheeshnagaraj/Documents/Workspace/Meteor/ydapp/CSV_Files/'; | 135 | var csv_filepath = '/Users/satheeshnagaraj/Documents/Workspace/Meteor/ydapp/CSV_Files/'; |
138 | 136 | ||
139 | 137 | ||
140 | for (let i = 0; i < data.length; i++) | 138 | for (let i = 0; i < data.length; i++) |
141 | { | 139 | { |
142 | 140 | ||
143 | //let item= {Errors:""}; | 141 | //let item= {Errors:""}; |
144 | let item = data[i]; | 142 | let item = data[i]; |
145 | delete item['Errors']; | 143 | delete item['Errors']; |
146 | var formate_validation = 1; | 144 | var formate_validation = 1; |
147 | var is_not_null = 1; | 145 | var is_not_null = 1; |
148 | var errors = []; | 146 | var errors = []; |
149 | for (var key in item) | 147 | for (var key in item) |
150 | { | 148 | { |
151 | var value = item[key]; | 149 | var value = item[key]; |
152 | var n = key.indexOf("*"); | 150 | var n = key.indexOf("*"); |
153 | if(n!=-1) { | 151 | if(n!=-1) { |
154 | if(!(validation.notNull(value))) | 152 | if(!(validation.notNull(value))) |
155 | { | 153 | { |
156 | errors.push(key+"is Empty"); | 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 | //console.log(validation.mobileNumber(item["Parent Mobile*"])); | 159 | //console.log(validation.mobileNumber(item["Parent Mobile*"])); |
162 | 160 | ||
163 | 161 | ||
164 | 162 | ||
165 | 163 | ||
166 | var formate_validation = validation.validateEmail(item["Parent Email*"]) && validation.mobileNumber(item["Parent Mobile*"]) ; //&& validation.validateEmail(item["Parent Mobile"]) ); | 164 | var formate_validation = validation.validateEmail(item["Parent Email*"]) && validation.mobileNumber(item["Parent Mobile*"]) ; //&& validation.validateEmail(item["Parent Mobile"]) ); |
167 | 165 | ||
168 | if (!(validation.validateEmail(item["Parent Email*"]))) | 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 | if (!(validation.mobileNumber(item["Parent Mobile*"]))) | 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 | var is_valid = formate_validation && is_not_null ; | 175 | var is_valid = formate_validation && is_not_null ; |
178 | 176 | ||
179 | // console.log(formate_validation); | 177 | // console.log(formate_validation); |
180 | if (is_valid) | 178 | if (is_valid) |
181 | { | 179 | { |
182 | CSV_valid_buffer.push(item); | 180 | CSV_valid_buffer.push(item); |
183 | console.log("----------------------------------------1"); | 181 | console.log("----------------------------------------1"); |
184 | Meteor.call('student.addCSV',item); | 182 | Meteor.call('student.addCSV',item); |
185 | console.log("----------------------------------------2"); | 183 | console.log("----------------------------------------2"); |
186 | 184 | ||
187 | // exists = Stores.findOne({ | 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 | // Stores.insert(item); | 190 | // Stores.insert(item); |
193 | // } | 191 | // } |
194 | // else | 192 | // else |
195 | // { | 193 | // { |
196 | // console.warn('Rejected. This item already exists.'); | 194 | // console.warn('Rejected. This item already exists.'); |
197 | // } | 195 | // } |
198 | } | 196 | } |
199 | else | 197 | else |
200 | { | 198 | { |
201 | var str = errors.toString(); | 199 | var str = errors.toString(); |
202 | item.Errors = str; | 200 | item.Errors = str; |
203 | CSV_invalid_buffer.push(item); | 201 | CSV_invalid_buffer.push(item); |
204 | //console.log(str); | 202 | //console.log(str); |
205 | // console.log(CSV_invalid_buffer); | 203 | // console.log(CSV_invalid_buffer); |
206 | } | 204 | } |
207 | } | 205 | } |
208 | console.log(csv_filepath+filename+"_CSV_invalid_data"+".csv"); | 206 | console.log(csv_filepath+filename+"_CSV_invalid_data"+".csv"); |
209 | 207 | ||
210 | Meteor.call('save_csv_data',{ item : CSV_invalid_buffer, filename: csv_filepath+filename+"_CSV_invalid_data"+".csv",csv_fiels :constants.csv_students_data()}); | 208 | Meteor.call('save_csv_data',{ item : CSV_invalid_buffer, filename: csv_filepath+filename+"_CSV_invalid_data"+".csv",csv_fiels :constants.csv_students_data()}); |
211 | Meteor.call('save_csv_data',{ item : CSV_valid_buffer,filename: csv_filepath+filename+"_CSV_valid_data"+".csv",csv_fiels :constants.csv_students_data()}); | 209 | Meteor.call('save_csv_data',{ item : CSV_valid_buffer,filename: csv_filepath+filename+"_CSV_valid_data"+".csv",csv_fiels :constants.csv_students_data()}); |
212 | return {}; | 210 | return {}; |
213 | }, | 211 | }, |
214 | 212 | ||
215 | }); | 213 | }); |
imports/server/collections.js
1 | import '/imports/collections/orgs/publications' | 1 | import '/imports/collections/orgs/publications' |
2 | import '/imports/collections/orgs/methods'; | 2 | import '/imports/collections/orgs/methods'; |
3 | 3 | ||
4 | import '/imports/collections/users/publications'; | 4 | import '/imports/collections/users/publications'; |
5 | 5 | ||
6 | import '/imports/collections/students/methods'; | 6 | import '/imports/collections/students/methods'; |
7 | import '/imports/collections/students/publications'; | 7 | import '/imports/collections/students/publications'; |
8 | import '/imports/collections/students/serverCsvUpload'; | ||
8 | 9 |
package.json
1 | { | 1 | { |
2 | "name": "application-name", | 2 | "name": "application-name", |
3 | "version": "1.0.0", | 3 | "version": "1.0.0", |
4 | "description": "Application description.", | 4 | "description": "Application description.", |
5 | "scripts": { | 5 | "scripts": { |
6 | "start": "meteor --settings settings-development.json", | 6 | "start": "meteor --settings settings-development.json", |
7 | "test": "meteor test --driver-package practicalmeteor:mocha --port 5000", | 7 | "test": "meteor test --driver-package practicalmeteor:mocha --port 5000", |
8 | "chimp-watch": "chimp --ddp=http://localhost:3000 --watch --mocha --path=tests", | 8 | "chimp-watch": "chimp --ddp=http://localhost:3000 --watch --mocha --path=tests", |
9 | "chimp-test": "chimp --ddp=http://localhost:3000 --mocha --path=tests", | 9 | "chimp-test": "chimp --ddp=http://localhost:3000 --mocha --path=tests", |
10 | "staging": "meteor deploy staging.meteor.com --settings settings-development.json", | 10 | "staging": "meteor deploy staging.meteor.com --settings settings-development.json", |
11 | "production": "meteor deploy production.meteor.com --settings settings-production.json" | 11 | "production": "meteor deploy production.meteor.com --settings settings-production.json" |
12 | }, | 12 | }, |
13 | "devDependencies": { | 13 | "devDependencies": { |
14 | "chimp": "^0.41.2", | 14 | "chimp": "^0.41.2", |
15 | "eslint": "^3.8.1", | 15 | "eslint": "^3.8.1", |
16 | "eslint-config-airbnb": "^12.0.0", | 16 | "eslint-config-airbnb": "^12.0.0", |
17 | "eslint-plugin-import": "^1.16.0", | 17 | "eslint-plugin-import": "^1.16.0", |
18 | "eslint-plugin-jsx-a11y": "^2.2.3", | 18 | "eslint-plugin-jsx-a11y": "^2.2.3", |
19 | "eslint-plugin-meteor": "^4.0.1", | 19 | "eslint-plugin-meteor": "^4.0.1", |
20 | "eslint-plugin-react": "^6.4.1" | 20 | "eslint-plugin-react": "^6.4.1" |
21 | }, | 21 | }, |
22 | "eslintConfig": { | 22 | "eslintConfig": { |
23 | "parserOptions": { | 23 | "parserOptions": { |
24 | "ecmaFeatures": { | 24 | "ecmaFeatures": { |
25 | "jsx": true | 25 | "jsx": true |
26 | } | 26 | } |
27 | }, | 27 | }, |
28 | "plugins": [ | 28 | "plugins": [ |
29 | "meteor", | 29 | "meteor", |
30 | "react" | 30 | "react" |
31 | ], | 31 | ], |
32 | "extends": [ | 32 | "extends": [ |
33 | "airbnb/base", | 33 | "airbnb/base", |
34 | "plugin:meteor/guide", | 34 | "plugin:meteor/guide", |
35 | "plugin:react/recommended" | 35 | "plugin:react/recommended" |
36 | ], | 36 | ], |
37 | "env": { | 37 | "env": { |
38 | "browser": true | 38 | "browser": true |
39 | }, | 39 | }, |
40 | "globals": { | 40 | "globals": { |
41 | "server": false, | 41 | "server": false, |
42 | "browser": false, | 42 | "browser": false, |
43 | "expect": false | 43 | "expect": false |
44 | }, | 44 | }, |
45 | "rules": { | 45 | "rules": { |
46 | "import/no-unresolved": 0, | 46 | "import/no-unresolved": 0, |
47 | "import/no-extraneous-dependencies": 0, | 47 | "import/no-extraneous-dependencies": 0, |
48 | "import/extensions": 0, | 48 | "import/extensions": 0, |
49 | "no-underscore-dangle": [ | 49 | "no-underscore-dangle": [ |
50 | "error", | 50 | "error", |
51 | { | 51 | { |
52 | "allow": [ | 52 | "allow": [ |
53 | "_id", | 53 | "_id", |
54 | "_ensureIndex", | 54 | "_ensureIndex", |
55 | "_verifyEmailToken", | 55 | "_verifyEmailToken", |
56 | "_resetPasswordToken", | 56 | "_resetPasswordToken", |
57 | "_name" | 57 | "_name" |
58 | ] | 58 | ] |
59 | } | 59 | } |
60 | ], | 60 | ], |
61 | "class-methods-use-this": 0 | 61 | "class-methods-use-this": 0 |
62 | } | 62 | } |
63 | }, | 63 | }, |
64 | "dependencies": { | 64 | "dependencies": { |
65 | "babel-runtime": "^6.18.0", | 65 | "babel-runtime": "^6.18.0", |
66 | "babyparse": "^0.4.6", | 66 | "babyparse": "^0.4.6", |
67 | "bcrypt": "^0.8.7", | 67 | "bcrypt": "^0.8.7", |
68 | "bootstrap": "^4.0.0-alpha.6", | 68 | "bootstrap": "^4.0.0-alpha.6", |
69 | "csv2json-convertor": "^1.2.0", | ||
69 | "csvtojson": "^1.1.4", | 70 | "csvtojson": "^1.1.4", |
70 | "fs": "0.0.1-security", | 71 | "fs": "0.0.1-security", |
71 | "jquery": "^2.2.4", | 72 | "jquery": "^2.2.4", |
72 | "jquery-ui": "^1.12.1", | 73 | "jquery-ui": "^1.12.1", |
73 | "jquery-validation": "^1.15.1", | 74 | "jquery-validation": "^1.15.1", |
75 | "json2csv": "^3.7.3", | ||
74 | "lodash": "^4.17.4", | 76 | "lodash": "^4.17.4", |
75 | "material-fabmenu": "0.0.1", | 77 | "material-fabmenu": "0.0.1", |
76 | "material-ui": "^0.17.1", | 78 | "material-ui": "^0.17.1", |
77 | "meteor-node-stubs": "^0.2.6", | 79 | "meteor-node-stubs": "^0.2.6", |
78 | "moment": "^2.18.0", | 80 | "moment": "^2.18.0", |
79 | "react": "^15.4.2", | 81 | "react": "^15.4.2", |
80 | "react-addons-css-transition-group": "^15.4.2", | 82 | "react-addons-css-transition-group": "^15.4.2", |
81 | "react-addons-pure-render-mixin": "^15.3.2", | 83 | "react-addons-pure-render-mixin": "^15.3.2", |
82 | "react-addons-transition-group": "^15.4.2", | 84 | "react-addons-transition-group": "^15.4.2", |
83 | "react-bootstrap": "^0.30.8", | 85 | "react-bootstrap": "^0.30.8", |
84 | "react-bootstrap-date-picker": "^4.0.0", | 86 | "react-bootstrap-date-picker": "^4.0.0", |
85 | "react-burger-menu": "^1.10.14", | 87 | "react-burger-menu": "^1.10.14", |
86 | "react-dom": "^15.4.2", | 88 | "react-dom": "^15.4.2", |
87 | "react-fontawesome": "^1.5.0", | 89 | "react-fontawesome": "^1.5.0", |
88 | "react-komposer": "^1.13.1", | 90 | "react-komposer": "^1.13.1", |
89 | "react-router": "^2.6.1", | 91 | "react-router": "^2.6.1", |
90 | "react-router-bootstrap": "^0.23.1", | 92 | "react-router-bootstrap": "^0.23.1", |
91 | "react-stepzilla": "^4.3.4", | 93 | "react-stepzilla": "^4.3.4", |
92 | "react-svg": "^2.1.19", | 94 | "react-svg": "^2.1.19", |
93 | "react-tap-event-plugin": "^2.0.1", | 95 | "react-tap-event-plugin": "^2.0.1", |
94 | "reactstrap": "^4.3.0", | 96 | "reactstrap": "^4.3.0", |
95 | "velocity-animate": "^1.4.3", | 97 | "velocity-animate": "^1.4.3", |
96 | "velocity-react": "^1.2.1" | 98 | "velocity-react": "^1.2.1" |
97 | } | 99 | } |
98 | } | 100 | } |
99 | 101 |