Blame view

src/pages/News/news.vue 21.6 KB
6566e8f29   Neeraj Sharma   design and functi...
1
  <template>
68d742034   Neeraj Sharma   implement new des...
2
3
    <v-container fluid class="body-color">
      <!-- ****** EDIT NEWS  ****** -->
db965de89   Amber Dev   added dialog pers...
4
      <v-dialog v-model="editNewsDialog" max-width="600px" persistent>
4dd422bef   Shikha Mishra   change ui of card...
5
        <v-card flat class="Card-style pa-2">
68d742034   Neeraj Sharma   implement new des...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
          <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
              </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  ******  -->
db965de89   Amber Dev   added dialog pers...
130
      <v-dialog v-model="dialog1" max-width="500px" persistent>
4dd422bef   Shikha Mishra   change ui of card...
131
        <v-card flat class="Card-style pa-3">
68d742034   Neeraj Sharma   implement new des...
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-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 ****** -->
db965de89   Amber Dev   added dialog pers...
286
      <v-dialog v-model="addNewsDialog" max-width="600px" v-if="addNewsDialog" persistent>
4dd422bef   Shikha Mishra   change ui of card...
287
        <v-card flat class="Card-style pa-2">
68d742034   Neeraj Sharma   implement new des...
288
289
290
          <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) => {
860da881d   Shikha Mishra   comment all consoles
477
478
479
480
            //   console.log("err====>", err);
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
6566e8f29   Neeraj Sharma   design and functi...
481
482
483
484
485
          });
      },
      pickFile() {
        this.$refs.image.click();
      },
6566e8f29   Neeraj Sharma   design and functi...
486
487
488
      onFilePicked(e) {
        // console.log(e)
        const files = e.target.files;
5b841b043   Neeraj Sharma   fix upload dyanm...
489
        /** fetch Image Name **/
6566e8f29   Neeraj Sharma   design and functi...
490
491
492
493
        if (files[0] !== undefined) {
          this.imageName = files[0].name;
          if (this.imageName.lastIndexOf(".") <= 0) {
            return;
5b841b043   Neeraj Sharma   fix upload dyanm...
494
495
496
497
498
499
          }
          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...
500
501
            const getResult = new Promise((resolve) => {
              fr.onload = (e) => {
5b841b043   Neeraj Sharma   fix upload dyanm...
502
503
504
505
506
507
508
                this.files.push(
                  // id: idx,
                  e.target.result
                );
              };
            });
            fr.readAsDataURL(file);
8e8d14254   Shikha Mishra   Cleared data whil...
509
            return getResult.then((file) => {
5b841b043   Neeraj Sharma   fix upload dyanm...
510
511
              return file;
            });
6566e8f29   Neeraj Sharma   design and functi...
512
          });
5b841b043   Neeraj Sharma   fix upload dyanm...
513
514
515
516
517
          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...
518
          });
