Blame view

src/pages/Subjects/subjects.vue 14.9 KB
beb598536   Neeraj Sharma   design and functi...
1
  <template>
68d742034   Neeraj Sharma   implement new des...
2
3
4
5
6
7
8
9
    <v-container fluid class="body-color">
      <!-- ****** EDIT  Subject ****** -->
      <v-dialog v-model="editSubjectDialog" max-width="400px">
        <v-card flat class="card-style pa-2" dark>
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Edit Subject</label>
              <v-icon size="24" class="right" @click="editSubjectDialog = false">cancel</v-icon>
beb598536   Neeraj Sharma   design and functi...
10
            </v-flex>
68d742034   Neeraj Sharma   implement new des...
11
12
13
          </v-layout>
          <v-container fluid>
            <v-form ref="formEditSubject" v-model="validEditSubject" lazy-validation>
46db0a3b5   Neeraj Sharma   add sunbject and ...
14
              <v-layout>
68d742034   Neeraj Sharma   implement new des...
15
16
                <v-flex xs4 class="pt-4 subheading">
                  <label class="right">Class:</label>
46db0a3b5   Neeraj Sharma   add sunbject and ...
17
                </v-flex>
68d742034   Neeraj Sharma   implement new des...
18
                <v-flex xs8 class="ml-3">
46db0a3b5   Neeraj Sharma   add sunbject and ...
19
20
21
                  <v-select
                    :items="classList"
                    label="Select Class"
68d742034   Neeraj Sharma   implement new des...
22
                    v-model="addSubject.selectName"
46db0a3b5   Neeraj Sharma   add sunbject and ...
23
24
25
                    item-text="classNum"
                    item-value="_id"
                    name="Select Class"
68d742034   Neeraj Sharma   implement new des...
26
                    :rules="nameEditSubjectRules"
46db0a3b5   Neeraj Sharma   add sunbject and ...
27
28
29
30
                    required
                  ></v-select>
                </v-flex>
              </v-layout>
68d742034   Neeraj Sharma   implement new des...
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-layout>
                <v-flex xs4 class="pt-4 subheading">
                  <label class="right">Subject:</label>
                </v-flex>
                <v-flex xs8 class="ml-3">
                  <v-text-field
                    placeholder="fill your Subject"
                    v-model="editedItem.subjectName"
                    :rules="subjectEditNameRules"
                    type="text"
                    name="email"
                    required
                  ></v-text-field>
                </v-flex>
              </v-layout>
              <v-flex xs12 sm12>
                <v-card-actions>
                  <v-btn round dark @click.native="close" class="clear-button">Cancel</v-btn>
                  <v-spacer></v-spacer>
                  <v-btn round dark @click="save" :loading="editLoading" class="add-button">Save</v-btn>
                </v-card-actions>
              </v-flex>
            </v-form>
          </v-container>
        </v-card>
      </v-dialog>
beb598536   Neeraj Sharma   design and functi...
57

68d742034   Neeraj Sharma   implement new des...
58
      <!-- ****** VIEW PROFIL NOTICE BOARD ******  -->
beb598536   Neeraj Sharma   design and functi...
59

68d742034   Neeraj Sharma   implement new des...
60
      <v-dialog v-model="viewSubjectDialog" max-width="600px">
c8fc8e42e   Shikha Mishra   solved issues
61
        <v-toolbar flat class="card-style pa-3" dark>
68d742034   Neeraj Sharma   implement new des...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
          <v-spacer></v-spacer>
          <v-toolbar-title>
            <h3>Subject</h3>
          </v-toolbar-title>
          <v-spacer></v-spacer>
          <v-icon @click="close1">close</v-icon>
        </v-toolbar>
        <v-card>
          <v-card-text>
            <v-container grid-list-md>
              <v-layout wrap>
                <v-flex>
                  <v-layout>
                    <v-flex xs7 sm6>
                      <h5 class="right my-1">
                        <b>Subject Name:</b>
                      </h5>
                    </v-flex>
                    <v-flex sm6 xs5>
                      <h5 class="my-1">{{ editedItem.subjectName }}</h5>
beb598536   Neeraj Sharma   design and functi...
82
83
                    </v-flex>
                  </v-layout>
