Blame view

src/pages/Exam/examAttendence.vue 25.3 KB
710438de6   Shikha Mishra   added teacher mod...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  <template>
    <v-container fluid class="body-color">
      <!-- *****  Exam Schedule 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="addExamAttendenceDialog = true"
        >
          <v-icon dark>add</v-icon>
        </v-btn>
        <v-btn
          round
          class="open-dialog-button hidden-sm-only hidden-xs-only"
          dark
          @click="addExamAttendenceDialog = true"
        >
          <v-icon class="white--text pr-1" size="20">add</v-icon>Add Exam Attendence
        </v-btn>
        <v-spacer></v-spacer>
        <v-flex xs8 sm3 md2 class="mr-3">
          <v-select
b039d39fb   Shikha Mishra   Hide Edit functio...
25
            v-model="getAttendence.examId"
710438de6   Shikha Mishra   added teacher mod...
26
27
28
29
30
31
32
33
34
35
            label="Select Exam"
            :rules="examRules"
            :items="examList"
            item-text="examName"
            item-value="_id"
            required
          ></v-select>
        </v-flex>
        <v-flex xs8 sm3 md2 class="mr-3">
          <v-select
b039d39fb   Shikha Mishra   Hide Edit functio...
36
            v-model="getAttendence.classId"
710438de6   Shikha Mishra   added teacher mod...
37
38
39
40
41
            label="Select your class"
            type="text"
            :items="classList"
            item-text="classNum"
            item-value="_id"
b039d39fb   Shikha Mishra   Hide Edit functio...
42
            @change="getSections(getAttendence.classId)"
710438de6   Shikha Mishra   added teacher mod...
43
44
45
46
47
            required
          ></v-select>
        </v-flex>
        <v-flex xs8 sm3 md2 class="mr-3">
          <v-select
b039d39fb   Shikha Mishra   Hide Edit functio...
48
            v-model="getAttendence.sectionId"
710438de6   Shikha Mishra   added teacher mod...
49
50
51
52
53
            label="Select your section"
            type="text"
            :items="addSection"
            item-text="name"
            item-value="_id"
b039d39fb   Shikha Mishra   Hide Edit functio...
54
            @change="getClassSubject(getAttendence.classId)"
710438de6   Shikha Mishra   added teacher mod...
55
56
57
58
59
            required
          ></v-select>
        </v-flex>
        <v-flex xs8 sm3 md2 class="mr-3">
          <v-select
b039d39fb   Shikha Mishra   Hide Edit functio...
60
            v-model="getAttendence.subjectId"
710438de6   Shikha Mishra   added teacher mod...
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
            label="Select Subject"
            :rules="subjectRules"
            :items="subjectList.subjects"
            item-text="subjectName"
            item-value="_id"
            @change="getExamAttendenceList()"
            required
          ></v-select>
        </v-flex>
  
        <v-card-title class="body-1" v-show="show">
          <v-btn icon large flat @click="displaySearch">
            <v-avatar size="27">
              <img src="/static/icon/search.png" alt="icon" />
            </v-avatar>
          </v-btn>
        </v-card-title>
612b79bb4   Amber Dev   made serch auto f...
78
        <v-flex xs8 sm8 md3 lg2 v-if="showSearch">
710438de6   Shikha Mishra   added teacher mod...
79
          <v-layout>
73679431a   Shikha Mishra   clear add exam at...
80
81
82
83
84
85
86
            <v-text-field
              autofocus
              v-model="search"
              label="Search"
              prepend-inner-icon="search"
              color="primary"
            ></v-text-field>
710438de6   Shikha Mishra   added teacher mod...
87
88
89
90
91
92
            <v-icon @click="closeSearch" color="error">close</v-icon>
          </v-layout>
        </v-flex>
      </v-toolbar>
  
      <v-data-table
058c4a6cf   Shikha Mishra   Improve the funct...
93
        v-if="showData"
710438de6   Shikha Mishra   added teacher mod...
94
95
96
97
98
99
100
101
102
103
        :headers="headers"
        :items="examData.students"
        :pagination.sync="pagination"
        :search="search"
      >
        <template slot="items" slot-scope="props">
          <tr class="tr">
            <td class="td td-row">{{ props.index + 1}}</td>
            <td class="text-xs-center td td-row">
              <v-avatar size="40">
