Blame view
src/pages/Administrator/bulkImport.vue
18.7 KB
1c69557ac
|
1 2 3 |
<template> <v-container fluid grid-list-md> <v-card flat> |
68d742034
|
4 |
<v-toolbar class="card-styles" dark flat> |
1c69557ac
|
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<v-spacer></v-spacer> <v-toolbar-title>Import</v-toolbar-title> <v-spacer></v-spacer> </v-toolbar> <v-container fluid> <v-layout> <v-flex xs12> <v-layout wrap> <v-flex xs6 sm5 lg2 class="pt-4"> <label class="title right">Add Teacher:</label> </v-flex> <v-flex xs12 sm6 lg3> <v-text-field v-model="teacherFileName" placeholder="Choose file" :disabled="true"></v-text-field> <input type="file" style="display: none" ref="file" |
6fe35f887
|
22 23 |
@change="convertFile" id="fileInput" |
1c69557ac
|
24 25 26 |
/> </v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> |
68d742034
|
27 |
<v-btn class="open-dialog-button" round dark block @click="pickFile"> |
1c69557ac
|
28 29 30 31 |
<v-icon small class="pr-1">refresh</v-icon>Upload </v-btn> </v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> |
68d742034
|
32 33 34 35 36 37 38 39 |
<v-btn class="add-button" round dark block @click="importTeacher()" :loading="loading" >import</v-btn> |
1c69557ac
|
40 41 42 |
</v-flex> <v-flex xs12 sm4 lg2 class="mt-1"> <download-csv :data="teacherData"> |
68d742034
|
43 |
<v-btn class="blue lighten-2" dark block round> |
1c69557ac
|
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<v-icon small class="pr-1">archive</v-icon>sample download </v-btn> </download-csv> </v-flex> </v-layout> </v-flex> </v-layout> <v-layout> <v-flex xs12> <v-layout wrap> <v-flex xs6 sm5 lg2 class="pt-4"> <label class="title right">Add Parent:</label> </v-flex> <v-flex xs12 sm6 lg3> <v-text-field v-model="parentFileName" placeholder="Choose file" :disabled="true"></v-text-field> |
6fe35f887
|
59 60 61 62 63 64 65 |
<input type="file" style="display: none" ref="parentfile" @change="parentFile" id="parentInput" /> |
1c69557ac
|
66 67 |
</v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> |
68d742034
|
68 |
<v-btn class="open-dialog-button" round dark block @click="pickParentFile"> |
1c69557ac
|
69 70 71 |
<v-icon small class="pr-1">refresh</v-icon>Upload </v-btn> </v-flex> |
748acd1a6
|
72 |
<v-flex xs6 sm4 lg2 class="mt-1" @click="importParent" :loading="parentLoading"> |
68d742034
|
73 |
<v-btn class="add-button" round dark block>import</v-btn> |
1c69557ac
|
74 75 76 |
</v-flex> <v-flex xs12 sm4 lg2 class="mt-1"> <download-csv :data="parentData"> |
68d742034
|
77 |
<v-btn class="blue lighten-2" dark block round> |
1c69557ac
|
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
<v-icon small class="pr-1">archive</v-icon>sample download </v-btn> </download-csv> </v-flex> </v-layout> </v-flex> </v-layout> <v-layout> <v-flex xs12> <v-layout wrap> <v-flex xs6 sm5 lg2 class="pt-4"> <label class="title right">Add User:</label> </v-flex> <v-flex xs12 sm6 lg3> |
6fe35f887
|
92 93 94 95 96 97 98 99 |
<v-text-field placeholder="Choose file" v-model="userFileName" :disabled="true"></v-text-field> <input type="file" style="display: none" ref="userfile" @change="userFile" id="userInput" /> |
1c69557ac
|
100 101 |
</v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> |
68d742034
|
102 |
<v-btn class="open-dialog-button" round dark block @click="pickUserFile"> |
1c69557ac
|
103 104 105 106 |
<v-icon small class="pr-1">refresh</v-icon>Upload </v-btn> </v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> |
68d742034
|
107 108 109 110 111 112 113 114 |
<v-btn class="add-button" round dark block @click="importUser" :loading="userLoading" >import</v-btn> |
1c69557ac
|
115 116 117 |
</v-flex> <v-flex xs12 sm4 lg2 class="mt-1"> <download-csv :data="userData"> |
68d742034
|
118 |
<v-btn class="blue lighten-2" dark block round> |
1c69557ac
|
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
<v-icon small class="pr-1">archive</v-icon>sample download </v-btn> </download-csv> </v-flex> </v-layout> </v-flex> </v-layout> <v-layout> <v-flex xs12> <v-layout wrap> <v-flex xs6 sm5 lg2 class="pt-4"> <label class="title right">Add Book:</label> </v-flex> <v-flex xs12 sm6 lg3> |
6fe35f887
|
133 134 135 136 137 138 139 140 |
<v-text-field placeholder="Choose file" v-model="bookFileName" :disabled="true"></v-text-field> <input type="file" style="display: none" ref="bookfile" @change="bookFile" id="bookInput" /> |
1c69557ac
|
141 142 |
</v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> |
68d742034
|
143 |
<v-btn class="open-dialog-button" round dark block @click="pickBookFile"> |
1c69557ac
|
144 145 146 147 |
<v-icon small class="pr-1">refresh</v-icon>Upload </v-btn> </v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> |
68d742034
|
148 149 150 151 152 153 154 155 |
<v-btn class="add-button" round dark block @click="importBook" :loading="BookLoading" >import</v-btn> |
1c69557ac
|
156 157 158 |
</v-flex> <v-flex xs12 sm4 lg2 class="mt-1"> <download-csv :data="bookData"> |
68d742034
|
159 |
<v-btn class="blue lighten-2" dark block round > |
1c69557ac
|
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
<v-icon small class="pr-1">archive</v-icon>sample download </v-btn> </download-csv> </v-flex> </v-layout> </v-flex> </v-layout> <v-layout> <v-flex xs12> <v-layout wrap> <v-flex xs6 sm5 lg2 class="pt-4"> <label class="title right">Add Student:</label> </v-flex> <v-flex xs12 sm6 lg3> |
f9b486fe1
|
174 175 176 177 178 179 180 181 |
<v-text-field placeholder="Choose file" v-model="bookStudentName" :disabled="true"></v-text-field> <input type="file" style="display: none" ref="studentfile" @change="studentFile" id="studentInput" /> |
1c69557ac
|
182 183 |
</v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> |
68d742034
|
184 |
<v-btn class="open-dialog-button" round dark block @click="pickStudentFile"> |
1c69557ac
|
185 186 187 188 |
<v-icon small class="pr-1">refresh</v-icon>Upload </v-btn> </v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> |
748acd1a6
|
189 |
<v-btn |
68d742034
|
190 191 |
class="add-button" round |
748acd1a6
|
192 193 194 195 196 |
dark block @click="importStudent()" :loading="studentLoading" >import</v-btn> |
1c69557ac
|
197 198 199 |
</v-flex> <v-flex xs12 sm4 lg2 class="mt-1"> <download-csv :data="studentData"> |
68d742034
|
200 |
<v-btn class="blue lighten-2" round dark block> |
1c69557ac
|
201 202 203 204 205 206 207 |
<v-icon small class="pr-1">archive</v-icon>sample download </v-btn> </download-csv> </v-flex> </v-layout> </v-flex> </v-layout> |
f9b486fe1
|
208 |
<!-- <v-layout> |
1c69557ac
|
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
<v-flex xs12> <v-layout wrap> <v-flex xs9 sm5 lg2 class="pt-4"> <label class="title right">Students & Parents:</label> </v-flex> <v-flex xs12 sm6 lg3> <v-text-field placeholder="Choose file" :disabled="true"></v-text-field> </v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> <v-btn class="grey" dark block> <v-icon small class="pr-1">refresh</v-icon>Upload </v-btn> </v-flex> <v-flex xs6 sm4 lg2 class="mt-1"> <v-btn class="grey" dark block>import</v-btn> </v-flex> <v-flex xs12 sm4 lg2 class="mt-1"> <v-btn class="blue lighten-2" dark block> <v-icon small class="pr-1">archive</v-icon>sample download </v-btn> </v-flex> </v-layout> </v-flex> |
f9b486fe1
|
232 |
</v-layout>--> |
1c69557ac
|
233 234 |
</v-container> </v-card> |
f9b486fe1
|
235 236 237 238 239 240 |
<v-snackbar :timeout="timeout" :top="y === 'top'" :right="x === 'right'" :vertical="mode === 'vertical'" v-model="snackbar" |
748acd1a6
|
241 |
:color="color" |
f9b486fe1
|
242 |
>{{ text }}</v-snackbar> |
1c69557ac
|
243 244 245 246 247 248 249 250 251 252 253 254 |
</v-container> </template> <script> import http from "@/Services/http.js"; import moment from "moment"; import teacherData from "@/script/teachers.js"; import studentData from "@/script/students.js"; import parentData from "@/script/parents.js"; import userData from "@/script/users.js"; import bookData from "@/script/books.js"; |
748acd1a6
|
255 |
import XLSX from "xlsx"; |
1c69557ac
|
256 257 258 |
export default { data: () => ({ |
f9b486fe1
|
259 |
loading: false, |
748acd1a6
|
260 261 262 263 |
parentLoading: false, userLoading: false, BookLoading: false, studentLoading: false, |
f9b486fe1
|
264 265 266 267 268 269 270 |
snackbar: false, y: "top", x: "right", mode: "", timeout: 3000, text: "", color: "", |
1c69557ac
|
271 272 273 274 275 |
teacherData: [], studentData: [], parentData: [], userData: [], bookData: [], |
6fe35f887
|
276 277 278 279 |
teacherFileJson: [], parentFileJson: [], userFileJson: [], bookFileJson: [], |
f9b486fe1
|
280 |
studentFileJson: [], |
1c69557ac
|
281 |
teacherFileName: "", |
1c69557ac
|
282 |
parentFileName: "", |
6fe35f887
|
283 284 |
userFileName: "", bookFileName: "", |
f9b486fe1
|
285 286 |
bookStudentName: "", token: "" |
1c69557ac
|
287 288 289 290 291 |
}), methods: { pickFile() { this.$refs.file.click(); }, |
6fe35f887
|
292 293 294 295 296 297 298 299 300 |
pickParentFile() { this.$refs.parentfile.click(); }, pickUserFile() { this.$refs.userfile.click(); }, pickBookFile() { this.$refs.bookfile.click(); }, |
f9b486fe1
|
301 302 303 |
pickStudentFile() { this.$refs.studentfile.click(); }, |
748acd1a6
|
304 |
convertFile(e) { |
6fe35f887
|
305 |
const input = document.getElementById("fileInput"); |
6fe35f887
|
306 |
this.teacherFileName = input.files[0].name; |
748acd1a6
|
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
// const reader = new FileReader(); // console.log("reader", reader); // reader.onload = () => { // let text = reader.result; // //convert text to json here // console.log("text", text); // var json = this.csvJSON(text); // }; // reader.readAsText(input.files[0]); var files = e.target.files, f = files[0]; var reader = new FileReader(); let array = []; let _this = this; reader.onload = function(e) { var data = new Uint8Array(e.target.result); var workbook = XLSX.read(data, { type: "array" }); let sheetName = workbook.SheetNames[0]; // /* DO SOMETHING WITH workbook HERE */ let worksheet = workbook.Sheets[sheetName]; array = XLSX.utils.sheet_to_json(worksheet); _this.teacherFileJson = array; }; reader.readAsArrayBuffer(f); |
6fe35f887
|
331 |
}, |
748acd1a6
|
332 |
parentFile(e) { |
6fe35f887
|
333 |
const input = document.getElementById("parentInput"); |
6fe35f887
|
334 |
this.parentFileName = input.files[0].name; |
748acd1a6
|
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
console.log("this.parentFileName", this.parentFileName); var files = e.target.files, f = files[0]; var reader = new FileReader(); let array = []; let _this = this; reader.onload = function(e) { var data = new Uint8Array(e.target.result); var workbook = XLSX.read(data, { type: "array" }); let sheetName = workbook.SheetNames[0]; // /* DO SOMETHING WITH workbook HERE */ let worksheet = workbook.Sheets[sheetName]; array = XLSX.utils.sheet_to_json(worksheet); _this.parentFileJson = array; }; reader.readAsArrayBuffer(f); |
6fe35f887
|
351 |
}, |
748acd1a6
|
352 |
userFile(e) { |
6fe35f887
|
353 |
const input = document.getElementById("userInput"); |
6fe35f887
|
354 |
this.userFileName = input.files[0].name; |
748acd1a6
|
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
var files = e.target.files, f = files[0]; var reader = new FileReader(); let array = []; let _this = this; reader.onload = function(e) { var data = new Uint8Array(e.target.result); var workbook = XLSX.read(data, { type: "array" }); let sheetName = workbook.SheetNames[0]; // /* DO SOMETHING WITH workbook HERE */ let worksheet = workbook.Sheets[sheetName]; array = XLSX.utils.sheet_to_json(worksheet); _this.userFileJson = array; }; reader.readAsArrayBuffer(f); |
6fe35f887
|
370 |
}, |
748acd1a6
|
371 |
bookFile(e) { |
6fe35f887
|
372 |
const input = document.getElementById("bookInput"); |
6fe35f887
|
373 |
this.bookFileName = input.files[0].name; |
748acd1a6
|
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
console.log("this.bookFileName", this.bookFileName); var files = e.target.files, f = files[0]; console.log("this.bookFileName", files); var reader = new FileReader(); console.log("reader================", reader); let array = []; let _this = this; reader.onload = function(e) { console.log("data", e.target.result); var data = new Uint8Array(e.target.result); console.log("data", data); var workbook = XLSX.read(data, { type: "array" }); let sheetName = workbook.SheetNames[0]; // /* DO SOMETHING WITH workbook HERE */ let worksheet = workbook.Sheets[sheetName]; array = XLSX.utils.sheet_to_json(worksheet); _this.bookFileJson = array; console.log("this.bookFileJson ", _this.bookFileJson); }; reader.readAsArrayBuffer(f); |
6fe35f887
|
395 |
}, |
748acd1a6
|
396 |
studentFile(e) { |
f9b486fe1
|
397 |
const input = document.getElementById("studentInput"); |
f9b486fe1
|
398 |
this.bookStudentName = input.files[0].name; |
748acd1a6
|
399 400 401 402 403 404 405 |
var files = e.target.files, f = files[0]; var reader = new FileReader(); let array = []; let _this = this; reader.onload = function(e) { var data = new Uint8Array(e.target.result); |
080d88547
|
406 |
var workbook = XLSX.read(data, { type: "array", cellDates: true }); |
748acd1a6
|
407 408 409 410 411 412 413 |
let sheetName = workbook.SheetNames[0]; // /* DO SOMETHING WITH workbook HERE */ let worksheet = workbook.Sheets[sheetName]; array = XLSX.utils.sheet_to_json(worksheet); _this.studentFileJson = array; }; reader.readAsArrayBuffer(f); |
f9b486fe1
|
414 |
}, |
748acd1a6
|
415 416 417 |
// csvJSON(csv) { // var lines = csv.split(" "); |
f9b486fe1
|
418 |
|
748acd1a6
|
419 420 |
// var result = []; // var headers = lines[0].split(","); |
f9b486fe1
|
421 |
|
748acd1a6
|
422 423 424 |
// for (var i = 1; i < lines.length; i++) { // var obj = {}; // var currentline = lines[i].split(","); |
f9b486fe1
|
425 |
|
748acd1a6
|
426 427 428 429 430 431 |
// for (var j = 0; j < headers.length; j++) { // obj[headers[j]] = currentline[j]; // } // this.teacherFileJson.push(obj); // } // }, |
6fe35f887
|
432 433 434 435 436 437 438 439 440 441 442 |
importTeacher() { this.loading = true; var teacherfile = {}; teacherfile.teacherData = this.teacherFileJson; http() .post("/importTeacherData", teacherfile, { headers: { Authorization: "Bearer " + this.token } }) .then(response => { this.snackbar = true; this.text = response.data.message; |
f9b486fe1
|
443 |
this.color = "green"; |
6fe35f887
|
444 445 446 447 448 |
this.loading = false; }) .catch(error => { this.snackbar = true; this.text = error.response.data.message; |
f9b486fe1
|
449 |
this.color = "red"; |
6fe35f887
|
450 451 452 453 |
this.loading = false; }); }, importParent() { |
748acd1a6
|
454 |
this.parentLoading = true; |
6fe35f887
|
455 456 457 458 459 460 461 462 463 |
var parentfile = {}; parentfile.parentData = this.parentFileJson; http() .post("/importParentData", parentfile, { headers: { Authorization: "Bearer " + this.token } }) .then(response => { this.snackbar = true; this.text = response.data.message; |
f9b486fe1
|
464 |
this.color = "green"; |
748acd1a6
|
465 |
this.parentLoading = false; |
6fe35f887
|
466 467 468 469 |
}) .catch(error => { this.snackbar = true; this.text = error.response.data.message; |
748acd1a6
|
470 |
this.parentLoading = false; |
f9b486fe1
|
471 |
this.color = "red"; |
6fe35f887
|
472 473 474 |
}); }, importUser() { |
748acd1a6
|
475 |
this.userLoading = true; |
6fe35f887
|
476 477 478 479 480 481 482 483 484 |
var userfile = {}; userfile.userData = this.userFileJson; http() .post("/importUserData", userfile, { headers: { Authorization: "Bearer " + this.token } }) .then(response => { this.snackbar = true; this.text = response.data.message; |
f9b486fe1
|
485 |
this.color = "green"; |
748acd1a6
|
486 |
this.userLoading = false; |
6fe35f887
|
487 488 489 490 |
}) .catch(error => { this.snackbar = true; this.text = error.response.data.message; |
748acd1a6
|
491 |
this.userLoading = false; |
f9b486fe1
|
492 |
this.color = "red"; |
6fe35f887
|
493 494 495 |
}); }, importBook() { |
748acd1a6
|
496 |
this.BookLoading = true; |
6fe35f887
|
497 498 499 500 501 502 503 504 505 |
var bookfile = {}; bookfile.bookData = this.bookFileJson; http() .post("/importBookData", bookfile, { headers: { Authorization: "Bearer " + this.token } }) .then(response => { this.snackbar = true; this.text = response.data.message; |
f9b486fe1
|
506 |
this.color = "green"; |
748acd1a6
|
507 |
this.BookLoading = false; |
f9b486fe1
|
508 509 510 511 512 |
}) .catch(error => { this.snackbar = true; this.text = error.response.data.message; this.color = "red"; |
748acd1a6
|
513 |
this.BookLoading = false; |
f9b486fe1
|
514 515 516 |
}); }, importStudent() { |
748acd1a6
|
517 |
this.studentLoading = true; |
f9b486fe1
|
518 |
var studentfile = {}; |
080d88547
|
519 |
console.log('this.studentFileJson', this.studentFileJson); |
f9b486fe1
|
520 521 522 523 524 525 526 527 528 |
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"; |
748acd1a6
|
529 |
this.studentLoading = false; |
6fe35f887
|
530 531 532 533 |
}) .catch(error => { this.snackbar = true; this.text = error.response.data.message; |
f9b486fe1
|
534 |
this.color = "red"; |
748acd1a6
|
535 |
this.studentLoading = false; |
6fe35f887
|
536 |
}); |
1c69557ac
|
537 538 539 |
} }, mounted() { |
6fe35f887
|
540 |
this.token = this.$store.state.token; |
f9b486fe1
|
541 |
|
1c69557ac
|
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
/** TEACHERS SAMPLE CSV */ const getTeacherData = teacherData(); this.teacherData = getTeacherData; /** STUDENTS SAMPLE CSV */ const getstudentData = studentData(); this.studentData = getstudentData; /** PARENTS SAMPLE CSV */ const getparentData = parentData(); this.parentData = getparentData; /** USERS SAMPLE CSV */ const getUserData = userData(); this.userData = getUserData; /** BOOKS SAMPLE CSV */ const getBookData = bookData(); this.bookData = getBookData; } }; |
6fe35f887
|
563 |
</script> |
68d742034
|
564 565 566 567 568 569 |
<style> .card-styles { background: #7f62f8 !important; border-color: #7f62f8 !important; } </style> |