68d742034   Neeraj Sharma   implement new des...
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
                </v-flex>
              </v-layout>
            </v-container>
          </v-card-text>
        </v-card>
      </v-dialog>
  
      <!-- ****** EXISTING SUBJECTS 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="addSubjectDialog = true"
        >
          <v-icon dark>add</v-icon>
        </v-btn>
        <v-flex xs1 class="hidden-sm-only hidden-xs-only">
          <v-btn round class="open-dialog-button" dark @click="addSubjectDialog = true">
            <v-icon class="white--text pr-1" size="20">add</v-icon>Add Subject
          </v-btn>
        </v-flex>
        <v-spacer></v-spacer>
        <v-flex lg2 md2 xs12 v-show="show">
          <v-select
            :items="classList"
            label="Select Your Class"
            v-model="selectClassId"
            item-text="classNum"
            item-value="_id"
            name="Select Class"
            :rules="nameRules"
            @change="getClassSubject"
            class="pl-2"
            required
          ></v-select>
        </v-flex>
        <v-card-title class="body-1" v-show="show">
          <v-btn icon flat @click="displaySearch">
            <v-avatar size="27">
aa310d61a   Shikha Mishra   added functionali...
125
              <img src="/static/icon/search.png" alt="icon" />
68d742034   Neeraj Sharma   implement new des...
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
            </v-avatar>
          </v-btn>
        </v-card-title>
        <v-flex xs9 sm9 md2 lg2 xl2 v-show="showSearch">
          <v-layout>
            <v-text-field
              v-model="search"
              label="Search"
              prepend-inner-icon="search"
              color="primary"
              style="transition: 0.8s cubic-bezier(0.25, 0.8, 0.25, 1); !important"
            ></v-text-field>
            <v-icon @click="closeSearch" color="error">close</v-icon>
          </v-layout>
        </v-flex>
      </v-toolbar>
      <v-data-table
        :headers="headers"
        :items="subjectList.subjects"
        :pagination.sync="pagination"
        :search="search"
      >
        <template slot="items" slot-scope="props">
          <tr class="tr">
            <td class="td-row td">{{ props.index + 1 }}</td>
            <td class="text-xs-center td td-row">{{ props.item.subjectName }}</td>
            <td class="text-xs-center td td-row">
              <span>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:25px; height:25px; "
                    class="mr-3"
                    @click="profile(props.item)"
aa310d61a   Shikha Mishra   added functionali...
160
                    src="/static/icon/view.png"
68d742034   Neeraj Sharma   implement new des...
161
162
163
164
165
166
167
168
169
                  />
                  <span>View</span>
                </v-tooltip>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:18px; "
                    class="mr-3"
                    @click="editItem(props.item)"
aa310d61a   Shikha Mishra   added functionali...
170
                    src="/static/icon/edit.png"
68d742034   Neeraj Sharma   implement new des...
171
172
173
174
175
176
177
178
179
                  />
                  <span>Edit</span>
                </v-tooltip>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:20px; "
                    class="mr-3"
                    @click="deleteItem(props.item)"
aa310d61a   Shikha Mishra   added functionali...
180
                    src="/static/icon/delete.png"
68d742034   Neeraj Sharma   implement new des...
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
                  />
                  <span>Delete</span>
                </v-tooltip>
              </span>
            </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>
      <!-- ****** ADD MULTIPLE Subject ****** -->
      <v-snackbar
        :timeout="timeout"
        :top="y === 'top'"
        :right="x === 'right'"
        :vertical="mode === 'vertical'"
        v-model="snackbar"
        :color="color"
      >{{ text }}</v-snackbar>
      <v-dialog v-model="addSubjectDialog" max-width="400px">
        <v-card flat class="card-style pa-2" dark>
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Add Subject</label>
              <v-icon size="24" class="right" @click="addSubjectDialog = false">cancel</v-icon>
beb598536   Neeraj Sharma   design and functi...
210
            </v-flex>
