Blame view

src/pages/Class/addclass.vue 11.3 KB
1ed542553   Neeraj Sharma   all api implement...
1
  <template>
68d742034   Neeraj Sharma   implement new des...
2
3
    <v-container fluid class="body-color">
      <!-- ****** EDIT  ClASS  ****** -->
db965de89   Amber Dev   added dialog pers...
4
      <v-dialog v-model="editClassDialog" max-width="400px" persistent>
68d742034   Neeraj Sharma   implement new des...
5
6
7
8
9
        <v-card flat class="card-style pa-2" dark>
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Edit Class</label>
              <v-icon size="24" class="right" @click="editClassDialog = false">cancel</v-icon>
aa8fc5033   Neeraj Sharma   implenment all pa...
10
            </v-flex>
68d742034   Neeraj Sharma   implement new des...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
          </v-layout>
          <v-container fluid>
            <v-layout justify-center>
              <v-flex xs12 sm12>
                <v-flex xs12>
                  <v-text-field v-model="editedItem.classNum" @keyup.enter="save" :rules="nameRules"></v-text-field>
                </v-flex>
                <v-card-actions>
                  <v-spacer></v-spacer>
                  <v-btn round dark @click="save" class="add-button">Save</v-btn>
                  <v-spacer></v-spacer>
                </v-card-actions>
              </v-flex>
            </v-layout>
          </v-container>
        </v-card>
      </v-dialog>
1ed542553   Neeraj Sharma   all api implement...
28

68d742034   Neeraj Sharma   implement new des...
29
      <!-- ****** PROFILE VIEW STUDENTS ******  -->
db965de89   Amber Dev   added dialog pers...
30
      <v-dialog v-model="profileClassDialog" max-width="400px" persistent>
68d742034   Neeraj Sharma   implement new des...
31
32
33
34
35
36
37
        <v-card flat class="card-style pa-3" dark>
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">View Class</label>
              <v-icon size="24" class="right" @click="profileClassDialog = false">cancel</v-icon>
            </v-flex>
          </v-layout>
058c4a6cf   Shikha Mishra   Improve the funct...
38
          <v-card-text>
68d742034   Neeraj Sharma   implement new des...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
            <v-container grid-list-md>
              <v-layout wrap>
                <v-flex xs6 sm6>
                  <h5 class="right my-1 subheading">
                    <b>Class Name:</b>
                  </h5>
                </v-flex>
                <v-flex sm6 xs6>
                  <h5 class="my-1">{{ editedItem.classNum }}</h5>
                </v-flex>
              </v-layout>
            </v-container>
          </v-card-text>
        </v-card>
      </v-dialog>
1ed542553   Neeraj Sharma   all api implement...
54

68d742034   Neeraj Sharma   implement new des...
55
      <!-- ****** Class Table ****** -->
1ed542553   Neeraj Sharma   all api implement...
56

68d742034   Neeraj Sharma   implement new des...
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
      <v-toolbar color="transparent" flat>
        <v-btn
          fab
          dark
          class="open-dialog-button hidden-xl-only hidden-md-only hidden-lg-only"
          small
          @click="addClassDialog = true"
        >
          <v-icon dark>add</v-icon>
        </v-btn>
        <v-btn
          round
          class="open-dialog-button hidden-sm-only hidden-xs-only"
          dark
          @click="addClassDialog = true"
        >
          <v-icon class="white--text pr-1" size="20">add</v-icon>Add Class
        </v-btn>
        <v-spacer></v-spacer>
        <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...
79
              <img src="/static/icon/search.png" alt="icon" />
68d742034   Neeraj Sharma   implement new des...
80
81
82
            </v-avatar>
          </v-btn>
        </v-card-title>
612b79bb4   Amber Dev   made serch auto f...
83
        <v-flex xs8 sm8 md3 lg2 v-if="showSearch">
68d742034   Neeraj Sharma   implement new des...
84
          <v-layout>
8e8d14254   Shikha Mishra   Cleared data whil...
85
86
87
88
89
90
91
            <v-text-field
              autofocus
              v-model="search"
              label="Search"
              prepend-inner-icon="search"
              color="primary"
            ></v-text-field>
68d742034   Neeraj Sharma   implement new des...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
            <v-icon @click="closeSearch" color="error">close</v-icon>
          </v-layout>
        </v-flex>
      </v-toolbar>
      <v-data-table
        :headers="headers"
        :items="classList"
        :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">{{ props.item.classNum}}</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...
114
                    src="/static/icon/view.png"
68d742034   Neeraj Sharma   implement new des...
115
116
117
118
119
120
121
122
123
                  />
                  <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...
