Blame view

src/pages/Academic/syllabus.vue 25.2 KB
710438de6   Shikha Mishra   added teacher mod...
1
2
3
  <template>
    <v-container fluid class="body-color">
      <!-- ****** EDIT  Syllabus ****** -->
db965de89   Amber Dev   added dialog pers...
4
      <v-dialog v-model="editSyllabusDialog" max-width="400px" persistent>
4dd422bef   Shikha Mishra   change ui of card...
5
        <v-card flat class="Card-style pa-2">
710438de6   Shikha Mishra   added teacher mod...
6
7
8
9
10
11
12
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Edit Syllabus</label>
              <v-icon size="24" class="right" @click="editSyllabusDialog = false">cancel</v-icon>
            </v-flex>
          </v-layout>
          <v-container fluid>
710438de6   Shikha Mishra   added teacher mod...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
            <v-form ref="formEditSyllabus" v-model="validEditSyllabus" lazy-validation>
              <v-layout>
                <v-flex xs4 sm4 class="pt-4 subheading">
                  <label class="right">Title :</label>
                </v-flex>
                <v-flex xs8 sm8 class="ml-3">
                  <v-text-field v-model="editedItem.title"></v-text-field>
                </v-flex>
              </v-layout>
              <v-layout>
                <v-flex xs4 class="pt-4 subheading">
                  <label class="right">Description:</label>
                </v-flex>
                <v-flex xs8 class="ml-3">
                  <v-text-field v-model="editedItem.description"></v-text-field>
                </v-flex>
              </v-layout>
              <v-layout>
                <v-flex xs4 class="pt-4 subheading">
                  <label class="right">Class:</label>
                </v-flex>
                <v-flex xs8 class="ml-3">
                  <v-select
                    :items="classList"
                    v-model="editedItem.classId"
                    label="Select Class"
                    item-text="classNum"
                    item-value="_id"
                    name="Select Class"
461ae2330   Shikha Mishra   improve update ap...
42
                    @change="getSections(addSyllabus.classId)"
710438de6   Shikha Mishra   added teacher mod...
43
44
45
46
                    required
                  ></v-select>
                </v-flex>
              </v-layout>
461ae2330   Shikha Mishra   improve update ap...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
              <!-- <v-layout>
                <v-flex xs4 sm4 class="pt-4 subheading">
                  <label class="right">Section :</label>
                </v-flex>
                <v-flex xs8 sm8 class="ml-3">
                  <v-select
                    :items="addSection"
                    label="Select Section"
                    item-text="name"
                    item-value="_id"
                    v-model="editedItem.sectionId"
                    name="Select Section"
                    class="px-2"
                    required
                  ></v-select>
                </v-flex>
d5fcb1cd1   Shikha Mishra   issues resolved
63
              </v-layout>-->
710438de6   Shikha Mishra   added teacher mod...
64
65
66
67
68
69
70
71
72
73
74
              <v-layout>
                <v-flex xs4 class="pt-4 subheading">
                  <label class="right">File:</label>
                </v-flex>
                <v-flex xs8 sm6 class="ml-3">
                  <v-text-field
                    label="Select file"
                    @click="pickFile"
                    v-model="imageName"
                    append-icon="attach_file"
                  ></v-text-field>
710438de6   Shikha Mishra   added teacher mod...
75
                </v-flex>
d10c26632   Shikha Mishra   Improve updateBoo...
76
77
78
79
80
81
82
                <input
                  type="file"
                  style="display:none"
                  ref="image"
                  accept="image/*"
                  @change="onFilePicked"
                />
710438de6   Shikha Mishra   added teacher mod...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
              </v-layout>
              <v-flex xs12 sm12>
                <v-card-actions>
                  <v-spacer></v-spacer>
                  <v-btn
                    round
                    dark
                    @click="save"
                    :loading="editLoading"
                    class="add-button"
                  >Update Syllabus</v-btn>
                </v-card-actions>
              </v-flex>
            </v-form>
          </v-container>
        </v-card>
      </v-dialog>
  
      <!-- ****** VIEW PROFIL NOTICE BOARD ******  -->
fa4edf929   Shikha Mishra   added option of u...
102
      <!-- <v-dialog v-model="viewSubjectDialog" max-width="600px">
