Blame view
src/pages/NoticeBoard/noticeBoard.vue
20.7 KB
beb598536
|
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 |
<v-container fluid class="body-color"> <!-- ****** Edit Notice Board ****** --> <v-dialog v-model="editNoticeBoardDialog" max-width="500px" scrollable> <v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Edit Notice Board</label> <v-icon size="24" class="right" @click="editNoticeBoardDialog = false">cancel</v-icon> </v-flex> </v-layout> <v-card-text> <v-layout> <v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center"> <img src="/static/icon/user.png" v-if="!editedItem.eventImageUrl && !imageUrl" width="100px" /> <img :src="editedItem.eventImageUrl" height="150" v-else-if="editedItem.eventImageUrl && !imageUrl" width="150px" /> <img v-if="imageUrl" :src="imageUrl" height="150" style="border-radius:50%; width:150px" /> <input type="file" style="display: none" ref="image" accept="image/*" @change="onFilePicked" /> </v-flex> </v-layout> <v-layout wrap> <v-flex xs12> |
f4df757fe
|
43 |
<v-layout> |
68d742034
|
44 45 46 47 48 49 50 51 52 53 54 |
<v-flex xs4 class="pt-4 subheading"> <label class="right">Title:</label> </v-flex> <v-flex xs8 class="ml-3"> <v-text-field v-model="editedItem.title" placeholder="fill your Title" name="name" type="text" required ></v-text-field> |
f4df757fe
|
55 56 |
</v-flex> </v-layout> |
68d742034
|
57 58 59 60 61 |
</v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Description:</label> |
f4df757fe
|
62 |
</v-flex> |
68d742034
|
63 64 65 66 67 68 69 70 |
<v-flex xs7 class="ml-3"> <v-text-field placeholder="fill your Description" v-model="editedItem.description" type="text" name="email" required ></v-text-field> |
f4df757fe
|
71 |
</v-flex> |
68d742034
|
72 73 74 75 76 77 78 |
</v-layout> </v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right hidden-xs-only hidden-sm-only">Uplaod Image:</label> <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Uplaod :</label> |
f4df757fe
|
79 |
</v-flex> |
68d742034
|
80 81 82 83 84 85 86 |
<v-flex xs7 class="ml-3"> <v-text-field label="Select Image" @click="pickFile" v-model="imageName" append-icon="attach_file" ></v-text-field> |
d10c26632
|
87 88 89 90 91 92 93 |
<input type="file" style="display: none" ref="image" accept="image/*" @change="onFilePicked" /> |
f4df757fe
|
94 95 |
</v-flex> </v-layout> |
68d742034
|
96 97 98 99 100 101 102 103 104 105 106 |
</v-flex> <v-flex xs12> <v-card-actions> <v-spacer></v-spacer> <v-btn round dark @click="save" class="add-button">Save</v-btn> </v-card-actions> </v-flex> </v-layout> </v-card-text> </v-card> </v-dialog> |
beb598536
|
107 |
|
68d742034
|
108 |
<!-- ****** VIEW PROFIL NOTICE BOARD ****** --> |
beb598536
|
109 |
|
68d742034
|
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 |
<v-dialog v-model="viewNoticeBoardDialog" max-width="600px" scrollable> <v-card flat class="card-style pa-3" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">View Notice Board</label> <v-icon size="24" class="right" @click="viewNoticeBoardDialog = false">cancel</v-icon> </v-flex> </v-layout> <v-card-text> <v-layout> <v-flex align-center justify-center layout text-xs-center> <img src="/static/icon/user.png" v-if="!editedItem.eventImageUrl" width="80" /> <img :src="editedItem.eventImageUrl" v-else-if="editedItem.eventImageUrl" class="img" width="200" /> </v-flex> </v-layout> <v-container grid-list-md> <v-layout wrap> <v-flex> <v-layout> <v-flex xs5 sm6> <h5 class="right my-1"> <b>Title:</b> </h5> </v-flex> <v-flex sm6 xs8> <h5 class="my-1">{{ editedItem.title }}</h5> |
beb598536
|
141 142 |
</v-flex> </v-layout> |
68d742034
|
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 |
<v-layout> <v-flex xs5 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-flex> </v-layout> </v-container> </v-card-text> </v-card> </v-dialog> <!-- ****** EXISTING Notice Board 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="addNoticeBoardDialog = true" > <v-icon dark>add</v-icon> </v-btn> <v-btn round class="open-dialog-button hidden-sm-only hidden-xs-only" dark @click="addNoticeBoardDialog = true" > <v-icon class="white--text pr-1" size="20">add</v-icon>Add Notice Board </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
|
182 |
<img src="/static/icon/search.png" alt="icon" /> |
68d742034
|
183 184 185 |
</v-avatar> </v-btn> </v-card-title> |
612b79bb4
|
186 |
<v-flex xs8 sm8 md3 lg2 v-if="showSearch"> |
68d742034
|
187 |
<v-layout> |
8e8d14254
|
188 189 190 191 192 193 194 |
<v-text-field autofocus v-model="search" label="Search" prepend-inner-icon="search" color="primary" ></v-text-field> |
68d742034
|
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
<v-icon @click="closeSearch" color="error">close</v-icon> </v-layout> </v-flex> </v-toolbar> <v-data-table :headers="headers" :items="notices" :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"> <v-avatar size="40"> <img :src="props.item.eventImageUrl" v-if="props.item.eventImageUrl" /> <img src="/static/icon/user.png" v-else-if="!props.item.eventImageUrl" /> </v-avatar> </td> <td class="text-xs-center td td-row">{{ props.item.title}}</td> <td class="text-xs-center td td-row"> |
b9759239c
|
216 217 218 219 220 221 222 223 |
<v-btn class="add-button" @click="generatePDF2Canvas(props.item)" :loading="loadingPdf" dark >{{ props.item.fileType }}</v-btn> </td> <td class="text-xs-center td td-row"> |
68d742034
|
224 225 226 227 228 229 230 |
<span> <v-tooltip top> <img slot="activator" style="cursor:pointer; width:25px; height:25px; " class="mr-3" @click="profile(props.item)" |
aa310d61a
|
231 |
src="/static/icon/view.png" |
68d742034
|
232 233 234 235 236 237 238 239 240 |
/> <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
|
241 |
src="/static/icon/edit.png" |
68d742034
|
242 243 244 245 246 247 248 249 |
/> <span>Edit</span> </v-tooltip> <v-tooltip top> <img slot="activator" style="cursor:pointer; width:20px; height:20px; " @click="deleteItem(props.item)" |
aa310d61a
|
250 |
src="/static/icon/delete.png" |
68d742034
|
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
/> <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 Notice Board ****** --> |
8e8d14254
|
266 |
<v-dialog v-model="addNoticeBoardDialog" max-width="600px" v-if="addNoticeBoardDialog"> |
68d742034
|
267 268 269 270 |
<v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Add Notice Board</label> |
8e8d14254
|
271 |
<v-icon size="24" class="right" @click="closeNoticeBoardModel">cancel</v-icon> |
68d742034
|
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
</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-layout> <v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center"> <v-avatar size="80px" v-if="!imageUrl"> <img src="/static/icon/user.png" /> </v-avatar> <input type="file" style="display: none" ref="image" accept="image/*" @change="onFilePicked" /> |
beb598536
|
290 |
|
68d742034
|
291 292 293 294 295 296 297 298 299 300 301 302 303 304 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 |
<v-avatar size="150px" v-if="imageUrl"> <img :src="imageUrl" height="150" /> </v-avatar> </v-flex> </v-layout> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Title:</label> </v-flex> <v-flex xs7 class="ml-3"> <v-text-field v-model="addNoticeBoard.title" placeholder="fill your Title" name="name" type="text" :rules="titleRules" required ></v-text-field> </v-flex> </v-layout> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Description:</label> </v-flex> <v-flex xs7 class="ml-3"> <v-text-field v-model="addNoticeBoard.description" placeholder="fill your Description" name="name" type="text" :rules="descriptionRules" required ></v-text-field> </v-flex> </v-layout> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right hidden-xs-only hidden-sm-only">Uplaod Image:</label> <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Uplaod :</label> </v-flex> <v-flex xs7 class="ml-3"> <v-text-field label="Select Image" @click="pickFile" v-model="imageName" append-icon="attach_file" ></v-text-field> |
b9759239c
|
338 339 340 341 342 343 344 |
<input type="file" style="display:none" ref="image" accept="image/*" @change="onFilePicked" /> |
68d742034
|
345 346 347 |
</v-flex> </v-layout> <v-layout> |
beb598536
|
348 |
<v-flex xs12> |
68d742034
|
349 350 351 352 353 |
<v-card-actions> <v-spacer></v-spacer> <v-btn @click="clear" round dark class="clear-button">clear</v-btn> <v-btn @click="submit" round dark :loading="loading" class="add-button">Add</v-btn> </v-card-actions> |
beb598536
|
354 355 |
</v-flex> </v-layout> |
68d742034
|
356 357 358 |
</v-form> </v-flex> </v-layout> |
beb598536
|
359 |
</v-container> |
68d742034
|
360 361 362 363 364 365 366 367 368 369 |
</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> |
36fc987df
|
370 371 372 |
<div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> |
68d742034
|
373 |
</v-container> |
beb598536
|
374 375 376 377 |
</template> <script> import http from "@/Services/http.js"; |
beb598536
|
378 379 380 381 382 383 384 385 386 |
export default { data: () => ({ snackbar: false, y: "top", x: "right", mode: "", timeout: 3000, text: "", |
68d742034
|
387 388 389 |
color: "", show: true, showSearch: false, |
fc82ac667
|
390 |
showLoader: false, |
beb598536
|
391 392 393 |
loading: false, date: null, search: "", |
68d742034
|
394 395 396 |
addNoticeBoardDialog: false, editNoticeBoardDialog: false, viewNoticeBoardDialog: false, |
beb598536
|
397 |
valid: true, |
beb598536
|
398 399 400 |
addclass: [], addSection: [], gender: ["Male", "Female"], |
beb598536
|
401 |
pagination: { |
8e8d14254
|
402 |
rowsPerPage: 10, |
beb598536
|
403 |
}, |
beb598536
|
404 405 406 |
imageName: "", imageUrl: "", imageFile: "", |
46db0a3b5
|
407 |
upload: "", |
b9759239c
|
408 |
loadingPdf: false, |
8e8d14254
|
409 410 |
titleRules: [(v) => !!v || " Title is required"], descriptionRules: [(v) => !!v || " Description is required"], |
beb598536
|
411 412 413 |
headers: [ { text: "No", |
68d742034
|
414 |
align: "", |
beb598536
|
415 |
sortable: false, |
8e8d14254
|
416 |
value: "No", |
beb598536
|
417 |
}, |
fc82ac667
|
418 |
{ |
68d742034
|
419 420 |
text: "Event Image", align: "center", |
fc82ac667
|
421 |
sortable: false, |
8e8d14254
|
422 |
value: "eventImageUrl", |
fc82ac667
|
423 |
}, |
68d742034
|
424 |
{ text: "Title", value: "title", sortable: false, align: "center" }, |
b9759239c
|
425 426 427 428 |
{ text: "File", value: "eventImageUrl", sortable: false, |
8e8d14254
|
429 |
align: "center", |
b9759239c
|
430 |
}, |
8e8d14254
|
431 |
{ text: "Action", value: "", sortable: false, align: "center" }, |
beb598536
|
432 |
], |
68d742034
|
433 |
notices: [], |
beb598536
|
434 |
editedIndex: -1, |
46db0a3b5
|
435 |
addNoticeBoard: {}, |
beb598536
|
436 437 |
editedItem: { title: "", |
8e8d14254
|
438 439 |
description: "", }, |
beb598536
|
440 |
}), |
8e8d14254
|
441 442 443 444 445 446 447 448 449 450 |
watch: { addNoticeBoardDialog: function (val) { if (!val) { this.addNoticeBoard = []; this.imageName = ""; this.imageFile = ""; this.imageUrl = ""; } }, }, |
beb598536
|
451 452 453 454 |
methods: { pickFile() { this.$refs.image.click(); }, |
46db0a3b5
|
455 |
getNoticeDataList() { |
36fc987df
|
456 |
this.showLoader = true; |
beb598536
|
457 458 459 |
var token = this.$store.state.token; http() .get("/getEventsList", { |
8e8d14254
|
460 |
headers: { Authorization: "Bearer " + token }, |
beb598536
|
461 |
}) |
8e8d14254
|
462 |
.then((response) => { |
68d742034
|
463 |
this.notices = response.data.data; |
36fc987df
|
464 |
this.showLoader = false; |
beb598536
|
465 |
}) |
8e8d14254
|
466 |
.catch((error) => { |
36fc987df
|
467 |
this.showLoader = false; |
a17c68a03
|
468 469 470 471 472 |
if (error.response.status === 401) { this.$router.replace({ path: "/" }); this.$store.dispatch("setToken", null); this.$store.dispatch("Id", null); } |
beb598536
|
473 474 475 |
}); }, editItem(item) { |
68d742034
|
476 |
this.editedIndex = this.notices.indexOf(item); |
beb598536
|
477 |
this.editedItem = Object.assign({}, item); |
68d742034
|
478 |
this.editNoticeBoardDialog = true; |
beb598536
|
479 480 |
}, profile(item) { |
68d742034
|
481 |
this.editedIndex = this.notices.indexOf(item); |
beb598536
|
482 |
this.editedItem = Object.assign({}, item); |
68d742034
|
483 |
this.viewNoticeBoardDialog = true; |
beb598536
|
484 485 486 |
}, deleteItem(item) { let deleteEvent = { |
8e8d14254
|
487 |
eventId: item._id, |
beb598536
|
488 489 490 491 492 |
}; http() .delete( "/deleteEvent", confirm("Are you sure you want to delete this?") && { |
8e8d14254
|
493 |
params: deleteEvent, |
beb598536
|
494 495 |
} ) |
8e8d14254
|
496 |
.then((response) => { |
beb598536
|
497 498 |
// console.log("deleteUers",deleteEvent) if ((this.snackbar = true)) { |
46db0a3b5
|
499 |
this.text = "Successfully delete Existing Notice Data"; |
beb598536
|
500 |
} |
b9759239c
|
501 502 |
this.snackbar = true; this.color = "green"; |
2d0fc1144
|
503 |
this.getNoticeDataList(); |
beb598536
|
504 |
}) |
8e8d14254
|
505 |
.catch((error) => { |
beb598536
|
506 |
// console.log(error); |
b9759239c
|
507 508 509 |
this.snackbar = true; this.text = error.response.data.message; this.color = "error"; |
beb598536
|
510 511 |
}); }, |
beb598536
|
512 |
close() { |
68d742034
|
513 |
this.editNoticeBoardDialog = false; |
beb598536
|
514 |
}, |
8e8d14254
|
515 516 517 518 519 520 521 |
closeNoticeBoardModel() { this.addNoticeBoardDialog = false; this.addNoticeBoard = []; this.imageName = ""; this.imageFile = ""; this.imageUrl = ""; }, |
beb598536
|
522 |
submit() { |
b9759239c
|
523 524 525 526 527 528 529 |
var signatures = { JVBERi0: "other", iVBORw0KGgo: "image", UEsDBBQ: "other", "/": "image", AAABAA: "image", IywiV2hhdC: "other", |
8e8d14254
|
530 |
bmFtZSxl: "other", |
b9759239c
|
531 532 533 534 535 536 537 538 |
}; function detectMimeType(b64) { for (var s in signatures) { if (b64.indexOf(s) === 0) { return signatures[s]; } } } |
beb598536
|
539 |
if (this.$refs.form.validate()) { |
2d0fc1144
|
540 541 542 543 |
if (this.imageUrl) { var str = this.imageUrl; const [baseUrl, imageUrl] = str.split(/,/); this.addNoticeBoard.upload = imageUrl; |
b9759239c
|
544 |
this.addNoticeBoard.fileType = detectMimeType(imageUrl); |
8e8d14254
|
545 |
this.addNoticeBoard.fileName = this.imageName; |
2d0fc1144
|
546 |
} |
beb598536
|
547 |
http() |
46db0a3b5
|
548 |
.post("/createEvent", this.addNoticeBoard) |
8e8d14254
|
549 |
.then((response) => { |
0551a0f15
|
550 551 |
this.imageUrl = ""; this.snackbar = true; |
68d742034
|
552 553 |
this.color = "green"; this.text = response.data.message; |
2d0fc1144
|
554 |
this.getNoticeDataList(); |
68d742034
|
555 |
this.addNoticeBoardDialog = false; |
beb598536
|
556 557 |
this.clear(); }) |
8e8d14254
|
558 |
.catch((error) => { |
0551a0f15
|
559 560 |
this.snackbar = true; this.text = error.response.data.message; |
68d742034
|
561 |
this.color = "error"; |
beb598536
|
562 563 564 |
}); } }, |
b9759239c
|
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
onFilePicked(e) { const files = e.target.files; this.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); }); } else { this.imageName = ""; this.imageFile = ""; this.imageUrl = ""; } }, |
beb598536
|
586 587 |
clear() { this.$refs.form.reset(); |
0551a0f15
|
588 |
this.imageUrl = ""; |
beb598536
|
589 590 |
}, save() { |
2d0fc1144
|
591 |
let editNoticeBoard = { |
beb598536
|
592 593 |
eventId: this.editedItem._id, title: this.editedItem.title, |
ef672f260
|
594 |
description: this.editedItem.description, |
8e8d14254
|
595 |
fileName: this.imageName, |
beb598536
|
596 |
}; |
b9759239c
|
597 598 599 600 601 602 |
var signatures = { JVBERi0: "other", iVBORw0KGgo: "image", UEsDBBQ: "other", "/": "image", AAABAA: "image", |
8e8d14254
|
603 |
IywiV2hhdC: "other", |
b9759239c
|
604 605 606 607 608 609 610 611 |
}; function detectMimeType(b64) { for (var s in signatures) { if (b64.indexOf(s) === 0) { return signatures[s]; } } } |
2d0fc1144
|
612 613 614 615 |
if (this.imageUrl) { var str = this.imageUrl; const [baseUrl, imageUrl] = str.split(/,/); editNoticeBoard.upload = imageUrl; |
b9759239c
|
616 |
editNoticeBoard.fileType = detectMimeType(imageUrl); |
2d0fc1144
|
617 |
} |
beb598536
|
618 |
http() |
2d0fc1144
|
619 |
.put("/updateEvent", editNoticeBoard) |
8e8d14254
|
620 |
.then((response) => { |
beb598536
|
621 |
if ((this.snackbar = true)) { |
46db0a3b5
|
622 |
this.text = "Successfully Edit Existing Notice Data"; |
beb598536
|
623 |
} |
d5fcb1cd1
|
624 625 |
this.color = "green"; this.snackbar = true; |
2d0fc1144
|
626 |
this.getNoticeDataList(); |
a17c68a03
|
627 |
this.close(); |
beb598536
|
628 |
}) |
8e8d14254
|
629 |
.catch((error) => { |
beb598536
|
630 |
// console.log(error); |
d5fcb1cd1
|
631 632 633 |
this.snackbar = true; this.text = error.response.data.message; this.color = "red"; |
beb598536
|
634 |
}); |
68d742034
|
635 636 637 638 639 640 641 642 |
}, displaySearch() { (this.show = false), (this.showSearch = true); }, closeSearch() { this.showSearch = false; this.show = true; this.search = ""; |
b9759239c
|
643 644 645 646 647 648 649 650 651 652 653 654 |
}, async generatePDF2Canvas(item) { var dataType = ""; var type = ""; if (item.fileType == "image") { dataType = "file.jpg"; } else if (item.fileType == "other") { dataType = "file.pdf"; type = "application/pdf"; } var FileSaver = require("file-saver"); FileSaver.saveAs(item.eventImageUrl, "image.jpg"); |
8e8d14254
|
655 |
}, |
beb598536
|
656 657 |
}, mounted() { |
46db0a3b5
|
658 |
this.getNoticeDataList(); |
8e8d14254
|
659 |
}, |
beb598536
|
660 |
}; |
68d742034
|
661 |
</script> |