Blame view

src/pages/Course/enrollStudents.vue 12.7 KB
229463bd5   Neeraj Sharma   implement design ...
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">
      <!-- ****** STUDENTS TABLE ****** -->
      <v-toolbar color="transparent" flat>
        <v-spacer></v-spacer>
        <v-flex xs12 sm4 md2>
          <v-select
            small
            :items="addclass"
            label="Select Class"
            v-model="getReport.classId"
            item-text="classNum"
            item-value="_id"
            name="Select Class"
            @change="getCourses(getReport.classId)"
            class="mr-2"
            required
          ></v-select>
        </v-flex>
        <v-flex xs12 sm4 md2>
          <v-select
            :items="courseData"
            label="Select Course"
            v-model="getReport.courseId"
0a5256600   Amber Dev   added events
25
            item-text="courseName"
229463bd5   Neeraj Sharma   implement design ...
26
27
28
29
30
31
32
33
34
35
36
37
38
            item-value="_id"
            required
            class="ml-2"
            @change="getStudentTable(getReport.courseId)"
          ></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...
39
        <v-flex xs8 sm8 md3 lg2 v-if="showSearch">
229463bd5   Neeraj Sharma   implement design ...
40
          <v-layout>
7f4d490dd   Amber Dev   hid snackbar from...
41
42
43
44
45
46
47
            <v-text-field
              autofocus
              v-model="search"
              label="Search"
              prepend-inner-icon="search"
              color="primary"
            ></v-text-field>
229463bd5   Neeraj Sharma   implement design ...
48
49
50
51
52
53
54
55
56
57
58
            <v-icon @click="closeSearch" color="error">close</v-icon>
          </v-layout>
        </v-flex>
      </v-toolbar>
      <v-data-table
        :headers="headers"
        :items="studentsData"
        :pagination.sync="pagination"
        :search="search"
        select-all
        v-model="selected"
b0f5f6684   Shikha Mishra   Conditionally sho...
59
        item-key="_id"
229463bd5   Neeraj Sharma   implement design ...
60
61
62
63
64
      >
        <template slot="items" slot-scope="props">
          <tr class="tr" :active="props.selected" @click="props.selected = !props.selected">
            <td class="text-xs-center td td-row">
              <v-checkbox
6ef520020   Neeraj Sharma   implement all fun...
65
66
                v-model="props.item.enroll"
                @change="selectParticularStudent(props.item)"