6566e8f29   Neeraj Sharma   design and functi...
519
520
521
522
523
524
525
        } else {
          this.imageName = "";
          this.imageFile = "";
          this.imageUrl = "";
        }
      },
      getNewsList() {
4b169b574   Neeraj Sharma   add loader in all...
526
        this.showLoader = true;
6566e8f29   Neeraj Sharma   design and functi...
527
528
529
        var token = this.$store.state.token;
        http()
          .get("/getNewsList", {
8e8d14254   Shikha Mishra   Cleared data whil...
530
            headers: { Authorization: "Bearer " + token },
6566e8f29   Neeraj Sharma   design and functi...
531
          })
8e8d14254   Shikha Mishra   Cleared data whil...
532
          .then((response) => {
6566e8f29   Neeraj Sharma   design and functi...
533
            this.desserts = response.data.data;
4b169b574   Neeraj Sharma   add loader in all...
534
            this.showLoader = false;
6566e8f29   Neeraj Sharma   design and functi...
535
          })
8e8d14254   Shikha Mishra   Cleared data whil...
536
          .catch((error) => {
4b169b574   Neeraj Sharma   add loader in all...
537
            this.showLoader = false;
aa8fc5033   Neeraj Sharma   implenment all pa...
538
            if (error.response.status === 401) {
a17c68a03   Neeraj Sharma   implement two rou...
539
540
541
542
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
6566e8f29   Neeraj Sharma   design and functi...
543
544
545
          });
      },
      editItem(item) {
8e6d1a7d7   Neeraj Sharma   solve bugs uplaod...
546
        this.files = [];
6566e8f29   Neeraj Sharma   design and functi...
547
548
        this.editedIndex = this.desserts.indexOf(item);
        this.editedItem = Object.assign({}, item);
68d742034   Neeraj Sharma   implement new des...
549
        this.editNewsDialog = true;
6566e8f29   Neeraj Sharma   design and functi...
550
551
552
553
554
555
      },
      profile(item) {
        this.editedIndex = this.desserts.indexOf(item);
        this.editedItem = Object.assign({}, item);
        this.dialog1 = true;
      },
6566e8f29   Neeraj Sharma   design and functi...
556
557
      deleteItem(item) {
        let deleteNews = {
8e8d14254   Shikha Mishra   Cleared data whil...
558
          newsId: item._id,
6566e8f29   Neeraj Sharma   design and functi...
559
560
561
562
563
        };
        http()
          .delete(
            "/deleteNews",
            confirm("Are you sure you want to delete this?") && {
8e8d14254   Shikha Mishra   Cleared data whil...
564
              params: deleteNews,
6566e8f29   Neeraj Sharma   design and functi...
565
566
            }
          )
8e8d14254   Shikha Mishra   Cleared data whil...
567
          .then((response) => {
68d742034   Neeraj Sharma   implement new des...
568
569
570
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
6566e8f29   Neeraj Sharma   design and functi...
571
572
            this.getNewsList();
          })
8e8d14254   Shikha Mishra   Cleared data whil...
573
          .catch((error) => {
68d742034   Neeraj Sharma   implement new des...
574
575
576
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
6566e8f29   Neeraj Sharma   design and functi...
577
578
          });
      },
5b841b043   Neeraj Sharma   fix upload dyanm...
579
      deleteImage(imageId, newsId) {
5b841b043   Neeraj Sharma   fix upload dyanm...
580
        let deleteImages = {
79006bdcb   Neeraj Sharma   uplaod images all...
581
          newsId: newsId,
8e8d14254   Shikha Mishra   Cleared data whil...
582
          imageId: imageId,
79006bdcb   Neeraj Sharma   uplaod images all...
583
584
585
        };
        http()
          .put("/deleteImages", deleteImages)
8e8d14254   Shikha Mishra   Cleared data whil...
586
          .then((response) => {
68d742034   Neeraj Sharma   implement new des...
587
588
589
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
8e6d1a7d7   Neeraj Sharma   solve bugs uplaod...
590
            this.close();
79006bdcb   Neeraj Sharma   uplaod images all...
591
          })
8e8d14254   Shikha Mishra   Cleared data whil...
592
          .catch((error) => {
68d742034   Neeraj Sharma   implement new des...
593
594
595
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
79006bdcb   Neeraj Sharma   uplaod images all...
596
597
          });
      },
6566e8f29   Neeraj Sharma   design and functi...
598
599
      close() {
        this.dialog = false;
6566e8f29   Neeraj Sharma   design and functi...
600
601
602
603
      },
      close1() {
        this.dialog1 = false;
      },
8e8d14254   Shikha Mishra   Cleared data whil...
604
605
606
607
608
609
610
611
      closeAddNewsModel() {
        this.addNewsDialog = false;
        this.addNews = [];
        this.imageName = "";
        this.imageFile = "";
        this.imageUrl = "";
        this.files = [];
      },
6566e8f29   Neeraj Sharma   design and functi...
612
613
      submit() {
        if (this.$refs.form.validate()) {
5b841b043   Neeraj Sharma   fix upload dyanm...
614
615
          let newsData = {
            title: this.addNews.title,
8e8d14254   Shikha Mishra   Cleared data whil...
616
            description: this.addNews.description,
5b841b043   Neeraj Sharma   fix upload dyanm...
617
618
619
620
621
622
623
624
625
626
          };
          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...
627
          }
9a1e18aba   Neeraj Sharma   display static im...
628
          this.loading = true;
6566e8f29   Neeraj Sharma   design and functi...
629
          http()
2b0e316ee   Neeraj Sharma   upload mytiple im...
630
            .post("/createNews", newsData)
8e8d14254   Shikha Mishra   Cleared data whil...
631
            .then((response) => {
0551a0f15   Neeraj Sharma   implemnet functio...
632
633
              this.files = [];
              this.snackbar = true;
68d742034   Neeraj Sharma   implement new des...
634
              this.text = response.data.message;
6566e8f29   Neeraj Sharma   design and functi...
635
              this.getNewsList();
68d742034   Neeraj Sharma   implement new des...
636
637
              this.color = "green";
              this.addNewsDialog = false;
506be6fd7   Neeraj Sharma   implemet dyamic i...
638
              this.loading = false;
6566e8f29   Neeraj Sharma   design and functi...
639
640
              this.clear();
            })
8e8d14254   Shikha Mishra   Cleared data whil...
641
            .catch((error) => {
0551a0f15   Neeraj Sharma   implemnet functio...
642
643
              this.snackbar = true;
              this.text = error.response.data.message;
68d742034   Neeraj Sharma   implement new des...
644
              this.color = "error";
6566e8f29   Neeraj Sharma   design and functi...
645
646
647
            });
        }
      },
