Blame view

src/pages/Class/addclass.vue 11.7 KB
1ed542553   Neeraj Sharma   all api implement...
1
  <template>
a17c68a03   Neeraj Sharma   implement two rou...
2
    <div>
687e0b929   Neeraj Sharma   add user,attenden...
3
      <v-tabs grow slider-color="gary">
1ed542553   Neeraj Sharma   all api implement...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
        <v-tab
          ripple
          @click="activeTab('existing')"
          v-bind:class="{ active: isActive }"
          id="tab"
          class="subheading"
        >Existing Class</v-tab>
        <v-tab
          ripple
          @click="activeTab('new')"
          v-bind:class="{ active: newActive }"
          id="tab1"
          User
          class="subheading"
        >Add New Class</v-tab>
f4df757fe   Neeraj Sharma   responsive vie in...
19
        <!-- ****** EDIT  ClASS  ****** -->
1ed542553   Neeraj Sharma   all api implement...
20
21
22
23
24
25
26
27
28
29
        <v-tab-item>
          <v-snackbar
            :timeout="timeout"
            :top="y === 'top'"
            :right="x === 'right'"
            :vertical="mode === 'vertical'"
            v-model="snackbar"
            color="success"
          >{{ text }}</v-snackbar>
          <v-dialog v-model="dialog" max-width="500px">
aa8fc5033   Neeraj Sharma   implenment all pa...
30
31
32
33
34
35
36
37
38
            <v-flex xs12 sm12 class>
              <v-toolbar color="grey lighten-2">
                <v-spacer></v-spacer>
                <v-toolbar-title>
                  <h3>Edit Class</h3>
                </v-toolbar-title>
                <v-spacer></v-spacer>
              </v-toolbar>
              <v-card>
495e4037c   Neeraj Sharma   update
39
40
41
42
43
44
45
46
                <v-container fluid>
                  <v-layout justify-center>
                    <v-flex xs12 sm9>
                      <v-layout style="position:relative;">
                        <v-flex xs3 lg2 class="pt-4 subheading">
                          <label class="right">Class:</label>
                        </v-flex>
                        <v-flex xs9 class="ml-2">
d9bb52b5b   Neeraj Sharma   implement trello ...
47
                          <v-text-field
495e4037c   Neeraj Sharma   update
48
                            v-model="editedItem.classNum"
d9bb52b5b   Neeraj Sharma   implement trello ...
49
                            @keyup.enter="save"
495e4037c   Neeraj Sharma   update
50
                            :rules="nameRules"
d9bb52b5b   Neeraj Sharma   implement trello ...
51
                          ></v-text-field>
495e4037c   Neeraj Sharma   update
52
53
54
55
56
57
58
59
60
61
                        </v-flex>
                      </v-layout>
                      <v-card-actions>
                        <v-btn round dark @click.native="close">Cancel</v-btn>
                        <v-spacer></v-spacer>
                        <v-btn round dark @click="save">Save</v-btn>
                      </v-card-actions>
                    </v-flex>
                  </v-layout>
                </v-container>
aa8fc5033   Neeraj Sharma   implenment all pa...
62
63
              </v-card>
            </v-flex>
1ed542553   Neeraj Sharma   all api implement...
64
65
66
67
          </v-dialog>
  
          <!-- ****** PROFILE VIEW STUDENTS ******  -->
          <v-dialog v-model="dialog1" max-width="600px">
506be6fd7   Neeraj Sharma   implemet dyamic i...
68
            <v-toolbar color="grey lighten-2">
1ed542553   Neeraj Sharma   all api implement...
69
              <v-spacer></v-spacer>
a17c68a03   Neeraj Sharma   implement two rou...
70
              <v-toolbar-title>
60e13c8f2   Neeraj Sharma   solve bugs
71
                <h3>Class</h3>
a17c68a03   Neeraj Sharma   implement two rou...
72
              </v-toolbar-title>
1ed542553   Neeraj Sharma   all api implement...
73
74
75
76
              <v-spacer></v-spacer>
              <v-icon @click="close1">close</v-icon>
            </v-toolbar>
            <v-card>
1ed542553   Neeraj Sharma   all api implement...
77
78
79
80
              <v-card-text>
                <v-container grid-list-md>
                  <v-layout wrap>
                    <v-flex>
1ed542553   Neeraj Sharma   all api implement...
81
                      <v-layout>