058c4a6cf   Shikha Mishra   Improve the funct...
104
105
106
107
108
                <img
                  :src="props.item.studentId.profilePicUrl"
                  v-if="props.item.studentId.profilePicUrl"
                />
                <img src="/static/icon/user.png" v-else-if="!props.item.studentId.profilePicUrl" />
710438de6   Shikha Mishra   added teacher mod...
109
110
111
112
113
114
              </v-avatar>
            </td>
            <td class="td td-row text-xs-center">{{ props.item.studentId.name}}</td>
            <td class="td td-row text-xs-center">{{ props.item.studentId.rollNo}}</td>
            <td class="td td-row text-xs-center">{{ props.item.studentId.email }}</td>
            <td class="td td-row text-xs-center">
058c4a6cf   Shikha Mishra   Improve the funct...
115
116
117
118
119
120
121
122
123
              <!-- <v-radio-group v-model="isPresent" row>
                <v-radio :value="props.item.isPresent"></v-radio>
              </v-radio-group>-->
              <v-checkbox
                v-model="props.item.isPresent"
                @click="markStudentAttendence(props.item)"
                primary
                hide-details
              ></v-checkbox>
710438de6   Shikha Mishra   added teacher mod...
124
125
126
127
128
129
130
131
132
133
            </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>
058c4a6cf   Shikha Mishra   Improve the funct...
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
      <!-- ****** ADD  Student Attendence ****** -->
      <v-dialog v-model="changeStudentAttendenceDialog" max-width="500px">
        <v-card flat>
          <v-layout class="pa-3 card-style white--text">
            <v-flex xs12>
              <label class="title text-xs-center">Change Student's Attendence</label>
              <v-icon
                size="24"
                class="right white--text"
                @click="changeStudentAttendenceDialog = false"
              >cancel</v-icon>
            </v-flex>
          </v-layout>
          <v-container fluid>
            <v-flex xs12>
              <h3>Are you sure you want to change the attendence</h3>
            </v-flex>
            <v-spacer></v-spacer>
  
            <v-flex xs12>
              <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn
                  @click.native="closeStudentAttendenceDialog"
                  round
                  dark
                  class="clear-button"
                >cancel</v-btn>
                <v-btn
                  @click="selectParticularStudent"
                  round
                  dark
                  :loading="loading"
                  class="add-button"
                >Yes</v-btn>
              </v-card-actions>
            </v-flex>
          </v-container>
        </v-card>
      </v-dialog>
710438de6   Shikha Mishra   added teacher mod...
174
      <!-- ****** ADD  Exam Attendence ****** -->
a4ac8d20f   Shikha Mishra   fixed issues of c...
175
      <v-dialog v-model="addExamAttendenceDialog" max-width="800px" v-if="addExamAttendenceDialog">
058c4a6cf   Shikha Mishra   Improve the funct...
176
177
        <v-card flat>
          <v-layout class="pa-3 card-style white--text">
710438de6   Shikha Mishra   added teacher mod...
178
179
            <v-flex xs12>
              <label class="title text-xs-center">Add Exam Attendence</label>
a4ac8d20f   Shikha Mishra   fixed issues of c...
180
              <v-icon size="24" class="right white--text" @click="closeAttendenceModel">cancel</v-icon>