6566e8f29   Neeraj Sharma   design and functi...
648
649
      clear() {
        this.$refs.form.reset();
0551a0f15   Neeraj Sharma   implemnet functio...
650
        this.files = [];
6566e8f29   Neeraj Sharma   design and functi...
651
652
      },
      save() {
5b841b043   Neeraj Sharma   fix upload dyanm...
653
654
655
        let editNews = {
          title: this.editedItem.title,
          description: this.editedItem.description,
8e8d14254   Shikha Mishra   Cleared data whil...
656
          newsId: this.editedItem._id,
5b841b043   Neeraj Sharma   fix upload dyanm...
657
658
        };
        if (this.files) {
a17c68a03   Neeraj Sharma   implement two rou...
659
660
661
662
663
664
665
          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...
666
          }
a17c68a03   Neeraj Sharma   implement two rou...
667
        }
6566e8f29   Neeraj Sharma   design and functi...
668
669
        http()
          .put("/updateNews", editNews)
8e8d14254   Shikha Mishra   Cleared data whil...
670
          .then((response) => {
68d742034   Neeraj Sharma   implement new des...
671
            this.snackbar = true;
d5fcb1cd1   Shikha Mishra   issues resolved
672
            this.text = "Successfully updated News";
68d742034   Neeraj Sharma   implement new des...
673
            this.color = "green";
d5fcb1cd1   Shikha Mishra   issues resolved
674
            this.editNewsDialog = false;
6566e8f29   Neeraj Sharma   design and functi...
675
            this.getNewsList();
79006bdcb   Neeraj Sharma   uplaod images all...
676
            this.close();
6566e8f29   Neeraj Sharma   design and functi...
677
          })
8e8d14254   Shikha Mishra   Cleared data whil...
678
          .catch((error) => {
68d742034   Neeraj Sharma   implement new des...
679
680
681
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
6566e8f29   Neeraj Sharma   design and functi...
682
          });
68d742034   Neeraj Sharma   implement new des...
683
684
685
686
687
688
689
690
      },
      displaySearch() {
        (this.show = false), (this.showSearch = true);
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
8e8d14254   Shikha Mishra   Cleared data whil...
691
      },
6566e8f29   Neeraj Sharma   design and functi...
692
693
694
    },
    mounted() {
      this.getNewsList();
5b841b043   Neeraj Sharma   fix upload dyanm...
695
      this.editItem;
8e8d14254   Shikha Mishra   Cleared data whil...
696
    },
6566e8f29   Neeraj Sharma   design and functi...
697
  };
68d742034   Neeraj Sharma   implement new des...
698
  </script>