710438de6   Shikha Mishra   added teacher mod...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
        <v-toolbar flat class="card-style pa-3" dark>
          <v-spacer></v-spacer>
          <v-toolbar-title>
            <h3>Subject</h3>
          </v-toolbar-title>
          <v-spacer></v-spacer>
          <v-icon @click="close1">close</v-icon>
        </v-toolbar>
        <v-card>
          <v-card-text>
            <v-container grid-list-md>
              <v-layout wrap>
                <v-flex>
                  <v-layout>
                    <v-flex xs7 sm6>
                      <h5 class="right my-1">
                        <b>Subject Name:</b>
                      </h5>
                    </v-flex>
                    <v-flex sm6 xs5>
                      <h5 class="my-1">{{ editedItem.subjectName }}</h5>
                    </v-flex>
                  </v-layout>
                </v-flex>
              </v-layout>
            </v-container>
          </v-card-text>
        </v-card>
fa4edf929   Shikha Mishra   added option of u...
131
      </v-dialog>-->
710438de6   Shikha Mishra   added teacher mod...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  
      <!-- ****** EXISTING SYLLABUS TABLE ****** -->
      <v-toolbar color="transparent" flat>
        <v-btn
          fab
          dark
          class="open-dialog-button hidden-xl-only hidden-md-only hidden-lg-only"
          small
          @click="addSyllabusDialog = true"
        >
          <v-icon dark>add</v-icon>
        </v-btn>
        <v-flex xs1 class="hidden-sm-only hidden-xs-only">
          <v-btn round class="open-dialog-button" dark @click="addSyllabusDialog = true">
            <v-icon class="white--text pr-1" size="20">add</v-icon>Add Syllabus
          </v-btn>
        </v-flex>
        <v-spacer></v-spacer>
        <v-flex lg2 md2 xs12 v-show="show">
          <v-select
            :items="classList"
            label="Select Class"
b039d39fb   Shikha Mishra   Hide Edit functio...
154
            v-model="showSyllabus.classId"
710438de6   Shikha Mishra   added teacher mod...
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
            item-text="classNum"
            item-value="_id"
            name="Select Class"
            :rules="classRules"
            @change="getSyallabusList"
            class="pl-2"
            required
          ></v-select>
        </v-flex>
        <v-card-title class="body-1" v-show="show">
          <v-btn icon flat @click="displaySearch">
            <v-avatar size="27">
              <img src="/static/icon/search.png" alt="icon" />
            </v-avatar>
          </v-btn>
        </v-card-title>
1fb26113b   Amber Dev   added auto focus ...
171
        <v-flex xs9 sm9 md2 lg2 xl2 v-if="showSearch">
710438de6   Shikha Mishra   added teacher mod...
172
173
          <v-layout>
            <v-text-field
8e8d14254   Shikha Mishra   Cleared data whil...
174
              autofocus
710438de6   Shikha Mishra   added teacher mod...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
              v-model="search"
              label="Search"
              prepend-inner-icon="search"
              color="primary"
              style="transition: 0.8s cubic-bezier(0.25, 0.8, 0.25, 1); !important"
            ></v-text-field>
            <v-icon @click="closeSearch" color="error">close</v-icon>
          </v-layout>
        </v-flex>
      </v-toolbar>
      <v-data-table
        :headers="headers"
        :items="syllabusList"
        :pagination.sync="pagination"
        :search="search"
      >
        <template slot="items" slot-scope="props">
          <tr class="tr">
            <td class="td-row td">{{ props.index + 1 }}</td>
            <td class="text-xs-center td td-row">{{ props.item.title }}</td>
            <td class="text-xs-center td td-row">{{ props.item.description }}</td>
            <td class="text-xs-center td td-row">{{ dates(props.item.created) }}</td>
fa4edf929   Shikha Mishra   added option of u...
197
            <td
dbcbd11f4   Shikha Mishra   improve filename ...
198
              class="text-xs-center td tgeneratePDF2Canvasd-row"
f35ab5f43   Amber Dev   bug in syllabus d...
199
              v-if="props.item.teacherId"
fa4edf929   Shikha Mishra   added option of u...
200
            >{{ props.item.teacherId.name }}</td>