710438de6   Shikha Mishra   added teacher mod...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
            </v-flex>
          </v-layout>
          <v-form ref="form" v-model="valid" lazy-validation class="text-xs-center">
            <v-container fluid>
              <v-flex xs12>
                <v-layout>
                  <v-flex xs5 class="pt-4 subheading">
                    <label class="right">Exam Name:</label>
                  </v-flex>
                  <v-flex xs7 sm7 md6 class="ml-3">
                    <v-select
                      label="Select Exam"
                      :rules="examRules"
                      :items="examList"
                      v-model="addAttendence.examId"
                      item-text="examName"
                      item-value="_id"
                    ></v-select>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-flex xs12>
                <v-layout>
                  <v-flex xs5 class="pt-4 subheading">
                    <label class="right">Class:</label>
                  </v-flex>
                  <v-flex xs7 sm7 md6 class="ml-3">
                    <v-select
                      v-model="addAttendence.classId"
                      label="Select Class"
                      type="text"
                      :items="classList"
                      item-text="classNum"
                      item-value="_id"
                      :rules="classRules"
                      @change="getSections(addAttendence.classId)"
                      required
                    ></v-select>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-flex xs12>
                <v-layout>
                  <v-flex xs5 class="pt-4 subheading">
                    <label class="right">Section:</label>
                  </v-flex>
                  <v-flex xs7 sm7 md6 class="ml-3">
                    <v-select
                      :items="addSection"
                      label="Select Section"
                      v-model="addAttendence.sectionId"
                      item-text="name"
                      item-value="_id"
                      name="Select Section"
                      :rules="sectionRules"
                      @change="getClassSubject(addAttendence.classId)"
                      required
                    ></v-select>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-flex xs12>
                <v-layout>
                  <v-flex xs5 class="pt-4 subheading">
                    <label class="right">Subject Name:</label>
                  </v-flex>
                  <v-flex xs7 sm7 md6 class="ml-3">
                    <v-select
                      :items="subjectList.subjects"
                      label="Select Subject"
                      item-text="subjectName"
                      v-model="addAttendence.subjectId"
                      item-value="_id"
                      name="Select Subject"
                      :rules="subjectRules"
                      required
                    ></v-select>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-layout>
                <v-flex xs12>
                  <v-card-actions>
                    <v-spacer class="hidden-xs-only"></v-spacer>
                    <v-btn
                      round
                      dark
                      @click="showTable"
                      :loading="loading"
                      class="add-button"
                    >Attendence</v-btn>
                  </v-card-actions>
                </v-flex>
              </v-layout>
            </v-container>
          </v-form>
          <v-flex xs12 v-show="attendeceTable" class>
            <v-data-table
058c4a6cf   Shikha Mishra   Improve the funct...
279
              :headers="studentheader"
710438de6   Shikha Mishra   added teacher mod...
280
281
282
              :items="studentsData"
              :pagination.sync="pagination"
              :search="search"
058c4a6cf   Shikha Mishra   Improve the funct...
283
284
285
              select-all
              v-model="selected"
              item-key="_id"
710438de6   Shikha Mishra   added teacher mod...
286
287
288
            >
              <template slot="items" slot-scope="props">
                <tr class="tr">
058c4a6cf   Shikha Mishra   Improve the funct...
289
290
291
292
293
294
295
296
297
                  <!-- <td class="td td-row">{{ props.index + 1}}</td> -->
                  <td class="td td-row">
                    <v-checkbox
                      v-model="props.item.attendence"
                      @change="markParticularStudentAttendence(props.item)"
                      primary
                      hide-details
                    ></v-checkbox>
                  </td>
710438de6   Shikha Mishra   added teacher mod...
298
299
300
301
302
303
304
305
306
                  <td class="text-xs-center td td-row">
                    <v-avatar size="40">
                      <img :src="props.item.profilePicUrl" v-if="props.item.profilePicUrl" />
                      <img src="/static/icon/user.png" v-else-if="!props.item.profilePicUrl" />
                    </v-avatar>
                  </td>
                  <td class="td td-row text-xs-center">{{ props.item.name}}</td>
                  <td class="td td-row text-xs-center">{{ props.item.rollNo}}</td>
                  <td class="td td-row text-xs-center">{{ props.item.email }}</td>
058c4a6cf   Shikha Mishra   Improve the funct...
307
                  <!-- <td class="td td-row text-xs-center">
710438de6   Shikha Mishra   added teacher mod...
308
309
310
311
312
313
314
315
                    <v-radio-group v-model="props.item.attendence" :mandatory="false" row>
                      <v-radio
                        v-for="attendences in attendenceType"
                        :key="attendences.value"
                        :label="`${attendences.label}`"
                        :value="attendences.value"
                      ></v-radio>
                    </v-radio-group>
058c4a6cf   Shikha Mishra   Improve the funct...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
                  </td>-->
                </tr>
              </template>
              <template slot="headers" slot-scope="props">
                <tr>
                  <th>
                    <v-checkbox
                      :input-value="props.all"
                      :indeterminate="props.indeterminate"
                      primary
                      hide-details
                      @click.native="selectAll"
                    ></v-checkbox>
                  </th>
                  <th
                    v-for="header in props.headers"
                    :key="header.text"
                    :class="['column sortable', pagination.descending ? 'desc' : 'asc', header.value === pagination.sortBy ? 'active' : '']"
                    @click="changeSort(header.value)"
                  >
                    <v-icon small>arrow_upward</v-icon>
                    {{ header.text }}
                  </th>
