Blame view

src/pages/Notification/notification.vue 14.9 KB
55f72b7d7   Neeraj Sharma   add new page are ...
1
  <template>
68d742034   Neeraj Sharma   implement new des...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    <v-container fluid class="body-color">
      <!-- ****** EDITS  NOTIFICATION DETAILS ****** -->
      <v-dialog v-model="editNotificationDialog" max-width="500px">
        <v-flex xs12 sm12>
          <v-card flat class="card-style pa-3" dark>
            <v-layout>
              <v-flex xs12>
                <label class="title text-xs-center">Edit Notification</label>
                <v-icon size="24" class="right" @click="editNotificationDialog = false">cancel</v-icon>
              </v-flex>
            </v-layout>
            <v-flex xs12 sm12>
              <v-layout>
                <v-flex xs4 class="pt-4 subheading">
                  <label class="right">Title:</label>
                </v-flex>
                <v-flex xs8 sm8 class="ml-3">
                  <v-text-field
                    v-model="editedItem.title"
                    placeholder="fill your Title"
                    name="name"
                    type="text"
                  ></v-text-field>
                </v-flex>
              </v-layout>
            </v-flex>
            <v-flex xs12 sm12>
              <v-layout>
                <v-flex xs4 class="pt-4 subheading">
                  <label class="right">Description:</label>
                </v-flex>
                <v-flex xs8 sm8 class="ml-3">
                  <v-text-field
                    placeholder="fill your Description"
                    v-model="editedItem.description"
                    type="text"
                  ></v-text-field>
                </v-flex>
              </v-layout>
            </v-flex>
            <v-layout>
              <v-flex xs12>
                <v-card-actions>
                  <v-spacer></v-spacer>
                  <v-btn round dark @click="save" :loading="editLoading" class="add-button">Save</v-btn>
                  <v-spacer></v-spacer>
                </v-card-actions>
              </v-flex>
            </v-layout>
          </v-card>
        </v-flex>
      </v-dialog>
55f72b7d7   Neeraj Sharma   add new page are ...
54

68d742034   Neeraj Sharma   implement new des...
55
      <!-- ****** PROFILE VIEW NOTIFICATION DEATILS ******  -->
55f72b7d7   Neeraj Sharma   add new page are ...
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
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
145
146
147
148
149
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
      <v-dialog v-model="profileNotificationDialog" max-width="400px">
        <v-card flat class="card-style pa-3" dark>
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">View Notification</label>
              <v-icon size="24" class="right" @click="profileNotificationDialog = false">cancel</v-icon>
            </v-flex>
          </v-layout>
          <v-card-text>
            <v-container grid-list-md>
              <v-layout wrap>
                <v-flex xs12>
                  <v-layout>
                    <v-flex xs4 sm6>
                      <h5 class="right my-1">
                        <b>Title:</b>
                      </h5>
                    </v-flex>
                    <v-flex sm6 xs8>
                      <h5 class="my-1">{{ editedItem.title }}</h5>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-layout>
                  <v-flex xs4 sm6>
                    <h5 class="right my-1">
                      <b>Description:</b>
                    </h5>
                  </v-flex>
                  <v-flex sm6 xs8>
                    <h5 class="my-1">{{ editedItem.description }}</h5>
                  </v-flex>
                </v-layout>
              </v-layout>
            </v-container>
          </v-card-text>
        </v-card>
      </v-dialog>
      <!-- ****** NOTIFICATION 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="addNotificationDialog = true"
        >
          <v-icon dark>add</v-icon>
        </v-btn>
        <v-btn
          round
          class="open-dialog-button hidden-sm-only hidden-xs-only"
          dark
          @click="addNotificationDialog = true"
        >
          <v-icon class="white--text pr-1" size="20">add</v-icon>Add Notification
        </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">
              <img src="/static/icon/dashboard icons-49.png" alt="icon" />
            </v-avatar>
          </v-btn>
        </v-card-title>
        <v-flex xs8 sm8 md3 lg2  v-show="showSearch">
          <v-layout>
            <v-text-field v-model="search" label="Search" prepend-inner-icon="search" color="primary"></v-text-field>
            <v-icon @click="closeSearch" color="error">close</v-icon>
          </v-layout>
        </v-flex>
      </v-toolbar>
      <v-data-table
        :headers="headers"
        :items="notifications"
        :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="td td-row text-xs-center">{{ props.item.title}}</td>
            <td class="td td-row text-xs-center">{{ props.item.description}}</td>
            <td class="td td-row text-xs-center">
              <span>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:25px; height:25px; "
                    class="mr-3"
                    @click="profile(props.item)"
                    src="/static/icon/dashboard icons-47.png"
                  />
                  <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)"
                    src="/static/icon/dashboard icons-50.png"
                  />
                  <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)"
                    src="/static/icon/dashboard icons-51.png"
                  />
                  <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 NOTIFICATION ****** -->
      <v-dialog v-model="addNotificationDialog" max-width="480px">
        <v-card flat class="card-style pa-2" dark>
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Add Notification</label>
              <v-icon size="24" class="right" @click="addNotificationDialog = false">cancel</v-icon>
            </v-flex>
          </v-layout>
          <v-form ref="form" v-model="valid" lazy-validation>
            <v-container fluid fill-height>
              <v-layout align-center wrap>
                <v-flex xs12>
