Blame view

src/pages/Attendence/viewStudentsAttendence.vue 14.4 KB
687e0b929   Neeraj Sharma   add user,attenden...
1
2
  <template>
    <v-container fluid grid-list-md>
c8a795168   Neeraj Sharma   iplement pdf down...
3
4
5
6
      <div v-show="hideData">
        <v-layout row>
          <v-btn color="grey" @click="exportPdf" class="right" dark>
            Export Pdf
6ae46ca27   Neeraj Sharma   implement upload ...
7
8
            <v-icon dark right size="20">save_alt</v-icon>
          </v-btn>
c8a795168   Neeraj Sharma   iplement pdf down...
9
10
11
12
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
          <v-dialog v-model="dialogExport" max-width="500px">
            <v-btn slot="activator" color="grey" class="right" dark>
              Export csv
              <v-icon dark right size="20">save_alt</v-icon>
            </v-btn>
            <v-card>
              <h3 class="text-xs-center py-2 grey lighten-1 white--text">Export</h3>
              <v-card-text>
                <v-container grid-list-md>
                  <v-layout wrap>
                    <v-flex xs12>
                      <v-menu
                        ref="menuStartDate"
                        :close-on-content-click="false"
                        v-model="menuStartDate"
                        :nudge-right="40"
                        :return-value.sync="startDate"
                        lazy
                        transition="scale-transition"
                        offset-y
                        full-width
                        min-width="290px"
                      >
                        <v-text-field
                          slot="activator"
                          v-model="startDate"
                          label="Select Start Date"
                          prepend-icon="event"
                          readonly
                        ></v-text-field>
                        <v-date-picker
                          v-model="startDate"
                          @input="$refs.menuStartDate.save(startDate)"
                        ></v-date-picker>
                      </v-menu>
                    </v-flex>
                    <v-flex xs12>
                      <v-menu
                        ref="menuEndDate"
                        :close-on-content-click="false"
                        v-model="menuEndDate"
                        :nudge-right="40"
                        :return-value.sync="endDate"
                        lazy
                        transition="scale-transition"
                        offset-y
                        full-width
                        min-width="290px"
687e0b929   Neeraj Sharma   add user,attenden...
57
                      >
c8a795168   Neeraj Sharma   iplement pdf down...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
131
132
133
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
                        <v-text-field
                          slot="activator"
                          v-model="endDate"
                          label="Select End Date"
                          prepend-icon="event"
                          readonly
                        ></v-text-field>
                        <v-date-picker v-model="endDate" @input="$refs.menuEndDate.save(endDate)"></v-date-picker>
                      </v-menu>
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-card-text>
              <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn color="blue darken-1" flat @click.native="dialogExport = false">Close</v-btn>
                <download-csv :data="json_data">
                  <v-btn color="blue darken-1" flat @click.native="exportData">Export</v-btn>
                </download-csv>
              </v-card-actions>
            </v-card>
          </v-dialog>
        </v-layout>
        <v-layout wrap>
          <v-flex xs12 sm12 md4>
            <v-card flat>
              <h3 class="text-xs-center py-2 grey lighten-1 white--text">Profile</h3>
              <v-card-text>
                <v-container>
                  <v-layout wrap>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex
                          xs12
                          class="text-xs-center text-sm-center text-md-center text-lg-center"
                        >
                          <v-avatar size="160px">
                            <img src="/static/icon/user.png" v-if="!studentData.profilePicUrl" />
                            <img
                              :src="studentData.profilePicUrl"
                              v-else-if="studentData.profilePicUrl"
                            />
                          </v-avatar>
                        </v-flex>
                      </v-layout>
                      <v-layout>
                        <v-flex xs12 sm12>
                          <h3 class="text-xs-center">
                            <b>{{ studentData.name }}</b>
                          </h3>
                          <p class="text-xs-center grey--text">Student</p>
                        </v-flex>
                      </v-layout>
                      <v-layout style="border: 1px solid lightgrey;">
                        <v-flex xs6 sm6 class="pa-0">
                          <h4 class="right">
                            <b>Roll No :</b>
                          </h4>
                        </v-flex>
                        <v-flex sm6 xs6 class="pa-0">
                          <h4>{{ studentData.rollNo }}</h4>
                        </v-flex>
                      </v-layout>
                      <v-layout style="border: 1px solid lightgrey;">
                        <v-flex xs6 sm6 class="pa-0">
                          <h4 class="right">
                            <b>Class :</b>
                          </h4>
                        </v-flex>
                        <v-flex sm6 xs6 class="right pa-0">
                          <h4>{{ studentData.classId.classNum }}</h4>
                        </v-flex>
                      </v-layout>
                      <v-layout style="border: 1px solid lightgrey;">
                        <v-flex xs6 sm6 class="right pa-0">
                          <h4 class="right">
                            <b>Section :</b>
                          </h4>
                        </v-flex>
                        <v-flex sm6 xs6 class="right pa-0">
                          <h4>{{ studentData.sectionId.name}}</h4>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-card-text>
            </v-card>
          </v-flex>
          <v-flex xs12 sm12 md8>
            <v-card flat>
              <h3 class="py-2 text-xs-center grey lighten-1 white--text">
                Attendence
                <span class="ml-4">
                  <v-avatar class="green caption" size="12"></v-avatar>
                  <span class="subheading">Present</span>
                </span>
                <span class="ml-4">
                  <v-avatar color="red caption" size="12" class></v-avatar>
                  <span class="subheading">Absent</span>
                </span>
              </h3>
              <YearCalendar
                v-model="year"
                :activeDates="activeDates"
                prefixClass="your_customized_wrapper_class"
                :activeClass="activeClass"
              ></YearCalendar>
            </v-card>
          </v-flex>
        </v-layout>
      </div>
      <v-layout v-show="showPdfData">
        <v-container>
          <v-flex xs12 sm12 md8 offset-sm2>
            <v-btn
              color="grey"
              @click="generatePDF2Canvas()"
              :loading="loadingPdf"
              class="right"
              dark
            >
