Blame view

src/pages/Attendence/studentAttendence.vue 15.1 KB
687e0b929   Neeraj Sharma   add user,attenden...
1
  <template>
68d742034   Neeraj Sharma   implement new des...
2
    <v-container fluid class="body-color">
687e0b929   Neeraj Sharma   add user,attenden...
3
4
5
6
7
8
9
10
      <v-snackbar
        :timeout="timeout"
        :top="y === 'top'"
        :right="x === 'right'"
        :vertical="mode === 'vertical'"
        v-model="snackbar"
        color="success"
      >{{ text }}</v-snackbar>
68d742034   Neeraj Sharma   implement new des...
11
12
      <!-- ****** ATTENDENCE STUDENTS TABLE ****** -->
      <!-- <download-csv :data="json_data">
6ae46ca27   Neeraj Sharma   implement upload ...
13
              <v-btn>Download Data</v-btn>
68d742034   Neeraj Sharma   implement new des...
14
15
      </download-csv>-->
      <v-toolbar color="transparent" flat>
710438de6   Shikha Mishra   added teacher mod...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
        <v-btn
          fab
          dark
          class="open-dialog-button hidden-xl-only hidden-md-only hidden-lg-only"
          small
          @click="addStudentAttendenceDialog = true"
        >
          <v-icon dark>add</v-icon>
        </v-btn>
        <v-btn
          v-if="role != 'ADMIN' && schoolRole != 'SCHOOLADMIN' "
          round
          class="open-dialog-button hidden-sm-only hidden-xs-only"
          dark
          @click="addStudentAttendenceDialog = true"
        >
          <v-icon class="white--text pr-1" size="20">add</v-icon>Add Student Attendence
        </v-btn>
68d742034   Neeraj Sharma   implement new des...
34
35
36
37
38
39
        <v-spacer></v-spacer>
        <v-flex xs12 sm4 md2>
          <v-select
            small
            :items="addclass"
            label="Select Class"
b0e0491ab   Shikha Mishra   solve the issue o...
40
            v-model="getAttendence.classId"
68d742034   Neeraj Sharma   implement new des...
41
42
43
            item-text="classNum"
            item-value="_id"
            name="Select Class"
b0e0491ab   Shikha Mishra   solve the issue o...
44
            @change="getSection(getAttendence.classId)"
710438de6   Shikha Mishra   added teacher mod...
45
46
47
48
49
50
51
52
53
            class="px-2"
            required
          ></v-select>
        </v-flex>
        <v-flex xs12 sm4 md2>
          <v-select
            small
            :items="addSection"
            label="Select Section"
b0e0491ab   Shikha Mishra   solve the issue o...
54
            v-model="getAttendence.sectionId"
710438de6   Shikha Mishra   added teacher mod...
55
56
57
            item-text="name"
            item-value="_id"
            name="Select Section"
8e8d14254   Shikha Mishra   Cleared data whil...
58
            @change="getStudentsDetail(getAttendence.sectionId)"
68d742034   Neeraj Sharma   implement new des...
59
60
61
62
63
64
65
            class="px-2"
            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">
aa310d61a   Shikha Mishra   added functionali...
66
              <img src="/static/icon/search.png" alt="icon" />
68d742034   Neeraj Sharma   implement new des...
67
68
69
            </v-avatar>
          </v-btn>
        </v-card-title>
612b79bb4   Amber Dev   made serch auto f...
70
        <v-flex xs8 sm8 md3 lg2 v-if="showSearch">
68d742034   Neeraj Sharma   implement new des...
71
          <v-layout>
8e8d14254   Shikha Mishra   Cleared data whil...
72
73
74
75
76
77
78
            <v-text-field
              autofocus
              v-model="search"
              label="Search"
              prepend-inner-icon="search"
              color="primary"
            ></v-text-field>
68d742034   Neeraj Sharma   implement new des...
79
            <v-icon @click="closeSearch" color="error">close</v-icon>
687e0b929   Neeraj Sharma   add user,attenden...
80
          </v-layout>
68d742034   Neeraj Sharma   implement new des...
81
82
        </v-flex>
      </v-toolbar>
