Blame view
src/pages/News/news.vue
22.1 KB
6566e8f29
|
1 2 |
<template> <v-app id="pages-dasboard"> |
687e0b929
|
3 |
<v-tabs grow slider-color="gray"> |
6566e8f29
|
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 |
<v-tab ripple @click="activeTab('existing')" v-bind:class="{ active: isActive }" id="tab" class="subheading" >Existing News</v-tab> <v-tab ripple @click="activeTab('new')" v-bind:class="{ active: newActive }" id="tab1" User class="subheading" >Add News</v-tab> <!-- ****** EDITS ALL NEWS DETAILS ****** --> <v-tab-item> <v-snackbar :timeout="timeout" :top="y === 'top'" :right="x === 'right'" :vertical="mode === 'vertical'" v-model="snackbar" color="success" >{{ text }}</v-snackbar> |
79006bdcb
|
31 |
<v-dialog v-model="dialog" max-width="1000px" scrollable> |
5b841b043
|
32 33 |
<v-card flat> <v-toolbar class="grey lighten-2" flat> |
6566e8f29
|
34 |
<v-spacer></v-spacer> |
5b841b043
|
35 36 37 |
<v-toolbar-title> <h3>Edit News</h3> </v-toolbar-title> |
6566e8f29
|
38 |
<v-spacer></v-spacer> |
5b841b043
|
39 40 |
</v-toolbar> <v-card-text style="height:600px;"> |
6566e8f29
|
41 42 |
<v-form ref="form"> <v-container fluid> |
79006bdcb
|
43 |
<v-layout row> |
5b841b043
|
44 |
<v-flex |
6566e8f29
|
45 |
xs12 |
79006bdcb
|
46 |
class="text-xs-center text-sm-center text-md-center text-lg-center my-4 mr-4" |
6566e8f29
|
47 |
> |
6566e8f29
|
48 |
<input |
79006bdcb
|
49 |
type="file" |
5b841b043
|
50 |
style="display: none" |
6566e8f29
|
51 52 |
ref="image" accept="image/*" |
79006bdcb
|
53 |
multiple |
6566e8f29
|
54 |
@change="onFilePicked" |
5b841b043
|
55 |
/> |
79006bdcb
|
56 |
<v-layout justify-center> |
5b841b043
|
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 |
<v-flex xs3 v-for="Image in editedItem.newsImageUrl" :key="Image._id" v-if="editedItem.newsImageUrl" class="profile-image-wrapper" > <img :src="Image.imageUrl" height="160" width="160" alt="News" class="pa-2" /> <v-icon class="red edit-profile-icon" dark @click="deleteImage(Image._id,editedItem._id)" >close</v-icon> </v-flex> <v-flex v-for="(file, index) in files" :key="index"> <img :src="file" height="160" width="160" class="pa-2" /> </v-flex> </v-layout> <img src="/static/icon/user.png" v-if="editedItem.newsImageUrl ==''" height="160" width="160" alt="News" /> |
6566e8f29
|
88 89 |
</v-flex> </v-layout> |
79006bdcb
|
90 |
<!-- </v-layout> --> |
6566e8f29
|
91 |
<v-layout> |
506be6fd7
|
92 |
<v-flex xs12 sm12> |
6566e8f29
|
93 94 95 96 |
<v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Title:</label> </v-flex> |
506be6fd7
|
97 |
<v-flex xs5 class="ml-3"> |
6566e8f29
|
98 99 100 101 102 103 104 105 106 107 |
<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> |
506be6fd7
|
108 |
<v-flex xs12 sm12> |
6566e8f29
|
109 110 111 112 |
<v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Description:</label> </v-flex> |
506be6fd7
|
113 |
<v-flex xs5 class="ml-3"> |
6566e8f29
|
114 115 116 117 118 119 120 121 122 123 |
<v-text-field placeholder="fill your Description" v-model="editedItem.description" type="text" name="email" required ></v-text-field> </v-flex> </v-layout> </v-flex> |
506be6fd7
|
124 125 126 |
<v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> |
79006bdcb
|
127 |
<label class="right">Add New Images:</label> |
506be6fd7
|
128 129 130 131 132 133 134 135 136 137 |
</v-flex> <v-flex xs5 class="ml-3"> <v-text-field label="Select Image" @click="pickFile" v-model="imageName" append-icon="attach_file" multiple ></v-text-field> </v-flex> |
5b841b043
|
138 139 |
</v-layout> </v-flex> |
6566e8f29
|
140 141 |
</v-layout> <v-layout> |
506be6fd7
|
142 |
<v-flex xs12 sm8 offset-sm2> |
6566e8f29
|
143 144 145 146 147 148 149 150 151 |
<v-card-actions> <v-btn round dark @click.native="close">Cancel</v-btn> <v-spacer></v-spacer> <v-btn round dark @click="save">Save</v-btn> </v-card-actions> </v-flex> </v-layout> </v-container> </v-form> |
5b841b043
|
152 153 |
</v-card-text> </v-card> |
6566e8f29
|
154 155 156 |
</v-dialog> <!-- ****** PROFILE VIEW ALL NEWS DEATILS ****** --> |
506be6fd7
|
157 158 |
<v-dialog v-model="dialog1" max-width="800px"> |
79006bdcb
|
159 160 |
<v-card> <v-toolbar color="grey lighten-2" flat> |
5b841b043
|
161 162 163 164 165 166 167 168 |
<v-spacer></v-spacer> <v-toolbar-title> <h3>News</h3> </v-toolbar-title> <v-spacer></v-spacer> <v-icon @click="close1">close</v-icon> </v-toolbar> <v-flex align-center justify-center layout text-xs-center> |
506be6fd7
|
169 |
<!-- <v-avatar size="50px" style="position:absolute; top:20px;"> |
6566e8f29
|
170 |
<img src="/static/icon/user.png"> |
5b841b043
|
171 |
</v-avatar>--> |
b8837635f
|
172 |
<span v-for="(image,i) in editedItem.newsImageUrl" :key="i" class="mt-4 pa-2"> |
5b841b043
|
173 174 |
<img :src="image.imageUrl" alt="News" width="240" height="180" /> </span> |
6566e8f29
|
175 176 177 178 179 |
</v-flex> <v-card-text> <v-container grid-list-md> <v-layout wrap> <v-flex> |
6566e8f29
|
180 181 |
<v-layout> <v-flex xs5 sm6> |
5b841b043
|
182 183 184 |
<h5 class="right my-1"> <b>Title:</b> </h5> |
6566e8f29
|
185 186 187 188 189 190 191 |
</v-flex> <v-flex sm6 xs8> <h5 class="my-1">{{ editedItem.title }}</h5> </v-flex> </v-layout> <v-layout> <v-flex xs5 sm6> |
5b841b043
|
192 193 194 |
<h5 class="right my-1"> <b>Description:</b> </h5> |
6566e8f29
|
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
</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> <v-snackbar :timeout="timeout" :top="y === 'top'" :right="x === 'right'" :vertical="mode === 'vertical'" v-model="snackbar" color="success" >{{ text }}</v-snackbar> <!-- ****** EXISTING-USERS NEWS TABLE ****** --> <v-data-table :headers="headers" :items="desserts" :pagination.sync="pagination" :search="search" > <template slot="items" slot-scope="props"> |
687e0b929
|
224 |
<td class="text-xs-center">{{ props.index + 1}}</td> |
5b841b043
|
225 226 227 228 229 |
<td id="td" class="text-xs-center"> <span v-for="(image,_id) in props.item.newsImageUrl" class="pa-2"> <img :src="image.imageUrl" alt="newsImage" width="100" height="70" /> </span> </td> |
6566e8f29
|
230 231 232 233 234 235 236 237 238 239 |
<td id="td" class="text-xs-center">{{ props.item.title}}</td> <td id="td" class="text-xs-center">{{ props.item.description}}</td> <td class="text-xs-center"> <span> <img style="cursor:pointer; width:25px; height:18px; " class="mr-5" @click="profile(props.item)" src="/static/icon/eye1.png" |
5b841b043
|
240 |
/> |
6566e8f29
|
241 242 243 244 245 |
<img style="cursor:pointer; width:20px; height:18px; " class="mr-5" @click="editItem(props.item)" src="/static/icon/edit1.png" |
5b841b043
|
246 |
/> |
6566e8f29
|
247 |
<img |
b39d2afd2
|
248 |
style="cursor:pointer;width:20px; height:20px; " |
6566e8f29
|
249 250 251 |
class="mr-5" @click="deleteItem(props.item)" src="/static/icon/delete1.png" |
5b841b043
|
252 |
/> |
6566e8f29
|
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
</span> </td> </template> <v-alert slot="no-results" :value="true" color="error" icon="warning" >Your search for "{{ search }}" found no results.</v-alert> </v-data-table> </v-tab-item> <!-- ****** ADD MULTIPLE NEWS ****** --> <v-tab-item> <v-container> <v-snackbar :timeout="timeout" :top="y === 'top'" :right="x === 'right'" :vertical="mode === 'vertical'" v-model="snackbar" color="success" >{{ text }}</v-snackbar> <v-flex xs12 sm12 class="my-4"> <v-card flat> <v-form ref="form" v-model="valid" lazy-validation> <v-container fluid> <v-layout> <v-flex |
79006bdcb
|
283 |
xs12 |
6566e8f29
|
284 285 |
class="text-xs-center text-sm-center text-md-center text-lg-center my-4 mr-4" > |
6566e8f29
|
286 287 |
<input type="file" |
5b841b043
|
288 |
style="display: none" |
6566e8f29
|
289 290 |
ref="image" accept="image/*" |
2b0e316ee
|
291 |
multiple |
6566e8f29
|
292 |
@change="onFilePicked" |
5b841b043
|
293 |
/> |
79006bdcb
|
294 |
<v-layout justify-center> |
5b841b043
|
295 296 |
<v-flex v-for="(file,index) in files" :key="index" v-if="files"> <img :src="file" height="160" width="160px;" /> |
6566e8f29
|
297 298 |
</v-flex> </v-layout> |
5b841b043
|
299 300 301 302 303 304 |
<img src="/static/icon/user.png" v-if="files ==''" height="140" width="180px;" /> |
6566e8f29
|
305 |
</v-flex> |
5b841b043
|
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 |
</v-layout> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Title:</label> </v-flex> <v-flex xs4 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 xs4 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> |
2b0e316ee
|
339 |
</v-layout> |
5b841b043
|
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
</v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Uplaod Image:</label> </v-flex> <v-flex xs4 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> |
6566e8f29
|
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
<v-layout> <v-flex xs12 sm6 offset-sm3> <v-card-actions> <v-btn @click="clear" round dark>clear</v-btn> <v-spacer></v-spacer> <v-btn @click="submit" round dark :loading="loading">Add</v-btn> </v-card-actions> </v-flex> </v-layout> </v-container> </v-form> </v-card> </v-flex> </v-container> </v-tab-item> </v-tabs> |
4b169b574
|
373 374 375 |
<div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> |
6566e8f29
|
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
</v-app> </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, date: null, search: "", |
5b841b043
|
394 |
showLoader: false, |
6566e8f29
|
395 396 397 398 399 400 401 |
dialog: false, dialog1: false, valid: true, isActive: true, newActive: false, addclass: [], addSection: [], |
6566e8f29
|
402 403 404 405 |
AddUsercredentials: {}, pagination: { rowsPerPage: 15 }, |
6566e8f29
|
406 407 408 |
imageName: "", imageUrl: "", imageFile: "", |
2b0e316ee
|
409 |
image: [], |
5b841b043
|
410 411 |
upload: "", files: [], |
6566e8f29
|
412 413 414 415 |
titleRules: [v => !!v || " Tilte is required"], descriptionRules: [v => !!v || " Description is required"], headers: [ { |
5f1d4b444
|
416 |
align: "justify-center", |
506be6fd7
|
417 |
text: "No", |
6566e8f29
|
418 419 420 |
sortable: false, value: "No" }, |
5b841b043
|
421 |
{ text: "Image", vaue: "image", sortable: false, align: "center" }, |
6566e8f29
|
422 |
{ text: "Title", value: "title", sortable: false, align: "center" }, |
5b841b043
|
423 424 425 426 427 428 |
{ text: "Description", value: "description", sortable: false, align: "center" }, |
6566e8f29
|
429 430 |
{ text: "Action", value: "", sortable: false, align: "center" } ], |
8bb178441
|
431 |
desserts: [], |
6566e8f29
|
432 433 434 |
editedIndex: -1, addNews: { title: "", |
5b841b043
|
435 |
description: "" |
6566e8f29
|
436 437 438 |
}, editedItem: { title: "", |
5b841b043
|
439 |
description: "" |
6566e8f29
|
440 441 442 443 444 |
}, defaultItem: { title: "", description: "" }, |
6566e8f29
|
445 |
}), |
6566e8f29
|
446 447 |
methods: { getSections(_id) { |
5b841b043
|
448 |
console.log("_id", _id); |
6566e8f29
|
449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
var token = this.$store.state.token; http() .get( "/getSectionsList", { params: { classId: _id } }, { headers: { Authorization: "Bearer " + token } } ) .then(response => { this.addSection = response.data.data; // console.log("getSectionsList=====>", this.addSection); }) .catch(err => { |
5f1d4b444
|
463 |
console.log("err====>", err); |
6566e8f29
|
464 465 466 467 468 469 |
// this.$router.replace({ path: '/' }); }); }, pickFile() { this.$refs.image.click(); }, |
6566e8f29
|
470 471 472 |
onFilePicked(e) { // console.log(e) const files = e.target.files; |
5b841b043
|
473 |
/** fetch Image Name **/ |
6566e8f29
|
474 475 476 477 |
if (files[0] !== undefined) { this.imageName = files[0].name; if (this.imageName.lastIndexOf(".") <= 0) { return; |
5b841b043
|
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
} 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
|
496 |
}); |
5b841b043
|
497 498 499 500 501 |
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
|
502 |
}); |
6566e8f29
|
503 504 505 506 507 508 509 |
} else { this.imageName = ""; this.imageFile = ""; this.imageUrl = ""; } }, getNewsList() { |
4b169b574
|
510 |
this.showLoader = true; |
6566e8f29
|
511 512 513 514 515 516 517 |
var token = this.$store.state.token; http() .get("/getNewsList", { headers: { Authorization: "Bearer " + token } }) .then(response => { this.desserts = response.data.data; |
4b169b574
|
518 |
this.showLoader = false; |
6566e8f29
|
519 520 521 522 |
// console.log("getNewsList=====>",this.desserts) }) .catch(err => { // console.log("err====>", err); |
4b169b574
|
523 |
this.showLoader = false; |
a17c68a03
|
524 525 526 527 528 |
if (error.response.status === 401) { this.$router.replace({ path: "/" }); this.$store.dispatch("setToken", null); this.$store.dispatch("Id", null); } |
6566e8f29
|
529 530 531 |
}); }, editItem(item) { |
8e6d1a7d7
|
532 |
this.files = []; |
6566e8f29
|
533 534 535 536 537 538 539 540 541 |
this.editedIndex = this.desserts.indexOf(item); this.editedItem = Object.assign({}, item); this.dialog = true; }, profile(item) { this.editedIndex = this.desserts.indexOf(item); this.editedItem = Object.assign({}, item); this.dialog1 = true; }, |
6566e8f29
|
542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
deleteItem(item) { let deleteNews = { newsId: item._id }; http() .delete( "/deleteNews", confirm("Are you sure you want to delete this?") && { params: deleteNews } ) .then(response => { // console.log("deleteNews",deleteNews) if ((this.snackbar = true)) { |
5f1d4b444
|
556 |
this.text = "Successfully delete Existing News"; |
6566e8f29
|
557 558 559 560 561 562 563 |
} this.getNewsList(); }) .catch(error => { // console.log(error); }); }, |
5b841b043
|
564 565 566 |
deleteImage(imageId, newsId) { console.log(imageId, newsId); let deleteImages = { |
79006bdcb
|
567 568 569 570 571 572 |
newsId: newsId, imageId: imageId }; http() .put("/deleteImages", deleteImages) .then(response => { |
5b841b043
|
573 |
console.log("deleteNews", deleteImages); |
79006bdcb
|
574 575 576 577 |
if ((this.snackbar = true)) { this.text = "Image deleted Successfully"; } this.getNewsList(); |
8e6d1a7d7
|
578 |
this.close(); |
79006bdcb
|
579 580 581 582 583 |
}) .catch(error => { console.log(error); }); }, |
6566e8f29
|
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
activeTab(type) { switch (type) { case "existing": this.newActive = false; this.isActive = true; break; default: this.newActive = true; this.isActive = false; break; } }, close() { this.dialog = false; setTimeout(() => { this.editedItem = Object.assign({}, this.defaultItem); this.editedIndex = -1; }, 300); }, close1() { this.dialog1 = false; }, |
6566e8f29
|
607 |
submit() { |
506be6fd7
|
608 |
this.loading = true; |
6566e8f29
|
609 |
if (this.$refs.form.validate()) { |
5b841b043
|
610 611 612 613 614 615 616 617 618 619 620 621 622 |
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
|
623 |
} |
6566e8f29
|
624 |
http() |
2b0e316ee
|
625 |
.post("/createNews", newsData) |
6566e8f29
|
626 |
.then(response => { |
5b841b043
|
627 |
console.log(newsData); |
6566e8f29
|
628 |
if ((this.snackbar = true)) { |
5f1d4b444
|
629 |
this.text = "New News added successfully"; |
6566e8f29
|
630 631 |
} this.getNewsList(); |
506be6fd7
|
632 |
this.loading = false; |
6566e8f29
|
633 634 635 |
this.clear(); }) .catch(error => { |
6566e8f29
|
636 637 638 639 640 641 |
if ((this.snackbar = true)) { this.text = error.response.data.message; } }); } }, |
6566e8f29
|
642 643 644 645 |
clear() { this.$refs.form.reset(); }, save() { |
5b841b043
|
646 647 648 |
let editNews = { title: this.editedItem.title, description: this.editedItem.description, |
a17c68a03
|
649 |
newsId: this.editedItem._id |
5b841b043
|
650 651 |
}; if (this.files) { |
a17c68a03
|
652 653 654 655 656 657 658 |
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
|
659 |
} |
a17c68a03
|
660 |
} |
6566e8f29
|
661 662 663 664 665 |
http() .put("/updateNews", editNews) .then(response => { // console.log("updateNews",updateNews); if ((this.snackbar = true)) { |
5f1d4b444
|
666 |
this.text = "Successfully Edit Existing News"; |
6566e8f29
|
667 668 |
} this.getNewsList(); |
79006bdcb
|
669 |
this.close(); |
6566e8f29
|
670 671 672 673 |
}) .catch(error => { // console.log(error); }); |
6566e8f29
|
674 |
}, |
6566e8f29
|
675 676 677 |
}, mounted() { this.getNewsList(); |
5b841b043
|
678 |
this.editItem; |
6566e8f29
|
679 |
}, |
a17c68a03
|
680 681 682 683 684 685 686 687 |
created() { this.$root.$on("app:search", search => { this.search = search; }); }, beforeDestroy() { // dont forget to remove the listener this.$root.$off("app:search"); |
6566e8f29
|
688 689 690 691 |
} }; </script> <style scoped> |
6566e8f29
|
692 |
.active { |
687e0b929
|
693 |
background-color: gray; |
6566e8f29
|
694 695 696 697 698 |
color: white !important; } .activebtn { color: black !important; } |
6566e8f29
|
699 |
</style> |