229463bd5   Neeraj Sharma   implement design ...
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
                primary
                hide-details
              ></v-checkbox>
            </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>
          </tr>
        </template>
        <template slot="headers" slot-scope="props">
          <tr>
            <th>
              <v-checkbox
                :input-value="props.all"
                :indeterminate="props.indeterminate"
                primary
                hide-details
                @click.native="toggleAll"
              ></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>
          </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-snackbar
        :timeout="timeout"
        :top="y === 'top'"
        :right="x === 'right'"
        :vertical="mode === 'vertical'"
        v-model="snackbar"
        color="success"
      >{{ 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 moment from "moment";
  
  export default {
    data: () => ({
      snackbar: false,
      y: "top",
      x: "right",
      mode: "",
      timeout: 3000,
      text: "",
      show: true,
      showSearch: false,
      showLoader: false,
      loading: false,
      date: null,
      search: "",
      addclass: [],
      pagination: {
b0e0491ab   Shikha Mishra   solve the issue o...
145
        rowsPerPage: 10,
229463bd5   Neeraj Sharma   implement design ...
146
147
148
149
150
151
      },
      headers: [
        {
          text: "Profile Pic",
          value: "profilprofilePicUrlePicUrl",
          sortable: false,
b0e0491ab   Shikha Mishra   solve the issue o...
152
          align: "center",
229463bd5   Neeraj Sharma   implement design ...
153
154
155
156
157
158
        },
        { text: "Name", value: "name", sortable: false, align: "center" },
        {
          text: "Mobile No",
          value: "fatherCellNo",
          sortable: false,
b0e0491ab   Shikha Mishra   solve the issue o...
159
          align: "center",
229463bd5   Neeraj Sharma   implement design ...
160
        },
b0e0491ab   Shikha Mishra   solve the issue o...
161
        { text: "Email", value: "email", sortable: false, align: "center" },
229463bd5   Neeraj Sharma   implement design ...
162
163
164
165
166
        // { text: "Action", value: "", sortable: false, align: "center" }
      ],
      token: "",
      selectStudents: {
        select: "",
b0e0491ab   Shikha Mishra   solve the issue o...
167
        selectSection: "",
229463bd5   Neeraj Sharma   implement design ...
168
169
170
171
172
173
174
175
176
177
178
      },
  
      role: "",
      schoolRole: "",
      menu: false,
      valid: true,
  
      getReport: {},
      studentsData: [],
      courseData: [],
      addSection: [],
b0e0491ab   Shikha Mishra   solve the issue o...
179
      selected: [],
229463bd5   Neeraj Sharma   implement design ...
180
181
182
183
184
185
186
187
    }),
    methods: {
      save(date) {
        this.$refs.menu.save(date);
      },
      getAllClass() {
        http()
          .get("/getClassesList", {
b0e0491ab   Shikha Mishra   solve the issue o...
188
            headers: { Authorization: "Bearer " + this.token },
229463bd5   Neeraj Sharma   implement design ...
189
          })
b0e0491ab   Shikha Mishra   solve the issue o...
190
          .then((response) => {
229463bd5   Neeraj Sharma   implement design ...
191
192
            this.addclass = response.data.data;
          })
b0e0491ab   Shikha Mishra   solve the issue o...
193
          .catch((error) => {
229463bd5   Neeraj Sharma   implement design ...
194
195
196
197
198
199
            // console.log("err====>", err);
            // this.$router.replace({ path: "/" });
          });
      },
      getCourses(classId) {
        this.showLoader = true;
b8258078b   Shikha Mishra   upload pdf sectio...
200
201
        this.studentsData = [];
        this.getReport.courseId = "";
229463bd5   Neeraj Sharma   implement design ...
202
203
204
        http()
          .get("/getCourseesList", {
            params: {
b0e0491ab   Shikha Mishra   solve the issue o...
205
206
              classId: classId,
            },
229463bd5   Neeraj Sharma   implement design ...
207
          })
b0e0491ab   Shikha Mishra   solve the issue o...
208
          .then((response) => {
229463bd5   Neeraj Sharma   implement design ...
209
210
211
            this.courseData = response.data.data;
            this.showLoader = false;
          })
b0e0491ab   Shikha Mishra   solve the issue o...
212
          .catch((err) => {
860da881d   Shikha Mishra   comment all consoles
213
            //   console.log("err====>", err);
229463bd5   Neeraj Sharma   implement design ...
214
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
215
216
217
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
229463bd5   Neeraj Sharma   implement design ...
218
219
          });
      },
7f4d490dd   Amber Dev   hid snackbar from...
220
      getStudents(message) {
229463bd5   Neeraj Sharma   implement design ...
221
222
223
224
        this.showLoader = true;
        http()
          .get("/getStudentsList", {
            params: {
b0e0491ab   Shikha Mishra   solve the issue o...
225
226
              classId: this.getReport.classId,
            },
229463bd5   Neeraj Sharma   implement design ...
227
          })
b0e0491ab   Shikha Mishra   solve the issue o...
228
          .then((response) => {
bf576e652   Rishav Singla   solved issue of p...
229
230
            this.studentsData = response.data.data.filter((item) => item.status);
            //this.studentsData = response.data.data;
229463bd5   Neeraj Sharma   implement design ...
231
232
233
234
235
236
            this.showLoader = false;
            // this.addStudentAttendenceDialog = false;
            var attendence = "";
            for (let i = 0; i < this.studentsData.length; i++) {
              this.studentsData[i].attendence = true;
            }
7f4d490dd   Amber Dev   hid snackbar from...
237
            this.getParticularCourse(message);
229463bd5   Neeraj Sharma   implement design ...
238
          })
b0e0491ab   Shikha Mishra   solve the issue o...
239
          .catch((error) => {
860da881d   Shikha Mishra   comment all consoles
240
            //   console.log("err====>", error);
229463bd5   Neeraj Sharma   implement design ...
241
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
242
243
244
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
229463bd5   Neeraj Sharma   implement design ...
245
246
247
          });
      },
      getStudentTable(id) {
6ef520020   Neeraj Sharma   implement all fun...
248
        // console.log("id", this.getReport.courseId);
7f4d490dd   Amber Dev   hid snackbar from...
249
        this.getStudents("noSnackbar");
229463bd5   Neeraj Sharma   implement design ...
250
251
252
253
254
255
      },
      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...
256
            isPresent: this.studentsData[j].attendence,
229463bd5   Neeraj Sharma   implement design ...
257
258
259
260
261
262
          });
        }
        if (this.$refs.form.validate()) {
          let attendanceData = {
            sectionId: this.getReport.sectionId,
            date: this.date,
b0e0491ab   Shikha Mishra   solve the issue o...
263
            students: studentsAttendence,
229463bd5   Neeraj Sharma   implement design ...
264
265
266
          };
          http()
            .put("/updateAttendance", attendanceData)
b0e0491ab   Shikha Mishra   solve the issue o...
267
            .then((response) => {
229463bd5   Neeraj Sharma   implement design ...
268
269
270
271
              this.snackbar = true;
              this.text = response.data.message;
              this.addStudentAttendenceDialog = false;
            })
b0e0491ab   Shikha Mishra   solve the issue o...
272
            .catch((error) => {
229463bd5   Neeraj Sharma   implement design ...
273
274
275
276
277
278
              this.snackbar = true;
              this.text = error.response.data.message;
            });
        }
      },
      toggleAll() {
b0f5f6684   Shikha Mishra   Conditionally sho...
279
280
281
282
283
284
        let withdraw = false;
        if (this.selected.length === this.studentsData.length) withdraw = true;
  
        if (withdraw) {
          var payload = {
            courseId: this.getReport.courseId,
b0e0491ab   Shikha Mishra   solve the issue o...
285
            enrollStudents: [],
b0f5f6684   Shikha Mishra   Conditionally sho...
286
287
288
          };
          http()
            .put("/enrollStudents", payload)
b0e0491ab   Shikha Mishra   solve the issue o...
289
            .then((response) => {
b0f5f6684   Shikha Mishra   Conditionally sho...
290
291
292
293
294
295
296
297
              this.snackbar = true;
              this.text = response.data.message;
              this.selected = [];
              for (let i = 0; i < this.studentsData.length; i++) {
                this.studentsData[i].enroll = false;
              }
              this.getParticularCourse();
            })
b0e0491ab   Shikha Mishra   solve the issue o...
298
            .catch((error) => {
b0f5f6684   Shikha Mishra   Conditionally sho...
299
300
301
302
303
304
              this.snackbar = true;
              this.text = error.response.data.message;
            });
        } else {
          let selectedStudentsArray = [];
          for (let item of this.studentsData) {
b0e0491ab   Shikha Mishra   solve the issue o...
305
            if (item.enroll === false || !item.enroll) {
b0f5f6684   Shikha Mishra   Conditionally sho...
306
307
308
309
310
311
              selectedStudentsArray.push({ studentId: item._id });
            }
          }
  
          var payload = {
            courseId: this.getReport.courseId,
b0e0491ab   Shikha Mishra   solve the issue o...
312
            enrollStudents: selectedStudentsArray,
b0f5f6684   Shikha Mishra   Conditionally sho...
313
314
315
          };
          http()
            .put("/enrollStudents", payload)
b0e0491ab   Shikha Mishra   solve the issue o...
316
            .then((response) => {
b0f5f6684   Shikha Mishra   Conditionally sho...
317
318
319
320
321
322
323
              this.snackbar = true;
              this.text = response.data.message;
              for (let i = 0; i < this.studentsData.length; i++) {
                this.studentsData[i].enroll = true;
              }
              this.getParticularCourse();
            })
b0e0491ab   Shikha Mishra   solve the issue o...
324
            .catch((error) => {
b0f5f6684   Shikha Mishra   Conditionally sho...
325
326
327
              this.snackbar = true;
              this.text = error.response.data.message;
            });
6ef520020   Neeraj Sharma   implement all fun...
328
        }
229463bd5   Neeraj Sharma   implement design ...
329
      },