124
                    src="/static/icon/edit.png"
68d742034   Neeraj Sharma   implement new des...
125
126
127
                  />
                  <span>Edit</span>
                </v-tooltip>
b039d39fb   Shikha Mishra   Hide Edit functio...
128
                <!-- <v-tooltip top>
68d742034   Neeraj Sharma   implement new des...
129
130
131
132
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:20px; "
                    @click="deleteItem(props.item)"
aa310d61a   Shikha Mishra   added functionali...
133
                    src="/static/icon/delete.png"
68d742034   Neeraj Sharma   implement new des...
134
135
                  />
                  <span>Delete</span>
058c4a6cf   Shikha Mishra   Improve the funct...
136
                </v-tooltip>-->
68d742034   Neeraj Sharma   implement new des...
137
138
139
140
141
142
143
144
145
146
147
              </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>
1ed542553   Neeraj Sharma   all api implement...
148

7efe02762   Amber Dev   made forms reset
149
      <!-- DIALOG BOX - ADD Class  -->
db965de89   Amber Dev   added dialog pers...
150
      <v-dialog v-model="addClassDialog" max-width="400px" v-if="addClassDialog" persistent>
68d742034   Neeraj Sharma   implement new des...
151
152
153
154
        <v-card flat class="card-style pa-2" dark>
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Add Class</label>
8e8d14254   Shikha Mishra   Cleared data whil...
155
156
157
158
159
              <v-icon
                size="24"
                class="right"
                @click="$refs.form.reset();addClassDialog = false"
              >cancel</v-icon>
68d742034   Neeraj Sharma   implement new des...
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
            </v-flex>
          </v-layout>
          <v-container fluid fill-height>
            <v-layout align-center>
              <v-flex xs12>
                <v-form ref="form" v-model="valid" lazy-validation>
                  <v-flex xs12 class="headline text-xs-center">
                    <label>Class</label>
                  </v-flex>
                  <v-flex xs12>
                    <v-text-field
                      v-model="addclasses.classNum"
                      placeholder="fill your class Name"
                      type="text"
                      :rules="nameRules"
                      required
                    ></v-text-field>
                  </v-flex>
                  <v-layout>
                    <v-flex xs12 sm12>
                      <v-card-actions>
                        <v-spacer></v-spacer>
                        <v-btn
                          @click="submit"
                          class="add-button"
                          round
                          dark
                          :loading="loading"
                        >Add Class</v-btn>
                        <v-spacer></v-spacer>
                      </v-card-actions>
1ed542553   Neeraj Sharma   all api implement...
191
192
                    </v-flex>
                  </v-layout>
68d742034   Neeraj Sharma   implement new des...
193
194
195
                </v-form>
              </v-flex>
            </v-layout>
1ed542553   Neeraj Sharma   all api implement...
196
          </v-container>
68d742034   Neeraj Sharma   implement new des...
197
198
        </v-card>
      </v-dialog>
4b169b574   Neeraj Sharma   add loader in all...
199
200
201
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
68d742034   Neeraj Sharma   implement new des...
202
203
204
205
206
207
208
209
210
      <v-snackbar
        :timeout="timeout"
        :top="y === 'top'"
        :right="x === 'right'"
        :vertical="mode === 'vertical'"
        v-model="snackbar"
        :color="color"
      >{{ text }}</v-snackbar>
    </v-container>
1ed542553   Neeraj Sharma   all api implement...
211
212
213
214
  </template>
  
  <script>
  import http from "@/Services/http.js";