710438de6   Shikha Mishra   added teacher mod...
339
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
390
391
392
393
394
395
396
397
398
399
                </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>
            <v-flex xs12 sm12>
              <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn @click="submit()" round dark :loading="loading" class="add-button">Submit</v-btn>
              </v-card-actions>
            </v-flex>
          </v-flex>
        </v-card>
      </v-dialog>
      <v-snackbar
        :timeout="timeout"
        :top="y === 'top'"
        :right="x === 'right'"
        :vertical="mode === 'vertical'"
        v-model="snackbar"
        :color="color"
      >{{ text }}</v-snackbar>
      <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";
  
  export default {
    data: () => ({
      snackbar: false,
      editDate: false,
      menu1: false,
      menuB: false,
      menu2: false,
      menuEdit: false,
      timeToEdit: false,
      show: true,
      showSearch: false,
      addExamAttendenceDialog: false,
      color: "",
      y: "top",
      x: "right",
      mode: "",
      timeout: 10000,
      text: "",
      loading: false,
      search: "",
      showLoader: false,
      valid: true,
      role: "",
      pagination: {
058c4a6cf   Shikha Mishra   Improve the funct...
400
        rowsPerPage: 10,
710438de6   Shikha Mishra   added teacher mod...
401
402
403
      },
      attendeceTable: false,
      isPresent: true,
058c4a6cf   Shikha Mishra   Improve the funct...
404
405
406
407
408
409
410
411
      examRules: [(v) => !!v || "Exam Name is required"],
      classRules: [(v) => !!v || "Class Name is required"],
      sectionRules: [(v) => !!v || "section is required"],
      subjectRules: [(v) => !!v || "Subject is required"],
      timeInRules: [(v) => !!v || "Time In is required"],
      timeOutRules: [(v) => !!v || "time Out s is required"],
      roomRules: [(v) => !!v || "Room is required"],
      examScheduleDateRules: [(v) => !!v || "Date is required"],
710438de6   Shikha Mishra   added teacher mod...
412
413
414
415
416
417
418
419
420
      studentsData: [],
      examData: [],
      students: [],
  
      headers: [
        {
          align: "",
          text: "No",
          sortable: false,
058c4a6cf   Shikha Mishra   Improve the funct...
421
          value: "No",
710438de6   Shikha Mishra   added teacher mod...
422
423
424
        },
        {
          text: "Profile Pic",
058c4a6cf   Shikha Mishra   Improve the funct...
425
          value: "profilePicUrl",
710438de6   Shikha Mishra   added teacher mod...
426
          sortable: false,
058c4a6cf   Shikha Mishra   Improve the funct...
427
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
428
429
430
431
432
        },
        {
          text: "Name",
          value: "name",
          sortable: false,
058c4a6cf   Shikha Mishra   Improve the funct...
433
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
434
435
436
437
438
        },
        {
          text: "Roll No",
          value: "rollNo",
          sortable: false,
058c4a6cf   Shikha Mishra   Improve the funct...
439
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
440
441
442
443
444
        },
        {
          text: "Email",
          value: "email",
          sortable: false,
058c4a6cf   Shikha Mishra   Improve the funct...
445
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
446
447
448
        },
        {
          text: "Action",
058c4a6cf   Shikha Mishra   Improve the funct...
449
          value: "isPresent",
710438de6   Shikha Mishra   added teacher mod...
450
          sortable: false,
058c4a6cf   Shikha Mishra   Improve the funct...
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
          align: "center",
        },
      ],
      studentheader: [
        {
          text: "Profile Pic",
          value: "profilePicUrl",
          sortable: false,
          align: "center",
        },
        {
          text: "Name",
          value: "name",
          sortable: false,
          align: "center",
        },
        {
          text: "Roll No",
          value: "rollNo",
          sortable: false,
          align: "center",
        },
        {
          text: "Email",
          value: "email",
          sortable: false,
          align: "center",
        },
710438de6   Shikha Mishra   added teacher mod...
479
480
481
482
      ],
      attendenceType: [
        {
          label: "",
058c4a6cf   Shikha Mishra   Improve the funct...
483
484
          value: true,
        },
710438de6   Shikha Mishra   added teacher mod...
485
486
487
488
489
490
491
      ],
      classList: [],
      addSection: [],
      examList: [],
      subjectList: [],
      subjects: [],
      addAttendence: {},
b039d39fb   Shikha Mishra   Hide Edit functio...
492
      getAttendence: {},
710438de6   Shikha Mishra   added teacher mod...
493
494
      editedItem: {
        sectionId: {
058c4a6cf   Shikha Mishra   Improve the funct...
495
496
          name: "",
        },
710438de6   Shikha Mishra   added teacher mod...
497
498
499
      },
      getScheduleData: {},
      ScheduleData: [],
058c4a6cf   Shikha Mishra   Improve the funct...
500
501
502
503
504
505
506
507
508
509
      token: "",
      showData: false,
      selected: [],
      changeStudentAttendenceDialog: false,
      closeStudentAttendenceDialog() {
        this.changeStudentAttendenceDialog = false;
      },
      selectedStudent: {},
      presentStudent: [],
      absentStudent: [],
710438de6   Shikha Mishra   added teacher mod...
510
    }),
a4ac8d20f   Shikha Mishra   fixed issues of c...
511
512
513
514
515
516
517
518
519
520
521
    watch: {
      addExamAttendenceDialog: function (val) {
        if (!val) {
          this.studentsData = [];
          this.selected = [];
          this.attendeceTable = false;
          this.valid = false;
          this.addAttendence = [];
        }
      },
    },
710438de6   Shikha Mishra   added teacher mod...
522
523
524
525
    methods: {
      pickFile() {
        this.$refs.image.click();
      },
058c4a6cf   Shikha Mishra   Improve the funct...
526
527
528
529
530
531
532
      markStudentAttendence(item) {
        this.selectedStudent = {
          id: item.studentId._id,
          isPresent: !item.isPresent,
        };
        this.changeStudentAttendenceDialog = true;
      },
710438de6   Shikha Mishra   added teacher mod...
533
534
535
536
537
      getSchedulesList() {
        this.showLoader = true;
        http()
          .get("/getSchedulesList", {
            params: { classId: this.getScheduleData.classId },
058c4a6cf   Shikha Mishra   Improve the funct...
538
            headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
539
          })
058c4a6cf   Shikha Mishra   Improve the funct...
540
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
541
            this.ScheduleData = response.data.data;
710438de6   Shikha Mishra   added teacher mod...
542
543
            this.showLoader = false;
          })
058c4a6cf   Shikha Mishra   Improve the funct...
544
          .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
            // console.log("err====>", err);
            this.showLoader = false;
            this.loadingSearch = false;
            this.snackbar = true;
            this.text = error.response.data.message;
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
          });
      },
      close() {
        this.dialog = false;
      },
