Blame view

src/pages/News/news.vue 21.4 KB
6566e8f29   Neeraj Sharma   design and functi...
1
  <template>
68d742034   Neeraj Sharma   implement new des...
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   Neeraj Sharma   responsive vie in...
24
25
                  <v-flex
                    xs12
68d742034   Neeraj Sharma   implement new des...
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   Neeraj Sharma   responsive vie in...
32
                  >
68d742034   Neeraj Sharma   implement new des...
33
34
35
36
37
38
                    <img
                      :src="Image.imageUrl"
                      height="100"
                      width="100"
                      alt="News"
                      class="pa-2 imgNews"
f4df757fe   Neeraj Sharma   responsive vie in...
39
                    />
68d742034   Neeraj Sharma   implement new des...
40
41
42
43
44
                    <v-icon
                      class="red edit-profile-icon"
                      dark
                      @click="deleteImage(Image._id,editedItem._id)"
                    >close</v-icon>
f4df757fe   Neeraj Sharma   responsive vie in...
45
                  </v-flex>
68d742034   Neeraj Sharma   implement new des...
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   Neeraj Sharma   responsive vie in...
56
                </v-layout>
68d742034   Neeraj Sharma   implement new des...
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   Neeraj Sharma   responsive vie in...
65
                  </v-flex>
68d742034   Neeraj Sharma   implement new des...
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   Neeraj Sharma   responsive vie in...
81
                  </v-flex>
68d742034   Neeraj Sharma   implement new des...
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   Neeraj Sharma   responsive vie in...
90
91
                  </v-flex>
                </v-layout>
68d742034   Neeraj Sharma   implement new des...
92
93
              </v-flex>
              <v-flex xs12>
f4df757fe   Neeraj Sharma   responsive vie in...
94
                <v-layout>
68d742034   Neeraj Sharma   implement new des...
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   Neeraj Sharma   responsive vie in...
107
108
                  </v-flex>
                </v-layout>
68d742034   Neeraj Sharma   implement new des...
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   Neeraj Sharma   design and functi...
159
                    </v-flex>
68d742034   Neeraj Sharma   implement new des...
160
161
                    <v-flex sm6 xs8>
                      <h5 class="my-1">{{ editedItem.title }}</h5>
5b841b043   Neeraj Sharma   fix upload dyanm...
162
                    </v-flex>
68d742034   Neeraj Sharma   implement new des...
163
164
165
166
167
168
                  </v-layout>
                  <v-layout>
                    <v-flex xs5 sm6>
                      <h5 class="right my-1">
                        <b>Description:</b>
                      </h5>
5b841b043   Neeraj Sharma   fix upload dyanm...
169
                    </v-flex>
68d742034   Neeraj Sharma   implement new des...
170
171
                    <v-flex sm6 xs8>
                      <h5 class="my-1">{{ editedItem.description }}</h5>
5b841b043   Neeraj Sharma   fix upload dyanm...
172
                    </v-flex>
68d742034   Neeraj Sharma   implement new des...
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   Shikha Mishra   added functionali...
203
              <img src="/static/icon/search.png" alt="icon" />
68d742034   Neeraj Sharma   implement new des...
204
205
206
            </v-avatar>
          </v-btn>
        </v-card-title>
612b79bb4   Amber Dev   made serch auto f...
207
        <v-flex xs8 sm8 md3 lg2 v-if="showSearch">
68d742034   Neeraj Sharma   implement new des...
208
          <v-layout>
8e8d14254   Shikha Mishra   Cleared data whil...
209
210
211
212
213
214
215
            <v-text-field
              autofocus
              v-model="search"
              label="Search"
              prepend-inner-icon="search"
              color="primary"
            ></v-text-field>
68d742034   Neeraj Sharma   implement new des...
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
245
246
247
248
249
250
            <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   Shikha Mishra   added functionali...
251
                    src="/static/icon/view.png"
68d742034   Neeraj Sharma   implement new des...
252
253
254
255
256
257
258
259
260
                  />
                  <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   Shikha Mishra   added functionali...
261
                    src="/static/icon/edit.png"
68d742034   Neeraj Sharma   implement new des...
262
263
264
265
266
267
268
269
                  />
                  <span>Edit</span>
                </v-tooltip>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:20px; "
                    @click="deleteItem(props.item)"