f4df757fe   Neeraj Sharma   responsive vie in...
197
198
199
                  <v-layout>
                    <v-flex xs4 class="pt-4 subheading">
                      <label class="right">Title:</label>
a17c68a03   Neeraj Sharma   implement two rou...
200
                    </v-flex>
68d742034   Neeraj Sharma   implement new des...
201
                    <v-flex xs8 sm8 class="ml-3">
f4df757fe   Neeraj Sharma   responsive vie in...
202
                      <v-text-field
68d742034   Neeraj Sharma   implement new des...
203
                        v-model="addNotification.title"
f4df757fe   Neeraj Sharma   responsive vie in...
204
                        placeholder="fill your Title"
f4df757fe   Neeraj Sharma   responsive vie in...
205
                        type="text"
68d742034   Neeraj Sharma   implement new des...
206
207
                        :rules="titleRules"
                        required
f4df757fe   Neeraj Sharma   responsive vie in...
208
                      ></v-text-field>
a17c68a03   Neeraj Sharma   implement two rou...
209
                    </v-flex>
f4df757fe   Neeraj Sharma   responsive vie in...
210
211
                  </v-layout>
                </v-flex>
68d742034   Neeraj Sharma   implement new des...
212
                <v-flex xs12>
f4df757fe   Neeraj Sharma   responsive vie in...
213
214
215
216
                  <v-layout>
                    <v-flex xs4 class="pt-4 subheading">
                      <label class="right">Description:</label>
                    </v-flex>
68d742034   Neeraj Sharma   implement new des...
217
                    <v-flex xs8 sm8 class="ml-3">
f4df757fe   Neeraj Sharma   responsive vie in...
218
219
                      <v-text-field
                        placeholder="fill your Description"
68d742034   Neeraj Sharma   implement new des...
220
221
                        :rules="descriptionRules"
                        v-model="addNotification.description"
f4df757fe   Neeraj Sharma   responsive vie in...
222
                        type="text"
68d742034   Neeraj Sharma   implement new des...
223
                        required
f4df757fe   Neeraj Sharma   responsive vie in...
224
225
226
227
228
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-layout>
68d742034   Neeraj Sharma   implement new des...
229
230
231
232
233
234
235
236
237
                  <v-flex xs12 sm12>
                    <v-layout class="hidden-xs-only hidden-sm-only right">
                      <v-btn @click="clear" round class="clear-button" dark>Clear</v-btn>
                      <v-btn @click="submit" round dark :loading="loading" class="add-button">Add</v-btn>
                    </v-layout>
                    <v-card-actions class="hidden-md-only hidden-lg-only hidden-xl-only">
                      <v-spacer></v-spacer>
                      <v-btn @click="clear" round class="clear-button" dark>Clear</v-btn>
                      <v-btn @click="submit" round dark :loading="loading" class="add-button">Add</v-btn>
f4df757fe   Neeraj Sharma   responsive vie in...
238
                      <v-spacer></v-spacer>
f4df757fe   Neeraj Sharma   responsive vie in...
239
240
241
                    </v-card-actions>
                  </v-flex>
                </v-layout>
68d742034   Neeraj Sharma   implement new des...
242
243
244
245
246
247
248
249
250
251
252
253
254
              </v-layout>
            </v-container>
          </v-form>
        </v-card>
      </v-dialog>
      <v-snackbar
        :timeout="timeout"
        :top="y === 'top'"
        :right="x === 'right'"
        :vertical="mode === 'vertical'"
        v-model="snackbar"
        :color="color"
      >{{ text }}</v-snackbar>
55f72b7d7   Neeraj Sharma   add new page are ...
255
256
257
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
68d742034   Neeraj Sharma   implement new des...
258
    </v-container>
55f72b7d7   Neeraj Sharma   add new page are ...
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
  </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: "",
      loading: false,
68d742034   Neeraj Sharma   implement new des...
274
      editLoading: false,
55f72b7d7   Neeraj Sharma   add new page are ...
275
276
      date: null,
      search: "",
68d742034   Neeraj Sharma   implement new des...
277
278
279
      color: "",
      show: true,
      showSearch: false,
a17c68a03   Neeraj Sharma   implement two rou...
280
      showLoader: false,