687e0b929   Neeraj Sharma   add user,attenden...
83
84
      <v-data-table
        :headers="headers"
710438de6   Shikha Mishra   added teacher mod...
85
        :items="studentsData"
687e0b929   Neeraj Sharma   add user,attenden...
86
87
88
89
        :pagination.sync="pagination"
        :search="search"
      >
        <template slot="items" slot-scope="props">
68d742034   Neeraj Sharma   implement new des...
90
91
92
93
94
95
96
97
98
          <tr class="tr">
            <td class="td td-row">{{ props.index + 1}}</td>
            <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="text-xs-center td td-row">{{ props.item.name}}</td>
710438de6   Shikha Mishra   added teacher mod...
99
            <td class="text-xs-center td td-row">{{ props.item.fatherCellNo}}</td>
68d742034   Neeraj Sharma   implement new des...
100
101
            <td class="text-xs-center td td-row">{{ props.item.email }}</td>
            <td class="text-xs-center td td-row">
2fe1115d8   Shikha Mishra   added csv button ...
102
              <router-link :to="{ name:'View Students Attendence',params: { id:props.item._id } }">
68d742034   Neeraj Sharma   implement new des...
103
104
105
106
107
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:25px; "
                    class="mr-3"
aa310d61a   Shikha Mishra   added functionali...
108
                    src="/static/icon/view.png"
68d742034   Neeraj Sharma   implement new des...
109
                  />
67a276510   Shikha Mishra   fixed all bugs
110
                  <span>View</span>
68d742034   Neeraj Sharma   implement new des...
111
112
                </v-tooltip>
              </router-link>
68d742034   Neeraj Sharma   implement new des...
113
114
            </td>
          </tr>
687e0b929   Neeraj Sharma   add user,attenden...
115
116
117
118
119
120
121
122
        </template>
        <v-alert
          slot="no-results"
          :value="true"
          color="error"
          icon="warning"
        >Your search for "{{ search }}" found no results.</v-alert>
      </v-data-table>
710438de6   Shikha Mishra   added teacher mod...
123
      <!-- ****** Add Students Attendece****** -->
8e8d14254   Shikha Mishra   Cleared data whil...
124
      <v-dialog v-model="addStudentAttendenceDialog" width="1600" v-if="addStudentAttendenceDialog">
710438de6   Shikha Mishra   added teacher mod...
125
126
127
128
        <v-card flat class="pa-2">
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Add Student Attendence</label>
8e8d14254   Shikha Mishra   Cleared data whil...
129
130
131
132
133
              <v-icon
                size="24"
                class="right"
                @click="$refs.form.reset();addStudentAttendenceDialog = false"
              >cancel</v-icon>
