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