a4ac8d20f   Shikha Mishra   fixed issues of c...
560
561
562
563
564
565
566
567
      closeAttendenceModel() {
        this.addExamAttendenceDialog = false;
        this.studentsData = [];
        this.selected = [];
        this.attendeceTable = false;
        this.valid = false;
        this.addAttendence = [];
      },
710438de6   Shikha Mishra   added teacher mod...
568
569
570
571
572
573
      submit() {
        var examAttendence = {
          examId: this.addAttendence.examId,
          classId: this.addAttendence.classId,
          sectionId: this.addAttendence.sectionId,
          subjectId: this.addAttendence.subjectId,
058c4a6cf   Shikha Mishra   Improve the funct...
574
          students: [],
710438de6   Shikha Mishra   added teacher mod...
575
        };
058c4a6cf   Shikha Mishra   Improve the funct...
576
577
578
579
580
581
582
        for (var j = 0; j < this.presentStudent.length; j++) {
          examAttendence.students.push({
            studentId: this.presentStudent[j],
            isPresent: true,
          });
        }
        for (var j = 0; j < this.absentStudent.length; j++) {
710438de6   Shikha Mishra   added teacher mod...
583
          examAttendence.students.push({
058c4a6cf   Shikha Mishra   Improve the funct...
584
585
            studentId: this.absentStudent[j],
            isPresent: false,
710438de6   Shikha Mishra   added teacher mod...
586
587
          });
        }
710438de6   Shikha Mishra   added teacher mod...
588
589
590
        if (this.$refs.form.validate()) {
          http()
            .post("/createExamAttendance", examAttendence)
058c4a6cf   Shikha Mishra   Improve the funct...
591
            .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
592
593
594
595
              this.snackbar = true;
              this.color = "success";
              this.text = "Successfully created exam attendence";
              this.addExamAttendenceDialog = false;
73679431a   Shikha Mishra   clear add exam at...
596
597
598
599
600
              this.studentsData = [];
              this.selected = [];
              this.attendeceTable = false;
              this.valid = false;
              this.addAttendence = [];
710438de6   Shikha Mishra   added teacher mod...
601
            })