8e8d14254   Shikha Mishra   Cleared data whil...
201
            <td class="text-xs-center td td-row" v-else>{{ props.item.schoolId.name }}</td>
461ae2330   Shikha Mishra   improve update ap...
202
            <td class="text-xs-center td td-row">
ab4a9d6ee   Shikha Mishra   file name issue s...
203
              <!-- <v-btn
d5fcb1cd1   Shikha Mishra   issues resolved
204
205
                class="add-button"
                @click="generatePDF2Canvas(props.item)"
461ae2330   Shikha Mishra   improve update ap...
206
207
                :loading="loadingPdf"
                dark
dbcbd11f4   Shikha Mishra   improve filename ...
208
209
              >{{ props.item.fileType }}</v-btn>-->
              <a
25766f5a4   Shikha Mishra   make filename vie...
210
                class="hover"
dbcbd11f4   Shikha Mishra   improve filename ...
211
212
                :href="props.item.documentUrl"
                target="_blank"
25766f5a4   Shikha Mishra   make filename vie...
213
                style="text-decoration: none!important; color: grey"
dbcbd11f4   Shikha Mishra   improve filename ...
214
              >
25766f5a4   Shikha Mishra   make filename vie...
215
216
217
218
219
                <!-- <v-btn flat block>
                <span>-->
                <h5>{{props.item.fileName}}</h5>
                <!-- </span>
                </v-btn>-->
ab4a9d6ee   Shikha Mishra   file name issue s...
220
              </a>
461ae2330   Shikha Mishra   improve update ap...
221
            </td>
710438de6   Shikha Mishra   added teacher mod...
222
223
            <td class="text-xs-center td td-row">
              <span>
710438de6   Shikha Mishra   added teacher mod...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:18px; "
                    class="mr-3"
                    @click="editItem(props.item)"
                    src="/static/icon/edit.png"
                  />
                  <span>Edit</span>
                </v-tooltip>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:20px; "
                    class="mr-3"
                    @click="deleteItem(props.item)"
                    src="/static/icon/delete.png"
                  />
                  <span>Delete</span>
                </v-tooltip>
              </span>
            </td>
          </tr>
        </template>
        <v-alert
          slot="no-results"
          :value="true"
          color="error"
          icon="warning"
        >Your search for "{{ search }}" found no results.</v-alert>
      </v-data-table>
      <!-- ****** ADD SYLLABUS ****** -->
      <v-snackbar
        :timeout="timeout"
        :top="y === 'top'"
        :right="x === 'right'"
        :vertical="mode === 'vertical'"
        v-model="snackbar"
        :color="color"
      >{{ text }}</v-snackbar>
db965de89   Amber Dev   added dialog pers...
264
      <v-dialog v-model="addSyllabusDialog" max-width="400px" v-if="addSyllabusDialog" persistent>
4dd422bef   Shikha Mishra   change ui of card...
265
        <v-card flat class="Card-style pa-2">
710438de6   Shikha Mishra   added teacher mod...
266
267
268
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Add Syllabus</label>
8e8d14254   Shikha Mishra   Cleared data whil...
269
              <v-icon size="24" class="right" @click="closeAddStudentModel">cancel</v-icon>
710438de6   Shikha Mishra   added teacher mod...
270
271
272
            </v-flex>
          </v-layout>
          <v-container fluid fill-height>
710438de6   Shikha Mishra   added teacher mod...
273
274
275
276
277
278
279
280
281
282
283
284
            <v-layout align-center>
              <v-flex xs12>
                <v-form ref="form" v-model="valid" lazy-validation>
                  <v-layout>
                    <v-flex xs4 sm4 class="pt-4 subheading">
                      <label class="right">Title :</label>
                    </v-flex>
                    <v-flex xs8 sm8 class="ml-3">
                      <v-text-field
                        v-model="addSyllabus.title"
                        name="name"
                        type="text"
8888e892f   Amber Dev   added label changes
285
                        placeholder="Add Title"
710438de6   Shikha Mishra   added teacher mod...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
                        :rules="titleRules"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs4 sm4 class="pt-4 subheading">
                      <label class="right">Description :</label>
                    </v-flex>
                    <v-flex xs8 sm8 class="ml-3">
                      <v-text-field
                        v-model="addSyllabus.description"
                        name="name"
                        type="text"