1ed542553   Neeraj Sharma   all api implement...
215
216
217
218
219
220
221
  
  export default {
    data: () => ({
      snackbar: false,
      y: "top",
      x: "right",
      mode: "",
68d742034   Neeraj Sharma   implement new des...
222
      timeout: 5000,
1ed542553   Neeraj Sharma   all api implement...
223
      text: "",
68d742034   Neeraj Sharma   implement new des...
224
225
226
      color: "",
      show: true,
      showSearch: false,
a17c68a03   Neeraj Sharma   implement two rou...
227
      showLoader: false,
1ed542553   Neeraj Sharma   all api implement...
228
      loading: false,
68d742034   Neeraj Sharma   implement new des...
229
      addClassDialog: false,
1ed542553   Neeraj Sharma   all api implement...
230
      search: "",
68d742034   Neeraj Sharma   implement new des...
231
232
      editClassDialog: false,
      profileClassDialog: false,
1ed542553   Neeraj Sharma   all api implement...
233
      valid: true,
1ed542553   Neeraj Sharma   all api implement...
234
      pagination: {
058c4a6cf   Shikha Mishra   Improve the funct...
235
        rowsPerPage: 10,
1ed542553   Neeraj Sharma   all api implement...
236
      },
058c4a6cf   Shikha Mishra   Improve the funct...
237
      nameRules: [(v) => !!v || " Class Name is required"],
1ed542553   Neeraj Sharma   all api implement...
238
239
240
      headers: [
        {
          text: "No",
506be6fd7   Neeraj Sharma   implemet dyamic i...
241
          align: "left",
1ed542553   Neeraj Sharma   all api implement...
242
          sortable: false,
058c4a6cf   Shikha Mishra   Improve the funct...
243
          value: "No",
1ed542553   Neeraj Sharma   all api implement...
244
        },
2b0e316ee   Neeraj Sharma   upload mytiple im...
245
        { text: "Class No", value: "classNum", sortable: false, align: "center" },
058c4a6cf   Shikha Mishra   Improve the funct...
246
        { text: "Action", value: "", sortable: false, align: "center" },
1ed542553   Neeraj Sharma   all api implement...
247
      ],
d9bb52b5b   Neeraj Sharma   implement trello ...
248
      classList: [],
1ed542553   Neeraj Sharma   all api implement...
249
250
      editedIndex: -1,
      editedItem: {
058c4a6cf   Shikha Mishra   Improve the funct...
251
        classNum: "",
1ed542553   Neeraj Sharma   all api implement...
252
      },
a17c68a03   Neeraj Sharma   implement two rou...
253
      addclasses: {
058c4a6cf   Shikha Mishra   Improve the funct...
254
255
        classNum: "",
      },
1ed542553   Neeraj Sharma   all api implement...
256
    }),
8e8d14254   Shikha Mishra   Cleared data whil...
257
258
259
260
261
262
263
    watch: {
      addClassDialog: function (val) {
        if (!val) {
          this.addclasses = [];
        }
      },
    },
1ed542553   Neeraj Sharma   all api implement...
264
265
    methods: {
      getClassList() {
4b169b574   Neeraj Sharma   add loader in all...
266
        this.showLoader = true;
1ed542553   Neeraj Sharma   all api implement...
267
268
        var token = this.$store.state.token;
        http()
2b0e316ee   Neeraj Sharma   upload mytiple im...
269
          .get("/getClassesList")
058c4a6cf   Shikha Mishra   Improve the funct...
270
          .then((response) => {
d9bb52b5b   Neeraj Sharma   implement trello ...
271
            this.classList = response.data.data;
4b169b574   Neeraj Sharma   add loader in all...
272
            this.showLoader = false;
1ed542553   Neeraj Sharma   all api implement...
273
          })
058c4a6cf   Shikha Mishra   Improve the funct...
274
          .catch((error) => {
4b169b574   Neeraj Sharma   add loader in all...
275
            this.showLoader = false;
a17c68a03   Neeraj Sharma   implement two rou...
276
277
278
279
280
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
1ed542553   Neeraj Sharma   all api implement...
281
282
283
          });
      },
      editItem(item) {
d9bb52b5b   Neeraj Sharma   implement trello ...
284
        this.editedIndex = this.classList.indexOf(item);
1ed542553   Neeraj Sharma   all api implement...
285
        this.editedItem = Object.assign({}, item);
68d742034   Neeraj Sharma   implement new des...
286
        this.editClassDialog = true;
1ed542553   Neeraj Sharma   all api implement...
287
288
      },
      profile(item) {
d9bb52b5b   Neeraj Sharma   implement trello ...
289
        this.editedIndex = this.classList.indexOf(item);
1ed542553   Neeraj Sharma   all api implement...
290
        this.editedItem = Object.assign({}, item);
68d742034   Neeraj Sharma   implement new des...
291
        this.profileClassDialog = true;
1ed542553   Neeraj Sharma   all api implement...
292
293
294
      },
      deleteItem(item) {
        let deleteStudent = {
058c4a6cf   Shikha Mishra   Improve the funct...
295
          classId: item._id,
1ed542553   Neeraj Sharma   all api implement...
296
297
298
299
300
        };
        http()
          .delete(
            "/deleteClass",
            confirm("Are you sure you want to delete this?") && {
058c4a6cf   Shikha Mishra   Improve the funct...
301
              params: deleteStudent,
1ed542553   Neeraj Sharma   all api implement...
302
303
            }
          )
058c4a6cf   Shikha Mishra   Improve the funct...
304
          .then((response) => {
68d742034   Neeraj Sharma   implement new des...
305
306
307
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
1ed542553   Neeraj Sharma   all api implement...
308
309
            this.getClassList();
          })
058c4a6cf   Shikha Mishra   Improve the funct...
310
          .catch((error) => {
68d742034   Neeraj Sharma   implement new des...
311
312
313
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
1ed542553   Neeraj Sharma   all api implement...
314
315
          });
      },
1ed542553   Neeraj Sharma   all api implement...
316
      close() {
68d742034   Neeraj Sharma   implement new des...
317
        this.editClassDialog = false;
1ed542553   Neeraj Sharma   all api implement...
318
      },
68d742034   Neeraj Sharma   implement new des...
319
320
      closeProfile() {
        this.profileClassDialog = false;
1ed542553   Neeraj Sharma   all api implement...
321
322
323
324
      },
      submit() {
        if (this.$refs.form.validate()) {
          let addClass = {
058c4a6cf   Shikha Mishra   Improve the funct...
325
            classNum: this.addclasses.classNum,
1ed542553   Neeraj Sharma   all api implement...
326
          };
5f1d4b444   Neeraj Sharma   fix design and fi...
327
          this.loading = true;
1ed542553   Neeraj Sharma   all api implement...
328
329
          http()
            .post("/createClass", addClass)
058c4a6cf   Shikha Mishra   Improve the funct...
330
            .then((response) => {
1ed542553   Neeraj Sharma   all api implement...
331
              this.getClassList();
68d742034   Neeraj Sharma   implement new des...
332
333
              this.snackbar = true;
              this.text = response.data.message;
058c4a6cf   Shikha Mishra   Improve the funct...
334
              this.color = "green";
7efe02762   Amber Dev   made forms reset
335
              // this.clear();
5f1d4b444   Neeraj Sharma   fix design and fi...
336
              this.loading = false;
8e8d14254   Shikha Mishra   Cleared data whil...
337
              this.$refs.form.reset();
68d742034   Neeraj Sharma   implement new des...
338
              this.addClassDialog = false;
1ed542553   Neeraj Sharma   all api implement...
339
            })
058c4a6cf   Shikha Mishra   Improve the funct...
340
            .catch((error) => {
5f1d4b444   Neeraj Sharma   fix design and fi...
341
              this.loading = false;
68d742034   Neeraj Sharma   implement new des...
342
343
344
              this.snackbar = true;
              this.color = "error";
              this.text = error.response.data.message;
1ed542553   Neeraj Sharma   all api implement...
345
346
347
            });
        }
      },
1ed542553   Neeraj Sharma   all api implement...
348
349
350
351
352
353
      clear() {
        this.$refs.form.reset();
      },
      save() {
        let editClass = {
          classId: this.editedItem._id,
058c4a6cf   Shikha Mishra   Improve the funct...
354
          classNum: this.editedItem.classNum,
1ed542553   Neeraj Sharma   all api implement...
355
356
357
        };
        http()
          .put("/updateClass", editClass)
058c4a6cf   Shikha Mishra   Improve the funct...
358
          .then((response) => {
68d742034   Neeraj Sharma   implement new des...
359
360
361
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
1ed542553   Neeraj Sharma   all api implement...
362
            this.getClassList();
68d742034   Neeraj Sharma   implement new des...
363
            this.close();
1ed542553   Neeraj Sharma   all api implement...
364
          })
058c4a6cf   Shikha Mishra   Improve the funct...
365
          .catch((error) => {
68d742034   Neeraj Sharma   implement new des...
366
367
368
            this.snackbar = true;
            this.text = error.response.data.message;
            this.color = "error";
1ed542553   Neeraj Sharma   all api implement...
369
370
            // console.log(error);
          });
68d742034   Neeraj Sharma   implement new des...
371
372
373
374
375
376
377
378
      },
      displaySearch() {
        (this.show = false), (this.showSearch = true);
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
058c4a6cf   Shikha Mishra   Improve the funct...
379
      },
1ed542553   Neeraj Sharma   all api implement...
380
381
382
    },
    mounted() {
      this.getClassList();
058c4a6cf   Shikha Mishra   Improve the funct...
383
    },
68d742034   Neeraj Sharma   implement new des...
384
385
386
387
388
389
390
391
392
    // created() {
    //   this.$root.$on("app:search", search => {
    //     this.search = search;
    //   });
    // },
    // beforeDestroy() {
    //   // dont forget to remove the listener
    //   this.$root.$off("app:search");
    // }
1ed542553   Neeraj Sharma   all api implement...
393
394
  };
  </script>
506be6fd7   Neeraj Sharma   implemet dyamic i...
395
  <style>
1ed542553   Neeraj Sharma   all api implement...
396
  </style>