058c4a6cf   Shikha Mishra   Improve the funct...
602
            .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
603
604
605
606
607
608
609
610
611
612
613
614
615
              this.snackbar = true;
              this.text = error.response.data.message;
            });
        }
      },
      clear() {
        this.$refs.form.reset();
        this.disable = false;
        this.loading = false;
      },
      getClass() {
        http()
          .get("/getClassesList", {
058c4a6cf   Shikha Mishra   Improve the funct...
616
            headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
617
          })
058c4a6cf   Shikha Mishra   Improve the funct...
618
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
619
620
            this.classList = response.data.data;
          })
058c4a6cf   Shikha Mishra   Improve the funct...
621
          .catch((err) => {
710438de6   Shikha Mishra   added teacher mod...
622
623
624
625
626
627
628
629
630
631
632
633
634
635
            // console.log("err====>", err);
          });
      },
      getSections(_id) {
        for (let i = 0; i < this.classList.length; i++) {
          if (_id == this.classList[i]._id) {
            // this.subjects = this.classList[i].subjects;
          }
        }
        http()
          .get(
            "/getSectionsList",
            { params: { classId: _id } },
            {
058c4a6cf   Shikha Mishra   Improve the funct...
636
              headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
637
638
            }
          )
058c4a6cf   Shikha Mishra   Improve the funct...
639
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
640
641
            this.addSection = response.data.data;
          })
058c4a6cf   Shikha Mishra   Improve the funct...
642
          .catch((err) => {});
710438de6   Shikha Mishra   added teacher mod...
643
644
645
646
647
648
649
650
651
      },
      getClassSubject(_id) {
        this.showLoader = true;
        // this.classId = this.classId;
        http()
          .get(
            "/getParticularClass",
            { params: { classId: _id } },
            {
058c4a6cf   Shikha Mishra   Improve the funct...
652
              headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
653
654
            }
          )
058c4a6cf   Shikha Mishra   Improve the funct...
655
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
656
657
658
            this.subjectList = response.data.data;
            this.showLoader = false;
          })
058c4a6cf   Shikha Mishra   Improve the funct...
659
          .catch((err) => {
710438de6   Shikha Mishra   added teacher mod...
660
661
662
663
664
665
666
667
            this.showLoader = false;
          });
      },
      getExamList() {
        this.showLoader = true;
        this.loadingSearch = true;
        http()
          .get("/getExamsList", {
058c4a6cf   Shikha Mishra   Improve the funct...
668
            headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
669
          })
058c4a6cf   Shikha Mishra   Improve the funct...
670
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
671
672
673
674
            this.examList = response.data.data;
            this.showLoader = false;
            this.loadingSearch = false;
          })
058c4a6cf   Shikha Mishra   Improve the funct...
675
          .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
            this.showLoader = false;
            this.loadingSearch = false;
            this.snackbar = true;
            this.text = error.response.data.message;
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
          });
      },
      showTable() {
        this.attendeceTable = true;
        this.getStudentList();
      },
      getStudentList() {
        this.showLoader = true;
        http()
          .get("/getStudentWithClass", {
            params: {
              classId: this.addAttendence.classId,
058c4a6cf   Shikha Mishra   Improve the funct...
697
698
              sectionId: this.addAttendence.sectionId,
            },
710438de6   Shikha Mishra   added teacher mod...
699
          })
058c4a6cf   Shikha Mishra   Improve the funct...
700
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
701
702
703
704
705
706
707
708
            this.studentsData = response.data.data;
            this.showLoader = false;
            // this.addExamAttendenceDialog = false;
            var attendence = "";
            for (let i = 0; i < this.studentsData.length; i++) {
              this.studentsData[i].attendence = false;
            }
          })
