Blame view

src/pages/News/news.vue 22.4 KB
6566e8f29   Neeraj Sharma   design and functi...
1
2
  <template>
    <v-app id="pages-dasboard">
687e0b929   Neeraj Sharma   add user,attenden...
3
      <v-tabs grow slider-color="gray">
6566e8f29   Neeraj Sharma   design and functi...
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   Neeraj Sharma   responsive vie in...
19
        <!-- ****** EDIT NEWS  ****** -->
6566e8f29   Neeraj Sharma   design and functi...
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   Neeraj Sharma   uplaod images all...
30
          <v-dialog v-model="dialog" max-width="1000px" scrollable>
5b841b043   Neeraj Sharma   fix upload dyanm...
31
32
            <v-card flat>
              <v-toolbar class="grey lighten-2" flat>
6566e8f29   Neeraj Sharma   design and functi...
33
                <v-spacer></v-spacer>
5b841b043   Neeraj Sharma   fix upload dyanm...
34
35
36
                <v-toolbar-title>
                  <h3>Edit News</h3>
                </v-toolbar-title>
6566e8f29   Neeraj Sharma   design and functi...
37
                <v-spacer></v-spacer>
5b841b043   Neeraj Sharma   fix upload dyanm...
38
              </v-toolbar>
79583580d   Neeraj Sharma   implement task ma...
39
              <v-card-text style="height:520px;">
f4df757fe   Neeraj Sharma   responsive vie in...
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   Neeraj Sharma   fix upload dyanm...
56
                      <v-flex
6566e8f29   Neeraj Sharma   design and functi...
57
                        xs12
f4df757fe   Neeraj Sharma   responsive vie in...
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   Neeraj Sharma   design and functi...
64
                      >
5b841b043   Neeraj Sharma   fix upload dyanm...
65
                        <img
f4df757fe   Neeraj Sharma   responsive vie in...
66
                          :src="Image.imageUrl"
5b841b043   Neeraj Sharma   fix upload dyanm...
67
68
69
                          height="160"
                          width="160"
                          alt="News"
f4df757fe   Neeraj Sharma   responsive vie in...
70
                          class="pa-2 imgNews"
5b841b043   Neeraj Sharma   fix upload dyanm...
71
                        />
f4df757fe   Neeraj Sharma   responsive vie in...
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   Neeraj Sharma   design and functi...
80
81
                      </v-flex>
                    </v-layout>
f4df757fe   Neeraj Sharma   responsive vie in...
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   Neeraj Sharma   design and functi...
94
                    <v-layout>
f4df757fe   Neeraj Sharma   responsive vie in...
95
96
                      <v-flex xs4 class="pt-4 subheading">
                        <label class="right">Title:</label>
6566e8f29   Neeraj Sharma   design and functi...
97
                      </v-flex>
f4df757fe   Neeraj Sharma   responsive vie in...
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   Neeraj Sharma   design and functi...
106
                      </v-flex>
f4df757fe   Neeraj Sharma   responsive vie in...
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   Neeraj Sharma   fix upload dyanm...
122
                      </v-flex>
6566e8f29   Neeraj Sharma   design and functi...
123
                    </v-layout>
f4df757fe   Neeraj Sharma   responsive vie in...
124
125
                  </v-flex>
                  <v-flex xs12>
6566e8f29   Neeraj Sharma   design and functi...
126
                    <v-layout>
f4df757fe   Neeraj Sharma   responsive vie in...
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   Neeraj Sharma   design and functi...
139
140
                      </v-flex>
                    </v-layout>
f4df757fe   Neeraj Sharma   responsive vie in...
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   Neeraj Sharma   fix upload dyanm...
152
153
              </v-card-text>
            </v-card>
6566e8f29   Neeraj Sharma   design and functi...
154
155
156
          </v-dialog>
  
          <!-- ****** PROFILE VIEW ALL NEWS DEATILS ******  -->
506be6fd7   Neeraj Sharma   implemet dyamic i...
157
158
  
          <v-dialog v-model="dialog1" max-width="800px">
79006bdcb   Neeraj Sharma   uplaod images all...
159
160
            <v-card>
              <v-toolbar color="grey lighten-2" flat>