a17c68a03   Neeraj Sharma   implement two rou...
82
                        <v-flex xs6 sm6>
aa8fc5033   Neeraj Sharma   implenment all pa...
83
84
85
                          <h5 class="right my-1">
                            <b>Class Name:</b>
                          </h5>
1ed542553   Neeraj Sharma   all api implement...
86
                        </v-flex>
a17c68a03   Neeraj Sharma   implement two rou...
87
                        <v-flex sm6 xs6>
1ed542553   Neeraj Sharma   all api implement...
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
                          <h5 class="my-1">{{ editedItem.classNum }}</h5>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-card-text>
            </v-card>
          </v-dialog>
  
          <v-snackbar
            :timeout="timeout"
            :top="y === 'top'"
            :right="x === 'right'"
            :vertical="mode === 'vertical'"
            v-model="snackbar"
            color="success"
          >{{ text }}</v-snackbar>
  
          <!-- ****** EXISTING-USERS Classess Table ****** -->
          <v-data-table
            :headers="headers"
d9bb52b5b   Neeraj Sharma   implement trello ...
110
            :items="classList"
1ed542553   Neeraj Sharma   all api implement...
111
112
113
114
            :pagination.sync="pagination"
            :search="search"
          >
            <template slot="items" slot-scope="props">
687e0b929   Neeraj Sharma   add user,attenden...
115
              <td>{{ props.index + 1 }}</td>
506be6fd7   Neeraj Sharma   implemet dyamic i...
116
              <td class="text-xs-center">{{ props.item.classNum}}</td>
1ed542553   Neeraj Sharma   all api implement...
117
118
              <td class="text-xs-center">
                <span>
495e4037c   Neeraj Sharma   update
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
                  <v-tooltip top>
                    <img
                      slot="activator"
                      style="cursor:pointer; width:25px; height:18px; "
                      class="mr5"
                      @click="profile(props.item)"
                      src="/static/icon/eye1.png"
                    />
                    <span>View</span>
                  </v-tooltip>
                  <v-tooltip top>
                    <img
                      slot="activator"
                      style="cursor:pointer; width:20px; height:18px; "
                      class="mr5"
                      @click="editItem(props.item)"
                      src="/static/icon/edit1.png"
                    />
                    <span>Edit</span>
                  </v-tooltip>
                  <v-tooltip top>
                    <img
                      slot="activator"
                      style="cursor:pointer; width:20px; height:20px; "
                      class="mr5"
                      @click="deleteItem(props.item)"
                      src="/static/icon/delete1.png"
                    />
                    <span>Delete</span>
                  </v-tooltip>
1ed542553   Neeraj Sharma   all api implement...
149
150
151
                </span>
              </td>
            </template>
a17c68a03   Neeraj Sharma   implement two rou...
152
            <v-alert
1ed542553   Neeraj Sharma   all api implement...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
              slot="no-results"
              :value="true"
              color="error"
              icon="warning"
            >Your search for "{{ search }}" found no results.</v-alert>
          </v-data-table>
        </v-tab-item>
  
        <!-- ****** ADD multiple Classess ****** -->
        <v-tab-item>
          <v-container>
            <v-snackbar
              :timeout="timeout"
              :top="y === 'top'"
              :right="x === 'right'"
              :vertical="mode === 'vertical'"
              v-model="snackbar"
              color="success"
            >{{ text }}</v-snackbar>
            <v-flex xs12 sm8 offset-sm2 class="top">
              <v-card flat>
                <v-container fluid fill-height>
                  <v-layout align-center>
79006bdcb   Neeraj Sharma   uplaod images all...
176
                    <v-flex xs12 class="mt-4">
1ed542553   Neeraj Sharma   all api implement...
177
178
179
                      <v-form ref="form" v-model="valid" lazy-validation>
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
506be6fd7   Neeraj Sharma   implemet dyamic i...
180
                            <label class="right">Class :</label>
1ed542553   Neeraj Sharma   all api implement...
181
182
                          </v-flex>
                          <v-flex xs6 class="ml-3">
d9bb52b5b   Neeraj Sharma   implement trello ...
183
                            <v-text-field
1ed542553   Neeraj Sharma   all api implement...
184
185
                              v-model="addclasses.classNum"
                              placeholder="fill your class Name"