058c4a6cf   Shikha Mishra   Improve the funct...
709
          .catch((err) => {
710438de6   Shikha Mishra   added teacher mod...
710
711
712
713
714
715
716
717
718
            console.log("err====>", err);
            this.showLoader = false;
          });
      },
      getExamAttendenceList() {
        this.showLoader = true;
        http()
          .get("/getExamAttendenceList", {
            params: {
b039d39fb   Shikha Mishra   Hide Edit functio...
719
720
721
              examId: this.getAttendence.examId,
              classId: this.getAttendence.classId,
              sectionId: this.getAttendence.sectionId,
058c4a6cf   Shikha Mishra   Improve the funct...
722
723
              subjectId: this.getAttendence.subjectId,
            },
710438de6   Shikha Mishra   added teacher mod...
724
          })
058c4a6cf   Shikha Mishra   Improve the funct...
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
          .then((response) => {
            this.examData = response.data.data;
            if (this.examData.length === 0) {
              this.showLoader = false;
              this.snackbar = true;
              this.text = "No Attendence found!";
              this.color = "error";
              return;
            }
            this.examData = this.examData[0];
            //   if (this.examData.students.length === 0) {
            //     this.showLoader = false;
            //     this.snackbar = true;
            //     this.text = "No Students found!";
            //     this.color = "error";
            //     return;
            //   }
            this.showData = true;
710438de6   Shikha Mishra   added teacher mod...
743
744
            this.showLoader = false;
          })
058c4a6cf   Shikha Mishra   Improve the funct...
745
          .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
746
747
748
749
            console.log("error", error);
            this.showLoader = false;
          });
      },
058c4a6cf   Shikha Mishra   Improve the funct...
750
751
752
753
754
755
756
757
758
759
760
761
      markParticularStudentAttendence(selected) {
        if (selected.attendence) {
          this.selected.push(selected);
        } else {
          for (var i = 0; i < this.selected.length; i++) {
            if (this.selected[i]._id === selected._id) {
              this.selected.splice(i, 1);
              break;
            }
          }
        }
        let presentIndex = this.presentStudent.indexOf(selected._id);
73679431a   Shikha Mishra   clear add exam at...
762
        let absentIndex = this.absentStudent.indexOf(selected._id);
058c4a6cf   Shikha Mishra   Improve the funct...
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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
        if (presentIndex > -1) {
          this.presentStudent.splice(presentIndex, 1);
          this.absentStudent.push(selected._id);
        } else {
          if (absentIndex > -1) {
            this.absentStudent.splice(absentIndex, 1);
          }
          this.presentStudent.push(selected._id);
        }
      },
      selectAll() {
        let markAbsent = false;
        if (this.selected.length === this.studentsData.length) markAbsent = true;
  
        this.presentStudent = [];
        this.absentStudent = [];
        this.selected = [];
  
        for (let i = 0; i < this.studentsData.length; i++) {
          if (markAbsent) {
            this.studentsData[i].attendence = false;
            this.absentStudent.push(this.studentsData[i]._id);
          } else {
            this.studentsData[i].attendence = true;
            this.presentStudent.push(this.studentsData[i]._id);
            this.selected.push(this.studentsData[i]);
          }
        }
      },
      selectParticularStudent(_id) {
        var payload = {
          examAttendanceId: this.examData._id,
          studentId: this.selectedStudent.id,
          isPresent: this.selectedStudent.isPresent,
        };
  
        http()
          .put("/updateExamAttendance", payload)
          .then((response) => {
            this.snackbar = true;
            this.color = "success";
            this.text = "Successfully change attendence";
            this.changeStudentAttendenceDialog = false;
            this.selectedStudent = {};
            this.getExamAttendenceList();
          })
          .catch((error) => {
            this.snackbar = true;
            this.text = error.response.data.message;
          });
      },
      changeSort(column) {
        if (this.pagination.sortBy === column) {
          this.pagination.descending = !this.pagination.descending;
        } else {
          this.pagination.sortBy = column;
          this.pagination.descending = false;
        }
      },
710438de6   Shikha Mishra   added teacher mod...
822
823
824
825
826
827
828
      displaySearch() {
        (this.show = false), (this.showSearch = true);
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
058c4a6cf   Shikha Mishra   Improve the funct...
829
      },
710438de6   Shikha Mishra   added teacher mod...
830
831
832
833
834
835
    },
    mounted() {
      this.token = this.$store.state.token;
      this.getClass();
      this.getExamList();
      this.role = this.$store.state.role;
058c4a6cf   Shikha Mishra   Improve the funct...
836
    },
710438de6   Shikha Mishra   added teacher mod...
837
838
  };
  </script>