5b841b043   Neeraj Sharma   fix upload dyanm...
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   Neeraj Sharma   solve bugs in news
169
                <span v-for="(image,i) in editedItem.newsImageUrl" :key="i" class="mt-4 pa-2">
f4df757fe   Neeraj Sharma   responsive vie in...
170
                  <img :src="image.imageUrl" alt="News" width="240" height="180" class="imgNews" />
5b841b043   Neeraj Sharma   fix upload dyanm...
171
                </span>
6566e8f29   Neeraj Sharma   design and functi...
172
173
174
175
176
              </v-flex>
              <v-card-text>
                <v-container grid-list-md>
                  <v-layout wrap>
                    <v-flex>
6566e8f29   Neeraj Sharma   design and functi...
177
178
                      <v-layout>
                        <v-flex xs5 sm6>
5b841b043   Neeraj Sharma   fix upload dyanm...
179
180
181
                          <h5 class="right my-1">
                            <b>Title:</b>
                          </h5>
6566e8f29   Neeraj Sharma   design and functi...
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   Neeraj Sharma   fix upload dyanm...
189
190
191
                          <h5 class="right my-1">
                            <b>Description:</b>
                          </h5>
6566e8f29   Neeraj Sharma   design and functi...
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   Neeraj Sharma   implenment all pa...
221
              <td class="text-xs-center">{{ props.index + 1}}</td>
5b841b043   Neeraj Sharma   fix upload dyanm...
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   Neeraj Sharma   design and functi...
227
228
229
230
              <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">
495e4037c   Neeraj Sharma   update
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
                 <span>
                  <v-tooltip top>
                    <img
                      slot="activator"
                      style="cursor:pointer; width:25px; height:18px; "
                      class="mr5"
                      @click="profile(props.item)"
                      src="/static/icon/eye1.png"
                    />
                    <span>View</span>
                  </v-tooltip>
                  <v-tooltip top>
                    <img
                      slot="activator"
                      style="cursor:pointer; width:20px; height:18px; "
                      class="mr5"
                      @click="editItem(props.item)"
                      src="/static/icon/edit1.png"
                    />
                    <span>Edit</span>
                  </v-tooltip>
                  <v-tooltip top>
                    <img
                      slot="activator"
                      style="cursor:pointer; width:20px; height:20px; "
                      class="mr5"
                      @click="deleteItem(props.item)"
                      src="/static/icon/delete1.png"
                    />
                    <span>Delete</span>
                  </v-tooltip>
6566e8f29   Neeraj Sharma   design and functi...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
                </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   Neeraj Sharma   uplaod images all...
292
                        xs12
f4df757fe   Neeraj Sharma   responsive vie in...
293
                        class="text-xs-center text-sm-center text-md-center text-lg-center my-4"
6566e8f29   Neeraj Sharma   design and functi...
294
                      >
6566e8f29   Neeraj Sharma   design and functi...
295
296
                        <input
                          type="file"
5b841b043   Neeraj Sharma   fix upload dyanm...
297
                          style="display: none"
6566e8f29   Neeraj Sharma   design and functi...
298
299
                          ref="image"
                          accept="image/*"
2b0e316ee   Neeraj Sharma   upload mytiple im...
300
                          multiple
6566e8f29   Neeraj Sharma   design and functi...
301
                          @change="onFilePicked"
5b841b043   Neeraj Sharma   fix upload dyanm...
302
                        />
79006bdcb   Neeraj Sharma   uplaod images all...
303
                        <v-layout justify-center>
5b841b043   Neeraj Sharma   fix upload dyanm...
304
                          <v-flex v-for="(file,index) in files" :key="index" v-if="files">
f4df757fe   Neeraj Sharma   responsive vie in...
305
                            <img :src="file" height="160" width="160px;" class="imgNews" />
6566e8f29   Neeraj Sharma   design and functi...
306
307
                          </v-flex>
                        </v-layout>
5b841b043   Neeraj Sharma   fix upload dyanm...
308
309
310
311
312
313
                        <img
                          src="/static/icon/user.png"
                          v-if="files ==''"
                          height="140"
                          width="180px;"
                        />
6566e8f29   Neeraj Sharma   design and functi...
314
                      </v-flex>