68d742034   Neeraj Sharma   implement new des...
281
282
      profileNotificationDialog: false,
      editNotificationDialog: false,
55f72b7d7   Neeraj Sharma   add new page are ...
283
      valid: true,
68d742034   Neeraj Sharma   implement new des...
284
      addNotificationDialog: false,
55f72b7d7   Neeraj Sharma   add new page are ...
285
      pagination: {
68d742034   Neeraj Sharma   implement new des...
286
        rowsPerPage: 10
55f72b7d7   Neeraj Sharma   add new page are ...
287
288
289
290
291
292
293
294
295
296
      },
      imageData: {},
      imageName: "",
      imageUrl: "",
      imageFile: "",
      titleRules: [v => !!v || " Tilte is required"],
      descriptionRules: [v => !!v || " Description is required"],
      headers: [
        {
          text: "No",
68d742034   Neeraj Sharma   implement new des...
297
          align: "",
55f72b7d7   Neeraj Sharma   add new page are ...
298
299
300
301
          sortable: false,
          value: "No"
        },
        { text: "Title", value: "title", sortable: false, align: "center" },
a17c68a03   Neeraj Sharma   implement two rou...
302
303
304
305
306
307
        {
          text: "Description",
          value: "description",
          sortable: false,
          align: "center"
        },
55f72b7d7   Neeraj Sharma   add new page are ...
308
309
        { text: "Action", value: "", sortable: false, align: "center" }
      ],
68d742034   Neeraj Sharma   implement new des...
310
      notifications: [],
55f72b7d7   Neeraj Sharma   add new page are ...
311
      editedIndex: -1,
a17c68a03   Neeraj Sharma   implement two rou...
312
313
314
      addNotification: {
        title: "",
        description: ""
55f72b7d7   Neeraj Sharma   add new page are ...
315
316
      },
      editedItem: {
a17c68a03   Neeraj Sharma   implement two rou...
317
318
        title: "",
        description: ""
a17c68a03   Neeraj Sharma   implement two rou...
319
      }