710438de6   Shikha Mishra   added teacher mod...
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
174
175
176
177
178
179
180
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
            </v-flex>
          </v-layout>
          <v-flex xs12 class="mt-4">
            <v-form ref="form" v-model="valid" lazy-validation>
              <v-flex xs12 sm12 lg12>
                <v-layout wrap>
                  <v-flex xs6 sm6 lg3 md4>
                    <v-layout>
                      <v-flex xs3 sm6 lg2 class="subheading mt-4">
                        <label class="right">Class:</label>
                      </v-flex>
                      <v-flex xs9 sm6 lg8 class="ml-2">
                        <v-select
                          v-model="getReport.classId"
                          label="Select your class"
                          type="text"
                          :items="addclass"
                          item-text="classNum"
                          item-value="_id"
                          :rules="classRules"
                          @change="getSection(getReport.classId)"
                          required
                        ></v-select>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs6 sm6 lg3 md8>
                    <v-layout>
                      <v-flex xs3 sm6 lg2 class="subheading mt-4">
                        <label class="right">Section:</label>
                      </v-flex>
                      <v-flex xs9 sm6 lg8 class="ml-2">
                        <v-select
                          :items="addSection"
                          label="Select your Section"
                          v-model="getReport.sectionId"
                          item-text="name"
                          item-value="_id"
                          name="Select Section"
                          :rules="sectionRules"
                          required
                        ></v-select>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs6 sm6 lg3 md4>
                    <v-menu
                      ref="menu"
                      :close-on-content-click="false"
                      v-model="menu"
                      :nudge-right="40"
                      lazy
                      transition="scale-transition"
                      offset-y
                      full-width
                      min-width="290px"
                    >
                      <v-text-field
                        slot="activator"
                        v-model="date"
                        label="Select Date"
                        append-icon="event"
                        :rules="dataValid"
                        readonly
                      ></v-text-field>
                      <v-date-picker
                        ref="picker"
                        v-model="date"
                        :max="new Date().toISOString().substr(0, 10)"
                        min="1950-01-01"
                        @change="save"
                      ></v-date-picker>
                    </v-menu>
                  </v-flex>
                  <v-flex xs6 sm6 lg9 md8>
                    <v-btn round dark class="add-button" @click="showTable">Attendence</v-btn>
                  </v-flex>
                </v-layout>
              </v-flex>
            </v-form>
          </v-flex>
          <v-flex xs12 v-show="attendeceTable" class>
            <v-data-table
              :headers="headers"
              :items="studentsData"
              :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">
                      <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="text-xs-center td td-row">{{ props.item.name}}</td>
                  <td class="text-xs-center td td-row">{{ props.item.fatherCellNo }}</td>
                  <td class="text-xs-center td td-row">{{ props.item.email }}</td>
                  <td class="text-xs-center td td-row">
                    <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>
                  </td>
                </tr>
              </template>
            </v-data-table>
            <v-flex xs12>
              <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn @click="update()" class="add-button" round dark>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="success"
      >{{ text }}</v-snackbar>
687e0b929   Neeraj Sharma   add user,attenden...
264
265
266
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
68d742034   Neeraj Sharma   implement new des...
267
    </v-container>
687e0b929   Neeraj Sharma   add user,attenden...
268
269
270
271
  </template>
  
  <script>
  import http from "@/Services/http.js";
