Blame view
src/pages/Notification/notification.vue
15.3 KB
55f72b7d7
|
1 |
<template> |
68d742034
|
2 3 |
<v-container fluid class="body-color"> <!-- ****** EDITS NOTIFICATION DETAILS ****** --> |
db965de89
|
4 |
<v-dialog v-model="editNotificationDialog" max-width="500px" persistent> |
68d742034
|
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-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
|
54 |
|
68d742034
|
55 |
<!-- ****** PROFILE VIEW NOTIFICATION DEATILS ****** --> |
55f72b7d7
|
56 |
|
db965de89
|
57 |
<v-dialog v-model="profileNotificationDialog" max-width="400px" persistent> |
68d742034
|
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 |
<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"> |
aa310d61a
|
118 |
<img src="/static/icon/search.png" alt="icon" /> |
68d742034
|
119 120 121 |
</v-avatar> </v-btn> </v-card-title> |
8e8d14254
|
122 |
<v-flex xs8 sm8 md3 lg2 v-if="showSearch"> |
68d742034
|
123 |
<v-layout> |
8e8d14254
|
124 125 126 127 128 129 130 |
<v-text-field autofocus v-model="search" label="Search" prepend-inner-icon="search" color="primary" ></v-text-field> |
68d742034
|
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
<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)" |
aa310d61a
|
154 |
src="/static/icon/view.png" |
68d742034
|
155 156 157 158 159 160 161 162 163 |
/> <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
|
164 |
src="/static/icon/edit.png" |
68d742034
|
165 166 167 168 169 170 171 172 173 |
/> <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
|
174 |
src="/static/icon/delete.png" |
68d742034
|
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
/> <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 ****** --> |
db965de89
|
191 |
<v-dialog v-model="addNotificationDialog" max-width="480px" v-if="addNotificationDialog" persistent> |
68d742034
|
192 193 194 195 |
<v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Add Notification</label> |
8e8d14254
|
196 |
<v-icon size="24" class="right" @click="closeAddNotificationModel">cancel</v-icon> |
68d742034
|
197 198 199 200 201 202 |
</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
|
203 204 205 |
<v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Title:</label> |
a17c68a03
|
206 |
</v-flex> |
68d742034
|
207 |
<v-flex xs8 sm8 class="ml-3"> |
f4df757fe
|
208 |
<v-text-field |
68d742034
|
209 |
v-model="addNotification.title" |
f4df757fe
|
210 |
placeholder="fill your Title" |
f4df757fe
|
211 |
type="text" |
68d742034
|
212 213 |
:rules="titleRules" required |
f4df757fe
|
214 |
></v-text-field> |
a17c68a03
|
215 |
</v-flex> |
f4df757fe
|
216 217 |
</v-layout> </v-flex> |
68d742034
|
218 |
<v-flex xs12> |
f4df757fe
|
219 220 221 222 |
<v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Description:</label> </v-flex> |
68d742034
|
223 |
<v-flex xs8 sm8 class="ml-3"> |
f4df757fe
|
224 225 |
<v-text-field placeholder="fill your Description" |
68d742034
|
226 227 |
:rules="descriptionRules" v-model="addNotification.description" |
f4df757fe
|
228 |
type="text" |
68d742034
|
229 |
required |
f4df757fe
|
230 231 232 233 234 |
></v-text-field> </v-flex> </v-layout> </v-flex> <v-layout> |
68d742034
|
235 236 237 238 239 240 241 242 243 |
<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
|
244 |
<v-spacer></v-spacer> |
f4df757fe
|
245 246 247 |
</v-card-actions> </v-flex> </v-layout> |
68d742034
|
248 249 250 251 252 253 254 255 256 257 258 259 260 |
</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
|
261 262 263 |
<div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> |
68d742034
|
264 |
</v-container> |
55f72b7d7
|
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
</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
|
280 |
editLoading: false, |
55f72b7d7
|
281 282 |
date: null, search: "", |
68d742034
|
283 284 285 |
color: "", show: true, showSearch: false, |
a17c68a03
|
286 |
showLoader: false, |
68d742034
|
287 288 |
profileNotificationDialog: false, editNotificationDialog: false, |
55f72b7d7
|
289 |
valid: true, |
68d742034
|
290 |
addNotificationDialog: false, |
55f72b7d7
|
291 |
pagination: { |
8e8d14254
|
292 |
rowsPerPage: 10, |
55f72b7d7
|
293 294 295 296 297 |
}, imageData: {}, imageName: "", imageUrl: "", imageFile: "", |
8e8d14254
|
298 299 |
titleRules: [(v) => !!v || " Tilte is required"], descriptionRules: [(v) => !!v || " Description is required"], |
55f72b7d7
|
300 301 302 |
headers: [ { text: "No", |
68d742034
|
303 |
align: "", |
55f72b7d7
|
304 |
sortable: false, |
8e8d14254
|
305 |
value: "No", |
55f72b7d7
|
306 307 |
}, { text: "Title", value: "title", sortable: false, align: "center" }, |
a17c68a03
|
308 309 310 311 |
{ text: "Description", value: "description", sortable: false, |
8e8d14254
|
312 |
align: "center", |
a17c68a03
|
313 |
}, |
8e8d14254
|
314 |
{ text: "Action", value: "", sortable: false, align: "center" }, |
55f72b7d7
|
315 |
], |
68d742034
|
316 |
notifications: [], |
55f72b7d7
|
317 |
editedIndex: -1, |
a17c68a03
|
318 319 |
addNotification: { title: "", |
8e8d14254
|
320 |
description: "", |
55f72b7d7
|
321 322 |
}, editedItem: { |
a17c68a03
|
323 |
title: "", |
8e8d14254
|
324 325 |
description: "", }, |
55f72b7d7
|
326 |
}), |
8e8d14254
|
327 328 329 330 331 332 333 |
watch: { addNotificationDialog: function (val) { if (!val) { this.addNotification = []; } }, }, |
55f72b7d7
|
334 335 336 337 338 339 |
methods: { pickFile() { this.$refs.image.click(); }, onFilePicked(e) { |
55f72b7d7
|
340 341 342 343 344 345 346 347 348 349 350 351 352 |
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
|
353 354 355 356 357 358 359 |
}); } else { this.imageName = ""; this.imageFile = ""; this.imageUrl = ""; } }, |
a17c68a03
|
360 |
getNotifications() { |
55f72b7d7
|
361 362 363 364 |
this.showLoader = true; var token = this.$store.state.token; http() .get("/getNotificationsList", { |
8e8d14254
|
365 |
headers: { Authorization: "Bearer " + token }, |
55f72b7d7
|
366 |
}) |
8e8d14254
|
367 |
.then((response) => { |
68d742034
|
368 |
this.notifications = response.data.data; |
55f72b7d7
|
369 |
this.showLoader = false; |
55f72b7d7
|
370 |
}) |
8e8d14254
|
371 |
.catch((error) => { |
55f72b7d7
|
372 |
this.showLoader = false; |
a17c68a03
|
373 374 375 376 377 |
if (error.response.status === 401) { this.$router.replace({ path: "/" }); this.$store.dispatch("setToken", null); this.$store.dispatch("Id", null); } |
55f72b7d7
|
378 379 380 |
}); }, editItem(item) { |
68d742034
|
381 |
this.editedIndex = this.notifications.indexOf(item); |
55f72b7d7
|
382 |
this.editedItem = Object.assign({}, item); |
68d742034
|
383 |
this.editNotificationDialog = true; |
55f72b7d7
|
384 385 |
}, profile(item) { |
68d742034
|
386 |
this.editedIndex = this.notifications.indexOf(item); |
55f72b7d7
|
387 |
this.editedItem = Object.assign({}, item); |
68d742034
|
388 |
this.profileNotificationDialog = true; |
55f72b7d7
|
389 390 391 392 |
}, deleteItem(item) { let deleteNotification = { |
8e8d14254
|
393 |
notificationId: item._id, |
55f72b7d7
|
394 395 396 397 398 |
}; http() .delete( "/deleteNotification", confirm("Are you sure you want to delete this?") && { |
8e8d14254
|
399 |
params: deleteNotification, |
55f72b7d7
|
400 401 |
} ) |
8e8d14254
|
402 |
.then((response) => { |
68d742034
|
403 404 405 |
this.snackbar = true; this.text = response.data.message; this.color = "green"; |
a17c68a03
|
406 |
this.getNotifications(); |
55f72b7d7
|
407 |
}) |
8e8d14254
|
408 |
.catch((error) => { |
68d742034
|
409 410 411 |
this.snackbar = true; this.text = error.response.data.message; this.color = "error"; |
55f72b7d7
|
412 413 |
}); }, |
55f72b7d7
|
414 |
close() { |
68d742034
|
415 |
this.editNotificationDialog = false; |
55f72b7d7
|
416 |
}, |
68d742034
|
417 418 |
closeNotificationDialog() { this.profileNotificationDialog = false; |
55f72b7d7
|
419 |
}, |
8e8d14254
|
420 421 422 423 |
closeAddNotificationModel() { this.addNotificationDialog = false; this.addNotification = []; }, |
55f72b7d7
|
424 425 426 427 |
submit() { if (this.$refs.form.validate()) { let imageData = new FormData(); imageData.append("upload", this.imageFile); |
55f72b7d7
|
428 429 |
let create = { title: this.addNotification.title, |
8e8d14254
|
430 |
description: this.addNotification.description, |
55f72b7d7
|
431 |
}; |
5f1d4b444
|
432 |
this.loading = true; |
55f72b7d7
|
433 434 |
http() .post("/createNotification", create) |
8e8d14254
|
435 |
.then((response) => { |
68d742034
|
436 437 438 |
this.snackbar = true; this.text = response.data.message; this.color = "green"; |
55f72b7d7
|
439 |
this.getNotifications(); |
5d5315b0f
|
440 |
this.addNotificationDialog = false; |
55f72b7d7
|
441 |
this.clear(); |
5f1d4b444
|
442 |
this.loading = false; |
55f72b7d7
|
443 |
}) |
8e8d14254
|
444 |
.catch((error) => { |
68d742034
|
445 446 447 |
this.snackbar = true; this.text = error.response.data.message; this.color = "error"; |
5f1d4b444
|
448 |
this.loading = false; |
55f72b7d7
|
449 450 451 |
}); } }, |
55f72b7d7
|
452 453 454 455 |
clear() { this.$refs.form.reset(); }, save() { |
a17c68a03
|
456 457 |
let imageData = new FormData(); imageData.append("upload", this.imageFile); |
55f72b7d7
|
458 |
let editNotification = { |
a17c68a03
|
459 460 |
notificationId: this.editedItem._id, title: this.editedItem.title, |
8e8d14254
|
461 |
description: this.editedItem.description, |
55f72b7d7
|
462 |
}; |
68d742034
|
463 |
this.editLoading = true; |
55f72b7d7
|
464 465 |
http() .put("/updateNotification", editNotification) |
8e8d14254
|
466 |
.then((response) => { |
68d742034
|
467 468 469 |
this.snackbar = true; this.text = response.data.message; this.color = "green"; |
55f72b7d7
|
470 |
this.getNotifications(); |
68d742034
|
471 472 |
this.close(); this.editLoading = false; |
55f72b7d7
|
473 |
}) |
8e8d14254
|
474 |
.catch((error) => { |
68d742034
|
475 476 477 478 |
this.editLoading = false; this.snackbar = true; this.color = "error"; this.text = error.response.data.message; |
55f72b7d7
|
479 |
}); |
68d742034
|
480 481 482 483 484 485 486 487 |
}, displaySearch() { (this.show = false), (this.showSearch = true); }, closeSearch() { this.showSearch = false; this.show = true; this.search = ""; |
8e8d14254
|
488 |
}, |
55f72b7d7
|
489 490 491 |
}, mounted() { this.getNotifications(); |
8e8d14254
|
492 |
}, |
55f72b7d7
|
493 |
}; |
68d742034
|
494 |
</script> |