Blame view
src/pages/Notification/notification.vue
14.9 KB
55f72b7d7
|
1 |
<template> |
68d742034
|
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
|
54 |
|
68d742034
|
55 |
<!-- ****** PROFILE VIEW NOTIFICATION DEATILS ****** --> |
55f72b7d7
|
56 |
|
68d742034
|
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 |
<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"> |
aa310d61a
|
118 |
<img src="/static/icon/search.png" alt="icon" /> |
68d742034
|
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 |
</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)" |
aa310d61a
|
148 |
src="/static/icon/view.png" |
68d742034
|
149 150 151 152 153 154 155 156 157 |
/> <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
|
158 |
src="/static/icon/edit.png" |
68d742034
|
159 160 161 162 163 164 165 166 167 |
/> <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
|
168 |
src="/static/icon/delete.png" |
68d742034
|
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 |
/> <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
|
197 198 199 |
<v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Title:</label> |
a17c68a03
|
200 |
</v-flex> |
68d742034
|
201 |
<v-flex xs8 sm8 class="ml-3"> |
f4df757fe
|
202 |
<v-text-field |
68d742034
|
203 |
v-model="addNotification.title" |
f4df757fe
|
204 |
placeholder="fill your Title" |
f4df757fe
|
205 |
type="text" |
68d742034
|
206 207 |
:rules="titleRules" required |
f4df757fe
|
208 |
></v-text-field> |
a17c68a03
|
209 |
</v-flex> |
f4df757fe
|
210 211 |
</v-layout> </v-flex> |
68d742034
|
212 |
<v-flex xs12> |
f4df757fe
|
213 214 215 216 |
<v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Description:</label> </v-flex> |
68d742034
|
217 |
<v-flex xs8 sm8 class="ml-3"> |
f4df757fe
|
218 219 |
<v-text-field placeholder="fill your Description" |
68d742034
|
220 221 |
:rules="descriptionRules" v-model="addNotification.description" |
f4df757fe
|
222 |
type="text" |
68d742034
|
223 |
required |
f4df757fe
|
224 225 226 227 228 |
></v-text-field> </v-flex> </v-layout> </v-flex> <v-layout> |
68d742034
|
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
|
238 |
<v-spacer></v-spacer> |
f4df757fe
|
239 240 241 |
</v-card-actions> </v-flex> </v-layout> |
68d742034
|
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
|
255 256 257 |
<div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> |
68d742034
|
258 |
</v-container> |
55f72b7d7
|
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
|
274 |
editLoading: false, |
55f72b7d7
|
275 276 |
date: null, search: "", |
68d742034
|
277 278 279 |
color: "", show: true, showSearch: false, |
a17c68a03
|
280 |
showLoader: false, |
68d742034
|
281 282 |
profileNotificationDialog: false, editNotificationDialog: false, |
55f72b7d7
|
283 |
valid: true, |
68d742034
|
284 |
addNotificationDialog: false, |
55f72b7d7
|
285 |
pagination: { |
68d742034
|
286 |
rowsPerPage: 10 |
55f72b7d7
|
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
|
297 |
align: "", |
55f72b7d7
|
298 299 300 301 |
sortable: false, value: "No" }, { text: "Title", value: "title", sortable: false, align: "center" }, |
a17c68a03
|
302 303 304 305 306 307 |
{ text: "Description", value: "description", sortable: false, align: "center" }, |
55f72b7d7
|
308 309 |
{ text: "Action", value: "", sortable: false, align: "center" } ], |
68d742034
|
310 |
notifications: [], |
55f72b7d7
|
311 |
editedIndex: -1, |
a17c68a03
|
312 313 314 |
addNotification: { title: "", description: "" |
55f72b7d7
|
315 316 |
}, editedItem: { |
a17c68a03
|
317 318 |
title: "", description: "" |
a17c68a03
|
319 |
} |
55f72b7d7
|
320 321 322 323 324 325 326 |
}), methods: { pickFile() { this.$refs.image.click(); }, onFilePicked(e) { |
55f72b7d7
|
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
|
340 341 342 343 344 345 346 |
}); } else { this.imageName = ""; this.imageFile = ""; this.imageUrl = ""; } }, |
a17c68a03
|
347 |
getNotifications() { |
55f72b7d7
|
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
|
355 |
this.notifications = response.data.data; |
55f72b7d7
|
356 |
this.showLoader = false; |
55f72b7d7
|
357 |
}) |
00e4bc4e1
|
358 |
.catch(error => { |
55f72b7d7
|
359 |
this.showLoader = false; |
a17c68a03
|
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
|
365 366 367 |
}); }, editItem(item) { |
68d742034
|
368 |
this.editedIndex = this.notifications.indexOf(item); |
55f72b7d7
|
369 |
this.editedItem = Object.assign({}, item); |
68d742034
|
370 |
this.editNotificationDialog = true; |
55f72b7d7
|
371 372 |
}, profile(item) { |
68d742034
|
373 |
this.editedIndex = this.notifications.indexOf(item); |
55f72b7d7
|
374 |
this.editedItem = Object.assign({}, item); |
68d742034
|
375 |
this.profileNotificationDialog = true; |
55f72b7d7
|
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
|
390 391 392 |
this.snackbar = true; this.text = response.data.message; this.color = "green"; |
a17c68a03
|
393 |
this.getNotifications(); |
55f72b7d7
|
394 395 |
}) .catch(error => { |
68d742034
|
396 397 398 |
this.snackbar = true; this.text = error.response.data.message; this.color = "error"; |
55f72b7d7
|
399 400 |
}); }, |
55f72b7d7
|
401 |
close() { |
68d742034
|
402 |
this.editNotificationDialog = false; |
55f72b7d7
|
403 |
}, |
68d742034
|
404 405 |
closeNotificationDialog() { this.profileNotificationDialog = false; |
55f72b7d7
|
406 407 408 409 410 |
}, submit() { if (this.$refs.form.validate()) { let imageData = new FormData(); imageData.append("upload", this.imageFile); |
55f72b7d7
|
411 412 |
let create = { title: this.addNotification.title, |
a17c68a03
|
413 |
description: this.addNotification.description |
55f72b7d7
|
414 |
}; |
5f1d4b444
|
415 |
this.loading = true; |
55f72b7d7
|
416 417 418 |
http() .post("/createNotification", create) .then(response => { |
68d742034
|
419 420 421 |
this.snackbar = true; this.text = response.data.message; this.color = "green"; |
55f72b7d7
|
422 |
this.getNotifications(); |
5d5315b0f
|
423 |
this.addNotificationDialog = false; |
55f72b7d7
|
424 |
this.clear(); |
5f1d4b444
|
425 |
this.loading = false; |
55f72b7d7
|
426 427 |
}) .catch(error => { |
68d742034
|
428 429 430 |
this.snackbar = true; this.text = error.response.data.message; this.color = "error"; |
5f1d4b444
|
431 |
this.loading = false; |
55f72b7d7
|
432 433 434 |
}); } }, |
55f72b7d7
|
435 436 437 438 |
clear() { this.$refs.form.reset(); }, save() { |
a17c68a03
|
439 440 |
let imageData = new FormData(); imageData.append("upload", this.imageFile); |
55f72b7d7
|
441 |
let editNotification = { |
a17c68a03
|
442 443 444 |
notificationId: this.editedItem._id, title: this.editedItem.title, description: this.editedItem.description |
55f72b7d7
|
445 |
}; |
68d742034
|
446 |
this.editLoading = true; |
55f72b7d7
|
447 448 449 |
http() .put("/updateNotification", editNotification) .then(response => { |
68d742034
|
450 451 452 |
this.snackbar = true; this.text = response.data.message; this.color = "green"; |
55f72b7d7
|
453 |
this.getNotifications(); |
68d742034
|
454 455 |
this.close(); this.editLoading = false; |
55f72b7d7
|
456 457 |
}) .catch(error => { |
68d742034
|
458 459 460 461 |
this.editLoading = false; this.snackbar = true; this.color = "error"; this.text = error.response.data.message; |
55f72b7d7
|
462 |
}); |
68d742034
|
463 464 465 466 467 468 469 470 |
}, displaySearch() { (this.show = false), (this.showSearch = true); }, closeSearch() { this.showSearch = false; this.show = true; this.search = ""; |
55f72b7d7
|
471 472 473 474 |
} }, mounted() { this.getNotifications(); |
55f72b7d7
|
475 476 |
} }; |
68d742034
|
477 |
</script> |