687e0b929   Neeraj Sharma   add user,attenden...
272
273
274
275
276
277
278
279
280
281
  import moment from "moment";
  
  export default {
    data: () => ({
      snackbar: false,
      y: "top",
      x: "right",
      mode: "",
      timeout: 3000,
      text: "",
68d742034   Neeraj Sharma   implement new des...
282
283
      show: true,
      showSearch: false,
687e0b929   Neeraj Sharma   add user,attenden...
284
285
286
287
288
289
      showLoader: false,
      loading: false,
      date: null,
      search: "",
      addclass: [],
      pagination: {
b0e0491ab   Shikha Mishra   solve the issue o...
290
        rowsPerPage: 10,
687e0b929   Neeraj Sharma   add user,attenden...
291
292
293
294
295
296
297
298
      },
      imageData: {},
      imageName: "",
      imageUrl: "",
      imageFile: "",
      headers: [
        {
          text: "No",
68d742034   Neeraj Sharma   implement new des...
299
          align: "",
687e0b929   Neeraj Sharma   add user,attenden...
300
          sortable: false,
b0e0491ab   Shikha Mishra   solve the issue o...
301
          value: "index",
687e0b929   Neeraj Sharma   add user,attenden...
302
303
304
305
306
        },
        {
          text: "Profile Pic",
          value: "profilprofilePicUrlePicUrl",
          sortable: false,
b0e0491ab   Shikha Mishra   solve the issue o...
307
          align: "center",
687e0b929   Neeraj Sharma   add user,attenden...
308
309
        },
        { text: "Name", value: "name", sortable: false, align: "center" },
710438de6   Shikha Mishra   added teacher mod...
310
311
312
313
        {
          text: "Mobile No",
          value: "fatherCellNo",
          sortable: false,
b0e0491ab   Shikha Mishra   solve the issue o...
314
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
315
        },
687e0b929   Neeraj Sharma   add user,attenden...
316
        { text: "Email", value: "email", sortable: false, align: "center" },
b0e0491ab   Shikha Mishra   solve the issue o...
317
        { text: "Attendance", value: "", sortable: false, align: "center" },
687e0b929   Neeraj Sharma   add user,attenden...
318
      ],
6ae46ca27   Neeraj Sharma   implement upload ...
319
      // json_data: [],
687e0b929   Neeraj Sharma   add user,attenden...
320
321
322
323
      parentId: "",
      token: "",
      selectStudents: {
        select: "",
b0e0491ab   Shikha Mishra   solve the issue o...
324
        selectSection: "",
710438de6   Shikha Mishra   added teacher mod...
325
326
327
328
329
330
331
332
333
334
      },
  
      role: "",
      schoolRole: "",
      addStudentAttendenceDialog: false,
      attendeceTable: false,
      menu: false,
      valid: true,
  
      getReport: {},
b0e0491ab   Shikha Mishra   solve the issue o...
335
      getAttendence: {},
710438de6   Shikha Mishra   added teacher mod...
336
337
338
339
340
      studentsList: [],
      studentsData: [],
      addSection: [],
  
      SectionName: ["A", "B", "C", "D", "E", "F"],
b0e0491ab   Shikha Mishra   solve the issue o...
341
342
343
344
      classRules: [(v) => !!v || "Class is required"],
      sectionRules: [(v) => !!v || "Class is required"],
      studentRules: [(v) => !!v || "Student is required"],
      dataValid: [(v) => !!v || "Date is required"],
710438de6   Shikha Mishra   added teacher mod...
345
346
347
348
  
      attendenceType: [
        {
          label: "Present",
b0e0491ab   Shikha Mishra   solve the issue o...
349
          value: true,
710438de6   Shikha Mishra   added teacher mod...
350
351
352
        },
        {
          label: "Absent",
b0e0491ab   Shikha Mishra   solve the issue o...
353
354
355
          value: false,
        },
      ],
687e0b929   Neeraj Sharma   add user,attenden...
356
    }),
8e8d14254   Shikha Mishra   Cleared data whil...
357
358
359
360
    watch: {
      addStudentAttendenceDialog: function (val) {
        if (!val) {
          this.getReport = [];
01a4a5246   Shikha Mishra   When the modal wa...
361
          // this.studentsData = [];
8e8d14254   Shikha Mishra   Cleared data whil...
362
363
364
        }
      },
    },
687e0b929   Neeraj Sharma   add user,attenden...
365
    methods: {
710438de6   Shikha Mishra   added teacher mod...
366
367
368
369
370
371
372
373
374
375
      save(date) {
        this.$refs.menu.save(date);
      },
      showTable() {
        this.attendeceTable = true;
        this.getStudents();
      },
      getAllClass() {
        http()
          .get("/getClassesList", {
b0e0491ab   Shikha Mishra   solve the issue o...
376
            headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
377
          })
b0e0491ab   Shikha Mishra   solve the issue o...
378
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
379
380
            this.addclass = response.data.data;
          })
b0e0491ab   Shikha Mishra   solve the issue o...
381
          .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
382
383
384
385
386
            // console.log("err====>", err);
            // this.$router.replace({ path: "/" });
          });
      },
      getSection(_id) {
6ae46ca27   Neeraj Sharma   implement upload ...
387
        this.showLoader = true;
687e0b929   Neeraj Sharma   add user,attenden...
388
389
        http()
          .get(
710438de6   Shikha Mishra   added teacher mod...
390
            "/getSectionsList",
687e0b929   Neeraj Sharma   add user,attenden...
391
392
            { params: { classId: _id } },
            {
b0e0491ab   Shikha Mishra   solve the issue o...
393
              headers: { Authorization: "Bearer " + this.token },
687e0b929   Neeraj Sharma   add user,attenden...
394
395
            }
          )
b0e0491ab   Shikha Mishra   solve the issue o...
396
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
397
            this.addSection = response.data.data;
6ae46ca27   Neeraj Sharma   implement upload ...
398
            this.showLoader = false;
687e0b929   Neeraj Sharma   add user,attenden...
399
          })
b0e0491ab   Shikha Mishra   solve the issue o...
400
          .catch((err) => {
6ae46ca27   Neeraj Sharma   implement upload ...
401
            this.showLoader = false;
710438de6   Shikha Mishra   added teacher mod...
402
            // console.log("err====>", err);
687e0b929   Neeraj Sharma   add user,attenden...
403
404
          });
      },