68d742034   Neeraj Sharma   implement new des...
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
          </v-layout>
          <v-container fluid fill-height>
            <v-layout align-center>
              <v-flex xs12>
                <v-form ref="form" v-model="valid" lazy-validation>
                  <v-layout>
                    <v-flex xs4 sm4 class="pt-4 subheading">
                      <label class="right">Class :</label>
                    </v-flex>
                    <v-flex xs8 sm8 class="ml-3">
                      <v-select
                        v-model="addSubject.classId"
                        label="Select your class"
                        type="text"
                        :items="classList"
                        item-text="classNum"
                        item-value="_id"
                        :rules="nameRules"
                        required
                      ></v-select>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs4 sm4 class="pt-4 subheading">
                      <label class="right">Subject :</label>
                    </v-flex>
                    <v-flex xs8 sm8 class="ml-3">
                      <v-text-field
                        v-model="addSubject.subjectName"
                        placeholder="fill your Subject Name"
                        name="name"
                        type="text"
                        :rules="subjectRules"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs12 sm12>
                      <v-card-actions>
                        <v-btn @click="clear" round dark class="clear-button">Clear</v-btn>
                        <v-spacer></v-spacer>
                        <v-btn @click="submit" round dark :loading="loading" class="add-button">Add</v-btn>
                      </v-card-actions>
                    </v-flex>
                  </v-layout>
                </v-form>
              </v-flex>
            </v-layout>
beb598536   Neeraj Sharma   design and functi...
260
          </v-container>
68d742034   Neeraj Sharma   implement new des...
261
262
        </v-card>
      </v-dialog>
36fc987df   Neeraj Sharma   add loader in all...
263
264
265
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
68d742034   Neeraj Sharma   implement new des...
266
    </v-container>
