Blame view

src/pages/Attendence/studentAttendence.vue 15.6 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****** -->
860da881d   Shikha Mishra   comment all consoles
124
125
126
127
128
129
      <v-dialog
        v-model="addStudentAttendenceDialog"
        width="1600"
        v-if="addStudentAttendenceDialog"
        persistent
      >
710438de6   Shikha Mishra   added teacher mod...
130
131
132
133
        <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...
134
135
136
137
138
              <v-icon
                size="24"
                class="right"
                @click="$refs.form.reset();addStudentAttendenceDialog = false"
              >cancel</v-icon>
710438de6   Shikha Mishra   added teacher mod...
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
264
265
266
267
268
            </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...
269
270
271
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
68d742034   Neeraj Sharma   implement new des...
272
    </v-container>
687e0b929   Neeraj Sharma   add user,attenden...
273
274
275
276
  </template>
  
  <script>
  import http from "@/Services/http.js";
687e0b929   Neeraj Sharma   add user,attenden...
277
278
279
280
281
282
283
284
285
286
  import moment from "moment";
  
  export default {
    data: () => ({
      snackbar: false,
      y: "top",
      x: "right",
      mode: "",
      timeout: 3000,
      text: "",
68d742034   Neeraj Sharma   implement new des...
287
288
      show: true,
      showSearch: false,
687e0b929   Neeraj Sharma   add user,attenden...
289
290
291
292
293
294
      showLoader: false,
      loading: false,
      date: null,
      search: "",
      addclass: [],
      pagination: {
b0e0491ab   Shikha Mishra   solve the issue o...
295
        rowsPerPage: 10,
687e0b929   Neeraj Sharma   add user,attenden...
296
297
298
299
300
301
302
303
      },
      imageData: {},
      imageName: "",
      imageUrl: "",
      imageFile: "",
      headers: [
        {
          text: "No",
68d742034   Neeraj Sharma   implement new des...
304
          align: "",
687e0b929   Neeraj Sharma   add user,attenden...
305
          sortable: false,
b0e0491ab   Shikha Mishra   solve the issue o...
306
          value: "index",
687e0b929   Neeraj Sharma   add user,attenden...
307
308
309
310
311
        },
        {
          text: "Profile Pic",
          value: "profilprofilePicUrlePicUrl",
          sortable: false,
b0e0491ab   Shikha Mishra   solve the issue o...
312
          align: "center",
687e0b929   Neeraj Sharma   add user,attenden...
313
314
        },
        { text: "Name", value: "name", sortable: false, align: "center" },
710438de6   Shikha Mishra   added teacher mod...
315
316
317
318
        {
          text: "Mobile No",
          value: "fatherCellNo",
          sortable: false,
b0e0491ab   Shikha Mishra   solve the issue o...
319
          align: "center",
710438de6   Shikha Mishra   added teacher mod...
320
        },
687e0b929   Neeraj Sharma   add user,attenden...
321
        { text: "Email", value: "email", sortable: false, align: "center" },
b0e0491ab   Shikha Mishra   solve the issue o...
322
        { text: "Attendance", value: "", sortable: false, align: "center" },
687e0b929   Neeraj Sharma   add user,attenden...
323
      ],
6ae46ca27   Neeraj Sharma   implement upload ...
324
      // json_data: [],
687e0b929   Neeraj Sharma   add user,attenden...
325
326
327
328
      parentId: "",
      token: "",
      selectStudents: {
        select: "",
b0e0491ab   Shikha Mishra   solve the issue o...
329
        selectSection: "",
710438de6   Shikha Mishra   added teacher mod...
330
331
332
333
334
335
336
337
338
339
      },
  
      role: "",
      schoolRole: "",
      addStudentAttendenceDialog: false,
      attendeceTable: false,
      menu: false,
      valid: true,
  
      getReport: {},
b0e0491ab   Shikha Mishra   solve the issue o...
340
      getAttendence: {},
710438de6   Shikha Mishra   added teacher mod...
341
342
343
344
345
      studentsList: [],
      studentsData: [],
      addSection: [],
  
      SectionName: ["A", "B", "C", "D", "E", "F"],
b0e0491ab   Shikha Mishra   solve the issue o...
346
347
348
349
      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...
350
351
352
353
  
      attendenceType: [
        {
          label: "Present",
b0e0491ab   Shikha Mishra   solve the issue o...
354
          value: true,
710438de6   Shikha Mishra   added teacher mod...
355
356
357
        },
        {
          label: "Absent",
b0e0491ab   Shikha Mishra   solve the issue o...
358
359
360
          value: false,
        },
      ],
687e0b929   Neeraj Sharma   add user,attenden...
361
    }),
8e8d14254   Shikha Mishra   Cleared data whil...
362
363
364
365
    watch: {
      addStudentAttendenceDialog: function (val) {
        if (!val) {
          this.getReport = [];
01a4a5246   Shikha Mishra   When the modal wa...
366
          // this.studentsData = [];
8e8d14254   Shikha Mishra   Cleared data whil...
367
368
369
        }
      },
    },
687e0b929   Neeraj Sharma   add user,attenden...
370
    methods: {
710438de6   Shikha Mishra   added teacher mod...
371
372
373
374
375
376
377
378
379
380
      save(date) {
        this.$refs.menu.save(date);
      },
      showTable() {
        this.attendeceTable = true;
        this.getStudents();
      },
      getAllClass() {
        http()
          .get("/getClassesList", {
b0e0491ab   Shikha Mishra   solve the issue o...
381
            headers: { Authorization: "Bearer " + this.token },
710438de6   Shikha Mishra   added teacher mod...
382
          })
b0e0491ab   Shikha Mishra   solve the issue o...
383
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
384
385
            this.addclass = response.data.data;
          })
b0e0491ab   Shikha Mishra   solve the issue o...
386
          .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
387
388
            // console.log("err====>", err);
            // this.$router.replace({ path: "/" });
860da881d   Shikha Mishra   comment all consoles
389
390
391
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
710438de6   Shikha Mishra   added teacher mod...
392
393
394
          });
      },
      getSection(_id) {
6ae46ca27   Neeraj Sharma   implement upload ...
395
        this.showLoader = true;
7014df603   Shikha Mishra   Improve placehold...
396
        this.studentsData = [];
687e0b929   Neeraj Sharma   add user,attenden...
397
398
        http()
          .get(
710438de6   Shikha Mishra   added teacher mod...
399
            "/getSectionsList",
687e0b929   Neeraj Sharma   add user,attenden...
400
401
            { params: { classId: _id } },
            {
b0e0491ab   Shikha Mishra   solve the issue o...
402
              headers: { Authorization: "Bearer " + this.token },
687e0b929   Neeraj Sharma   add user,attenden...
403
404
            }
          )
b0e0491ab   Shikha Mishra   solve the issue o...
405
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
406
            this.addSection = response.data.data;
6ae46ca27   Neeraj Sharma   implement upload ...
407
            this.showLoader = false;
687e0b929   Neeraj Sharma   add user,attenden...
408
          })
