Commit f9b486fe1c384e04584aa74447d02320937798ce

Authored by Neeraj Sharma
1 parent 6fe35f887d

implemrent all task

src/Services/http.js
... ... @@ -3,7 +3,7 @@ import store from '@/store/store'
3 3  
4 4 export default () => {
5 5 return axios.create({
6   - // baseURL: 'http://192.168.0.108:3002/v1',
  6 + // baseURL: 'http://192.168.2.221:3002/v1',
7 7 baseURL: 'http://13.234.251.173:8001/v1',
8 8 headers: {
9 9 Authorization: `Bearer ${store.state.token}`
... ...
src/pages/Administrator/bulkImport.vue
... ... @@ -150,15 +150,22 @@
150 150 <label class="title right">Add Student:</label>
151 151 </v-flex>
152 152 <v-flex xs12 sm6 lg3>
153   - <v-text-field placeholder="Choose file" :disabled="true"></v-text-field>
  153 + <v-text-field placeholder="Choose file" v-model="bookStudentName" :disabled="true"></v-text-field>
  154 + <input
  155 + type="file"
  156 + style="display: none"
  157 + ref="studentfile"
  158 + @change="studentFile"
  159 + id="studentInput"
  160 + />
154 161 </v-flex>
155 162 <v-flex xs6 sm4 lg2 class="mt-1">
156   - <v-btn class="grey" dark block>
  163 + <v-btn class="grey" dark block @click="pickStudentFile">
157 164 <v-icon small class="pr-1">refresh</v-icon>Upload
158 165 </v-btn>
159 166 </v-flex>
160 167 <v-flex xs6 sm4 lg2 class="mt-1">
161   - <v-btn class="grey" dark block>import</v-btn>
  168 + <v-btn class="grey" dark block @click="importStudent()">import</v-btn>
162 169 </v-flex>
163 170 <v-flex xs12 sm4 lg2 class="mt-1">
164 171 <download-csv :data="studentData">
... ... @@ -170,7 +177,7 @@
170 177 </v-layout>
171 178 </v-flex>
172 179 </v-layout>
173   - <v-layout>
  180 + <!-- <v-layout>
174 181 <v-flex xs12>
175 182 <v-layout wrap>
176 183 <v-flex xs9 sm5 lg2 class="pt-4">
... ... @@ -194,9 +201,17 @@
194 201 </v-flex>
195 202 </v-layout>
196 203 </v-flex>
197   - </v-layout>
  204 + </v-layout>-->
198 205 </v-container>
199 206 </v-card>
  207 + <v-snackbar
  208 + :timeout="timeout"
  209 + :top="y === 'top'"
  210 + :right="x === 'right'"
  211 + :vertical="mode === 'vertical'"
  212 + v-model="snackbar"
  213 + :color= color
  214 + >{{ text }}</v-snackbar>
200 215 </v-container>
201 216 </template>
202 217  
... ... @@ -212,6 +227,14 @@ import bookData from &quot;@/script/books.js&quot;;
212 227  
213 228 export default {
214 229 data: () => ({
  230 + loading: false,
  231 + snackbar: false,
  232 + y: "top",
  233 + x: "right",
  234 + mode: "",
  235 + timeout: 3000,
  236 + text: "",
  237 + color: "",
215 238 teacherData: [],
216 239 studentData: [],
217 240 parentData: [],
... ... @@ -221,12 +244,13 @@ export default {
221 244 parentFileJson: [],
222 245 userFileJson: [],
223 246 bookFileJson: [],
  247 + studentFileJson: [],
224 248 teacherFileName: "",
225 249 parentFileName: "",
226 250 userFileName: "",
227 251 bookFileName: "",
228   - token: "",
229   - loading: false
  252 + bookStudentName: "",
  253 + token: ""
230 254 }),
231 255 methods: {
232 256 pickFile() {
... ... @@ -241,6 +265,9 @@ export default {
241 265 pickBookFile() {
242 266 this.$refs.bookfile.click();
243 267 },
  268 + pickStudentFile() {
  269 + this.$refs.studentfile.click();
  270 + },
244 271 convertFile() {
245 272 const input = document.getElementById("fileInput");
246 273 const reader = new FileReader();
... ... @@ -248,10 +275,8 @@ export default {
248 275 let text = reader.result;
249 276 //convert text to json here
250 277 var json = this.csvJSON(text);
251   - // console.log("CSV: ", json);
252 278 };
253 279 reader.readAsText(input.files[0]);
254   - // console.log("input.files[0]", input.files[0].name);
255 280 this.teacherFileName = input.files[0].name;
256 281 },
257 282 parentFile() {
... ... @@ -261,10 +286,8 @@ export default {
261 286 let text = reader.result;
262 287 //convert text to json here
263 288 var json = this.csvParentJSON(text);
264   - // console.log("CSV: ", json);
265 289 };
266 290 reader.readAsText(input.files[0]);
267   - // console.log("input.files[0]", input.files[0].name);
268 291 this.parentFileName = input.files[0].name;
269 292 },
270 293 userFile() {
... ... @@ -274,10 +297,8 @@ export default {
274 297 let text = reader.result;
275 298 //convert text to json here
276 299 var json = this.csvUserJSON(text);
277   - // console.log("CSV: ", json);
278 300 };
279 301 reader.readAsText(input.files[0]);
280   - // console.log("input.files[0]", input.files[0].name);
281 302 this.userFileName = input.files[0].name;
282 303 },
283 304 bookFile() {
... ... @@ -287,12 +308,21 @@ export default {
287 308 let text = reader.result;
288 309 //convert text to json here
289 310 var json = this.csvBookJSON(text);
290   - // console.log("CSV: ", json);
291 311 };
292 312 reader.readAsText(input.files[0]);
293   - // console.log("input.files[0]", input.files[0].name);
294 313 this.bookFileName = input.files[0].name;
295 314 },
  315 + studentFile() {
  316 + const input = document.getElementById("studentInput");
  317 + const reader = new FileReader();
  318 + reader.onload = () => {
  319 + let text = reader.result;
  320 + //convert text to json here
  321 + var json = this.csvStudentJSON(text);
  322 + };
  323 + reader.readAsText(input.files[0]);
  324 + this.bookStudentName = input.files[0].name;
  325 + },
296 326 csvJSON(csv) {
297 327 var lines = csv.split("\n");
298 328  
... ... @@ -306,7 +336,6 @@ export default {
306 336 for (var j = 0; j < headers.length; j++) {
307 337 obj[headers[j]] = currentline[j];
308 338 }
309   - console.log("obj", obj);
310 339 this.teacherFileJson.push(obj);
311 340 }
312 341 },
... ... @@ -324,7 +353,6 @@ export default {
324 353 for (var j = 0; j < headers.length; j++) {
325 354 obj[headers[j]] = currentline[j];
326 355 }
327   -
328 356 this.parentFileJson.push(obj);
329 357 }
330 358 },
... ... @@ -364,6 +392,23 @@ export default {
364 392 this.bookFileJson.push(obj);
365 393 }
366 394 },
  395 + csvStudentJSON(cvsBook) {
  396 + var lines = cvsBook.split("\n");
  397 +
  398 + var result = [];
  399 +
  400 + var headers = lines[0].split(",");
  401 +
  402 + for (var i = 1; i < lines.length; i++) {
  403 + var obj = {};
  404 + var currentline = lines[i].split(",");
  405 +
  406 + for (var j = 0; j < headers.length; j++) {
  407 + obj[headers[j]] = currentline[j];
  408 + }
  409 + this.studentFileJson.push(obj);
  410 + }
  411 + },
367 412 importTeacher() {
368 413 this.loading = true;
369 414 var teacherfile = {};
... ... @@ -375,11 +420,13 @@ export default {
375 420 .then(response => {
376 421 this.snackbar = true;
377 422 this.text = response.data.message;
  423 + this.color = "green";
378 424 this.loading = false;
379 425 })
380 426 .catch(error => {
381 427 this.snackbar = true;
382 428 this.text = error.response.data.message;
  429 + this.color = "red";
383 430 this.loading = false;
384 431 });
385 432 },
... ... @@ -394,12 +441,14 @@ export default {
394 441 .then(response => {
395 442 this.snackbar = true;
396 443 this.text = response.data.message;
  444 + this.color = "green";
397 445 this.loading = false;
398 446 })
399 447 .catch(error => {
400 448 this.snackbar = true;
401 449 this.text = error.response.data.message;
402 450 this.loading = false;
  451 + this.color = "red";
403 452 });
404 453 },
405 454 importUser() {
... ... @@ -413,12 +462,14 @@ export default {
413 462 .then(response => {
414 463 this.snackbar = true;
415 464 this.text = response.data.message;
  465 + this.color = "green";
416 466 this.loading = false;
417 467 })
418 468 .catch(error => {
419 469 this.snackbar = true;
420 470 this.text = error.response.data.message;
421 471 this.loading = false;
  472 + this.color = "red";
422 473 });
423 474 },
424 475 importBook() {
... ... @@ -432,17 +483,41 @@ export default {
432 483 .then(response => {
433 484 this.snackbar = true;
434 485 this.text = response.data.message;
  486 + this.color = "green";
  487 + this.loading = false;
  488 + })
  489 + .catch(error => {
  490 + this.snackbar = true;
  491 + this.text = error.response.data.message;
  492 + this.color = "red";
  493 + this.loading = false;
  494 + });
  495 + },
  496 + importStudent() {
  497 + this.loading = true;
  498 + var studentfile = {};
  499 + studentfile.studentData = this.studentFileJson;
  500 + http()
  501 + .post("/importStudentData", studentfile, {
  502 + headers: { Authorization: "Bearer " + this.token }
  503 + })
  504 + .then(response => {
  505 + this.snackbar = true;
  506 + this.text = response.data.message;
  507 + this.color = "green";
435 508 this.loading = false;
436 509 })
437 510 .catch(error => {
438 511 this.snackbar = true;
439 512 this.text = error.response.data.message;
  513 + this.color = "red";
440 514 this.loading = false;
441 515 });
442 516 }
443 517 },
444 518 mounted() {
445 519 this.token = this.$store.state.token;
  520 +
446 521 /** TEACHERS SAMPLE CSV */
447 522 const getTeacherData = teacherData();
448 523 this.teacherData = getTeacherData;
... ...
src/script/students.js
... ... @@ -3,28 +3,62 @@ export default () =&gt; {
3 3 const students = [{
4 4 "name": "Rishav Singla",
5 5 "email": "rsingla.rishu@gmail.com",
  6 + "className": "1",
  7 + "sectionName": "A",
6 8 "rollNo": "1",
7 9 "dob": "1993-10-08",
8 10 "gender": "Male",
9 11 "bloodGroup": "A+",
10 12 "mobile": "9914092452",
  13 + "height": "5'11",
  14 + "medicalNotes": "No",
11 15 "city": "Chandigarh",
12 16 "country": "India",
13 17 "presentAddress": "Mohali Sector ",
14 18 "state": "Punjab",
  19 + "allergies": "No",
  20 + "establishmentYear": "2019",
  21 + "fatherCellNo": "09988772222",
  22 + "fatherName": "Raj",
  23 + "parentEmail": "rajkumar123@gmail.com",
  24 + "motherCellNo": "8877112266",
  25 + "motherName": "Simran",
  26 + "permanentAddress": "Mohali",
  27 + "pincode": "160062",
  28 + "presentAddress": "Mohali Sector ",
  29 + "role": 4,
  30 + "rollNo": "1",
  31 + "weight": "72"
15 32 },
16 33 {
17 34 "name": "Shubham Chugh",
18 35 "email": "shubham@theideazfactory.com",
  36 + "className": "10",
  37 + "sectionName": "A",
19 38 "rollNo": "2",
20 39 "dob": "1994-05-29",
21 40 "gender": "Male",
22 41 "bloodGroup": "A+",
23 42 "mobile": "8077362128",
  43 + "height": "5'8",
  44 + "medicalNotes": "No",
  45 + "motherCellNo": "7878654323",
24 46 "city": "Chandigarh",
25 47 "country": "India",
26 48 "presentAddress": "#1571, ground floor, sector 7C",
27 49 "state": "Chandigarh",
  50 + "allergies": "No",
  51 + "establishmentYear": "2019",
  52 + "parentEmail": "SureshKumar321@gmail.com",
  53 + "fatherCellNo": "09898787865",
  54 + "fatherName": "Suresh Kumar",
  55 + "motherName": "Shinki",
  56 + "permanentAddress": "Sector 43 Chandigarh",
  57 + "pincode": " 160036",
  58 + "presentAddress": "Sector 43 Chandigarh",
  59 + "role": 4,
  60 + "rollNo": "2",
  61 + "weight": "70"
28 62 },
29 63 ]
30 64 return students;
... ...