8888e892f   Amber Dev   added label changes
300
                        placeholder="Add Description"
710438de6   Shikha Mishra   added teacher mod...
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
                        :rules="descriptionRules"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs4 class="pt-4 subheading">
                      <label class="right">Class:</label>
                    </v-flex>
                    <v-flex xs8 class="ml-3">
                      <v-select
                        :items="classList"
                        v-model="addSyllabus.classId"
                        label="Select Class"
                        item-text="classNum"
                        item-value="_id"
                        name="Select Class"
fa4edf929   Shikha Mishra   added option of u...
318
319
320
321
322
                        @change="getSections(addSyllabus.classId)"
                        required
                      ></v-select>
                    </v-flex>
                  </v-layout>
461ae2330   Shikha Mishra   improve update ap...
323
                  <!-- <v-layout>
fa4edf929   Shikha Mishra   added option of u...
324
325
326
327
328
329
330
331
332
333
334
335
                    <v-flex xs4 sm4 class="pt-4 subheading">
                      <label class="right">Section :</label>
                    </v-flex>
                    <v-flex xs8 sm8 class="ml-3">
                      <v-select
                        :items="addSection"
                        label="Select Section"
                        item-text="name"
                        item-value="_id"
                        v-model="addSyllabus.sectionId"
                        name="Select Section"
                        class="px-2"
710438de6   Shikha Mishra   added teacher mod...
336
337
338
                        required
                      ></v-select>
                    </v-flex>
d5fcb1cd1   Shikha Mishra   issues resolved
339
                  </v-layout>-->
710438de6   Shikha Mishra   added teacher mod...
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
                  <v-layout>
                    <v-flex xs4 class="pt-4 subheading">
                      <label class="right">File:</label>
                    </v-flex>
                    <v-flex xs8 sm6 class="ml-3">
                      <v-text-field
                        label="Select file"
                        @click="pickFile"
                        v-model="imageName"
                        append-icon="attach_file"
                      ></v-text-field>
                      <input
                        type="file"
                        style="display:none"
                        ref="image"
                        accept="image/*"
                        @change="onFilePicked"
                      />
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs12 sm12>
                      <v-card-actions>
                        <v-spacer></v-spacer>
                        <v-btn
                          @click="submit"
                          round
                          dark
                          :loading="loading"
                          class="add-button"
                        >Add Syllabus</v-btn>
                      </v-card-actions>
                    </v-flex>
                  </v-layout>
                </v-form>
              </v-flex>
            </v-layout>
          </v-container>
        </v-card>
      </v-dialog>
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
    </v-container>
  </template>
  
  <script>
  import http from "@/Services/http.js";
  import Util from "@/util";
  import moment from "moment";
fa4edf929   Shikha Mishra   added option of u...
390
  import jsPDF from "jspdf";
d5fcb1cd1   Shikha Mishra   issues resolved
391
  import { saveAs } from "file-saver";