1ed542553   Neeraj Sharma   all api implement...
186
187
188
                              type="text"
                              :rules="nameRules"
                              required
d9bb52b5b   Neeraj Sharma   implement trello ...
189
                            ></v-text-field>
1ed542553   Neeraj Sharma   all api implement...
190
191
192
193
194
                          </v-flex>
                        </v-layout>
                        <v-layout>
                          <v-flex xs12 sm9 offset-sm2>
                            <v-card-actions>
1ed542553   Neeraj Sharma   all api implement...
195
196
                              <v-spacer></v-spacer>
                              <v-btn @click="submit" round dark :loading="loading">Add</v-btn>
79006bdcb   Neeraj Sharma   uplaod images all...
197
                              <v-spacer></v-spacer>
1ed542553   Neeraj Sharma   all api implement...
198
199
200
201
202
203
204
205
206
207
208
209
                            </v-card-actions>
                          </v-flex>
                        </v-layout>
                      </v-form>
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-card>
            </v-flex>
          </v-container>
        </v-tab-item>
      </v-tabs>
4b169b574   Neeraj Sharma   add loader in all...
210
211
212
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
a17c68a03   Neeraj Sharma   implement two rou...
213
    </div>
1ed542553   Neeraj Sharma   all api implement...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
  </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: "",
a17c68a03   Neeraj Sharma   implement two rou...
228
      showLoader: false,
1ed542553   Neeraj Sharma   all api implement...
229
230
231
      loading: false,
      date: null,
      search: "",
1ed542553   Neeraj Sharma   all api implement...
232
233
234
235
236
237
238
239
240
      dialog: false,
      dialog1: false,
      valid: true,
      isActive: true,
      newActive: false,
      AddUsercredentials: {},
      pagination: {
        rowsPerPage: 15
      },
46db0a3b5   Neeraj Sharma   add sunbject and ...
241
      nameRules: [v => !!v || " Class Name is required"],
1ed542553   Neeraj Sharma   all api implement...
242
243
244
      headers: [
        {
          text: "No",
506be6fd7   Neeraj Sharma   implemet dyamic i...
245
          align: "left",
1ed542553   Neeraj Sharma   all api implement...
246
247
248
          sortable: false,
          value: "No"
        },
2b0e316ee   Neeraj Sharma   upload mytiple im...
249
        { text: "Class No", value: "classNum", sortable: false, align: "center" },
1ed542553   Neeraj Sharma   all api implement...
250
251
        { text: "Action", value: "", sortable: false, align: "center" }
      ],
d9bb52b5b   Neeraj Sharma   implement trello ...
252
      classList: [],
1ed542553   Neeraj Sharma   all api implement...
253
254
255
256
      editedIndex: -1,
      editedItem: {
        classNum: ""
      },
a17c68a03   Neeraj Sharma   implement two rou...
257
      addclasses: {
1ed542553   Neeraj Sharma   all api implement...
258
        classNum: ""
a17c68a03   Neeraj Sharma   implement two rou...
259
      }
1ed542553   Neeraj Sharma   all api implement...
260
    }),