5b841b043   Neeraj Sharma   fix upload dyanm...
315
316
317
                    </v-layout>
                    <v-flex xs12>
                      <v-layout>
aa8fc5033   Neeraj Sharma   implenment all pa...
318
                        <v-flex xs4 sm4 class="pt-4 subheading">
5b841b043   Neeraj Sharma   fix upload dyanm...
319
320
                          <label class="right">Title:</label>
                        </v-flex>
aa8fc5033   Neeraj Sharma   implenment all pa...
321
                        <v-flex sm4 xs8 class="ml-3">
5b841b043   Neeraj Sharma   fix upload dyanm...
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
                          <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   Neeraj Sharma   implenment all pa...
338
                        <v-flex sm4 xs8 class="ml-3">
5b841b043   Neeraj Sharma   fix upload dyanm...
339
340
341
342
343
344
345
346
347
                          <v-text-field
                            placeholder="fill your Description"
                            :rules="descriptionRules"
                            v-model="addNews.description"
                            type="text"
                            name="email"
                            required
                          ></v-text-field>
                        </v-flex>
2b0e316ee   Neeraj Sharma   upload mytiple im...
348
                      </v-layout>
5b841b043   Neeraj Sharma   fix upload dyanm...
349
350
351
352
                    </v-flex>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
aa8fc5033   Neeraj Sharma   implenment all pa...
353
354
                          <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   Neeraj Sharma   fix upload dyanm...
355
                        </v-flex>
aa8fc5033   Neeraj Sharma   implenment all pa...
356
                        <v-flex xs8 sm4 class="ml-3">
5b841b043   Neeraj Sharma   fix upload dyanm...
357
358
359
360
361
362
363
364
365
366
                          <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   Neeraj Sharma   design and functi...
367
                    <v-layout>
f4df757fe   Neeraj Sharma   responsive vie in...
368
369
370
371
372
373
374
375
376
                      <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   Neeraj Sharma   design and functi...
377
378
379
380
381
382
383
384
385
                      </v-flex>
                    </v-layout>
                  </v-container>
                </v-form>
              </v-card>
            </v-flex>
          </v-container>
        </v-tab-item>
      </v-tabs>
4b169b574   Neeraj Sharma   add loader in all...
386
387
388
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
6566e8f29   Neeraj Sharma   design and functi...
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
    </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   Neeraj Sharma   fix upload dyanm...
407
      showLoader: false,
6566e8f29   Neeraj Sharma   design and functi...
408
409
410
411
412
413
414
      dialog: false,
      dialog1: false,
      valid: true,
      isActive: true,
      newActive: false,
      addclass: [],
      addSection: [],
6566e8f29   Neeraj Sharma   design and functi...
415
416
417
418
      AddUsercredentials: {},
      pagination: {
        rowsPerPage: 15
      },
6566e8f29   Neeraj Sharma   design and functi...
419
420
421
      imageName: "",
      imageUrl: "",
      imageFile: "",
2b0e316ee   Neeraj Sharma   upload mytiple im...
422
      image: [],
5b841b043   Neeraj Sharma   fix upload dyanm...
423
424
      upload: "",
      files: [],
6566e8f29   Neeraj Sharma   design and functi...
425
426
427
428
      titleRules: [v => !!v || " Tilte is required"],
      descriptionRules: [v => !!v || " Description is required"],
      headers: [
        {
5f1d4b444   Neeraj Sharma   fix design and fi...
429
          align: "justify-center",
506be6fd7   Neeraj Sharma   implemet dyamic i...
430
          text: "No",
6566e8f29   Neeraj Sharma   design and functi...
431
432
433
          sortable: false,
          value: "No"
        },
5b841b043   Neeraj Sharma   fix upload dyanm...
434
        { text: "Image", vaue: "image", sortable: false, align: "center" },
6566e8f29   Neeraj Sharma   design and functi...
435
        { text: "Title", value: "title", sortable: false, align: "center" },
5b841b043   Neeraj Sharma   fix upload dyanm...
436
437
438
439
440
441
        {
          text: "Description",
          value: "description",
          sortable: false,
          align: "center"
        },
6566e8f29   Neeraj Sharma   design and functi...
442
443
        { text: "Action", value: "", sortable: false, align: "center" }
      ],