beb598536   Neeraj Sharma   design and functi...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
  </template>
  
  <script>
  import http from "@/Services/http.js";
  import Util from "@/util";
  
  export default {
    data: () => ({
      snackbar: false,
      y: "top",
      x: "right",
      mode: "",
      timeout: 3000,
      text: "",
0721aca93   Neeraj Sharma   solve bugs in sub...
281
      color: "",
68d742034   Neeraj Sharma   implement new des...
282
283
      show: true,
      showSearch: false,
fc82ac667   Neeraj Sharma   fix design and re...
284
      showLoader: false,
beb598536   Neeraj Sharma   design and functi...
285
      loading: false,
afc98f028   Neeraj Sharma   implement class v...
286
      editLoading: false,
beb598536   Neeraj Sharma   design and functi...
287
288
      date: null,
      search: "",
68d742034   Neeraj Sharma   implement new des...
289
290
      viewSubjectDialog: false,
      editSubjectDialog: false,
beb598536   Neeraj Sharma   design and functi...
291
      valid: true,
afc98f028   Neeraj Sharma   implement class v...
292
      validEditSubject: true,
68d742034   Neeraj Sharma   implement new des...
293
294
295
      addSubjectDialog: false,
      // isActive: true,
      // newActive: false,
beb598536   Neeraj Sharma   design and functi...
296
      gender: ["Male", "Female"],
beb598536   Neeraj Sharma   design and functi...
297
      pagination: {
68d742034   Neeraj Sharma   implement new des...
298
        rowsPerPage: 10
beb598536   Neeraj Sharma   design and functi...
299
      },
46db0a3b5   Neeraj Sharma   add sunbject and ...
300
301
      token: "",
      nameRules: [v => !!v || " Class Name is required"],
afc98f028   Neeraj Sharma   implement class v...
302
      nameEditSubjectRules: [v => !!v || " Class Name is required"],
46db0a3b5   Neeraj Sharma   add sunbject and ...
303
      subjectRules: [v => !!v || " Subject Name is required"],
39fb2832e   Neeraj Sharma   implement class v...
304
      subjectEditNameRules: [v => !!v || " Subject Name is required"],
beb598536   Neeraj Sharma   design and functi...
305
306
307
      headers: [
        {
          text: "No",
68d742034   Neeraj Sharma   implement new des...
308
          align: "",
beb598536   Neeraj Sharma   design and functi...
309
310
311
          sortable: false,
          value: "No"
        },
fc82ac667   Neeraj Sharma   fix design and re...
312
        {
46db0a3b5   Neeraj Sharma   add sunbject and ...
313
314
          text: "Subject Name",
          value: "subjectName",
fc82ac667   Neeraj Sharma   fix design and re...
315
316
317
          sortable: false,
          align: "center"
        },
beb598536   Neeraj Sharma   design and functi...
318
319
        { text: "Action", value: "", sortable: false, align: "center" }
      ],
46db0a3b5   Neeraj Sharma   add sunbject and ...
320
321
      subjectList: [],
      classList: [],
beb598536   Neeraj Sharma   design and functi...
322
      editedIndex: -1,
46db0a3b5   Neeraj Sharma   add sunbject and ...
323
324
      addSubject: {},
      selectClassId: "",
0721aca93   Neeraj Sharma   solve bugs in sub...
325
      selectClassId: "",
beb598536   Neeraj Sharma   design and functi...
326
      editedItem: {
46db0a3b5   Neeraj Sharma   add sunbject and ...
327
        subjectName: ""
a17c68a03   Neeraj Sharma   implement two rou...
328
      }
beb598536   Neeraj Sharma   design and functi...
329
    }),
beb598536   Neeraj Sharma   design and functi...
330
331
332
333
    methods: {
      pickFile() {
        this.$refs.image.click();
      },
beb598536   Neeraj Sharma   design and functi...
334
      editItem(item) {
c8fc8e42e   Shikha Mishra   solved issues
335
        this.editedIndex = this.subjectList.subjects;
beb598536   Neeraj Sharma   design and functi...
336
337
        this.editedItem = Object.assign({}, item);
        this.dialog = true;
c8fc8e42e   Shikha Mishra   solved issues
338
        this.editSubjectDialog = true;
beb598536   Neeraj Sharma   design and functi...
339
340
      },
      profile(item) {
c8fc8e42e   Shikha Mishra   solved issues
341
        this.editedIndex = this.subjectList.subjects;
beb598536   Neeraj Sharma   design and functi...
342
343
        this.editedItem = Object.assign({}, item);
        this.dialog1 = true;
c8fc8e42e   Shikha Mishra   solved issues
344
        this.viewSubjectDialog = true;
beb598536   Neeraj Sharma   design and functi...
345
346
      },
      deleteItem(item) {
46db0a3b5   Neeraj Sharma   add sunbject and ...
347
        let deleteSubject = {
0721aca93   Neeraj Sharma   solve bugs in sub...
348
          classId: this.selectClassId,
46db0a3b5   Neeraj Sharma   add sunbject and ...
349
          subjectId: item._id
beb598536   Neeraj Sharma   design and functi...
350
351
352
        };
        http()
          .delete(
46db0a3b5   Neeraj Sharma   add sunbject and ...
353
            "/deleteSubject",
beb598536   Neeraj Sharma   design and functi...
354
            confirm("Are you sure you want to delete this?") && {
46db0a3b5   Neeraj Sharma   add sunbject and ...
355
              params: deleteSubject
beb598536   Neeraj Sharma   design and functi...
356
357
358
            }
          )
          .then(response => {
0721aca93   Neeraj Sharma   solve bugs in sub...
359
360
361
            this.getClassSubject();
            this.snackbar = true;
            this.text = "Successfully delete Existing Subject";
beb598536   Neeraj Sharma   design and functi...
362
363
          })
          .catch(error => {
c8fc8e42e   Shikha Mishra   solved issues
364
365
366
            this.snackbar = true;
            this.text = error.response.data.message;
            this.color = "error";
beb598536   Neeraj Sharma   design and functi...
367
368
          });
      },
beb598536   Neeraj Sharma   design and functi...
369
      close() {
68d742034   Neeraj Sharma   implement new des...
370
        this.editSubjectDialog = false;
beb598536   Neeraj Sharma   design and functi...
371
372
      },
      close1() {
68d742034   Neeraj Sharma   implement new des...
373
        this.viewSubjectDialog = false;
beb598536   Neeraj Sharma   design and functi...
374
375
376
      },
      submit() {
        if (this.$refs.form.validate()) {
beb598536   Neeraj Sharma   design and functi...
377
          http()
46db0a3b5   Neeraj Sharma   add sunbject and ...
378
            .post("/addSubject", this.addSubject)
beb598536   Neeraj Sharma   design and functi...
379
            .then(response => {
0721aca93   Neeraj Sharma   solve bugs in sub...
380
381
382
              this.getClassSubject();
              this.snackbar = true;
              this.text = "New Subject added successfully";
beb598536   Neeraj Sharma   design and functi...
383
              this.clear();
0721aca93   Neeraj Sharma   solve bugs in sub...
384
              this.color = "green";
68d742034   Neeraj Sharma   implement new des...
385
              this.addSubjectDialog = false;
beb598536   Neeraj Sharma   design and functi...
386
387
388
            })
            .catch(error => {
              // console.log(error);
0721aca93   Neeraj Sharma   solve bugs in sub...
389
390
391
              this.snackbar = true;
              this.text = error.response.data.message;
              this.color = "error";
beb598536   Neeraj Sharma   design and functi...
392
393
394
            });
        }
      },
beb598536   Neeraj Sharma   design and functi...
395
396
397
398
      clear() {
        this.$refs.form.reset();
      },
      save() {
afc98f028   Neeraj Sharma   implement class v...
399
400
401
402
403
404
405
406
407
408
409
        if (this.$refs.formEditSubject.validate()) {
          let editSubject = {
            classId: this.addSubject.selectName,
            subjectId: this.editedItem._id,
            subjectName: this.editedItem.subjectName
          };
          this.editLoading = true;
          http()
            .put("/updateSubject", editSubject)
            .then(response => {
              this.snackbar = true;
46db0a3b5   Neeraj Sharma   add sunbject and ...
410
              this.text = "Successfully Edit Existing Subject";
afc98f028   Neeraj Sharma   implement class v...
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
              this.editLoading = false;
              http()
                .get(
                  "/getParticularClass",
                  { params: { classId: this.selectClassId } },
                  {
                    headers: { Authorization: "Bearer " + this.token }
                  }
                )
                .then(response => {
                  this.subjectList = response.data.data;
                  this.getClassSubject();
                  this.snackbar = true;
                  this.color = "green";
                  this.text = response.data.message;
                  this.close();
                })
                .catch(err => {
                  console.log("err====>", err);
                });
            })
            .catch(error => {
              this.editLoading = false;
  
              // console.log(error);
            });
        }
beb598536   Neeraj Sharma   design and functi...
438
      },
0721aca93   Neeraj Sharma   solve bugs in sub...
439
      getClassSubject() {
68d742034   Neeraj Sharma   implement new des...
440
        this.showLoader = true;
0721aca93   Neeraj Sharma   solve bugs in sub...
441
        this.selectClassId = this.selectClassId;
46db0a3b5   Neeraj Sharma   add sunbject and ...
442
443
444
445
446
447
448
449
450
451
        http()
          .get(
            "/getParticularClass",
            { params: { classId: this.selectClassId } },
            {
              headers: { Authorization: "Bearer " + this.token }
            }
          )
          .then(response => {
            this.subjectList = response.data.data;
68d742034   Neeraj Sharma   implement new des...
452
            this.showLoader = false;
46db0a3b5   Neeraj Sharma   add sunbject and ...
453
454
          })
          .catch(err => {
68d742034   Neeraj Sharma   implement new des...
455
            this.showLoader = false;
46db0a3b5   Neeraj Sharma   add sunbject and ...
456
457
458
459
460
461
462
463
464
465
          });
      },
      getClass() {
        http()
          .get("/getClassesList", {
            headers: { Authorization: "Bearer " + this.token }
          })
          .then(response => {
            this.classList = response.data.data;
          })
00e4bc4e1   Neeraj Sharma   fixed auntentication
466
          .catch(error => {
a17c68a03   Neeraj Sharma   implement two rou...
467
468
469
470
471
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
46db0a3b5   Neeraj Sharma   add sunbject and ...
472
          });
68d742034   Neeraj Sharma   implement new des...
473
474
475
476
477
478
479
480
      },
      displaySearch() {
        (this.show = false), (this.showSearch = true);
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
beb598536   Neeraj Sharma   design and functi...
481
482
483
      }
    },
    mounted() {
46db0a3b5   Neeraj Sharma   add sunbject and ...
484
485
486
      this.token = this.$store.state.token;
      // this.getNoticeDataList();
      this.getClass();
beb598536   Neeraj Sharma   design and functi...
487
488
    }
  };
68d742034   Neeraj Sharma   implement new des...
489
  </script>