b0e0491ab   Shikha Mishra   solve the issue o...
409
          .catch((err) => {
6ae46ca27   Neeraj Sharma   implement upload ...
410
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
411
412
413
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
710438de6   Shikha Mishra   added teacher mod...
414
            // console.log("err====>", err);
687e0b929   Neeraj Sharma   add user,attenden...
415
416
          });
      },
710438de6   Shikha Mishra   added teacher mod...
417
418
      getStudents(_id) {
        this.showLoader = true;
687e0b929   Neeraj Sharma   add user,attenden...
419
        http()
710438de6   Shikha Mishra   added teacher mod...
420
421
          .get("/getStudentWithClass", {
            params: {
8e8d14254   Shikha Mishra   Cleared data whil...
422
423
424
425
426
427
428
429
430
431
432
433
434
435
              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) => {
860da881d   Shikha Mishra   comment all consoles
436
            //   console.log("err====>", error);
8e8d14254   Shikha Mishra   Cleared data whil...
437
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
438
439
440
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
8e8d14254   Shikha Mishra   Cleared data whil...
441
442
443
444
445
446
447
          });
      },
      getStudentsDetail(_id) {
        this.showLoader = true;
        http()
          .get("/getStudentWithClass", {
            params: {
b0e0491ab   Shikha Mishra   solve the issue o...
448
449
450
              classId: this.getAttendence.classId,
              sectionId: this.getAttendence.sectionId,
            },
687e0b929   Neeraj Sharma   add user,attenden...
451
          })
b0e0491ab   Shikha Mishra   solve the issue o...
452
          .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
453
454
455
456
457
458
459
            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...
460
          })
b0e0491ab   Shikha Mishra   solve the issue o...
461
          .catch((error) => {
860da881d   Shikha Mishra   comment all consoles
462
            //   console.log("err====>", error);
710438de6   Shikha Mishra   added teacher mod...
463
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
464
465
466
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
710438de6   Shikha Mishra   added teacher mod...
467
468
469
470
471
472
473
          });
      },
      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...
474
            isPresent: this.studentsData[j].attendence,
687e0b929   Neeraj Sharma   add user,attenden...
475
          });
710438de6   Shikha Mishra   added teacher mod...
476
477
478
479
480
        }
        if (this.$refs.form.validate()) {
          let attendanceData = {
            sectionId: this.getReport.sectionId,
            date: this.date,
b0e0491ab   Shikha Mishra   solve the issue o...
481
            students: studentsAttendence,
710438de6   Shikha Mishra   added teacher mod...
482
483
484
          };
          http()
            .put("/updateAttendance", attendanceData)
b0e0491ab   Shikha Mishra   solve the issue o...
485
            .then((response) => {
710438de6   Shikha Mishra   added teacher mod...
486
487
488
489
              this.snackbar = true;
              this.text = response.data.message;
              this.addStudentAttendenceDialog = false;
            })
b0e0491ab   Shikha Mishra   solve the issue o...
490
            .catch((error) => {
710438de6   Shikha Mishra   added teacher mod...
491
492
493
494
              this.snackbar = true;
              this.text = error.response.data.message;
            });
        }
68d742034   Neeraj Sharma   implement new des...
495
      },
710438de6   Shikha Mishra   added teacher mod...
496

68d742034   Neeraj Sharma   implement new des...
497
      displaySearch() {
8e8d14254   Shikha Mishra   Cleared data whil...
498
499
        this.show = false;
        this.showSearch = true;
68d742034   Neeraj Sharma   implement new des...
500
501
502
503
504
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
b0e0491ab   Shikha Mishra   solve the issue o...
505
      },
687e0b929   Neeraj Sharma   add user,attenden...
506
507
508
509
510
    },
    mounted() {
      // this.getStudentList();
      this.token = this.$store.state.token;
      this.getAllClass();
710438de6   Shikha Mishra   added teacher mod...
511
      this.role = this.$store.state.role;
b0e0491ab   Shikha Mishra   solve the issue o...
512
    },
687e0b929   Neeraj Sharma   add user,attenden...
513
  };
68d742034   Neeraj Sharma   implement new des...
514
  </script>