710438de6   Shikha Mishra   added teacher mod...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
  
  export default {
    data: () => ({
      snackbar: false,
      y: "top",
      x: "right",
      mode: "",
      timeout: 3000,
      text: "",
      color: "",
      show: true,
      showSearch: false,
      showLoader: false,
      loading: false,
      editLoading: false,
      date: null,
      search: "",
710438de6   Shikha Mishra   added teacher mod...
409
410
411
412
      editSyllabusDialog: false,
      valid: true,
      validEditSyllabus: true,
      addSyllabusDialog: false,
461ae2330   Shikha Mishra   improve update ap...
413
      loadingPdf: false,
fa4edf929   Shikha Mishra   added option of u...
414

710438de6   Shikha Mishra   added teacher mod...
415
      pagination: {
8e8d14254   Shikha Mishra   Cleared data whil...
416
        rowsPerPage: 10,
710438de6   Shikha Mishra   added teacher mod...
417
418
419
      },
      token: "",
      upload: "",
8e8d14254   Shikha Mishra   Cleared data whil...
420
421
422
423
      titleRules: [(v) => !!v || " Title is required"],
      descriptionRules: [(v) => !!v || " Description is required"],
      classRules: [(v) => !!v || " Class Name is required"],
      fileRules: [(v) => !!v || " File is required"],
710438de6   Shikha Mishra   added teacher mod...
424
425
426
427
428
      headers: [
        {
          text: "No",
          align: "",
          sortable: false,
8e8d14254   Shikha Mishra   Cleared data whil...
429
          value: "No",
710438de6   Shikha Mishra   added teacher mod...
430
431
432
433
434
        },
        {
          text: "Title",
          value: "title",
          sortable: false,
8e8d14254   Shikha Mishra   Cleared data whil...
435
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
436
437
438
439
440
        },
        {
          text: "Description",
          value: "description",
          sortable: false,
8e8d14254   Shikha Mishra   Cleared data whil...
441
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
442
443
444
445
446
        },
        {
          text: "Date",
          value: "created",
          sortable: false,
8e8d14254   Shikha Mishra   Cleared data whil...
447
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
448
449
450
451
452
        },
        {
          text: "Uploader",
          value: "upload",
          sortable: false,
8e8d14254   Shikha Mishra   Cleared data whil...
453
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
454
        },
fa4edf929   Shikha Mishra   added option of u...
455
456
457
458
        {
          text: "File",
          value: "documentUrl",
          sortable: false,
8e8d14254   Shikha Mishra   Cleared data whil...
459
          align: "center",
fa4edf929   Shikha Mishra   added option of u...
460
        },
8e8d14254   Shikha Mishra   Cleared data whil...
461
        { text: "Action", value: "", sortable: false, align: "center" },
710438de6   Shikha Mishra   added teacher mod...
462
463
464
      ],
      syllabusList: [],
      classList: [],
fa4edf929   Shikha Mishra   added option of u...
465
      addSection: [],
710438de6   Shikha Mishra   added teacher mod...
466
467
      editedIndex: -1,
      addSyllabus: {},
b039d39fb   Shikha Mishra   Hide Edit functio...
468
      showSyllabus: {},
fa4edf929   Shikha Mishra   added option of u...
469

710438de6   Shikha Mishra   added teacher mod...
470
      editedItem: {
8e8d14254   Shikha Mishra   Cleared data whil...
471
        subjectName: "",
710438de6   Shikha Mishra   added teacher mod...
472
473
474
475
      },
      imageData: {},
      imageName: "",
      imageUrl: "",
8e8d14254   Shikha Mishra   Cleared data whil...
476
      imageFile: "",
710438de6   Shikha Mishra   added teacher mod...
477
    }),
fa4edf929   Shikha Mishra   added option of u...
478

8e8d14254   Shikha Mishra   Cleared data whil...
479
480
481
482
483
484
485
486
    watch: {
      addSyllabusDialog: function (val) {
        if (!val) {
          this.addSyllabus = [];
          this.imageName = "";
        }
      },
    },
710438de6   Shikha Mishra   added teacher mod...
487
488
489
490
    methods: {
      pickFile() {
        this.$refs.image.click();
      },
8e8d14254   Shikha Mishra   Cleared data whil...
491
      dates: function (date) {
710438de6   Shikha Mishra   added teacher mod...
492
493
494
495
496
497
498
499
        return moment(date).format("MMMM DD, YYYY");
      },
      editItem(item) {
        this.editedIndex = this.syllabusList;
        this.editedItem = Object.assign({}, item);
        this.dialog = true;
        this.editSyllabusDialog = true;
      },
fa4edf929   Shikha Mishra   added option of u...
500
      download(item) {
710438de6   Shikha Mishra   added teacher mod...
501
502
503
        this.editedIndex = this.syllabusList;
        this.editedItem = Object.assign({}, item);
        this.dialog1 = true;
710438de6   Shikha Mishra   added teacher mod...
504
505
506
      },
      deleteItem(item) {
        let deleteSyallabus = {
8e8d14254   Shikha Mishra   Cleared data whil...
507
          syallabusId: item._id,
710438de6   Shikha Mishra   added teacher mod...
508
509
510
511
512
        };
        http()
          .delete(
            "/deleteSyallabus",
            confirm("Are you sure you want to delete this?") && {
8e8d14254   Shikha Mishra   Cleared data whil...
513
              params: deleteSyallabus,
710438de6   Shikha Mishra   added teacher mod...
514
515
            }
          )
8e8d14254   Shikha Mishra   Cleared data whil...
516
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
517
518
519
520
521
            this.getSyallabusList();
            this.snackbar = true;
            this.color = "green";
            this.text = "Successfully delete Existing Syllabus";
          })
8e8d14254   Shikha Mishra   Cleared data whil...
522
          .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
523
524
525
526
527
528
529
530
            this.snackbar = true;
            this.text = error.response.data.message;
            this.color = "error";
          });
      },
      close() {
        this.editSyllabusDialog = false;
      },