7140ae6bf   Neeraj Sharma   fixed al,l
180
              Download
c8a795168   Neeraj Sharma   iplement pdf down...
181
182
183
184
              <v-icon dark right size="20">save_alt</v-icon>
            </v-btn>
          </v-flex>
        </v-container>
687e0b929   Neeraj Sharma   add user,attenden...
185
      </v-layout>
c8a795168   Neeraj Sharma   iplement pdf down...
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
      <v-layout v-show="showPdfData">
        <v-container>
          <v-layout v-show="showPdfData">
            <v-flex xs12 sm12 md8 offset-sm2>
              <div ref="printMe">
                <v-flex xs12 class="pl-3">
                  <v-layout>
                    <v-flex xs6 sm2 class="pa-0 mb-1">
                      <h4>
                        <b>Name</b>
                      </h4>
                    </v-flex>
                    <v-flex sm10 xs6 class="pa-0">
                      <h4>: {{ studentData.name }}</h4>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs6 sm2 class="pa-0 mb-1">
                      <h4>
                        <b>Type</b>
                      </h4>
                    </v-flex>
                    <v-flex sm10 xs6 class="pa-0 mb-1">
                      <h4>: Student</h4>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs6 sm2 class="pa-0 mb-1">
                      <h4>
                        <b>Roll No</b>
                      </h4>
                    </v-flex>
                    <v-flex sm10 xs6 class="pa-0 mb-1">
                      <h4>: {{ studentData.rollNo }}</h4>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs6 sm2 class="pa-0 mb-1">
                      <h4>
                        <b>Class</b>
                      </h4>
                    </v-flex>
                    <v-flex sm10 xs6 class="pa-0 mb-1">
                      <h4>: {{ studentData.classId.classNum }}</h4>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs6 sm2 class="pa-0 mb-1">
                      <h4>
                        <b>Section</b>
                      </h4>
                    </v-flex>
                    <v-flex sm10 xs6 class="pa-0 mb-3">
                      <h4>: {{ studentData.sectionId.name}}</h4>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-card flat>
                  <h3 class="py-2 text-xs-center grey lighten-1 white--text">
                    Attendence
                    <span class="ml-4">
                      <v-avatar class="green caption" size="12"></v-avatar>
                      <span class="subheading">Present</span>
                    </span>
                    <span class="ml-4">
                      <v-avatar color="red caption" size="12" class></v-avatar>
                      <span class="subheading">Absent</span>
                    </span>
                  </h3>
                  <YearCalendar
                    v-model="year"
                    :activeDates="activeDates"
                    prefixClass="your_customized_wrapper_class"
                    :activeClass="activeClass"
                  ></YearCalendar>
                </v-card>
              </div>
            </v-flex>
          </v-layout>
        </v-container>
      </v-layout>
      <img :src="output" v-show="false"/>
6ae46ca27   Neeraj Sharma   implement upload ...
268
269
270
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
687e0b929   Neeraj Sharma   add user,attenden...
271
272
    </v-container>
  </template>
c8a795168   Neeraj Sharma   iplement pdf down...
273
  <script lang="js">
687e0b929   Neeraj Sharma   add user,attenden...
274
275
276
  import moment from "moment";
  import http from "@/Services/http.js";
  import YearCalendar from "vue-material-year-calendar";
c8a795168   Neeraj Sharma   iplement pdf down...
277
278
279
  import jsPDF from 'jspdf';
      // eslint-disable-next-line
  import autoTable from 'jspdf-autotable';