aa310d61a   Shikha Mishra   added functionali...
270
                    src="/static/icon/delete.png"
68d742034   Neeraj Sharma   implement new des...
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 ****** -->
8e8d14254   Shikha Mishra   Cleared data whil...
286
      <v-dialog v-model="addNewsDialog" max-width="600px" v-if="addNewsDialog">
68d742034   Neeraj Sharma   implement new des...
287
288
289
290
        <v-card flat class="card-style pa-2" dark>
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Add News</label>
8e8d14254   Shikha Mishra   Cleared data whil...
291
              <v-icon size="24" class="right" @click="closeAddNewsModel">cancel</v-icon>
6566e8f29   Neeraj Sharma   design and functi...
292
            </v-flex>
68d742034   Neeraj Sharma   implement new des...
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
372
373
374
375
376
377
          </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   Neeraj Sharma   add loader in all...
378
379
380
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
68d742034   Neeraj Sharma   implement new des...
381
    </v-container>
6566e8f29   Neeraj Sharma   design and functi...
382
383
384
385
  </template>
  
  <script>
  import http from "@/Services/http.js";
6566e8f29   Neeraj Sharma   design and functi...
386
387
388
389
390
391
392
  
  export default {
    data: () => ({
      snackbar: false,
      y: "top",
      x: "right",
      mode: "",
68d742034   Neeraj Sharma   implement new des...
393
394
      timeout: 5000,
      color: "",
6566e8f29   Neeraj Sharma   design and functi...
395
396
397
398
      text: "",
      loading: false,
      date: null,
      search: "",
68d742034   Neeraj Sharma   implement new des...
399
400
      show: true,
      showSearch: false,
5b841b043   Neeraj Sharma   fix upload dyanm...
401
      showLoader: false,
68d742034   Neeraj Sharma   implement new des...
402
403
      editNewsDialog: false,
      addNewsDialog: false,
6566e8f29   Neeraj Sharma   design and functi...
404
405
      dialog1: false,
      valid: true,
6566e8f29   Neeraj Sharma   design and functi...
406
407
      addclass: [],
      addSection: [],
6566e8f29   Neeraj Sharma   design and functi...
408
      pagination: {
8e8d14254   Shikha Mishra   Cleared data whil...
409
        rowsPerPage: 10,
6566e8f29   Neeraj Sharma   design and functi...
410
      },
6566e8f29   Neeraj Sharma   design and functi...
411
412
413
      imageName: "",
      imageUrl: "",
      imageFile: "",
2b0e316ee   Neeraj Sharma   upload mytiple im...
414
      image: [],
5b841b043   Neeraj Sharma   fix upload dyanm...
415
416
      upload: "",
      files: [],
8e8d14254   Shikha Mishra   Cleared data whil...
417
418
      titleRules: [(v) => !!v || " Tilte is required"],
      descriptionRules: [(v) => !!v || " Description is required"],
6566e8f29   Neeraj Sharma   design and functi...
419
420
      headers: [
        {
5f1d4b444   Neeraj Sharma   fix design and fi...
421
          align: "justify-center",
506be6fd7   Neeraj Sharma   implemet dyamic i...
422
          text: "No",
6566e8f29   Neeraj Sharma   design and functi...
423
          sortable: false,
8e8d14254   Shikha Mishra   Cleared data whil...
424
          value: "No",
6566e8f29   Neeraj Sharma   design and functi...
425
        },
5b841b043   Neeraj Sharma   fix upload dyanm...
426
        { text: "Image", vaue: "image", sortable: false, align: "center" },
6566e8f29   Neeraj Sharma   design and functi...
427
        { text: "Title", value: "title", sortable: false, align: "center" },
5b841b043   Neeraj Sharma   fix upload dyanm...
428
429
430
431
        {
          text: "Description",
          value: "description",
          sortable: false,
8e8d14254   Shikha Mishra   Cleared data whil...
432
          align: "center",
5b841b043   Neeraj Sharma   fix upload dyanm...
433
        },
8e8d14254   Shikha Mishra   Cleared data whil...
434
        { text: "Action", value: "", sortable: false, align: "center" },
6566e8f29   Neeraj Sharma   design and functi...
435
      ],
8bb178441   Neeraj Sharma   implemnt api in s...
436
      desserts: [],
6566e8f29   Neeraj Sharma   design and functi...
437
438
439
      editedIndex: -1,
      addNews: {
        title: "",
8e8d14254   Shikha Mishra   Cleared data whil...
440
        description: "",
6566e8f29   Neeraj Sharma   design and functi...
441
442
443
      },
      editedItem: {
        title: "",
8e8d14254   Shikha Mishra   Cleared data whil...
444
        description: "",
6566e8f29   Neeraj Sharma   design and functi...
445
446
447
      },
      defaultItem: {
        title: "",
8e8d14254   Shikha Mishra   Cleared data whil...
448
449
        description: "",
      },
6566e8f29   Neeraj Sharma   design and functi...
450
    }),
8e8d14254   Shikha Mishra   Cleared data whil...
451
452
453
454
455
456
457
458
459
460
461
    watch: {
      addNewsDialog: function (val) {
        if (!val) {
          this.addNews = [];
          this.imageName = "";
          this.imageFile = "";
          this.imageUrl = "";
          this.files = [];
        }
      },
    },
6566e8f29   Neeraj Sharma   design and functi...
462
463
464
465
466
467
468
469
    methods: {
      getSections(_id) {
        var token = this.$store.state.token;
        http()
          .get(
            "/getSectionsList",
            { params: { classId: _id } },
            {
8e8d14254   Shikha Mishra   Cleared data whil...
470
              headers: { Authorization: "Bearer " + token },
6566e8f29   Neeraj Sharma   design and functi...
471
472
            }
          )
8e8d14254   Shikha Mishra   Cleared data whil...
473
          .then((response) => {
6566e8f29   Neeraj Sharma   design and functi...
474
            this.addSection = response.data.data;
6566e8f29   Neeraj Sharma   design and functi...
475
          })
8e8d14254   Shikha Mishra   Cleared data whil...
476
          .catch((err) => {
5f1d4b444   Neeraj Sharma   fix design and fi...
477
            console.log("err====>", err);
6566e8f29   Neeraj Sharma   design and functi...
478
479
480
481
482
          });
      },
      pickFile() {
        this.$refs.image.click();
      },
6566e8f29   Neeraj Sharma   design and functi...
483
484
485
      onFilePicked(e) {
        // console.log(e)
        const files = e.target.files;
5b841b043   Neeraj Sharma   fix upload dyanm...
486
        /** fetch Image Name **/
6566e8f29   Neeraj Sharma   design and functi...
487
488
489
490
        if (files[0] !== undefined) {
          this.imageName = files[0].name;
          if (this.imageName.lastIndexOf(".") <= 0) {
            return;
5b841b043   Neeraj Sharma   fix upload dyanm...
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();
8e8d14254   Shikha Mishra   Cleared data whil...
497
498
            const getResult = new Promise((resolve) => {
              fr.onload = (e) => {
5b841b043   Neeraj Sharma   fix upload dyanm...
499
500
501
502
503
504
505
                this.files.push(
                  // id: idx,
                  e.target.result
                );
              };
            });
            fr.readAsDataURL(file);
8e8d14254   Shikha Mishra   Cleared data whil...
506
            return getResult.then((file) => {
5b841b043   Neeraj Sharma   fix upload dyanm...
507
508
              return file;
            });
6566e8f29   Neeraj Sharma   design and functi...
509
          });
5b841b043   Neeraj Sharma   fix upload dyanm...
510
511
512
513
514
          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   Neeraj Sharma   upload mytiple im...
515
          });
6566e8f29   Neeraj Sharma   design and functi...
516
517
518
519
520
521
522
        } else {
          this.imageName = "";
          this.imageFile = "";
          this.imageUrl = "";
        }
      },
      getNewsList() {
4b169b574   Neeraj Sharma   add loader in all...
523
        this.showLoader = true;
6566e8f29   Neeraj Sharma   design and functi...
524
525
526
        var token = this.$store.state.token;
        http()
          .get("/getNewsList", {
8e8d14254   Shikha Mishra   Cleared data whil...
527
            headers: { Authorization: "Bearer " + token },
6566e8f29   Neeraj Sharma   design and functi...
528
          })
8e8d14254   Shikha Mishra   Cleared data whil...
529
          .then((response) => {
6566e8f29   Neeraj Sharma   design and functi...
530
            this.desserts = response.data.data;
4b169b574   Neeraj Sharma   add loader in all...
531
            this.showLoader = false;
6566e8f29   Neeraj Sharma   design and functi...
532
          })
8e8d14254   Shikha Mishra   Cleared data whil...
533
          .catch((error) => {
4b169b574   Neeraj Sharma   add loader in all...
534
            this.showLoader = false;
aa8fc5033   Neeraj Sharma   implenment all pa...
535
            if (error.response.status === 401) {
a17c68a03   Neeraj Sharma   implement two rou...
536
537
538
539
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
6566e8f29   Neeraj Sharma   design and functi...
540
541
542
          });
      },
      editItem(item) {
8e6d1a7d7   Neeraj Sharma   solve bugs uplaod...
543
        this.files = [];
6566e8f29   Neeraj Sharma   design and functi...
544
545
        this.editedIndex = this.desserts.indexOf(item);
        this.editedItem = Object.assign({}, item);
68d742034   Neeraj Sharma   implement new des...
546
        this.editNewsDialog = true;
6566e8f29   Neeraj Sharma   design and functi...
547
548
549
550
551
552
      },
      profile(item) {
        this.editedIndex = this.desserts.indexOf(item);
        this.editedItem = Object.assign({}, item);
        this.dialog1 = true;
      },
6566e8f29   Neeraj Sharma   design and functi...
553
554
      deleteItem(item) {
        let deleteNews = {
8e8d14254   Shikha Mishra   Cleared data whil...
555
          newsId: item._id,
6566e8f29   Neeraj Sharma   design and functi...
556
557
558
559
560
        };
        http()
          .delete(
            "/deleteNews",
            confirm("Are you sure you want to delete this?") && {
8e8d14254   Shikha Mishra   Cleared data whil...
561
              params: deleteNews,
6566e8f29   Neeraj Sharma   design and functi...
562
563
            }
          )
8e8d14254   Shikha Mishra   Cleared data whil...
564
          .then((response) => {
68d742034   Neeraj Sharma   implement new des...
565
566
567
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
6566e8f29   Neeraj Sharma   design and functi...
568
569
            this.getNewsList();
          })
8e8d14254   Shikha Mishra   Cleared data whil...
570
          .catch((error) => {
68d742034   Neeraj Sharma   implement new des...
571
572
573
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
6566e8f29   Neeraj Sharma   design and functi...
574
575
          });
      },
5b841b043   Neeraj Sharma   fix upload dyanm...
576
      deleteImage(imageId, newsId) {
5b841b043   Neeraj Sharma   fix upload dyanm...
577
        let deleteImages = {
79006bdcb   Neeraj Sharma   uplaod images all...
578
          newsId: newsId,
8e8d14254   Shikha Mishra   Cleared data whil...
579
          imageId: imageId,
79006bdcb   Neeraj Sharma   uplaod images all...
580
581
582
        };
        http()
          .put("/deleteImages", deleteImages)
8e8d14254   Shikha Mishra   Cleared data whil...
583
          .then((response) => {
68d742034   Neeraj Sharma   implement new des...
584
585
586
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
8e6d1a7d7   Neeraj Sharma   solve bugs uplaod...
587
            this.close();
79006bdcb   Neeraj Sharma   uplaod images all...
588
          })
8e8d14254   Shikha Mishra   Cleared data whil...
589
          .catch((error) => {
68d742034   Neeraj Sharma   implement new des...
590
591
592
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
79006bdcb   Neeraj Sharma   uplaod images all...
593
594
          });
      },
6566e8f29   Neeraj Sharma   design and functi...
595
596
      close() {
        this.dialog = false;
6566e8f29   Neeraj Sharma   design and functi...
597
598
599
600
      },
      close1() {
        this.dialog1 = false;
      },
8e8d14254   Shikha Mishra   Cleared data whil...
601
602
603
604
605
606
607
608
      closeAddNewsModel() {
        this.addNewsDialog = false;
        this.addNews = [];
        this.imageName = "";
        this.imageFile = "";
        this.imageUrl = "";
        this.files = [];
      },
6566e8f29   Neeraj Sharma   design and functi...
609
610
      submit() {
        if (this.$refs.form.validate()) {
5b841b043   Neeraj Sharma   fix upload dyanm...
611
612
          let newsData = {
            title: this.addNews.title,
8e8d14254   Shikha Mishra   Cleared data whil...
613
            description: this.addNews.description,
5b841b043   Neeraj Sharma   fix upload dyanm...
614
615
616
617
618
619
620
621
622
623
          };
          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   Neeraj Sharma   upload mytiple im...
624
          }
9a1e18aba   Neeraj Sharma   display static im...
625
          this.loading = true;
6566e8f29   Neeraj Sharma   design and functi...
626
          http()
2b0e316ee   Neeraj Sharma   upload mytiple im...
627
            .post("/createNews", newsData)
8e8d14254   Shikha Mishra   Cleared data whil...
628
            .then((response) => {
0551a0f15   Neeraj Sharma   implemnet functio...
629
630
              this.files = [];
              this.snackbar = true;
68d742034   Neeraj Sharma   implement new des...
631
              this.text = response.data.message;
6566e8f29   Neeraj Sharma   design and functi...
632
              this.getNewsList();
68d742034   Neeraj Sharma   implement new des...
633
634
              this.color = "green";
              this.addNewsDialog = false;
506be6fd7   Neeraj Sharma   implemet dyamic i...
635
              this.loading = false;
6566e8f29   Neeraj Sharma   design and functi...
636
637
              this.clear();
            })
8e8d14254   Shikha Mishra   Cleared data whil...
638
            .catch((error) => {
0551a0f15   Neeraj Sharma   implemnet functio...
639
640
              this.snackbar = true;
              this.text = error.response.data.message;
68d742034   Neeraj Sharma   implement new des...
641
              this.color = "error";
6566e8f29   Neeraj Sharma   design and functi...
642
643
644
            });
        }
      },