55f72b7d7   Neeraj Sharma   add new page are ...
320
321
322
323
324
325
326
    }),
    methods: {
      pickFile() {
        this.$refs.image.click();
      },
  
      onFilePicked(e) {
55f72b7d7   Neeraj Sharma   add new page are ...
327
328
329
330
331
332
333
334
335
336
337
338
339
        const files = e.target.files;
        this.imageData.upload = e.target.files[0];
        if (files[0] !== undefined) {
          this.imageName = files[0].name;
          if (this.imageName.lastIndexOf(".") <= 0) {
            return;
          }
          const fr = new FileReader();
          fr.readAsDataURL(files[0]);
          fr.addEventListener("load", () => {
            this.imageUrl = fr.result;
            this.imageFile = files[0]; // this is an image file that can be sent to server...
            this.imageData.imageUrl = URL.createObjectURL(this.imageFile);
55f72b7d7   Neeraj Sharma   add new page are ...
340
341
342
343
344
345
346
          });
        } else {
          this.imageName = "";
          this.imageFile = "";
          this.imageUrl = "";
        }
      },
a17c68a03   Neeraj Sharma   implement two rou...
347
      getNotifications() {
55f72b7d7   Neeraj Sharma   add new page are ...
348
349
350
351
352
353
354
        this.showLoader = true;
        var token = this.$store.state.token;
        http()
          .get("/getNotificationsList", {
            headers: { Authorization: "Bearer " + token }
          })
          .then(response => {
68d742034   Neeraj Sharma   implement new des...
355
            this.notifications = response.data.data;
55f72b7d7   Neeraj Sharma   add new page are ...
356
            this.showLoader = false;
55f72b7d7   Neeraj Sharma   add new page are ...
357
          })
00e4bc4e1   Neeraj Sharma   fixed auntentication
358
          .catch(error => {
55f72b7d7   Neeraj Sharma   add new page are ...
359
            this.showLoader = false;
a17c68a03   Neeraj Sharma   implement two rou...
360
361
362
363
364
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
55f72b7d7   Neeraj Sharma   add new page are ...
365
366
367
          });
      },
      editItem(item) {
68d742034   Neeraj Sharma   implement new des...
368
        this.editedIndex = this.notifications.indexOf(item);
55f72b7d7   Neeraj Sharma   add new page are ...
369
        this.editedItem = Object.assign({}, item);
68d742034   Neeraj Sharma   implement new des...
370
        this.editNotificationDialog = true;
55f72b7d7   Neeraj Sharma   add new page are ...
371
372
      },
      profile(item) {
68d742034   Neeraj Sharma   implement new des...
373
        this.editedIndex = this.notifications.indexOf(item);
55f72b7d7   Neeraj Sharma   add new page are ...
374
        this.editedItem = Object.assign({}, item);
68d742034   Neeraj Sharma   implement new des...
375
        this.profileNotificationDialog = true;
55f72b7d7   Neeraj Sharma   add new page are ...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
      },
  
      deleteItem(item) {
        let deleteNotification = {
          notificationId: item._id
        };
        http()
          .delete(
            "/deleteNotification",
            confirm("Are you sure you want to delete this?") && {
              params: deleteNotification
            }
          )
          .then(response => {
68d742034   Neeraj Sharma   implement new des...
390
391
392
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
a17c68a03   Neeraj Sharma   implement two rou...
393
            this.getNotifications();
55f72b7d7   Neeraj Sharma   add new page are ...
394
395
          })
          .catch(error => {
68d742034   Neeraj Sharma   implement new des...
396
397
398
            this.snackbar = true;
            this.text = error.response.data.message;
            this.color = "error";
55f72b7d7   Neeraj Sharma   add new page are ...
399
400
          });
      },
55f72b7d7   Neeraj Sharma   add new page are ...
401
      close() {
68d742034   Neeraj Sharma   implement new des...
402
        this.editNotificationDialog = false;
55f72b7d7   Neeraj Sharma   add new page are ...
403
      },
68d742034   Neeraj Sharma   implement new des...
404
405
      closeNotificationDialog() {
        this.profileNotificationDialog = false;
55f72b7d7   Neeraj Sharma   add new page are ...
406
407
408
409
410
      },
      submit() {
        if (this.$refs.form.validate()) {
          let imageData = new FormData();
          imageData.append("upload", this.imageFile);
55f72b7d7   Neeraj Sharma   add new page are ...
411
412
          let create = {
            title: this.addNotification.title,
a17c68a03   Neeraj Sharma   implement two rou...
413
            description: this.addNotification.description
55f72b7d7   Neeraj Sharma   add new page are ...
414
          };
5f1d4b444   Neeraj Sharma   fix design and fi...
415
          this.loading = true;
55f72b7d7   Neeraj Sharma   add new page are ...
416
417
418
          http()
            .post("/createNotification", create)
            .then(response => {
68d742034   Neeraj Sharma   implement new des...
419
420
421
              this.snackbar = true;
              this.text = response.data.message;
              this.color = "green";
55f72b7d7   Neeraj Sharma   add new page are ...
422
423
              this.getNotifications();
              this.clear();
5f1d4b444   Neeraj Sharma   fix design and fi...
424
              this.loading = false;
55f72b7d7   Neeraj Sharma   add new page are ...
425
426
            })
            .catch(error => {
68d742034   Neeraj Sharma   implement new des...
427
428
429
              this.snackbar = true;
              this.text = error.response.data.message;
              this.color = "error";
5f1d4b444   Neeraj Sharma   fix design and fi...
430
              this.loading = false;
55f72b7d7   Neeraj Sharma   add new page are ...
431
432
433
            });
        }
      },
55f72b7d7   Neeraj Sharma   add new page are ...
434
435
436
437
      clear() {
        this.$refs.form.reset();
      },
      save() {
a17c68a03   Neeraj Sharma   implement two rou...
438
439
        let imageData = new FormData();
        imageData.append("upload", this.imageFile);
55f72b7d7   Neeraj Sharma   add new page are ...
440
        let editNotification = {
a17c68a03   Neeraj Sharma   implement two rou...
441
442
443
          notificationId: this.editedItem._id,
          title: this.editedItem.title,
          description: this.editedItem.description
55f72b7d7   Neeraj Sharma   add new page are ...
444
        };
68d742034   Neeraj Sharma   implement new des...
445
        this.editLoading = true;
55f72b7d7   Neeraj Sharma   add new page are ...
446
447
448
        http()
          .put("/updateNotification", editNotification)
          .then(response => {
68d742034   Neeraj Sharma   implement new des...
449
450
451
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
55f72b7d7   Neeraj Sharma   add new page are ...
452
            this.getNotifications();
68d742034   Neeraj Sharma   implement new des...
453
454
            this.close();
            this.editLoading = false;
55f72b7d7   Neeraj Sharma   add new page are ...
455
456
          })
          .catch(error => {
68d742034   Neeraj Sharma   implement new des...
457
458
459
460
            this.editLoading = false;
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
55f72b7d7   Neeraj Sharma   add new page are ...
461
          });
68d742034   Neeraj Sharma   implement new des...
462
463
464
465
466
467
468
469
      },
      displaySearch() {
        (this.show = false), (this.showSearch = true);
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
55f72b7d7   Neeraj Sharma   add new page are ...
470
471
472
473
      }
    },
    mounted() {
      this.getNotifications();
55f72b7d7   Neeraj Sharma   add new page are ...
474
475
    }
  };
68d742034   Neeraj Sharma   implement new des...
476
  </script>