8bb178441   Neeraj Sharma   implemnt api in s...
444
      desserts: [],
6566e8f29   Neeraj Sharma   design and functi...
445
446
447
      editedIndex: -1,
      addNews: {
        title: "",
5b841b043   Neeraj Sharma   fix upload dyanm...
448
        description: ""
6566e8f29   Neeraj Sharma   design and functi...
449
450
451
      },
      editedItem: {
        title: "",
5b841b043   Neeraj Sharma   fix upload dyanm...
452
        description: ""
6566e8f29   Neeraj Sharma   design and functi...
453
454
455
456
      },
      defaultItem: {
        title: "",
        description: ""
aa8fc5033   Neeraj Sharma   implenment all pa...
457
      }
6566e8f29   Neeraj Sharma   design and functi...
458
    }),
6566e8f29   Neeraj Sharma   design and functi...
459
460
    methods: {
      getSections(_id) {
5b841b043   Neeraj Sharma   fix upload dyanm...
461
        console.log("_id", _id);
6566e8f29   Neeraj Sharma   design and functi...
462
463
464
465
466
467
468
469
470
471
472
473
474
475
        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   Neeraj Sharma   fix design and fi...
476
            console.log("err====>", err);
6566e8f29   Neeraj Sharma   design and functi...
477
478
479
480
481
482
            // this.$router.replace({ path: '/' });
          });
      },
      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
497
498
499
500
501
502
503
504
505
506
507
508
          }
          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   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
527
528
529
530
        var token = this.$store.state.token;
        http()
          .get("/getNewsList", {
            headers: { Authorization: "Bearer " + token }
          })
          .then(response => {
            this.desserts = response.data.data;
4b169b574   Neeraj Sharma   add loader in all...
531
            this.showLoader = false;
6566e8f29   Neeraj Sharma   design and functi...
532
533
            // console.log("getNewsList=====>",this.desserts)
          })
00e4bc4e1   Neeraj Sharma   fixed auntentication
534
          .catch(error => {
6566e8f29   Neeraj Sharma   design and functi...
535
            // console.log("err====>", err);
4b169b574   Neeraj Sharma   add loader in all...
536
            this.showLoader = false;
aa8fc5033   Neeraj Sharma   implenment all pa...
537
            if (error.response.status === 401) {
a17c68a03   Neeraj Sharma   implement two rou...
538
539
540
541
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
6566e8f29   Neeraj Sharma   design and functi...
542
543
544
          });
      },
      editItem(item) {
8e6d1a7d7   Neeraj Sharma   solve bugs uplaod...
545
        this.files = [];
6566e8f29   Neeraj Sharma   design and functi...
546
547
548
549
550
551
552
553
554
        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   Neeraj Sharma   design and functi...
555
556
557
558
559
560
561
562
563
564
565
566
567
568
      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   Neeraj Sharma   fix design and fi...
569
              this.text = "Successfully delete Existing News";
6566e8f29   Neeraj Sharma   design and functi...
570
571
572
573
574
575
576
            }
            this.getNewsList();
          })
          .catch(error => {
            // console.log(error);
          });
      },
5b841b043   Neeraj Sharma   fix upload dyanm...
577
578
579
      deleteImage(imageId, newsId) {
        console.log(imageId, newsId);
        let deleteImages = {
79006bdcb   Neeraj Sharma   uplaod images all...
580
581
582
583
584
585
          newsId: newsId,
          imageId: imageId
        };
        http()
          .put("/deleteImages", deleteImages)
          .then(response => {
5b841b043   Neeraj Sharma   fix upload dyanm...
586
            console.log("deleteNews", deleteImages);
79006bdcb   Neeraj Sharma   uplaod images all...
587
588
589
590
            if ((this.snackbar = true)) {
              this.text = "Image deleted Successfully";
            }
            this.getNewsList();
8e6d1a7d7   Neeraj Sharma   solve bugs uplaod...
591
            this.close();
79006bdcb   Neeraj Sharma   uplaod images all...
592
593
594
595
596
          })
          .catch(error => {
            console.log(error);
          });
      },