b0f5f6684   Shikha Mishra   Conditionally sho...
330

229463bd5   Neeraj Sharma   implement design ...
331
      selectParticularStudent(selected) {
229463bd5   Neeraj Sharma   implement design ...
332
        let selectedStudentsArray = [];
6ef520020   Neeraj Sharma   implement all fun...
333
        selectedStudentsArray.push({ studentId: selected._id });
b0f5f6684   Shikha Mishra   Conditionally sho...
334
335
  
        let isExists = false;
b0e0491ab   Shikha Mishra   solve the issue o...
336
337
        for (let item of this.selected) {
          if (item._id === selected._id) {
b0f5f6684   Shikha Mishra   Conditionally sho...
338
339
340
341
            isExists = true;
            break;
          }
        }
dea4d2889   Neeraj Sharma   task commited
342
        if (selected.enroll === true) {
b0f5f6684   Shikha Mishra   Conditionally sho...
343
          if (!isExists) this.selected.push(selected);
6ef520020   Neeraj Sharma   implement all fun...
344
345
          var payload = {
            courseId: this.getReport.courseId,
b0e0491ab   Shikha Mishra   solve the issue o...
346
            enrollStudents: selectedStudentsArray,
6ef520020   Neeraj Sharma   implement all fun...
347
348
349
          };
          http()
            .put("/enrollStudents", payload)
b0e0491ab   Shikha Mishra   solve the issue o...
350
            .then((response) => {
6ef520020   Neeraj Sharma   implement all fun...
351
352
              this.snackbar = true;
              this.text = response.data.message;
337068e6f   Shikha Mishra   Improve snackbar ...
353
              this.getParticularCourse("noSnackbar");
6ef520020   Neeraj Sharma   implement all fun...
354
            })
b0e0491ab   Shikha Mishra   solve the issue o...
355
            .catch((error) => {
6ef520020   Neeraj Sharma   implement all fun...
356
357
358
359
360
361
362
363
364
365
366
              this.snackbar = true;
              this.text = error.response.data.message;
            });
        }
        if (
          selected.enroll == false &&
          selected.enroll != undefined &&
          selected.enroll != null
        ) {
          var payloadDeleteStudents = {
            courseId: this.getReport.courseId,
b0e0491ab   Shikha Mishra   solve the issue o...
367
            enrollStudentsId: selected.enrollId,
6ef520020   Neeraj Sharma   implement all fun...
368
369
370
          };
          http()
            .put("/deleteStudents", payloadDeleteStudents)
b0e0491ab   Shikha Mishra   solve the issue o...
371
            .then((response) => {
6ef520020   Neeraj Sharma   implement all fun...
372
373
              this.snackbar = true;
              this.text = response.data.message;
dea4d2889   Neeraj Sharma   task commited
374
              this.getParticularCourse();
6ef520020   Neeraj Sharma   implement all fun...
375
            })
b0e0491ab   Shikha Mishra   solve the issue o...
376
            .catch((error) => {
6ef520020   Neeraj Sharma   implement all fun...
377
378
379
380
              this.snackbar = true;
              this.text = error.response.data.message;
            });
        }
229463bd5   Neeraj Sharma   implement design ...
381
      },
