Blame view
src/pages/News/news.vue
20.8 KB
6566e8f29
|
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 |
<v-container fluid class="body-color"> <!-- ****** EDIT NEWS ****** --> <v-dialog v-model="editNewsDialog" max-width="600px"> <v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Edit News</label> <v-icon size="24" class="right" @click="editNewsDialog = false">cancel</v-icon> </v-flex> </v-layout> <v-card-text> <v-layout row> <v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center my-4"> <input type="file" style="display: none" ref="image" accept="image/*" multiple @change="onFilePicked" /> <v-layout justify-center> |
f4df757fe
|
24 25 |
<v-flex xs12 |
68d742034
|
26 27 28 29 30 31 |
sm12 md3 v-for="Image in editedItem.newsImageUrl" :key="Image._id" v-if="editedItem.newsImageUrl" class="profile-image-wrapper" |
f4df757fe
|
32 |
> |
68d742034
|
33 34 35 36 37 38 |
<img :src="Image.imageUrl" height="100" width="100" alt="News" class="pa-2 imgNews" |
f4df757fe
|
39 |
/> |
68d742034
|
40 41 42 43 44 |
<v-icon class="red edit-profile-icon" dark @click="deleteImage(Image._id,editedItem._id)" >close</v-icon> |
f4df757fe
|
45 |
</v-flex> |
68d742034
|
46 47 48 49 50 51 52 53 54 55 |
<v-flex v-for="(file, index) in files" :key="index"> <img :src="file" height="100" width="100" class="pa-2" /> </v-flex> <img src="/static/icon/user.png" v-if="files == '' && editedItem.newsImageUrl == ''" height="100" width="100" alt="News" /> |
f4df757fe
|
56 |
</v-layout> |
68d742034
|
57 58 59 60 61 62 63 64 |
</v-flex> </v-layout> <!-- </v-layout> --> <v-layout wrap> <v-flex xs12 sm12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Title:</label> |
f4df757fe
|
65 |
</v-flex> |
68d742034
|
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
<v-flex sm6 xs8 class="ml-3"> <v-text-field v-model="editedItem.title" placeholder="fill your Title" name="name" type="text" required ></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> |
f4df757fe
|
81 |
</v-flex> |
68d742034
|
82 83 84 85 86 87 88 89 |
<v-flex sm6 xs8 class="ml-3"> <v-text-field placeholder="fill your Description" v-model="editedItem.description" type="text" name="email" required ></v-text-field> |
f4df757fe
|
90 91 |
</v-flex> </v-layout> |
68d742034
|
92 93 |
</v-flex> <v-flex xs12> |
f4df757fe
|
94 |
<v-layout> |
68d742034
|
95 96 97 98 99 100 101 102 103 104 105 106 |
<v-flex xs4 class="pt-4 subheading"> <label class="right hidden-xs-only hidden-sm-only">Add New Images:</label> <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Uplaod :</label> </v-flex> <v-flex sm6 xs8 class="ml-3"> <v-text-field label="Select Image" @click="pickFile" v-model="imageName" append-icon="attach_file" multiple ></v-text-field> |
f4df757fe
|
107 108 |
</v-flex> </v-layout> |
68d742034
|
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 |
</v-flex> </v-layout> <v-layout> <v-flex xs12 sm9 offset-sm2 class="hidden-xs-only hidden-sm-only"> <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-flex xs12 class="hidden-lg-only hidden-md-only hidden-xl-only"> <v-card-actions> <v-spacer></v-spacer> <v-btn round dark @click="save" class="add-button">Save</v-btn> <v-spacer></v-spacer> </v-card-actions> </v-flex> </v-layout> </v-card-text> </v-card> </v-dialog> <!-- ****** PROFILE NEWS ****** --> <v-dialog v-model="dialog1" max-width="500px"> <v-card flat class="card-style pa-3" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">View News</label> <v-icon size="24" class="right" @click="dialog1 = false">cancel</v-icon> </v-flex> </v-layout> <v-card-text> <v-flex align-center justify-center layout text-xs-center> <span v-for="(image,i) in editedItem.newsImageUrl" :key="i" class="pa-2"> <img :src="image.imageUrl" alt="News" width="100" height="100" class="imgNews" /> </span> <img src="/static/icon/user.png" v-if="editedItem.newsImageUrl == ''" height="80" width="80" alt="News" /> </v-flex> <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> |
6566e8f29
|
159 |
</v-flex> |
68d742034
|
160 161 |
<v-flex sm6 xs8> <h5 class="my-1">{{ editedItem.title }}</h5> |
5b841b043
|
162 |
</v-flex> |
68d742034
|
163 164 165 166 167 168 |
</v-layout> <v-layout> <v-flex xs5 sm6> <h5 class="right my-1"> <b>Description:</b> </h5> |
5b841b043
|
169 |
</v-flex> |
68d742034
|
170 171 |
<v-flex sm6 xs8> <h5 class="my-1">{{ editedItem.description }}</h5> |
5b841b043
|
172 |
</v-flex> |
68d742034
|
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
</v-layout> </v-flex> </v-layout> </v-container> </v-card-text> </v-card> </v-dialog> <!-- ****** EXISTING-USERS NEWS 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="addNewsDialog = true" > <v-icon dark>add</v-icon> </v-btn> <v-btn round class="open-dialog-button hidden-sm-only hidden-xs-only" dark @click="addNewsDialog = true" > <v-icon class="white--text pr-1" size="20">add</v-icon>Add News </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
|
203 |
<img src="/static/icon/search.png" alt="icon" /> |
68d742034
|
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
</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="desserts" :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"> <span v-for="(image,_id) in props.item.newsImageUrl" class="pa-2"> <img :src="image.imageUrl" alt="newsImage" width="40" height="40" /> </span> <img src="/static/icon/user.png" v-if="props.item.newsImageUrl == ''" width="40" alt="News" /> </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
|
245 |
src="/static/icon/view.png" |
68d742034
|
246 247 248 249 250 251 252 253 254 |
/> <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
|
255 |
src="/static/icon/edit.png" |
68d742034
|
256 257 258 259 260 261 262 263 |
/> <span>Edit</span> </v-tooltip> <v-tooltip top> <img slot="activator" style="cursor:pointer; width:20px; height:20px; " @click="deleteItem(props.item)" |
aa310d61a
|
264 |
src="/static/icon/delete.png" |
68d742034
|
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
/> <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 NEWS ****** --> <v-dialog v-model="addNewsDialog" max-width="600px"> <v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Add News</label> <v-icon size="24" class="right" @click="addNewsDialog = false">cancel</v-icon> |
6566e8f29
|
286 |
</v-flex> |
68d742034
|
287 288 289 290 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 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
</v-layout> <v-form ref="form" v-model="valid" lazy-validation> <v-container fluid> <v-layout> <v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center my-4"> <input type="file" style="display: none" ref="image" accept="image/*" multiple @change="onFilePicked" /> <v-layout justify-center> <v-flex v-for="(file,index) in files" :key="index" v-if="files"> <img :src="file" height="100" width="100;" class="imgNews" /> </v-flex> </v-layout> <img src="/static/icon/user.png" v-if="files ==''" height="80" width="80" /> </v-flex> </v-layout> <v-flex xs12> <v-layout> <v-flex xs4 sm4 class="pt-4 subheading"> <label class="right">Title:</label> </v-flex> <v-flex sm6 xs8 class="ml-3"> <v-text-field v-model="addNews.title" placeholder="fill your Title" name="name" type="text" :rules="titleRules" required ></v-text-field> </v-flex> </v-layout> </v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Description:</label> </v-flex> <v-flex sm6 xs8 class="ml-3"> <v-text-field placeholder="fill your Description" :rules="descriptionRules" v-model="addNews.description" type="text" name="email" required ></v-text-field> </v-flex> </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> </v-flex> <v-flex xs8 sm6 class="ml-3"> <v-text-field label="Select Image" @click="pickFile" v-model="imageName" append-icon="attach_file" multiple ></v-text-field> </v-flex> </v-layout> </v-flex> <v-layout> <v-flex xs11> <v-layout> <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> </v-layout> </v-flex> </v-layout> </v-container> </v-form> </v-card> </v-dialog> |
4b169b574
|
372 373 374 |
<div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> |
68d742034
|
375 |
</v-container> |
6566e8f29
|
376 377 378 379 |
</template> <script> import http from "@/Services/http.js"; |
6566e8f29
|
380 381 382 383 384 385 386 |
export default { data: () => ({ snackbar: false, y: "top", x: "right", mode: "", |
68d742034
|
387 388 |
timeout: 5000, color: "", |
6566e8f29
|
389 390 391 392 |
text: "", loading: false, date: null, search: "", |
68d742034
|
393 394 |
show: true, showSearch: false, |
5b841b043
|
395 |
showLoader: false, |
68d742034
|
396 397 |
editNewsDialog: false, addNewsDialog: false, |
6566e8f29
|
398 399 |
dialog1: false, valid: true, |
6566e8f29
|
400 401 |
addclass: [], addSection: [], |
6566e8f29
|
402 |
pagination: { |
68d742034
|
403 |
rowsPerPage: 10 |
6566e8f29
|
404 |
}, |
6566e8f29
|
405 406 407 |
imageName: "", imageUrl: "", imageFile: "", |
2b0e316ee
|
408 |
image: [], |
5b841b043
|
409 410 |
upload: "", files: [], |
6566e8f29
|
411 412 413 414 |
titleRules: [v => !!v || " Tilte is required"], descriptionRules: [v => !!v || " Description is required"], headers: [ { |
5f1d4b444
|
415 |
align: "justify-center", |
506be6fd7
|
416 |
text: "No", |
6566e8f29
|
417 418 419 |
sortable: false, value: "No" }, |
5b841b043
|
420 |
{ text: "Image", vaue: "image", sortable: false, align: "center" }, |
6566e8f29
|
421 |
{ text: "Title", value: "title", sortable: false, align: "center" }, |
5b841b043
|
422 423 424 425 426 427 |
{ text: "Description", value: "description", sortable: false, align: "center" }, |
6566e8f29
|
428 429 |
{ text: "Action", value: "", sortable: false, align: "center" } ], |
8bb178441
|
430 |
desserts: [], |
6566e8f29
|
431 432 433 |
editedIndex: -1, addNews: { title: "", |
5b841b043
|
434 |
description: "" |
6566e8f29
|
435 436 437 |
}, editedItem: { title: "", |
5b841b043
|
438 |
description: "" |
6566e8f29
|
439 440 441 442 |
}, defaultItem: { title: "", description: "" |
aa8fc5033
|
443 |
} |
6566e8f29
|
444 |
}), |
6566e8f29
|
445 446 447 448 449 450 451 452 453 454 455 456 457 |
methods: { getSections(_id) { var token = this.$store.state.token; http() .get( "/getSectionsList", { params: { classId: _id } }, { headers: { Authorization: "Bearer " + token } } ) .then(response => { this.addSection = response.data.data; |
6566e8f29
|
458 459 |
}) .catch(err => { |
5f1d4b444
|
460 |
console.log("err====>", err); |
6566e8f29
|
461 462 463 464 465 |
}); }, pickFile() { this.$refs.image.click(); }, |
6566e8f29
|
466 467 468 |
onFilePicked(e) { // console.log(e) const files = e.target.files; |
5b841b043
|
469 |
/** fetch Image Name **/ |
6566e8f29
|
470 471 472 473 |
if (files[0] !== undefined) { this.imageName = files[0].name; if (this.imageName.lastIndexOf(".") <= 0) { return; |
5b841b043
|
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
} this.files = []; // console.log("files", this.files); /** Select many image and showing many image add to news card **/ const test = Array.from(files).forEach((file, idx) => { const fr = new FileReader(); const getResult = new Promise(resolve => { fr.onload = e => { this.files.push( // id: idx, e.target.result ); }; }); fr.readAsDataURL(file); return getResult.then(file => { return file; }); |
6566e8f29
|
492 |
}); |
5b841b043
|
493 494 495 496 497 |
const fr = new FileReader(); fr.readAsDataURL(files[0]); fr.addEventListener("load", () => { this.imageFile = files; // this is an image file that can be sent to server... // console.log("uploadImage=======>", this.imageFile ); |
2b0e316ee
|
498 |
}); |
6566e8f29
|
499 500 501 502 503 504 505 |
} else { this.imageName = ""; this.imageFile = ""; this.imageUrl = ""; } }, getNewsList() { |
4b169b574
|
506 |
this.showLoader = true; |
6566e8f29
|
507 508 509 510 511 512 513 |
var token = this.$store.state.token; http() .get("/getNewsList", { headers: { Authorization: "Bearer " + token } }) .then(response => { this.desserts = response.data.data; |
4b169b574
|
514 |
this.showLoader = false; |
6566e8f29
|
515 |
}) |
00e4bc4e1
|
516 |
.catch(error => { |
4b169b574
|
517 |
this.showLoader = false; |
aa8fc5033
|
518 |
if (error.response.status === 401) { |
a17c68a03
|
519 520 521 522 |
this.$router.replace({ path: "/" }); this.$store.dispatch("setToken", null); this.$store.dispatch("Id", null); } |
6566e8f29
|
523 524 525 |
}); }, editItem(item) { |
8e6d1a7d7
|
526 |
this.files = []; |
6566e8f29
|
527 528 |
this.editedIndex = this.desserts.indexOf(item); this.editedItem = Object.assign({}, item); |
68d742034
|
529 |
this.editNewsDialog = true; |
6566e8f29
|
530 531 532 533 534 535 |
}, profile(item) { this.editedIndex = this.desserts.indexOf(item); this.editedItem = Object.assign({}, item); this.dialog1 = true; }, |
6566e8f29
|
536 537 538 539 540 541 542 543 544 545 546 547 |
deleteItem(item) { let deleteNews = { newsId: item._id }; http() .delete( "/deleteNews", confirm("Are you sure you want to delete this?") && { params: deleteNews } ) .then(response => { |
68d742034
|
548 549 550 |
this.snackbar = true; this.text = response.data.message; this.color = "green"; |
6566e8f29
|
551 552 553 |
this.getNewsList(); }) .catch(error => { |
68d742034
|
554 555 556 |
this.snackbar = true; this.color = "error"; this.text = error.response.data.message; |
6566e8f29
|
557 558 |
}); }, |
5b841b043
|
559 |
deleteImage(imageId, newsId) { |
5b841b043
|
560 |
let deleteImages = { |
79006bdcb
|
561 562 563 564 565 566 |
newsId: newsId, imageId: imageId }; http() .put("/deleteImages", deleteImages) .then(response => { |
68d742034
|
567 568 569 |
this.snackbar = true; this.text = response.data.message; this.color = "green"; |
8e6d1a7d7
|
570 |
this.close(); |
79006bdcb
|
571 572 |
}) .catch(error => { |
68d742034
|
573 574 575 |
this.snackbar = true; this.color = "error"; this.text = error.response.data.message; |
79006bdcb
|
576 577 |
}); }, |
6566e8f29
|
578 579 |
close() { this.dialog = false; |
6566e8f29
|
580 581 582 583 |
}, close1() { this.dialog1 = false; }, |
6566e8f29
|
584 585 |
submit() { if (this.$refs.form.validate()) { |
5b841b043
|
586 587 588 589 590 591 592 593 594 595 596 597 598 |
let newsData = { title: this.addNews.title, description: this.addNews.description }; if (this.files) { var ary = []; var imageData = []; ary = this.files; for (let i = 0; i < ary.length; i++) { const [baseUrl, imageUrl] = ary[i].split(/,/); imageData.push(imageUrl); newsData.upload = imageData; } |
2b0e316ee
|
599 |
} |
9a1e18aba
|
600 |
this.loading = true; |
6566e8f29
|
601 |
http() |
2b0e316ee
|
602 |
.post("/createNews", newsData) |
6566e8f29
|
603 |
.then(response => { |
0551a0f15
|
604 605 |
this.files = []; this.snackbar = true; |
68d742034
|
606 |
this.text = response.data.message; |
6566e8f29
|
607 |
this.getNewsList(); |
68d742034
|
608 609 |
this.color = "green"; this.addNewsDialog = false; |
506be6fd7
|
610 |
this.loading = false; |
6566e8f29
|
611 612 613 |
this.clear(); }) .catch(error => { |
0551a0f15
|
614 615 |
this.snackbar = true; this.text = error.response.data.message; |
68d742034
|
616 |
this.color = "error"; |
6566e8f29
|
617 618 619 |
}); } }, |
6566e8f29
|
620 621 |
clear() { this.$refs.form.reset(); |
0551a0f15
|
622 |
this.files = []; |
6566e8f29
|
623 624 |
}, save() { |
5b841b043
|
625 626 627 |
let editNews = { title: this.editedItem.title, description: this.editedItem.description, |
a17c68a03
|
628 |
newsId: this.editedItem._id |
5b841b043
|
629 630 |
}; if (this.files) { |
a17c68a03
|
631 632 633 634 635 636 637 |
var ary = []; var imageData = []; ary = this.files; for (let i = 0; i < ary.length; i++) { const [baseUrl, imageUrl] = ary[i].split(/,/); imageData.push(imageUrl); editNews.upload = imageData; |
5b841b043
|
638 |
} |
a17c68a03
|
639 |
} |
6566e8f29
|
640 641 642 |
http() .put("/updateNews", editNews) .then(response => { |
68d742034
|
643 644 645 |
this.snackbar = true; this.text = response.data.message; this.color = "green"; |
6566e8f29
|
646 |
this.getNewsList(); |
79006bdcb
|
647 |
this.close(); |
6566e8f29
|
648 649 |
}) .catch(error => { |
68d742034
|
650 651 652 |
this.snackbar = true; this.color = "error"; this.text = error.response.data.message; |
6566e8f29
|
653 |
}); |
68d742034
|
654 655 656 657 658 659 660 661 |
}, displaySearch() { (this.show = false), (this.showSearch = true); }, closeSearch() { this.showSearch = false; this.show = true; this.search = ""; |
aa8fc5033
|
662 |
} |
6566e8f29
|
663 664 665 |
}, mounted() { this.getNewsList(); |
5b841b043
|
666 |
this.editItem; |
6566e8f29
|
667 668 |
} }; |
68d742034
|
669 |
</script> |