From f9b486fe1c384e04584aa74447d02320937798ce Mon Sep 17 00:00:00 2001 From: Neeraj Sharma Date: Thu, 5 Dec 2019 13:28:07 +0530 Subject: [PATCH] implemrent all task --- src/Services/http.js | 2 +- src/pages/Administrator/bulkImport.vue | 109 ++++++++++++++++++++++++++++----- src/script/students.js | 34 ++++++++++ 3 files changed, 127 insertions(+), 18 deletions(-) diff --git a/src/Services/http.js b/src/Services/http.js index 2ed0575..bcd38b0 100644 --- a/src/Services/http.js +++ b/src/Services/http.js @@ -3,7 +3,7 @@ import store from '@/store/store' export default () => { return axios.create({ - // baseURL: 'http://192.168.0.108:3002/v1', + // baseURL: 'http://192.168.2.221:3002/v1', baseURL: 'http://13.234.251.173:8001/v1', headers: { Authorization: `Bearer ${store.state.token}` diff --git a/src/pages/Administrator/bulkImport.vue b/src/pages/Administrator/bulkImport.vue index f51eb38..517cea7 100644 --- a/src/pages/Administrator/bulkImport.vue +++ b/src/pages/Administrator/bulkImport.vue @@ -150,15 +150,22 @@ - + + - + refreshUpload - import + import @@ -170,7 +177,7 @@ - + + {{ text }} @@ -212,6 +227,14 @@ import bookData from "@/script/books.js"; export default { data: () => ({ + loading: false, + snackbar: false, + y: "top", + x: "right", + mode: "", + timeout: 3000, + text: "", + color: "", teacherData: [], studentData: [], parentData: [], @@ -221,12 +244,13 @@ export default { parentFileJson: [], userFileJson: [], bookFileJson: [], + studentFileJson: [], teacherFileName: "", parentFileName: "", userFileName: "", bookFileName: "", - token: "", - loading: false + bookStudentName: "", + token: "" }), methods: { pickFile() { @@ -241,6 +265,9 @@ export default { pickBookFile() { this.$refs.bookfile.click(); }, + pickStudentFile() { + this.$refs.studentfile.click(); + }, convertFile() { const input = document.getElementById("fileInput"); const reader = new FileReader(); @@ -248,10 +275,8 @@ export default { let text = reader.result; //convert text to json here var json = this.csvJSON(text); - // console.log("CSV: ", json); }; reader.readAsText(input.files[0]); - // console.log("input.files[0]", input.files[0].name); this.teacherFileName = input.files[0].name; }, parentFile() { @@ -261,10 +286,8 @@ export default { let text = reader.result; //convert text to json here var json = this.csvParentJSON(text); - // console.log("CSV: ", json); }; reader.readAsText(input.files[0]); - // console.log("input.files[0]", input.files[0].name); this.parentFileName = input.files[0].name; }, userFile() { @@ -274,10 +297,8 @@ export default { let text = reader.result; //convert text to json here var json = this.csvUserJSON(text); - // console.log("CSV: ", json); }; reader.readAsText(input.files[0]); - // console.log("input.files[0]", input.files[0].name); this.userFileName = input.files[0].name; }, bookFile() { @@ -287,12 +308,21 @@ export default { let text = reader.result; //convert text to json here var json = this.csvBookJSON(text); - // console.log("CSV: ", json); }; reader.readAsText(input.files[0]); - // console.log("input.files[0]", input.files[0].name); this.bookFileName = input.files[0].name; }, + studentFile() { + const input = document.getElementById("studentInput"); + const reader = new FileReader(); + reader.onload = () => { + let text = reader.result; + //convert text to json here + var json = this.csvStudentJSON(text); + }; + reader.readAsText(input.files[0]); + this.bookStudentName = input.files[0].name; + }, csvJSON(csv) { var lines = csv.split("\n"); @@ -306,7 +336,6 @@ export default { for (var j = 0; j < headers.length; j++) { obj[headers[j]] = currentline[j]; } - console.log("obj", obj); this.teacherFileJson.push(obj); } }, @@ -324,7 +353,6 @@ export default { for (var j = 0; j < headers.length; j++) { obj[headers[j]] = currentline[j]; } - this.parentFileJson.push(obj); } }, @@ -364,6 +392,23 @@ export default { this.bookFileJson.push(obj); } }, + csvStudentJSON(cvsBook) { + var lines = cvsBook.split("\n"); + + var result = []; + + var headers = lines[0].split(","); + + for (var i = 1; i < lines.length; i++) { + var obj = {}; + var currentline = lines[i].split(","); + + for (var j = 0; j < headers.length; j++) { + obj[headers[j]] = currentline[j]; + } + this.studentFileJson.push(obj); + } + }, importTeacher() { this.loading = true; var teacherfile = {}; @@ -375,11 +420,13 @@ export default { .then(response => { this.snackbar = true; this.text = response.data.message; + this.color = "green"; this.loading = false; }) .catch(error => { this.snackbar = true; this.text = error.response.data.message; + this.color = "red"; this.loading = false; }); }, @@ -394,12 +441,14 @@ export default { .then(response => { this.snackbar = true; this.text = response.data.message; + this.color = "green"; this.loading = false; }) .catch(error => { this.snackbar = true; this.text = error.response.data.message; this.loading = false; + this.color = "red"; }); }, importUser() { @@ -413,12 +462,14 @@ export default { .then(response => { this.snackbar = true; this.text = response.data.message; + this.color = "green"; this.loading = false; }) .catch(error => { this.snackbar = true; this.text = error.response.data.message; this.loading = false; + this.color = "red"; }); }, importBook() { @@ -432,17 +483,41 @@ export default { .then(response => { this.snackbar = true; this.text = response.data.message; + this.color = "green"; + this.loading = false; + }) + .catch(error => { + this.snackbar = true; + this.text = error.response.data.message; + this.color = "red"; + this.loading = false; + }); + }, + importStudent() { + this.loading = true; + var studentfile = {}; + studentfile.studentData = this.studentFileJson; + http() + .post("/importStudentData", studentfile, { + headers: { Authorization: "Bearer " + this.token } + }) + .then(response => { + this.snackbar = true; + this.text = response.data.message; + this.color = "green"; this.loading = false; }) .catch(error => { this.snackbar = true; this.text = error.response.data.message; + this.color = "red"; this.loading = false; }); } }, mounted() { this.token = this.$store.state.token; + /** TEACHERS SAMPLE CSV */ const getTeacherData = teacherData(); this.teacherData = getTeacherData; diff --git a/src/script/students.js b/src/script/students.js index 936330b..661fe8a 100644 --- a/src/script/students.js +++ b/src/script/students.js @@ -3,28 +3,62 @@ export default () => { const students = [{ "name": "Rishav Singla", "email": "rsingla.rishu@gmail.com", + "className": "1", + "sectionName": "A", "rollNo": "1", "dob": "1993-10-08", "gender": "Male", "bloodGroup": "A+", "mobile": "9914092452", + "height": "5'11", + "medicalNotes": "No", "city": "Chandigarh", "country": "India", "presentAddress": "Mohali Sector ", "state": "Punjab", + "allergies": "No", + "establishmentYear": "2019", + "fatherCellNo": "09988772222", + "fatherName": "Raj", + "parentEmail": "rajkumar123@gmail.com", + "motherCellNo": "8877112266", + "motherName": "Simran", + "permanentAddress": "Mohali", + "pincode": "160062", + "presentAddress": "Mohali Sector ", + "role": 4, + "rollNo": "1", + "weight": "72" }, { "name": "Shubham Chugh", "email": "shubham@theideazfactory.com", + "className": "10", + "sectionName": "A", "rollNo": "2", "dob": "1994-05-29", "gender": "Male", "bloodGroup": "A+", "mobile": "8077362128", + "height": "5'8", + "medicalNotes": "No", + "motherCellNo": "7878654323", "city": "Chandigarh", "country": "India", "presentAddress": "#1571, ground floor, sector 7C", "state": "Chandigarh", + "allergies": "No", + "establishmentYear": "2019", + "parentEmail": "SureshKumar321@gmail.com", + "fatherCellNo": "09898787865", + "fatherName": "Suresh Kumar", + "motherName": "Shinki", + "permanentAddress": "Sector 43 Chandigarh", + "pincode": " 160036", + "presentAddress": "Sector 43 Chandigarh", + "role": 4, + "rollNo": "2", + "weight": "70" }, ] return students; -- 2.0.0