Commit fa4edf92926eb8116080de2ee3efc183ff282be3
1 parent
8669ee94e5
Exists in
master
and in
3 other branches
added option of upload images and pdf
Showing
2 changed files
with
225 additions
and
164 deletions
Show diff stats
src/pages/Academic/assignment.vue
... | ... | @@ -12,34 +12,6 @@ |
12 | 12 | <v-container fluid> |
13 | 13 | <v-form ref="formEditAssignment" v-model="validEditAssignment" lazy-validation> |
14 | 14 | <v-layout> |
15 | - <v-flex | |
16 | - xs12 | |
17 | - class="text-xs-center text-sm-center text-md-center text-lg-center my-4 mr-4" | |
18 | - > | |
19 | - <v-avatar size="140px" v-if="!editedItem.file && !imageUrl"> | |
20 | - <img src="/static/icon/user.png" /> | |
21 | - </v-avatar> | |
22 | - <img | |
23 | - :src="editedItem.file" | |
24 | - v-else-if="editedItem.file && !imageUrl" | |
25 | - style="border-radius:50%; width:150px" | |
26 | - /> | |
27 | - <img | |
28 | - v-if="imageUrl" | |
29 | - :src="imageUrl" | |
30 | - height="150" | |
31 | - style="border-radius:50%; width:150px" | |
32 | - /> | |
33 | - <input | |
34 | - type="file" | |
35 | - style="display:none" | |
36 | - ref="image" | |
37 | - accept="image/*" | |
38 | - @change="onFilePicked" | |
39 | - /> | |
40 | - </v-flex> | |
41 | - </v-layout> | |
42 | - <v-layout> | |
43 | 15 | <v-flex xs4 class="pt-4 subheading"> |
44 | 16 | <label class="right">Title:</label> |
45 | 17 | </v-flex> |
... | ... | @@ -138,11 +110,12 @@ |
138 | 110 | </v-layout> |
139 | 111 | <v-layout> |
140 | 112 | <v-flex xs4 class="pt-4 subheading"> |
141 | - <label class="right">File:</label> | |
113 | + <label class="right hidden-xs-only hidden-sm-only">Uplaod File:</label> | |
114 | + <label class="right hidden-lg-only hidden-md-only hidden-xl-only">File :</label> | |
142 | 115 | </v-flex> |
143 | - <v-flex xs8 class="ml-3"> | |
116 | + <v-flex xs8 sm8 class="ml-3"> | |
144 | 117 | <v-text-field |
145 | - label="Select Image" | |
118 | + label="Select File" | |
146 | 119 | @click="pickFile" |
147 | 120 | v-model="imageName" |
148 | 121 | append-icon="attach_file" |
... | ... | @@ -268,7 +241,7 @@ |
268 | 241 | :search="search" |
269 | 242 | > |
270 | 243 | <template slot="items" slot-scope="props"> |
271 | - <tr class="tr"> | |
244 | + <tr class="tr" v-show="hideData"> | |
272 | 245 | <td class="td-row td">{{ props.index + 1 }}</td> |
273 | 246 | <td class="text-xs-center td td-row">{{ props.item.title }}</td> |
274 | 247 | <td class="text-xs-center td td-row">{{ props.item.description }}</td> |
... | ... | @@ -282,12 +255,18 @@ |
282 | 255 | class="text-xs-center td td-row" |
283 | 256 | v-if="role != 'TEACHER' " |
284 | 257 | >{{ props.item.schoolId .name }}</td> |
285 | - <!-- <td class="text-xs-center td td-row">{{ props.item.file }}</td> --> | |
258 | + <!-- <td class="td td-row text-xs-center" v-show="showPdfData"> | |
259 | + <a href="" target="" @click="exportFile">{{ props.item.file }}</a> | |
260 | + </td>--> | |
286 | 261 | <td class="text-xs-center td td-row"> |
287 | - <v-avatar> | |
288 | - <img :src="props.item.file" v-if="props.item.file" /> | |
289 | - <img src="/static/icon/user.png" v-else-if="!props.item.file" /> | |
290 | - </v-avatar> | |
262 | + <!-- <v-btn | |
263 | + class="right add-button" | |
264 | + @click="generatePDF2Canvas()" | |
265 | + :loading="loadingPdf" | |
266 | + dark | |
267 | + >--> | |
268 | + {{ props.item.file }} | |
269 | + <!-- </v-btn> --> | |
291 | 270 | </td> |
292 | 271 | <td class="text-xs-center td td-row"> |
293 | 272 | <span> |
... | ... | @@ -354,19 +333,6 @@ |
354 | 333 | <v-flex xs12> |
355 | 334 | <v-form ref="form" v-model="valid" lazy-validation> |
356 | 335 | <v-layout> |
357 | - <v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center"> | |
358 | - <v-avatar size="80px"> | |
359 | - <img src="/static/icon/user.png" v-if="!imageUrl" /> | |
360 | - </v-avatar> | |
361 | - <img | |
362 | - :src="imageUrl" | |
363 | - height="150" | |
364 | - v-if="imageUrl" | |
365 | - style="border-radius:50%; width:150px" | |
366 | - /> | |
367 | - </v-flex> | |
368 | - </v-layout> | |
369 | - <v-layout> | |
370 | 336 | <v-flex xs4 sm4 class="pt-4 subheading"> |
371 | 337 | <label class="right">Title :</label> |
372 | 338 | </v-flex> |
... | ... | @@ -374,6 +340,7 @@ |
374 | 340 | <v-text-field |
375 | 341 | name="name" |
376 | 342 | type="text" |
343 | + label="Select Title" | |
377 | 344 | :rules="titleRules" |
378 | 345 | v-model="addAssignment.title" |
379 | 346 | required |
... | ... | @@ -388,6 +355,7 @@ |
388 | 355 | <v-text-field |
389 | 356 | name="name" |
390 | 357 | type="text" |
358 | + label="Select Description" | |
391 | 359 | :rules="descriptionRules" |
392 | 360 | v-model="addAssignment.description" |
393 | 361 | required |
... | ... | @@ -482,11 +450,12 @@ |
482 | 450 | </v-layout> |
483 | 451 | <v-layout> |
484 | 452 | <v-flex xs4 class="pt-4 subheading"> |
485 | - <label class="right">File:</label> | |
453 | + <label class="right hidden-xs-only hidden-sm-only">Uplaod File:</label> | |
454 | + <label class="right hidden-lg-only hidden-md-only hidden-xl-only">File:</label> | |
486 | 455 | </v-flex> |
487 | - <v-flex xs8 sm6 class="ml-3"> | |
456 | + <v-flex xs8 class="ml-3"> | |
488 | 457 | <v-text-field |
489 | - label="Select file" | |
458 | + label="Select File" | |
490 | 459 | @click="pickFile" |
491 | 460 | v-model="imageName" |
492 | 461 | append-icon="attach_file" |
... | ... | @@ -503,7 +472,6 @@ |
503 | 472 | <v-layout> |
504 | 473 | <v-flex xs12 sm12> |
505 | 474 | <v-card-actions> |
506 | - <!-- <v-btn @click="clear" round dark class="clear-button">Clear</v-btn> --> | |
507 | 475 | <v-spacer></v-spacer> |
508 | 476 | <v-btn |
509 | 477 | @click="submit" |
... | ... | @@ -531,6 +499,7 @@ |
531 | 499 | import http from "@/Services/http.js"; |
532 | 500 | import Util from "@/util"; |
533 | 501 | import moment from "moment"; |
502 | +import jsPDF from "jspdf"; | |
534 | 503 | |
535 | 504 | export default { |
536 | 505 | data: () => ({ |
... | ... | @@ -556,8 +525,7 @@ export default { |
556 | 525 | valid: true, |
557 | 526 | validEditAssignment: true, |
558 | 527 | addAssignmentDialog: false, |
559 | - // isActive: true, | |
560 | - // newActive: false, | |
528 | + | |
561 | 529 | pagination: { |
562 | 530 | rowsPerPage: 10 |
563 | 531 | }, |
... | ... | @@ -607,6 +575,11 @@ export default { |
607 | 575 | }, |
608 | 576 | { text: "Action", value: "", sortable: false, align: "center" } |
609 | 577 | ], |
578 | + | |
579 | + showPdfData: false, | |
580 | + loadingPdf: false, | |
581 | + hideData: true, | |
582 | + | |
610 | 583 | assignmentData: [], |
611 | 584 | subjectList: [], |
612 | 585 | classList: [], |
... | ... | @@ -621,7 +594,7 @@ export default { |
621 | 594 | classId: "", |
622 | 595 | sectionId: "", |
623 | 596 | subjectName: "", |
624 | - file: "" | |
597 | + fileType: "" | |
625 | 598 | }, |
626 | 599 | addAssignment: {}, |
627 | 600 | |
... | ... | @@ -699,16 +672,39 @@ export default { |
699 | 672 | subjectName: this.addAssignment.subjectName, |
700 | 673 | file: this.addAssignment.imageName |
701 | 674 | }; |
675 | + var signatures = { | |
676 | + "JVBERi0": "other", | |
677 | + "iVBORw0KGgo": "image", | |
678 | + "UEsDBBQ": "other", | |
679 | + "/": "image", | |
680 | + "AAABAA": "image", | |
681 | + "IywiV2hhdC": "other", | |
682 | + "bmFtZSxl": "other" | |
683 | + }; | |
684 | + function detectMimeType(b64) { | |
685 | + for (var s in signatures) { | |
686 | + if (b64.indexOf(s) === 0) { | |
687 | + return signatures[s]; | |
688 | + } | |
689 | + } | |
690 | + } | |
702 | 691 | if (this.$refs.form.validate()) { |
692 | + if (this.imageUrl) { | |
693 | + var str = this.imageUrl; | |
694 | + const [baseUrl, imageUrl] = str.split(/,/); | |
695 | + addAssignment.upload = imageUrl; | |
696 | + addAssignment.fileType = detectMimeType(imageUrl); | |
697 | + } | |
698 | + console.log("data===>", addAssignment); | |
703 | 699 | http() |
704 | 700 | .post("/createAssignment", addAssignment) |
705 | 701 | .then(response => { |
706 | - this.getAssignmentList(); | |
707 | 702 | this.snackbar = true; |
708 | 703 | this.text = "Syllabus added successfully"; |
709 | 704 | this.clear(); |
710 | 705 | this.color = "green"; |
711 | 706 | this.addAssignmentDialog = false; |
707 | + this.getAssignmentList(); | |
712 | 708 | }) |
713 | 709 | .catch(error => { |
714 | 710 | // console.log(error); |
... | ... | @@ -736,7 +732,7 @@ export default { |
736 | 732 | this.loadingSearch = false; |
737 | 733 | }) |
738 | 734 | .catch(error => { |
739 | - // console.log("err====>", err);u | |
735 | + // console.log("err====>", err); | |
740 | 736 | this.showLoader = false; |
741 | 737 | this.loadingSearch = false; |
742 | 738 | this.snackbar = true; |
... | ... | @@ -764,6 +760,28 @@ export default { |
764 | 760 | file: this.addAssignment.imageName |
765 | 761 | }; |
766 | 762 | this.editLoading = true; |
763 | + var signatures = { | |
764 | + "JVBERi0": "other", | |
765 | + "iVBORw0KGgo": "image", | |
766 | + "UEsDBBQ": "other", | |
767 | + "/": "image", | |
768 | + "AAABAA": "image", | |
769 | + "IywiV2hhdC": "other", | |
770 | + "bmFtZSxl": "other" | |
771 | + }; | |
772 | + function detectMimeType(b64) { | |
773 | + for (var s in signatures) { | |
774 | + if (b64.indexOf(s) === 0) { | |
775 | + return signatures[s]; | |
776 | + } | |
777 | + } | |
778 | + } | |
779 | + if (this.imageUrl) { | |
780 | + var str = this.imageUrl; | |
781 | + const [baseUrl, imageUrl] = str.split(/,/); | |
782 | + editAssignment.upload = imageUrl; | |
783 | + editAssignment.fileType = detectMimeType(imageUrl); | |
784 | + } | |
767 | 785 | http() |
768 | 786 | .put("/updateAssignment", editAssignment) |
769 | 787 | .then(response => { |
... | ... | @@ -772,24 +790,7 @@ export default { |
772 | 790 | this.color = "green"; |
773 | 791 | this.editLoading = false; |
774 | 792 | this.editAssignmentDialog = false; |
775 | - http() | |
776 | - .get( | |
777 | - "/getParticularClass", | |
778 | - { params: { classId: _id } }, | |
779 | - { | |
780 | - headers: { Authorization: "Bearer " + this.token } | |
781 | - } | |
782 | - ) | |
783 | - .then(response => { | |
784 | - this.assignmentData = response.data.data; | |
785 | - this.showLoader = false; | |
786 | - this.snackbar = true; | |
787 | - this.color = "green"; | |
788 | - this.close(); | |
789 | - }) | |
790 | - .catch(err => { | |
791 | - this.showLoader = false; | |
792 | - }); | |
793 | + this.getAssignmentList(); | |
793 | 794 | }) |
794 | 795 | .catch(error => { |
795 | 796 | this.editLoading = false; |
... | ... | @@ -852,10 +853,8 @@ export default { |
852 | 853 | }); |
853 | 854 | }, |
854 | 855 | onFilePicked(e) { |
855 | - // console.log(e) | |
856 | 856 | const files = e.target.files; |
857 | 857 | this.upload = e.target.files[0]; |
858 | - console.log("imageData-upload========>", this.upload); | |
859 | 858 | if (files[0] !== undefined) { |
860 | 859 | this.imageName = files[0].name; |
861 | 860 | if (this.imageName.lastIndexOf(".") <= 0) { |
... | ... | @@ -866,9 +865,6 @@ export default { |
866 | 865 | fr.addEventListener("load", () => { |
867 | 866 | this.imageUrl = fr.result; |
868 | 867 | this.imageFile = files[0]; // this is an image file that can be sent to server... |
869 | - // this.imageData.imageUrl = URL.createObjectURL(this.imageFile); | |
870 | - // console.log("upload=======>", this.imageData.imageUrl); | |
871 | - console.log("imageFile", this.imageUrl); | |
872 | 868 | }); |
873 | 869 | } else { |
874 | 870 | this.imageName = ""; |
... | ... | @@ -883,14 +879,34 @@ export default { |
883 | 879 | this.showSearch = false; |
884 | 880 | this.show = true; |
885 | 881 | this.search = ""; |
882 | + }, | |
883 | + | |
884 | + exportFile() { | |
885 | + this.hideData = false; | |
886 | + this.showPdfData = true; | |
887 | + }, | |
888 | + async generatePDF2Canvas() { | |
889 | + this.loadingPdf = true; | |
890 | + const el = this.$refs.printMe; | |
891 | + // add option type to get the image version | |
892 | + // if not provided the promise will return | |
893 | + // the canvas. | |
894 | + const options = { | |
895 | + type: "dataURL" | |
896 | + }; | |
897 | + this.output = await this.$html2canvas(el, options); | |
898 | + if (this.output) { | |
899 | + this.loadingPdf = false; | |
900 | + } | |
901 | + let doc = new jsPDF(); | |
902 | + doc.addImage(this.output, "JPEG", 5, 10, 200, 280); | |
903 | + doc.save("File.pdf"); | |
886 | 904 | } |
887 | 905 | }, |
888 | 906 | mounted() { |
889 | 907 | this.token = this.$store.state.token; |
890 | 908 | this.role = this.$store.state.role; |
891 | - // this.getNoticeDataList(); | |
892 | 909 | this.getClass(); |
893 | - // this.getAssignmentList(); | |
894 | 910 | } |
895 | 911 | }; |
896 | 912 | </script> |
897 | 913 | \ No newline at end of file | ... | ... |
src/pages/Academic/syllabus.vue
... | ... | @@ -10,34 +10,6 @@ |
10 | 10 | </v-flex> |
11 | 11 | </v-layout> |
12 | 12 | <v-container fluid> |
13 | - <!-- <v-layout> | |
14 | - <v-flex | |
15 | - xs12 | |
16 | - class="text-xs-center text-sm-center text-md-center text-lg-center my-4 mr-4" | |
17 | - > | |
18 | - <v-avatar size="140px" v-if="!editedItem.fileUrl && !imageUrl"> | |
19 | - <img src="/static/icon/user.png" /> | |
20 | - </v-avatar> | |
21 | - <img | |
22 | - :src="editedItem.fileUrl" | |
23 | - v-else-if="editedItem.fileUrl && !imageUrl" | |
24 | - style="border-radius:50%; width:150px" | |
25 | - /> | |
26 | - <img | |
27 | - v-if="imageUrl" | |
28 | - :src="imageUrl" | |
29 | - height="150" | |
30 | - style="border-radius:50%; width:150px" | |
31 | - /> | |
32 | - <input | |
33 | - type="file" | |
34 | - style="display:none" | |
35 | - ref="image" | |
36 | - accept="image/*" | |
37 | - @change="onFilePicked" | |
38 | - /> | |
39 | - </v-flex> | |
40 | - </v-layout> --> | |
41 | 13 | <v-form ref="formEditSyllabus" v-model="validEditSyllabus" lazy-validation> |
42 | 14 | <v-layout> |
43 | 15 | <v-flex xs4 sm4 class="pt-4 subheading"> |
... | ... | @@ -82,13 +54,6 @@ |
82 | 54 | v-model="imageName" |
83 | 55 | append-icon="attach_file" |
84 | 56 | ></v-text-field> |
85 | - <!-- <input | |
86 | - type="file" | |
87 | - style="display:none" | |
88 | - ref="image" | |
89 | - accept="image/*" | |
90 | - @change="onFilePicked" | |
91 | - />--> | |
92 | 57 | </v-flex> |
93 | 58 | </v-layout> |
94 | 59 | <v-flex xs12 sm12> |
... | ... | @@ -110,7 +75,7 @@ |
110 | 75 | |
111 | 76 | <!-- ****** VIEW PROFIL NOTICE BOARD ****** --> |
112 | 77 | |
113 | - <v-dialog v-model="viewSubjectDialog" max-width="600px"> | |
78 | + <!-- <v-dialog v-model="viewSubjectDialog" max-width="600px"> | |
114 | 79 | <v-toolbar flat class="card-style pa-3" dark> |
115 | 80 | <v-spacer></v-spacer> |
116 | 81 | <v-toolbar-title> |
... | ... | @@ -139,7 +104,7 @@ |
139 | 104 | </v-container> |
140 | 105 | </v-card-text> |
141 | 106 | </v-card> |
142 | - </v-dialog> | |
107 | + </v-dialog>--> | |
143 | 108 | |
144 | 109 | <!-- ****** EXISTING SYLLABUS TABLE ****** --> |
145 | 110 | <v-toolbar color="transparent" flat> |
... | ... | @@ -204,9 +169,15 @@ |
204 | 169 | <td class="text-xs-center td td-row">{{ props.item.title }}</td> |
205 | 170 | <td class="text-xs-center td td-row">{{ props.item.description }}</td> |
206 | 171 | <td class="text-xs-center td td-row">{{ dates(props.item.created) }}</td> |
207 | - <td class="text-xs-center td td-row" v-if="role != 'ADMIN' ">{{ props.item.teacherId.name }}</td> | |
208 | - <td class="text-xs-center td td-row" v-if="role != 'TEACHER' ">{{ props.item.schoolId.name }}</td> | |
209 | - <!-- <td class="text-xs-center td td-row">{{ props.item.fileType }}</td> --> | |
172 | + <td | |
173 | + class="text-xs-center td td-row" | |
174 | + v-if="role != 'ADMIN' " | |
175 | + >{{ props.item.teacherId.name }}</td> | |
176 | + <td | |
177 | + class="text-xs-center td td-row" | |
178 | + v-if="role != 'TEACHER' " | |
179 | + >{{ props.item.schoolId.name }}</td> | |
180 | + <td class="text-xs-center td td-row">{{ props.item.documentUrl }}</td> | |
210 | 181 | <td class="text-xs-center td td-row"> |
211 | 182 | <span> |
212 | 183 | <!-- <v-tooltip top> |
... | ... | @@ -214,7 +185,7 @@ |
214 | 185 | slot="activator" |
215 | 186 | style="cursor:pointer; width:25px; height:25px; " |
216 | 187 | class="mr-3" |
217 | - @click="profile(props.item)" | |
188 | + @click="generatePDF2Canvas()" | |
218 | 189 | src="/static/icon/download1.png" |
219 | 190 | /> |
220 | 191 | <span>Download</span> |
... | ... | @@ -268,19 +239,6 @@ |
268 | 239 | </v-flex> |
269 | 240 | </v-layout> |
270 | 241 | <v-container fluid fill-height> |
271 | - <!-- <v-layout> | |
272 | - <v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center"> | |
273 | - <v-avatar size="80px"> | |
274 | - <img src="/static/icon/user.png" v-if="!imageUrl" /> | |
275 | - </v-avatar> | |
276 | - <img | |
277 | - :src="imageUrl" | |
278 | - height="150" | |
279 | - v-if="imageUrl" | |
280 | - style="border-radius:50%; width:150px" | |
281 | - /> | |
282 | - </v-flex> | |
283 | - </v-layout> --> | |
284 | 242 | <v-layout align-center> |
285 | 243 | <v-flex xs12> |
286 | 244 | <v-form ref="form" v-model="valid" lazy-validation> |
... | ... | @@ -293,6 +251,7 @@ |
293 | 251 | v-model="addSyllabus.title" |
294 | 252 | name="name" |
295 | 253 | type="text" |
254 | + label="Add Title" | |
296 | 255 | :rules="titleRules" |
297 | 256 | required |
298 | 257 | ></v-text-field> |
... | ... | @@ -307,6 +266,7 @@ |
307 | 266 | v-model="addSyllabus.description" |
308 | 267 | name="name" |
309 | 268 | type="text" |
269 | + label="Add Description" | |
310 | 270 | :rules="descriptionRules" |
311 | 271 | required |
312 | 272 | ></v-text-field> |
... | ... | @@ -324,6 +284,24 @@ |
324 | 284 | item-text="classNum" |
325 | 285 | item-value="_id" |
326 | 286 | name="Select Class" |
287 | + @change="getSections(addSyllabus.classId)" | |
288 | + required | |
289 | + ></v-select> | |
290 | + </v-flex> | |
291 | + </v-layout> | |
292 | + <v-layout> | |
293 | + <v-flex xs4 sm4 class="pt-4 subheading"> | |
294 | + <label class="right">Section :</label> | |
295 | + </v-flex> | |
296 | + <v-flex xs8 sm8 class="ml-3"> | |
297 | + <v-select | |
298 | + :items="addSection" | |
299 | + label="Select Section" | |
300 | + item-text="name" | |
301 | + item-value="_id" | |
302 | + v-model="addSyllabus.sectionId" | |
303 | + name="Select Section" | |
304 | + class="px-2" | |
327 | 305 | required |
328 | 306 | ></v-select> |
329 | 307 | </v-flex> |
... | ... | @@ -378,6 +356,7 @@ |
378 | 356 | import http from "@/Services/http.js"; |
379 | 357 | import Util from "@/util"; |
380 | 358 | import moment from "moment"; |
359 | +import jsPDF from "jspdf"; | |
381 | 360 | |
382 | 361 | export default { |
383 | 362 | data: () => ({ |
... | ... | @@ -395,13 +374,11 @@ export default { |
395 | 374 | editLoading: false, |
396 | 375 | date: null, |
397 | 376 | search: "", |
398 | - viewSubjectDialog: false, | |
399 | 377 | editSyllabusDialog: false, |
400 | 378 | valid: true, |
401 | 379 | validEditSyllabus: true, |
402 | 380 | addSyllabusDialog: false, |
403 | - // isActive: true, | |
404 | - // newActive: false, | |
381 | + | |
405 | 382 | pagination: { |
406 | 383 | rowsPerPage: 10 |
407 | 384 | }, |
... | ... | @@ -442,19 +419,20 @@ export default { |
442 | 419 | sortable: false, |
443 | 420 | align: "center" |
444 | 421 | }, |
445 | - // { | |
446 | - // text: "File", | |
447 | - // value: "fileType", | |
448 | - // sortable: false, | |
449 | - // align: "center" | |
450 | - // }, | |
422 | + { | |
423 | + text: "File", | |
424 | + value: "documentUrl", | |
425 | + sortable: false, | |
426 | + align: "center" | |
427 | + }, | |
451 | 428 | { text: "Action", value: "", sortable: false, align: "center" } |
452 | 429 | ], |
453 | 430 | syllabusList: [], |
454 | 431 | classList: [], |
432 | + addSection: [], | |
455 | 433 | editedIndex: -1, |
456 | 434 | addSyllabus: {}, |
457 | - // selectClassId: "", | |
435 | + | |
458 | 436 | editedItem: { |
459 | 437 | subjectName: "" |
460 | 438 | }, |
... | ... | @@ -463,6 +441,7 @@ export default { |
463 | 441 | imageUrl: "", |
464 | 442 | imageFile: "" |
465 | 443 | }), |
444 | + | |
466 | 445 | methods: { |
467 | 446 | pickFile() { |
468 | 447 | this.$refs.image.click(); |
... | ... | @@ -476,11 +455,10 @@ export default { |
476 | 455 | this.dialog = true; |
477 | 456 | this.editSyllabusDialog = true; |
478 | 457 | }, |
479 | - profile(item) { | |
458 | + download(item) { | |
480 | 459 | this.editedIndex = this.syllabusList; |
481 | 460 | this.editedItem = Object.assign({}, item); |
482 | 461 | this.dialog1 = true; |
483 | - this.viewSubjectDialog = true; | |
484 | 462 | }, |
485 | 463 | deleteItem(item) { |
486 | 464 | let deleteSyallabus = { |
... | ... | @@ -508,9 +486,7 @@ export default { |
508 | 486 | close() { |
509 | 487 | this.editSyllabusDialog = false; |
510 | 488 | }, |
511 | - close1() { | |
512 | - this.viewSubjectDialog = false; | |
513 | - }, | |
489 | + | |
514 | 490 | submit() { |
515 | 491 | // var addSyllabus = { |
516 | 492 | // classId: this.addSyllabus.classId, |
... | ... | @@ -519,11 +495,28 @@ export default { |
519 | 495 | // upload: this.addSyllabus.upload, |
520 | 496 | // fileType: this.addSyllabus.fileType |
521 | 497 | // }; |
498 | + var signatures = { | |
499 | + JVBERi0: "other", | |
500 | + iVBORw0KGgo: "image", | |
501 | + UEsDBBQ: "other", | |
502 | + "/": "image", | |
503 | + AAABAA: "image", | |
504 | + IywiV2hhdC: "other", | |
505 | + bmFtZSxl: "other" | |
506 | + }; | |
507 | + function detectMimeType(b64) { | |
508 | + for (var s in signatures) { | |
509 | + if (b64.indexOf(s) === 0) { | |
510 | + return signatures[s]; | |
511 | + } | |
512 | + } | |
513 | + } | |
522 | 514 | if (this.$refs.form.validate()) { |
523 | 515 | if (this.imageUrl) { |
524 | 516 | var str = this.imageUrl; |
525 | 517 | const [baseUrl, imageUrl] = str.split(/,/); |
526 | 518 | this.addSyllabus.upload = imageUrl; |
519 | + this.addSyllabus.fileType = detectMimeType(imageUrl); | |
527 | 520 | } |
528 | 521 | http() |
529 | 522 | .post("/createSyallabus", this.addSyllabus) |
... | ... | @@ -544,10 +537,8 @@ export default { |
544 | 537 | } |
545 | 538 | }, |
546 | 539 | onFilePicked(e) { |
547 | - // console.log(e) | |
548 | 540 | const files = e.target.files; |
549 | 541 | this.upload = e.target.files[0]; |
550 | - console.log("imageData-upload========>", this.upload); | |
551 | 542 | if (files[0] !== undefined) { |
552 | 543 | this.imageName = files[0].name; |
553 | 544 | if (this.imageName.lastIndexOf(".") <= 0) { |
... | ... | @@ -559,8 +550,6 @@ export default { |
559 | 550 | this.imageUrl = fr.result; |
560 | 551 | this.imageFile = files[0]; // this is an image file that can be sent to server... |
561 | 552 | this.imageData.imageUrl = URL.createObjectURL(this.imageFile); |
562 | - // console.log("upload=======>", this.imageData.imageUrl); | |
563 | - // console.log("imageFile", this.imageUrl); | |
564 | 553 | }); |
565 | 554 | } else { |
566 | 555 | this.imageName = ""; |
... | ... | @@ -575,14 +564,35 @@ export default { |
575 | 564 | if (this.$refs.formEditSyllabus.validate()) { |
576 | 565 | let syllabusData = { |
577 | 566 | syallabusId: this.editedItem._id, |
578 | - sectionId: this.editedItem.sectionId, | |
579 | - classId: this.editedItem.classId, | |
580 | - title: this.editedItem.title, | |
581 | - description: this.editedItem.description, | |
582 | - upload: this.editedItem.upload, | |
583 | - fileType: this.editedItem.fileType | |
567 | + classId: this.addSyllabus.classId, | |
568 | + sectionId: this.addSyllabus.sectionId, | |
569 | + title: this.addSyllabus.title, | |
570 | + description: this.addSyllabus.description, | |
571 | + upload: this.addSyllabus.upload, | |
572 | + fileType: this.addSyllabus.fileType | |
584 | 573 | }; |
585 | 574 | this.editLoading = true; |
575 | + var signatures = { | |
576 | + JVBERi0: "other", | |
577 | + iVBORw0KGgo: "image", | |
578 | + UEsDBBQ: "other", | |
579 | + "/": "image", | |
580 | + AAABAA: "image", | |
581 | + IywiV2hhdC: "other" | |
582 | + }; | |
583 | + function detectMimeType(b64) { | |
584 | + for (var s in signatures) { | |
585 | + if (b64.indexOf(s) === 0) { | |
586 | + return signatures[s]; | |
587 | + } | |
588 | + } | |
589 | + } | |
590 | + if (this.imageUrl) { | |
591 | + var str = this.imageUrl; | |
592 | + const [baseUrl, imageUrl] = str.split(/,/); | |
593 | + syllabusData.upload = imageUrl; | |
594 | + syllabusData.fileType = detectMimeType(imageUrl); | |
595 | + } | |
586 | 596 | http() |
587 | 597 | .put("/updateSyallabus", syllabusData) |
588 | 598 | .then(response => { |
... | ... | @@ -651,6 +661,25 @@ export default { |
651 | 661 | } |
652 | 662 | }); |
653 | 663 | }, |
664 | + getSections(_id) { | |
665 | + var token = this.$store.state.token; | |
666 | + this.showLoader = true; | |
667 | + http() | |
668 | + .get( | |
669 | + "/getSectionsList", | |
670 | + { params: { classId: _id } }, | |
671 | + { | |
672 | + headers: { Authorization: "Bearer " + token } | |
673 | + } | |
674 | + ) | |
675 | + .then(response => { | |
676 | + this.addSection = response.data.data; | |
677 | + this.showLoader = false; | |
678 | + }) | |
679 | + .catch(err => { | |
680 | + this.showLoader = false; | |
681 | + }); | |
682 | + }, | |
654 | 683 | displaySearch() { |
655 | 684 | (this.show = false), (this.showSearch = true); |
656 | 685 | }, |
... | ... | @@ -658,13 +687,29 @@ export default { |
658 | 687 | this.showSearch = false; |
659 | 688 | this.show = true; |
660 | 689 | this.search = ""; |
690 | + }, | |
691 | + async generatePDF2Canvas() { | |
692 | + this.loadingPdf = true; | |
693 | + const el = this.$refs.printMe; | |
694 | + // add option type to get the image version | |
695 | + // if not provided the promise will return | |
696 | + // the canvas. | |
697 | + const options = { | |
698 | + type: "dataURL" | |
699 | + }; | |
700 | + this.output = await this.$html2canvas(el, options); | |
701 | + if (this.output) { | |
702 | + this.loadingPdf = false; | |
703 | + } | |
704 | + let doc = new jsPDF(); | |
705 | + doc.addImage(this.output, "JPEG", 5, 10, 200, 280); | |
706 | + doc.save("File.pdf"); | |
661 | 707 | } |
662 | 708 | }, |
663 | 709 | mounted() { |
664 | 710 | this.token = this.$store.state.token; |
665 | 711 | this.role = this.$store.state.role; |
666 | 712 | this.getClass(); |
667 | - // this.getSyallabusList(); | |
668 | 713 | } |
669 | 714 | }; |
670 | 715 | </script> |
671 | 716 | \ No newline at end of file | ... | ... |