6566e8f29   Neeraj Sharma   design and functi...
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
      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   Neeraj Sharma   design and functi...
620
      submit() {
506be6fd7   Neeraj Sharma   implemet dyamic i...
621
        this.loading = true;
6566e8f29   Neeraj Sharma   design and functi...
622
        if (this.$refs.form.validate()) {
5b841b043   Neeraj Sharma   fix upload dyanm...
623
624
625
626
627
628
629
630
631
632
633
634
635
          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   Neeraj Sharma   upload mytiple im...
636
          }
6566e8f29   Neeraj Sharma   design and functi...
637
          http()
2b0e316ee   Neeraj Sharma   upload mytiple im...
638
            .post("/createNews", newsData)
6566e8f29   Neeraj Sharma   design and functi...
639
            .then(response => {
0551a0f15   Neeraj Sharma   implemnet functio...
640
641
642
              this.files = [];
              this.snackbar = true;
              this.text = "New News added successfully";
6566e8f29   Neeraj Sharma   design and functi...
643
              this.getNewsList();
506be6fd7   Neeraj Sharma   implemet dyamic i...
644
              this.loading = false;
6566e8f29   Neeraj Sharma   design and functi...
645
646
647
              this.clear();
            })
            .catch(error => {
0551a0f15   Neeraj Sharma   implemnet functio...
648
649
              this.snackbar = true;
              this.text = error.response.data.message;
6566e8f29   Neeraj Sharma   design and functi...
650
651
652
            });
        }
      },
6566e8f29   Neeraj Sharma   design and functi...
653
654
      clear() {
        this.$refs.form.reset();
0551a0f15   Neeraj Sharma   implemnet functio...
655
        this.files = [];
6566e8f29   Neeraj Sharma   design and functi...
656
657
      },
      save() {
5b841b043   Neeraj Sharma   fix upload dyanm...
658
659
660
        let editNews = {
          title: this.editedItem.title,
          description: this.editedItem.description,
a17c68a03   Neeraj Sharma   implement two rou...
661
          newsId: this.editedItem._id
5b841b043   Neeraj Sharma   fix upload dyanm...
662
663
        };
        if (this.files) {
a17c68a03   Neeraj Sharma   implement two rou...
664
665
666
667
668
669
670
          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...
671
          }
a17c68a03   Neeraj Sharma   implement two rou...
672
        }
6566e8f29   Neeraj Sharma   design and functi...
673
674
675
676
677
        http()
          .put("/updateNews", editNews)
          .then(response => {
            // console.log("updateNews",updateNews);
            if ((this.snackbar = true)) {
5f1d4b444   Neeraj Sharma   fix design and fi...
678
              this.text = "Successfully Edit Existing News";
6566e8f29   Neeraj Sharma   design and functi...
679
680
            }
            this.getNewsList();
79006bdcb   Neeraj Sharma   uplaod images all...
681
            this.close();
6566e8f29   Neeraj Sharma   design and functi...
682
683
684
685
          })
          .catch(error => {
            // console.log(error);
          });
aa8fc5033   Neeraj Sharma   implenment all pa...
686
      }
6566e8f29   Neeraj Sharma   design and functi...
687
688
689
    },
    mounted() {
      this.getNewsList();
5b841b043   Neeraj Sharma   fix upload dyanm...
690
      this.editItem;
6566e8f29   Neeraj Sharma   design and functi...
691
    },
a17c68a03   Neeraj Sharma   implement two rou...
692
693
694
695
696
697
698
699
    created() {
      this.$root.$on("app:search", search => {
        this.search = search;
      });
    },
    beforeDestroy() {
      // dont forget to remove the listener
      this.$root.$off("app:search");
6566e8f29   Neeraj Sharma   design and functi...
700
701
702
703
    }
  };
  </script>
  <style scoped>
6566e8f29   Neeraj Sharma   design and functi...
704
  .active {
687e0b929   Neeraj Sharma   add user,attenden...
705
    background-color: gray;
6566e8f29   Neeraj Sharma   design and functi...
706
707
708
709
710
    color: white !important;
  }
  .activebtn {
    color: black !important;
  }
6566e8f29   Neeraj Sharma   design and functi...
711
  </style>