710438de6   Shikha Mishra   added teacher mod...
405
406
      getStudents(_id) {
        this.showLoader = true;
687e0b929   Neeraj Sharma   add user,attenden...
407
        http()
710438de6   Shikha Mishra   added teacher mod...
408
409
          .get("/getStudentWithClass", {
            params: {
8e8d14254   Shikha Mishra   Cleared data whil...
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
              classId: this.getReport.classId,
              sectionId: this.getReport.sectionId,
            },
          })
          .then((response) => {
            this.studentsData = response.data.data;
            this.showLoader = false;
            // this.addStudentAttendenceDialog = false;
            var attendence = "";
            for (let i = 0; i < this.studentsData.length; i++) {
              this.studentsData[i].attendence = true;
            }
          })
          .catch((error) => {
            console.log("err====>", error);
            this.showLoader = false;
          });
      },
      getStudentsDetail(_id) {
        this.showLoader = true;
        http()
          .get("/getStudentWithClass", {
            params: {
b0e0491ab   Shikha Mishra   solve the issue o...
433
434
435
              classId: this.getAttendence.classId,
              sectionId: this.getAttendence.sectionId,
            },
687e0b929   Neeraj Sharma   add user,attenden...
436
          })
b0e0491ab   Shikha Mishra   solve the issue o...
437
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
438
439
440
441
442
443
444
            this.studentsData = response.data.data;
            this.showLoader = false;
            // this.addStudentAttendenceDialog = false;
            var attendence = "";
            for (let i = 0; i < this.studentsData.length; i++) {
              this.studentsData[i].attendence = true;
            }
687e0b929   Neeraj Sharma   add user,attenden...
445
          })
b0e0491ab   Shikha Mishra   solve the issue o...
446
          .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
447
448
449
450
451
452
453
454
455
            console.log("err====>", error);
            this.showLoader = false;
          });
      },
      update() {
        var studentsAttendence = [];
        for (var j = 0; j < this.studentsData.length; j++) {
          studentsAttendence.push({
            studentId: this.studentsData[j]._id,
b0e0491ab   Shikha Mishra   solve the issue o...
456
            isPresent: this.studentsData[j].attendence,
687e0b929   Neeraj Sharma   add user,attenden...
457
          });
710438de6   Shikha Mishra   added teacher mod...
458
459
460
461
462
        }
        if (this.$refs.form.validate()) {
          let attendanceData = {
            sectionId: this.getReport.sectionId,
            date: this.date,
b0e0491ab   Shikha Mishra   solve the issue o...
463
            students: studentsAttendence,
710438de6   Shikha Mishra   added teacher mod...
464
465
466
          };
          http()
            .put("/updateAttendance", attendanceData)
b0e0491ab   Shikha Mishra   solve the issue o...
467
            .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
468
469
470
471
              this.snackbar = true;
              this.text = response.data.message;
              this.addStudentAttendenceDialog = false;
            })
b0e0491ab   Shikha Mishra   solve the issue o...
472
            .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
473
474
475
476
              this.snackbar = true;
              this.text = error.response.data.message;
            });
        }
68d742034   Neeraj Sharma   implement new des...
477
      },
710438de6   Shikha Mishra   added teacher mod...
478

68d742034   Neeraj Sharma   implement new des...
479
      displaySearch() {
8e8d14254   Shikha Mishra   Cleared data whil...
480
481
        this.show = false;
        this.showSearch = true;
68d742034   Neeraj Sharma   implement new des...
482
483
484
485
486
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
b0e0491ab   Shikha Mishra   solve the issue o...
487
      },
687e0b929   Neeraj Sharma   add user,attenden...
488
489
490
491
492
    },
    mounted() {
      // this.getStudentList();
      this.token = this.$store.state.token;
      this.getAllClass();
710438de6   Shikha Mishra   added teacher mod...
493
      this.role = this.$store.state.role;
b0e0491ab   Shikha Mishra   solve the issue o...
494
    },
687e0b929   Neeraj Sharma   add user,attenden...
495
  };
68d742034   Neeraj Sharma   implement new des...
496
  </script>