Blame view
src/pages/News/news.vue
22 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 |
<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> |
f4df757fe
|
19 |
<!-- ****** EDIT NEWS ****** --> |
6566e8f29
|
20 21 22 23 24 25 26 27 28 29 |
<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
|
30 |
<v-dialog v-model="dialog" max-width="1000px" scrollable> |
5b841b043
|
31 32 |
<v-card flat> <v-toolbar class="grey lighten-2" flat> |
6566e8f29
|
33 |
<v-spacer></v-spacer> |
5b841b043
|
34 35 36 |
<v-toolbar-title> <h3>Edit News</h3> </v-toolbar-title> |
6566e8f29
|
37 |
<v-spacer></v-spacer> |
5b841b043
|
38 39 |
</v-toolbar> <v-card-text style="height:600px;"> |
f4df757fe
|
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<!-- <v-form ref="form"> <v-container fluid>--> <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> |
5b841b043
|
56 |
<v-flex |
6566e8f29
|
57 |
xs12 |
f4df757fe
|
58 59 60 61 62 63 |
sm12 md3 v-for="Image in editedItem.newsImageUrl" :key="Image._id" v-if="editedItem.newsImageUrl" class="profile-image-wrapper" |
6566e8f29
|
64 |
> |
5b841b043
|
65 |
<img |
f4df757fe
|
66 |
:src="Image.imageUrl" |
5b841b043
|
67 68 69 |
height="160" width="160" alt="News" |
f4df757fe
|
70 |
class="pa-2 imgNews" |
5b841b043
|
71 |
/> |
f4df757fe
|
72 73 74 75 76 77 78 79 |
<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" /> |
6566e8f29
|
80 81 |
</v-flex> </v-layout> |
f4df757fe
|
82 83 84 85 86 87 88 89 90 91 92 93 |
<img src="/static/icon/user.png" v-if="editedItem.newsImageUrl ==''" height="160" width="160" alt="News" /> </v-flex> </v-layout> <!-- </v-layout> --> <v-layout wrap> <v-flex xs12 sm12> |
6566e8f29
|
94 |
<v-layout> |
f4df757fe
|
95 96 |
<v-flex xs4 class="pt-4 subheading"> <label class="right">Title:</label> |
6566e8f29
|
97 |
</v-flex> |
f4df757fe
|
98 99 100 101 102 103 104 105 |
<v-flex sm5 xs8 class="ml-3"> <v-text-field v-model="editedItem.title" placeholder="fill your Title" name="name" type="text" required ></v-text-field> |
6566e8f29
|
106 |
</v-flex> |
f4df757fe
|
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
</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 sm5 xs8 class="ml-3"> <v-text-field placeholder="fill your Description" v-model="editedItem.description" type="text" name="email" required ></v-text-field> |
5b841b043
|
122 |
</v-flex> |
6566e8f29
|
123 |
</v-layout> |
f4df757fe
|
124 125 |
</v-flex> <v-flex xs12> |
6566e8f29
|
126 |
<v-layout> |
f4df757fe
|
127 128 129 130 131 132 133 134 135 136 137 138 |
<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 sm5 xs8 class="ml-3"> <v-text-field label="Select Image" @click="pickFile" v-model="imageName" append-icon="attach_file" multiple ></v-text-field> |
6566e8f29
|
139 140 |
</v-flex> </v-layout> |
f4df757fe
|
141 142 143 144 145 146 147 148 149 150 151 |
</v-flex> </v-layout> <v-layout> <v-flex xs12 sm8 offset-sm2> <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> |
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> |
b8837635f
|
169 |
<span v-for="(image,i) in editedItem.newsImageUrl" :key="i" class="mt-4 pa-2"> |
f4df757fe
|
170 |
<img :src="image.imageUrl" alt="News" width="240" height="180" class="imgNews" /> |
5b841b043
|
171 |
</span> |
6566e8f29
|
172 173 174 175 176 |
</v-flex> <v-card-text> <v-container grid-list-md> <v-layout wrap> <v-flex> |
6566e8f29
|
177 178 |
<v-layout> <v-flex xs5 sm6> |
5b841b043
|
179 180 181 |
<h5 class="right my-1"> <b>Title:</b> </h5> |
6566e8f29
|
182 183 184 185 186 187 188 |
</v-flex> <v-flex sm6 xs8> <h5 class="my-1">{{ editedItem.title }}</h5> </v-flex> </v-layout> <v-layout> <v-flex xs5 sm6> |
5b841b043
|
189 190 191 |
<h5 class="right my-1"> <b>Description:</b> </h5> |
6566e8f29
|
192 193 194 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 |
</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"> |
aa8fc5033
|
221 |
<td class="text-xs-center">{{ props.index + 1}}</td> |
5b841b043
|
222 223 224 225 226 |
<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
|
227 228 229 230 231 232 233 234 235 236 |
<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
|
237 |
/> |
6566e8f29
|
238 239 240 241 242 |
<img style="cursor:pointer; width:20px; height:18px; " class="mr-5" @click="editItem(props.item)" src="/static/icon/edit1.png" |
5b841b043
|
243 |
/> |
6566e8f29
|
244 |
<img |
b39d2afd2
|
245 |
style="cursor:pointer;width:20px; height:20px; " |
6566e8f29
|
246 247 248 |
class="mr-5" @click="deleteItem(props.item)" src="/static/icon/delete1.png" |
5b841b043
|
249 |
/> |
6566e8f29
|
250 251 252 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 |
</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
|
280 |
xs12 |
f4df757fe
|
281 |
class="text-xs-center text-sm-center text-md-center text-lg-center my-4" |
6566e8f29
|
282 |
> |
6566e8f29
|
283 284 |
<input type="file" |
5b841b043
|
285 |
style="display: none" |
6566e8f29
|
286 287 |
ref="image" accept="image/*" |
2b0e316ee
|
288 |
multiple |
6566e8f29
|
289 |
@change="onFilePicked" |
5b841b043
|
290 |
/> |
79006bdcb
|
291 |
<v-layout justify-center> |
5b841b043
|
292 |
<v-flex v-for="(file,index) in files" :key="index" v-if="files"> |
f4df757fe
|
293 |
<img :src="file" height="160" width="160px;" class="imgNews" /> |
6566e8f29
|
294 295 |
</v-flex> </v-layout> |
5b841b043
|
296 297 298 299 300 301 |
<img src="/static/icon/user.png" v-if="files ==''" height="140" width="180px;" /> |
6566e8f29
|
302 |
</v-flex> |
5b841b043
|
303 304 305 |
</v-layout> <v-flex xs12> <v-layout> |
aa8fc5033
|
306 |
<v-flex xs4 sm4 class="pt-4 subheading"> |
5b841b043
|
307 308 |
<label class="right">Title:</label> </v-flex> |
aa8fc5033
|
309 |
<v-flex sm4 xs8 class="ml-3"> |
5b841b043
|
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
<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> |
aa8fc5033
|
326 |
<v-flex sm4 xs8 class="ml-3"> |
5b841b043
|
327 328 329 330 331 332 333 334 335 |
<v-text-field placeholder="fill your Description" :rules="descriptionRules" v-model="addNews.description" type="text" name="email" required ></v-text-field> </v-flex> |
2b0e316ee
|
336 |
</v-layout> |
5b841b043
|
337 338 339 340 |
</v-flex> <v-flex xs12> <v-layout> <v-flex xs4 class="pt-4 subheading"> |
aa8fc5033
|
341 342 |
<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> |
5b841b043
|
343 |
</v-flex> |
aa8fc5033
|
344 |
<v-flex xs8 sm4 class="ml-3"> |
5b841b043
|
345 346 347 348 349 350 351 352 353 354 |
<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
|
355 |
<v-layout> |
f4df757fe
|
356 357 358 359 360 361 362 363 364 |
<v-flex xs12 sm5 offset-sm3> <v-layout> <v-flex xs6> <v-btn @click="clear" round class="ml-3" dark>clear</v-btn> </v-flex> <v-flex xs6> <v-btn @click="submit" round dark :loading="loading" class="right">Add</v-btn> </v-flex> </v-layout> |
6566e8f29
|
365 366 367 368 369 370 371 372 373 |
</v-flex> </v-layout> </v-container> </v-form> </v-card> </v-flex> </v-container> </v-tab-item> </v-tabs> |
4b169b574
|
374 375 376 |
<div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> |
6566e8f29
|
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
</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
|
395 |
showLoader: false, |
6566e8f29
|
396 397 398 399 400 401 402 |
dialog: false, dialog1: false, valid: true, isActive: true, newActive: false, addclass: [], addSection: [], |
6566e8f29
|
403 404 405 406 |
AddUsercredentials: {}, pagination: { rowsPerPage: 15 }, |
6566e8f29
|
407 408 409 |
imageName: "", imageUrl: "", imageFile: "", |
2b0e316ee
|
410 |
image: [], |
5b841b043
|
411 412 |
upload: "", files: [], |
6566e8f29
|
413 414 415 416 |
titleRules: [v => !!v || " Tilte is required"], descriptionRules: [v => !!v || " Description is required"], headers: [ { |
5f1d4b444
|
417 |
align: "justify-center", |
506be6fd7
|
418 |
text: "No", |
6566e8f29
|
419 420 421 |
sortable: false, value: "No" }, |
5b841b043
|
422 |
{ text: "Image", vaue: "image", sortable: false, align: "center" }, |
6566e8f29
|
423 |
{ text: "Title", value: "title", sortable: false, align: "center" }, |
5b841b043
|
424 425 426 427 428 429 |
{ text: "Description", value: "description", sortable: false, align: "center" }, |
6566e8f29
|
430 431 |
{ text: "Action", value: "", sortable: false, align: "center" } ], |
8bb178441
|
432 |
desserts: [], |
6566e8f29
|
433 434 435 |
editedIndex: -1, addNews: { title: "", |
5b841b043
|
436 |
description: "" |
6566e8f29
|
437 438 439 |
}, editedItem: { title: "", |
5b841b043
|
440 |
description: "" |
6566e8f29
|
441 442 443 444 |
}, defaultItem: { title: "", description: "" |
aa8fc5033
|
445 |
} |
6566e8f29
|
446 |
}), |
6566e8f29
|
447 448 |
methods: { getSections(_id) { |
5b841b043
|
449 |
console.log("_id", _id); |
6566e8f29
|
450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
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
|
464 |
console.log("err====>", err); |
6566e8f29
|
465 466 467 468 469 470 |
// this.$router.replace({ path: '/' }); }); }, pickFile() { this.$refs.image.click(); }, |
6566e8f29
|
471 472 473 |
onFilePicked(e) { // console.log(e) const files = e.target.files; |
5b841b043
|
474 |
/** fetch Image Name **/ |
6566e8f29
|
475 476 477 478 |
if (files[0] !== undefined) { this.imageName = files[0].name; if (this.imageName.lastIndexOf(".") <= 0) { return; |
5b841b043
|
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
} 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
|
497 |
}); |
5b841b043
|
498 499 500 501 502 |
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
|
503 |
}); |
6566e8f29
|
504 505 506 507 508 509 510 |
} else { this.imageName = ""; this.imageFile = ""; this.imageUrl = ""; } }, getNewsList() { |
4b169b574
|
511 |
this.showLoader = true; |
6566e8f29
|
512 513 514 515 516 517 518 |
var token = this.$store.state.token; http() .get("/getNewsList", { headers: { Authorization: "Bearer " + token } }) .then(response => { this.desserts = response.data.data; |
4b169b574
|
519 |
this.showLoader = false; |
6566e8f29
|
520 521 522 523 |
// console.log("getNewsList=====>",this.desserts) }) .catch(err => { // console.log("err====>", err); |
4b169b574
|
524 |
this.showLoader = false; |
aa8fc5033
|
525 |
if (error.response.status === 401) { |
a17c68a03
|
526 527 528 529 |
this.$router.replace({ path: "/" }); this.$store.dispatch("setToken", null); this.$store.dispatch("Id", null); } |
6566e8f29
|
530 531 532 |
}); }, editItem(item) { |
8e6d1a7d7
|
533 |
this.files = []; |
6566e8f29
|
534 535 536 537 538 539 540 541 542 |
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
|
543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
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
|
557 |
this.text = "Successfully delete Existing News"; |
6566e8f29
|
558 559 560 561 562 563 564 |
} this.getNewsList(); }) .catch(error => { // console.log(error); }); }, |
5b841b043
|
565 566 567 |
deleteImage(imageId, newsId) { console.log(imageId, newsId); let deleteImages = { |
79006bdcb
|
568 569 570 571 572 573 |
newsId: newsId, imageId: imageId }; http() .put("/deleteImages", deleteImages) .then(response => { |
5b841b043
|
574 |
console.log("deleteNews", deleteImages); |
79006bdcb
|
575 576 577 578 |
if ((this.snackbar = true)) { this.text = "Image deleted Successfully"; } this.getNewsList(); |
8e6d1a7d7
|
579 |
this.close(); |
79006bdcb
|
580 581 582 583 584 |
}) .catch(error => { console.log(error); }); }, |
6566e8f29
|
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
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
|
608 |
submit() { |
506be6fd7
|
609 |
this.loading = true; |
6566e8f29
|
610 |
if (this.$refs.form.validate()) { |
5b841b043
|
611 612 613 614 615 616 617 618 619 620 621 622 623 |
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
|
624 |
} |
6566e8f29
|
625 |
http() |
2b0e316ee
|
626 |
.post("/createNews", newsData) |
6566e8f29
|
627 |
.then(response => { |
5b841b043
|
628 |
console.log(newsData); |
6566e8f29
|
629 |
if ((this.snackbar = true)) { |
5f1d4b444
|
630 |
this.text = "New News added successfully"; |
6566e8f29
|
631 632 |
} this.getNewsList(); |
506be6fd7
|
633 |
this.loading = false; |
6566e8f29
|
634 635 636 |
this.clear(); }) .catch(error => { |
6566e8f29
|
637 638 639 640 641 642 |
if ((this.snackbar = true)) { this.text = error.response.data.message; } }); } }, |
6566e8f29
|
643 644 645 646 |
clear() { this.$refs.form.reset(); }, save() { |
5b841b043
|
647 648 649 |
let editNews = { title: this.editedItem.title, description: this.editedItem.description, |
a17c68a03
|
650 |
newsId: this.editedItem._id |
5b841b043
|
651 652 |
}; if (this.files) { |
a17c68a03
|
653 654 655 656 657 658 659 |
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
|
660 |
} |
a17c68a03
|
661 |
} |
6566e8f29
|
662 663 664 665 666 |
http() .put("/updateNews", editNews) .then(response => { // console.log("updateNews",updateNews); if ((this.snackbar = true)) { |
5f1d4b444
|
667 |
this.text = "Successfully Edit Existing News"; |
6566e8f29
|
668 669 |
} this.getNewsList(); |
79006bdcb
|
670 |
this.close(); |
6566e8f29
|
671 672 673 674 |
}) .catch(error => { // console.log(error); }); |
aa8fc5033
|
675 |
} |
6566e8f29
|
676 677 678 |
}, mounted() { this.getNewsList(); |
5b841b043
|
679 |
this.editItem; |
6566e8f29
|
680 |
}, |
a17c68a03
|
681 682 683 684 685 686 687 688 |
created() { this.$root.$on("app:search", search => { this.search = search; }); }, beforeDestroy() { // dont forget to remove the listener this.$root.$off("app:search"); |
6566e8f29
|
689 690 691 692 |
} }; </script> <style scoped> |
6566e8f29
|
693 |
.active { |
687e0b929
|
694 |
background-color: gray; |
6566e8f29
|
695 696 697 698 699 |
color: white !important; } .activebtn { color: black !important; } |
6566e8f29
|
700 |
</style> |