6566e8f29   Neeraj Sharma   design and functi...
645
646
      clear() {
        this.$refs.form.reset();
0551a0f15   Neeraj Sharma   implemnet functio...
647
        this.files = [];
6566e8f29   Neeraj Sharma   design and functi...
648
649
      },
      save() {
5b841b043   Neeraj Sharma   fix upload dyanm...
650
651
652
        let editNews = {
          title: this.editedItem.title,
          description: this.editedItem.description,
8e8d14254   Shikha Mishra   Cleared data whil...
653
          newsId: this.editedItem._id,
5b841b043   Neeraj Sharma   fix upload dyanm...
654
655
        };
        if (this.files) {
a17c68a03   Neeraj Sharma   implement two rou...
656
657
658
659
660
661
662
          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   Neeraj Sharma   fix upload dyanm...
663
          }
a17c68a03   Neeraj Sharma   implement two rou...
664
        }
6566e8f29   Neeraj Sharma   design and functi...
665
666
        http()
          .put("/updateNews", editNews)
8e8d14254   Shikha Mishra   Cleared data whil...
667
          .then((response) => {
68d742034   Neeraj Sharma   implement new des...
668
            this.snackbar = true;
d5fcb1cd1   Shikha Mishra   issues resolved
669
            this.text = "Successfully updated News";
68d742034   Neeraj Sharma   implement new des...
670
            this.color = "green";
d5fcb1cd1   Shikha Mishra   issues resolved
671
            this.editNewsDialog = false;
6566e8f29   Neeraj Sharma   design and functi...
672
            this.getNewsList();
79006bdcb   Neeraj Sharma   uplaod images all...
673
            this.close();
6566e8f29   Neeraj Sharma   design and functi...
674
          })
8e8d14254   Shikha Mishra   Cleared data whil...
675
          .catch((error) => {
68d742034   Neeraj Sharma   implement new des...
676
677
678
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
6566e8f29   Neeraj Sharma   design and functi...
679
          });
68d742034   Neeraj Sharma   implement new des...
680
681
682
683
684
685
686
687
      },
      displaySearch() {
        (this.show = false), (this.showSearch = true);
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
8e8d14254   Shikha Mishra   Cleared data whil...
688
      },
6566e8f29   Neeraj Sharma   design and functi...
689
690
691
    },
    mounted() {
      this.getNewsList();
5b841b043   Neeraj Sharma   fix upload dyanm...
692
      this.editItem;
8e8d14254   Shikha Mishra   Cleared data whil...
693
    },
6566e8f29   Neeraj Sharma   design and functi...
694
  };
68d742034   Neeraj Sharma   implement new des...
695
  </script>