1ed542553   Neeraj Sharma   all api implement...
261
262
    methods: {
      getClassList() {
4b169b574   Neeraj Sharma   add loader in all...
263
        this.showLoader = true;
1ed542553   Neeraj Sharma   all api implement...
264
265
        var token = this.$store.state.token;
        http()
2b0e316ee   Neeraj Sharma   upload mytiple im...
266
          .get("/getClassesList")
1ed542553   Neeraj Sharma   all api implement...
267
          .then(response => {
d9bb52b5b   Neeraj Sharma   implement trello ...
268
            this.classList = response.data.data;
4b169b574   Neeraj Sharma   add loader in all...
269
            this.showLoader = false;
1ed542553   Neeraj Sharma   all api implement...
270
          })
00e4bc4e1   Neeraj Sharma   fixed auntentication
271
          .catch(error => {
4b169b574   Neeraj Sharma   add loader in all...
272
            this.showLoader = false;
a17c68a03   Neeraj Sharma   implement two rou...
273
274
275
276
277
            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...
278
279
280
          });
      },
      editItem(item) {
d9bb52b5b   Neeraj Sharma   implement trello ...
281
        this.editedIndex = this.classList.indexOf(item);
1ed542553   Neeraj Sharma   all api implement...
282
283
284
285
        this.editedItem = Object.assign({}, item);
        this.dialog = true;
      },
      profile(item) {
d9bb52b5b   Neeraj Sharma   implement trello ...
286
        this.editedIndex = this.classList.indexOf(item);
1ed542553   Neeraj Sharma   all api implement...
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
        this.editedItem = Object.assign({}, item);
        this.dialog1 = true;
      },
      deleteItem(item) {
        let deleteStudent = {
          classId: item._id
        };
        http()
          .delete(
            "/deleteClass",
            confirm("Are you sure you want to delete this?") && {
              params: deleteStudent
            }
          )
          .then(response => {
            // console.log("deleteUers",deleteStudent)
            if ((this.snackbar = true)) {
5f1d4b444   Neeraj Sharma   fix design and fi...
304
              this.text = "Successfully delete Existing Class";
1ed542553   Neeraj Sharma   all api implement...
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
            }
            this.getClassList();
          })
          .catch(error => {
            // console.log(error);
          });
      },
      activeTab(type) {
        switch (type) {
          case "existing":
            this.newActive = false;
            this.isActive = true;
            break;
  
          default:
            this.newActive = true;
            this.isActive = false;
            break;
        }
      },
      close() {
        this.dialog = false;
        setTimeout(() => {
          this.editedItem = Object.assign({}, this.defaultItem);
          this.editedIndex = -1;
        }, 300);
      },
      close1() {
        this.dialog1 = false;
      },
      submit() {
        if (this.$refs.form.validate()) {
          let addClass = {
            classNum: this.addclasses.classNum
          };
          console.log(addClass);
5f1d4b444   Neeraj Sharma   fix design and fi...
341
          this.loading = true;
1ed542553   Neeraj Sharma   all api implement...
342
343
344
345
346
          http()
            .post("/createClass", addClass)
            .then(response => {
              this.getClassList();
              if ((this.snackbar = true)) {
5f1d4b444   Neeraj Sharma   fix design and fi...
347
                this.text = "New class added successfully";
1ed542553   Neeraj Sharma   all api implement...
348
              }
1ed542553   Neeraj Sharma   all api implement...
349
              this.clear();
5f1d4b444   Neeraj Sharma   fix design and fi...
350
              this.loading = false;
1ed542553   Neeraj Sharma   all api implement...
351
352
353
            })
            .catch(error => {
              // console.log(error);
5f1d4b444   Neeraj Sharma   fix design and fi...
354
              this.loading = false;
1ed542553   Neeraj Sharma   all api implement...
355
356
357
358
359
360
              if ((this.snackbar = true)) {
                this.text = error.response.data.message;
              }
            });
        }
      },
1ed542553   Neeraj Sharma   all api implement...
361
362
363
364
365
366
367
368
369
370
371
      clear() {
        this.$refs.form.reset();
      },
      save() {
        let editClass = {
          classId: this.editedItem._id,
          classNum: this.editedItem.classNum
        };
        http()
          .put("/updateClass", editClass)
          .then(response => {
1ed542553   Neeraj Sharma   all api implement...
372
            if ((this.snackbar = true)) {
5f1d4b444   Neeraj Sharma   fix design and fi...
373
              this.text = "Successfully Edit Existing Class";
1ed542553   Neeraj Sharma   all api implement...
374
375
376
377
378
379
380
            }
            this.getClassList();
          })
          .catch(error => {
            // console.log(error);
          });
        this.close();
1ed542553   Neeraj Sharma   all api implement...
381
382
383
384
      }
    },
    mounted() {
      this.getClassList();
a17c68a03   Neeraj Sharma   implement two rou...
385
      // console.log("this.search",this.search)
1ed542553   Neeraj Sharma   all api implement...
386
    },
a17c68a03   Neeraj Sharma   implement two rou...
387
388
389
390
391
392
393
394
    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...
395
396
397
    }
  };
  </script>
506be6fd7   Neeraj Sharma   implemet dyamic i...
398
  <style>
1ed542553   Neeraj Sharma   all api implement...
399
  .active {
687e0b929   Neeraj Sharma   add user,attenden...
400
    background-color: gray;
1ed542553   Neeraj Sharma   all api implement...
401
402
403
404
405
    color: white !important;
  }
  .activebtn {
    color: black !important;
  }
1ed542553   Neeraj Sharma   all api implement...
406
  </style>