Blame view

src/pages/Class/addclass.vue 11 KB
1ed542553   Neeraj Sharma   all api implement...
1
  <template>
68d742034   Neeraj Sharma   implement new des...
2
3
4
5
6
7
8
9
    <v-container fluid class="body-color">
      <!-- ****** EDIT  ClASS  ****** -->
      <v-dialog v-model="editClassDialog" max-width="400px">
        <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
30
31
32
33
34
35
36
37
      <!-- ****** PROFILE VIEW STUDENTS ******  -->
      <v-dialog v-model="profileClassDialog" max-width="400px">
        <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>
612b79bb4   Amber Dev   made serch auto f...
85
            <v-text-field autofocus v-model="search" label="Search" prepend-inner-icon="search" color="primary"></v-text-field>
68d742034   Neeraj Sharma   implement new des...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
            <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...
108
                    src="/static/icon/view.png"
68d742034   Neeraj Sharma   implement new des...
109
110
111
112
113
114
115
116
117
                  />
                  <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...
118
                    src="/static/icon/edit.png"
68d742034   Neeraj Sharma   implement new des...
119
120
121
                  />
                  <span>Edit</span>
                </v-tooltip>
b039d39fb   Shikha Mishra   Hide Edit functio...
122
                <!-- <v-tooltip top>
68d742034   Neeraj Sharma   implement new des...
123
124
125
126
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:20px; "
                    @click="deleteItem(props.item)"
aa310d61a   Shikha Mishra   added functionali...
127
                    src="/static/icon/delete.png"
68d742034   Neeraj Sharma   implement new des...
128
129
                  />
                  <span>Delete</span>
058c4a6cf   Shikha Mishra   Improve the funct...
130
                </v-tooltip>-->
68d742034   Neeraj Sharma   implement new des...
131
132
133
134
135
136
137
138
139
140
141
              </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...
142

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