8e8d14254   Shikha Mishra   Cleared data whil...
531
532
      closeAddStudentModel() {
        this.addSyllabusDialog = false;
01a4a5246   Shikha Mishra   When the modal wa...
533
        //   this.syllabusList = [];
8e8d14254   Shikha Mishra   Cleared data whil...
534
535
536
        this.addSyllabus = [];
        this.imageName = "";
      },
fa4edf929   Shikha Mishra   added option of u...
537

710438de6   Shikha Mishra   added teacher mod...
538
539
540
541
542
543
544
545
      submit() {
        // var addSyllabus = {
        //   classId: this.addSyllabus.classId,
        //   title: this.addSyllabus.title,
        //   description: this.addSyllabus.description,
        //   upload: this.addSyllabus.upload,
        //   fileType: this.addSyllabus.fileType
        // };
fa4edf929   Shikha Mishra   added option of u...
546
        var signatures = {
ab4a9d6ee   Shikha Mishra   file name issue s...
547
548
549
550
551
552
553
          //   JVBERi0: "other",
          //   iVBORw0KGgo: "image",
          //   UEsDBBQ: "other",
          //   "/": "image",
          //   AAABAA: "image",
          //   IywiV2hhdC: "other",
          //   bmFtZSxl: "other",
fa4edf929   Shikha Mishra   added option of u...
554
555
556
557
558
559
560
561
        };
        function detectMimeType(b64) {
          for (var s in signatures) {
            if (b64.indexOf(s) === 0) {
              return signatures[s];
            }
          }
        }
710438de6   Shikha Mishra   added teacher mod...
562
563
564
565
566
        if (this.$refs.form.validate()) {
          if (this.imageUrl) {
            var str = this.imageUrl;
            const [baseUrl, imageUrl] = str.split(/,/);
            this.addSyllabus.upload = imageUrl;
fa4edf929   Shikha Mishra   added option of u...
567
            this.addSyllabus.fileType = detectMimeType(imageUrl);
ef672f260   Neeraj Sharma   add file name in ...
568
            this.addSyllabus.fileName = this.imageName;
710438de6   Shikha Mishra   added teacher mod...
569
570
571
          }
          http()
            .post("/createSyallabus", this.addSyllabus)
8e8d14254   Shikha Mishra   Cleared data whil...
572
            .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
573
574
575
576
577
578
579
              this.getSyallabusList();
              this.snackbar = true;
              this.text = "Syllabus added successfully";
              this.clear();
              this.color = "green";
              this.addSyllabusDialog = false;
            })
8e8d14254   Shikha Mishra   Cleared data whil...
580
            .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