687e0b929   Neeraj Sharma   add user,attenden...
280
281
282
283
284
  
  export default {
    components: { YearCalendar },
    data() {
      return {
c8a795168   Neeraj Sharma   iplement pdf down...
285
286
287
288
        showPdfData:false,
        hideData:true,
        loadingPdf:false,
        output:null,
687e0b929   Neeraj Sharma   add user,attenden...
289
        studentsList: [],
6ae46ca27   Neeraj Sharma   implement upload ...
290
291
292
293
294
295
296
        json_data: [],
        dialogExport: false,
        startDate: "",
        endDate: "",
        menuEndDate: false,
        menuStartDate: false,
        showLoader: false,
687e0b929   Neeraj Sharma   add user,attenden...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
        token: "",
        year: new Date().getFullYear(),
        activeDates: [],
        activeClass: "",
        studentData: {}
      };
    },
    mounted() {
      this.token = this.$store.state.token;
      this.getStudentAttendence();
      this.getStudentData();
    },
    methods: {
      dates: function(date) {
        return moment(date).format("MMMM DD, YYYY");
      },
      getStudentAttendence() {
6ae46ca27   Neeraj Sharma   implement upload ...
314
        this.showLoader = true;
687e0b929   Neeraj Sharma   add user,attenden...
315
316
317
318
319
320
321
322
323
        http()
          .get(
            "/studentAttendance",
            { params: { studentId: this.$route.params.id } },
            {
              headers: { Authorization: "Bearer " + this.token }
            }
          )
          .then(response => {
6ae46ca27   Neeraj Sharma   implement upload ...
324
            this.showLoader = false;
687e0b929   Neeraj Sharma   add user,attenden...
325
326
327
328
329
            let array = [];
            for (let i = 0; i < response.data.data.length; i++) {
              if (response.data.data[i].students[0].isPresent == true) {
                array.push({
                  date: response.data.data[i].date,
a99e002d3   Neeraj Sharma   solve bygs atten...
330
                  className: "green"
687e0b929   Neeraj Sharma   add user,attenden...
331
332
333
334
335
336
337
338
339
340
                });
              } else if (response.data.data[i].students[0].isPresent == false) {
                array.push({
                  date: response.data.data[i].date,
                  className: "red"
                });
              }
            }
            this.activeDates = array;
          })
ab54b5656   Neeraj Sharma   implement library...
341
          .catch(error => {
6ae46ca27   Neeraj Sharma   implement upload ...
342
343
344
345
346
            this.showLoader = false;
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
00e4bc4e1   Neeraj Sharma   fixed auntentication
347
              this.$store.dispatch("Role", null);
6ae46ca27   Neeraj Sharma   implement upload ...
348
            }
687e0b929   Neeraj Sharma   add user,attenden...
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
          });
      },
      getStudentData() {
        http()
          .get(
            "/getParticularStudentDetail",
            { params: { studentId: this.$route.params.id } },
            {
              headers: { Authorization: "Bearer " + this.token }
            }
          )
          .then(response => {
            this.studentData = response.data.data;
          })
          .catch(err => {
            console.log("err====>", err);
            // this.$router.replace({ path: '/' });
          });
6ae46ca27   Neeraj Sharma   implement upload ...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
      },
      exportData() {
        http()
          .get(
            "/studentAttendanceByMonth",
            {
              params: {
                studentId: this.$route.params.id,
                startDate: this.startDate,
                endDate: this.endDate
              }
            },
            {
              headers: { Authorization: "Bearer " + this.token }
            }
          )
          .then(response => {
            this.json_data = response.data.data;
c8a795168   Neeraj Sharma   iplement pdf down...
385
            this.dialogExport = true;
6ae46ca27   Neeraj Sharma   implement upload ...
386
387
388
389
390
          })
          .catch(err => {
            console.log("err====>", err);
            // this.$router.replace({ path: '/' });
          });
c8a795168   Neeraj Sharma   iplement pdf down...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
      },
      exportPdf(){
          this.hideData = false;
          this.showPdfData = true   
      },
       async  generatePDF2Canvas(){
              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(this.output);
              if(this.output) {
                 this.loadingPdf = false
              }
              let doc = new jsPDF();
              doc.addImage(this.output, 'JPEG', 5, 10, 200, 280);
37150e7c1   Neeraj Sharma   implement school ...
412
              doc.save("Attendance.pdf");
c8a795168   Neeraj Sharma   iplement pdf down...
413
          }
687e0b929   Neeraj Sharma   add user,attenden...
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
    }
  };
  </script>
  
  <style lang="stylus">
  .your_customized_wrapper_class {
    background-color: #0aa;
    color: white;
  
    &.red {
      background-color: red;
      color: white;
  
      &:after {
        background-size: 100% 100%;
      }
    }
  
    &.blue {
      background-color: #0000aa;
      color: white;
    }
  
    &.your_customized_classname {
      background-color: yellow;
      color: black;
    }
  }
  </style>