7f4d490dd   Amber Dev   hid snackbar from...
382
      getParticularCourse(message) {
b0f5f6684   Shikha Mishra   Conditionally sho...
383
        this.selected = [];
11d037abe   Neeraj Sharma   commit code
384
        var payload = {
b0e0491ab   Shikha Mishra   solve the issue o...
385
          courseId: this.getReport.courseId,
11d037abe   Neeraj Sharma   commit code
386
387
388
        };
        http()
          .get("/getParticularCourse", {
b0e0491ab   Shikha Mishra   solve the issue o...
389
            params: payload,
11d037abe   Neeraj Sharma   commit code
390
          })
b0e0491ab   Shikha Mishra   solve the issue o...
391
          .then((response) => {
6ef520020   Neeraj Sharma   implement all fun...
392
393
394
395
396
            for (let i = 0; i < response.data.data.enrollStudents.length; i++) {
              var studentId = {};
              studentId = response.data.data.enrollStudents[i];
              for (let j = 0; j < this.studentsData.length; j++) {
                if (studentId.studentId == this.studentsData[j]._id) {
6ef520020   Neeraj Sharma   implement all fun...
397
398
                  this.studentsData[j].enroll = true;
                  this.studentsData[j].enrollId = studentId._id;
b0f5f6684   Shikha Mishra   Conditionally sho...
399
400
                  this.selected.push(this.studentsData[j]);
                  break;
6ef520020   Neeraj Sharma   implement all fun...
401
402
403
                }
              }
            }
7f4d490dd   Amber Dev   hid snackbar from...
404
405
406
407
            if (message != "noSnackbar") {
              this.snackbar = true;
              this.text = response.data.message;
            }
11d037abe   Neeraj Sharma   commit code
408
          })
b0e0491ab   Shikha Mishra   solve the issue o...
409
          .catch((error) => {
11d037abe   Neeraj Sharma   commit code
410
411
412
413
            this.snackbar = true;
            this.text = error.response.data.message;
          });
      },
229463bd5   Neeraj Sharma   implement design ...
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
      changeSort(column) {
        if (this.pagination.sortBy === column) {
          this.pagination.descending = !this.pagination.descending;
        } else {
          this.pagination.sortBy = column;
          this.pagination.descending = false;
        }
      },
      displaySearch() {
        this.show = false;
        this.showSearch = true;
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
b0e0491ab   Shikha Mishra   solve the issue o...
430
      },
229463bd5   Neeraj Sharma   implement design ...
431
432
433
434
435
436
    },
    mounted() {
      // this.getStudentList();
      this.token = this.$store.state.token;
      this.role = this.$store.state.role;
      this.getAllClass();
b0e0491ab   Shikha Mishra   solve the issue o...
437
    },
229463bd5   Neeraj Sharma   implement design ...
438
439
  };
  </script>