581
582
583
584
585
586
587
588
              // console.log(error);
              this.snackbar = true;
              this.text = error.response.data.message;
              this.color = "error";
            });
        }
      },
      onFilePicked(e) {
710438de6   Shikha Mishra   added teacher mod...
589
590
        const files = e.target.files;
        this.upload = e.target.files[0];
710438de6   Shikha Mishra   added teacher mod...
591
592
593
594
595
596
597
598
599
600
601
        if (files[0] !== undefined) {
          this.imageName = files[0].name;
          if (this.imageName.lastIndexOf(".") <= 0) {
            return;
          }
          const fr = new FileReader();
          fr.readAsDataURL(files[0]);
          fr.addEventListener("load", () => {
            this.imageUrl = fr.result;
            this.imageFile = files[0]; // this is an image file that can be sent to server...
            this.imageData.imageUrl = URL.createObjectURL(this.imageFile);
710438de6   Shikha Mishra   added teacher mod...
602
603
604
605
606
607
608
609
610
611
612
613
614
615
          });
        } else {
          this.imageName = "";
          this.imageFile = "";
          this.imageUrl = "";
        }
      },
      clear() {
        this.$refs.form.reset();
      },
      save() {
        if (this.$refs.formEditSyllabus.validate()) {
          let syllabusData = {
            syallabusId: this.editedItem._id,
461ae2330   Shikha Mishra   improve update ap...
616
617
618
619
620
            classId: this.editedItem.classId._id,
            // sectionId: this.editedItem.sectionId,
            title: this.editedItem.title,
            description: this.editedItem.description,
            upload: this.editedItem.upload,
ef672f260   Neeraj Sharma   add file name in ...
621
            fileType: this.editedItem.fileType,
8e8d14254   Shikha Mishra   Cleared data whil...
622
            fileName: this.imageName,
710438de6   Shikha Mishra   added teacher mod...
623
624
          };
          this.editLoading = true;
fa4edf929   Shikha Mishra   added option of u...
625
          var signatures = {
ab4a9d6ee   Shikha Mishra   file name issue s...
626
627
628
629
630
631
            //   JVBERi0: "other",
            //   iVBORw0KGgo: "image",
            //   UEsDBBQ: "other",
            //   "/": "image",
            //   AAABAA: "image",
            //   IywiV2hhdC: "other",
fa4edf929   Shikha Mishra   added option of u...
632
633
634
635
636
637
638
639
640
641
642
643
644
645
          };
          function detectMimeType(b64) {
            for (var s in signatures) {
              if (b64.indexOf(s) === 0) {
                return signatures[s];
              }
            }
          }
          if (this.imageUrl) {
            var str = this.imageUrl;
            const [baseUrl, imageUrl] = str.split(/,/);
            syllabusData.upload = imageUrl;
            syllabusData.fileType = detectMimeType(imageUrl);
          }
710438de6   Shikha Mishra   added teacher mod...
646
647
          http()
            .put("/updateSyallabus", syllabusData)
8e8d14254   Shikha Mishra   Cleared data whil...
648
            .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
649
650
651
652
653
654
655
656
657
658
              this.snackbar = true;
              this.text = "Successfully Edit Existing Syllabus";
              this.color = "green";
              this.editLoading = false;
              this.editSyllabusDialog = false;
              http()
                .get(
                  "/getSyallabusList",
                  { params: { classId: this.addSyllabus.classId } },
                  {
8e8d14254   Shikha Mishra   Cleared data whil...
659
                    headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
660
661
                  }
                )
8e8d14254   Shikha Mishra   Cleared data whil...
662
                .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
663
664
665
666
667
668
                  this.syllabusList = response.data.data;
                  this.getSyallabusList();
                  this.snackbar = true;
                  this.color = "green";
                  this.close();
                })
8e8d14254   Shikha Mishra   Cleared data whil...
669
                .catch((err) => {
ba420d0d1   Shikha Mishra   Solve add subject...
670
                  // console.log("err====>", err);
710438de6   Shikha Mishra   added teacher mod...
671
672
673
674
                  this.text = error.response.data.message;
                  this.color = "error";
                });
            })
8e8d14254   Shikha Mishra   Cleared data whil...
675
            .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
676
677
678
679
680
681
682
683
684
              this.editLoading = false;
            });
        }
      },
      getSyallabusList() {
        this.showLoader = true;
        http()
          .get(
            "/getSyallabusList",
b039d39fb   Shikha Mishra   Hide Edit functio...
685
            { params: { classId: this.showSyllabus.classId } },
710438de6   Shikha Mishra   added teacher mod...
686
            {
8e8d14254   Shikha Mishra   Cleared data whil...
687
              headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
688
689
            }
          )
8e8d14254   Shikha Mishra   Cleared data whil...
690
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
691
692
693
            this.syllabusList = response.data.data;
            this.showLoader = false;
          })
8e8d14254   Shikha Mishra   Cleared data whil...
694
          .catch((err) => {
710438de6   Shikha Mishra   added teacher mod...
695
696
697
698
699
700
            this.showLoader = false;
          });
      },
      getClass() {
        http()
          .get("/getClassesList", {
8e8d14254   Shikha Mishra   Cleared data whil...
701
            headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
702
          })
8e8d14254   Shikha Mishra   Cleared data whil...
703
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
704
705
            this.classList = response.data.data;
          })
