Blame view
imports/client/views/org/admin/students/UploadCsv.js
2.84 KB
5d043355e
|
1 |
// import {UploadCsv } from '/imports/collections/students/UploadCsv' |
15998a6af
|
2 3 4 5 6 7 |
import _ from 'lodash'; import { Meteor } from 'meteor/meteor'; import React, { Component } from 'react'; import { Link,browserHistory } from 'react-router'; import { FormGroup,Panel,Table, |
b02441289
|
8 |
ButtonToolbar,Modal,ControlLabel,HelpBlock, |
15998a6af
|
9 |
FormControl,Glyphicon,Button } from 'react-bootstrap'; |
b02441289
|
10 |
// import { AddStudentForm } from './addStudentForm'; |
f3432726e
|
11 12 13 |
import { FilesCollection } from 'meteor/ostrio:files'; const Papa = this.Papa; // console.log(this); |
15998a6af
|
14 15 16 |
const style = { margin: 12, }; |
b02441289
|
17 18 19 20 21 22 23 24 25 |
function FieldGroup({ id, label, help, ...props }) { return ( <FormGroup controlId={id}> <ControlLabel>{label}</ControlLabel> <FormControl {...props} /> {help && <HelpBlock>{help}</HelpBlock>} </FormGroup> ); } |
15998a6af
|
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
export class UploadCsv extends Component { constructor(props) { super(props); this.state = { show: false }; this.showModal = this.showModal.bind(this); this.hideModal = this.hideModal.bind(this); this.onUpdate = this.onUpdate.bind(this); }; showModal() { this.setState({show: true}); } hideModal() { this.setState({show: false}); } onUpdate(key, value) { this.setState({[key]: value}); }; |
d0a93cc6d
|
47 48 49 |
uploadStudentCsv(e){ e.preventDefault(); e.persist(); |
f3432726e
|
50 51 |
var file = $('input[type="file"]').prop("files")[0]; Papa.parse(file, { |
5d043355e
|
52 53 54 55 56 |
header: true, complete: function(csvData) { console.log("csvData"); console.log(csvData); if(csvData){ |
f3432726e
|
57 |
Meteor.call('student.uploadCsv', csvData, function (error, result) { |
5d043355e
|
58 59 60 61 |
console.log("error"); console.log(error); console.log("result"); console.log(result); |
f3432726e
|
62 63 64 65 |
}) } } }); |
d0a93cc6d
|
66 |
} |
15998a6af
|
67 68 |
render() { |
b02441289
|
69 |
console.log(this.props); |
15998a6af
|
70 71 72 73 74 75 76 77 78 79 80 81 |
return ( <ButtonToolbar> <Button bsStyle="primary" onClick={this.showModal}> Upload CSV </Button> <Modal {...this.props} show={this.state.show} onHide={this.hideModal} dialogClassName="custom-modal" > <Modal.Header closeButton> |
925ffa9d3
|
82 |
<Modal.Title id="contained-modal-title-lg">Upload Csv file</Modal.Title> |
15998a6af
|
83 84 |
</Modal.Header> <Modal.Body> |
d0a93cc6d
|
85 |
<form onSubmit={ (e) => this.uploadStudentCsv(e) } > |
15998a6af
|
86 87 88 89 |
<FieldGroup id="formControlsFile" type="file" label="File" |
d5b679c21
|
90 |
help="Upload you CSV here." |
15998a6af
|
91 |
/> |
d0a93cc6d
|
92 |
<Button type="submit" bsStyle="default">Upload File</Button> |
b02441289
|
93 |
</form> |
15998a6af
|
94 95 96 97 98 99 100 101 102 103 |
</Modal.Body> <Modal.Footer> <Button onClick={this.hideModal}>Close</Button> </Modal.Footer> </Modal> </ButtonToolbar> ); }; }; |