8e8d14254   Shikha Mishra   Cleared data whil...
706
          .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
707
708
709
710
711
712
713
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
          });
      },
fa4edf929   Shikha Mishra   added option of u...
714
715
716
717
718
719
720
721
      getSections(_id) {
        var token = this.$store.state.token;
        this.showLoader = true;
        http()
          .get(
            "/getSectionsList",
            { params: { classId: _id } },
            {
8e8d14254   Shikha Mishra   Cleared data whil...
722
              headers: { Authorization: "Bearer " + token },
fa4edf929   Shikha Mishra   added option of u...
723
724
            }
          )
8e8d14254   Shikha Mishra   Cleared data whil...
725
          .then((response) => {
fa4edf929   Shikha Mishra   added option of u...
726
727
728
            this.addSection = response.data.data;
            this.showLoader = false;
          })
8e8d14254   Shikha Mishra   Cleared data whil...
729
          .catch((err) => {
fa4edf929   Shikha Mishra   added option of u...
730
731
732
            this.showLoader = false;
          });
      },
710438de6   Shikha Mishra   added teacher mod...
733
734
735
736
737
738
739
      displaySearch() {
        (this.show = false), (this.showSearch = true);
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
fa4edf929   Shikha Mishra   added option of u...
740
      },
461ae2330   Shikha Mishra   improve update ap...
741

d5fcb1cd1   Shikha Mishra   issues resolved
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
      async generatePDF2Canvas(item) {
        // console.log("documentUrl", documentUrl);
        // this.loadingPdf = true;
        // const el = this.$refs.printMe;
        // add option type to get the image version
        // if not provided the promise will return
        // the canvas.
        // const options = {
        //   type: "dataURL"
        // };
        // this.output = await this.$html2canvas(el, options);
        // console.log("el,option", this.output);
        // if (this.output) {
        //   this.loadingPdf = false;
        // }
        // let doc = new jsPDF();
        // doc.addImage(this.output,"JPEG", 5, 10, 200, 280);
        // doc.save("File.pdf");
  
        // function download(documentUrl, filename) {
        //   fetch(documentUrl).then(function(t) {
        //     return t.blob().then(b => {
        //       var a = document.createElement("a");
        //       a.href = URL.createObjectURL(b);
        //       a.setAttribute("download", "filename");
        //       a.click();
        //     });
        //   });
        // }
        var dataType = "";
        var type = "";
        if (item.fileType == "image") {
          dataType = "file.jpg";
        } else if (item.fileType == "other") {
          dataType = "file.pdf";
          type = "application/pdf";
        }
        var FileSaver = require("file-saver");
        FileSaver.saveAs(item.documentUrl, "image.jpg");
  
        // var blob = new Blob([item.documentUrl], {
        //   type: type
        // });
        // FileSaver.saveAs(blob, dataType);
        // const url = window.URL.createObjectURL(new Blob([item.documentUrl],{ type: type } ));
        // console.log("document", item.documentUrl);
        // const link = document.createElement("a");
        // link.href = url;
        // link.setAttribute("download", dataType); //or any other extension
        // document.body.appendChild(link);
        // link.click();
  
        //  const blob = window.URL.createObjectURL(new Blob([item.documentUrl],{ type: type } ));
        //   const link = document.createElement('a')
        //   link.href = URL.createObjectURL(blob)
        //   link.download = dataType
        //   link.click()
        //   URL.revokeObjectURL(link.href)
8e8d14254   Shikha Mishra   Cleared data whil...
800
      },
710438de6   Shikha Mishra   added teacher mod...
801
802
803
804
805
    },
    mounted() {
      this.token = this.$store.state.token;
      this.role = this.$store.state.role;
      this.getClass();
8e8d14254   Shikha Mishra   Cleared data whil...
806
    },
710438de6   Shikha Mishra   added teacher mod...
807
  };
25766f5a4   Shikha Mishra   make filename vie...
808
809
810
811
812
813
814
815
  </script>
  
  <style scoped>
  a:hover :hover {
    text-decoration: underline !important;
    color: blue;
  }
  </style>