Blame view

src/pages/News/news.vue 22.8 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
                      </v-flex>
b55157526   Neeraj Sharma   fixed upload imag...
81
82
83
84
85
86
87
                      <img
                        src="/static/icon/user.png"
                        v-if="files == '' && editedItem.newsImageUrl == ''"
                        height="160"
                        width="160"
                        alt="News"
                      />
6566e8f29   Neeraj Sharma   design and functi...
88
                    </v-layout>
f4df757fe   Neeraj Sharma   responsive vie in...
89
90
91
92
93
                  </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
                <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>
6566e8f29   Neeraj Sharma   design and functi...
168
              <v-card-text>
b4b24ab44   Neeraj Sharma   fixed all
169
170
171
172
173
174
175
176
177
178
179
180
                <v-flex align-center justify-center layout text-xs-center>
                  <span v-for="(image,i) in editedItem.newsImageUrl" :key="i" class="mt-4 pa-2">
                    <img :src="image.imageUrl" alt="News" width="240" height="180" class="imgNews" />
                  </span>
                  <img
                    src="/static/icon/user.png"
                    v-if="editedItem.newsImageUrl == ''"
                    height="100"
                    width="100"
                    alt="News"
                  />
                </v-flex>
6566e8f29   Neeraj Sharma   design and functi...
181
182
183
                <v-container grid-list-md>
                  <v-layout wrap>
                    <v-flex>
6566e8f29   Neeraj Sharma   design and functi...
184
185
                      <v-layout>
                        <v-flex xs5 sm6>
5b841b043   Neeraj Sharma   fix upload dyanm...
186
187
188
                          <h5 class="right my-1">
                            <b>Title:</b>
                          </h5>
6566e8f29   Neeraj Sharma   design and functi...
189
190
191
192
193
194
195
                        </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...
196
197
198
                          <h5 class="right my-1">
                            <b>Description:</b>
                          </h5>
6566e8f29   Neeraj Sharma   design and functi...
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
                        </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...
228
              <td class="text-xs-center">{{ props.index + 1}}</td>
5b841b043   Neeraj Sharma   fix upload dyanm...
229
230
231
232
              <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>
9a1e18aba   Neeraj Sharma   display static im...
233
234
235
236
237
238
                <img
                  src="/static/icon/user.png"
                  v-if="props.item.newsImageUrl == ''"
                  width="60"
                  alt="News"
                />
5b841b043   Neeraj Sharma   fix upload dyanm...
239
              </td>
6566e8f29   Neeraj Sharma   design and functi...
240
241
242
243
              <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">
9a1e18aba   Neeraj Sharma   display static im...
244
                <span>
495e4037c   Neeraj Sharma   update
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
                  <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...
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
                </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...
305
                        xs12
f4df757fe   Neeraj Sharma   responsive vie in...
306
                        class="text-xs-center text-sm-center text-md-center text-lg-center my-4"
6566e8f29   Neeraj Sharma   design and functi...
307
                      >
6566e8f29   Neeraj Sharma   design and functi...
308
309
                        <input
                          type="file"
5b841b043   Neeraj Sharma   fix upload dyanm...
310
                          style="display: none"
6566e8f29   Neeraj Sharma   design and functi...
311
312
                          ref="image"
                          accept="image/*"
2b0e316ee   Neeraj Sharma   upload mytiple im...
313
                          multiple
6566e8f29   Neeraj Sharma   design and functi...
314
                          @change="onFilePicked"
5b841b043   Neeraj Sharma   fix upload dyanm...
315
                        />
79006bdcb   Neeraj Sharma   uplaod images all...
316
                        <v-layout justify-center>
5b841b043   Neeraj Sharma   fix upload dyanm...
317
                          <v-flex v-for="(file,index) in files" :key="index" v-if="files">
f4df757fe   Neeraj Sharma   responsive vie in...
318
                            <img :src="file" height="160" width="160px;" class="imgNews" />
6566e8f29   Neeraj Sharma   design and functi...
319
320
                          </v-flex>
                        </v-layout>
5b841b043   Neeraj Sharma   fix upload dyanm...
321
322
323
324
325
326
                        <img
                          src="/static/icon/user.png"
                          v-if="files ==''"
                          height="140"
                          width="180px;"
                        />
6566e8f29   Neeraj Sharma   design and functi...
327
                      </v-flex>
5b841b043   Neeraj Sharma   fix upload dyanm...
328
329
330
                    </v-layout>
                    <v-flex xs12>
                      <v-layout>
aa8fc5033   Neeraj Sharma   implenment all pa...
331
                        <v-flex xs4 sm4 class="pt-4 subheading">
5b841b043   Neeraj Sharma   fix upload dyanm...
332
333
                          <label class="right">Title:</label>
                        </v-flex>
aa8fc5033   Neeraj Sharma   implenment all pa...
334
                        <v-flex sm4 xs8 class="ml-3">
5b841b043   Neeraj Sharma   fix upload dyanm...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
                          <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...
351
                        <v-flex sm4 xs8 class="ml-3">
5b841b043   Neeraj Sharma   fix upload dyanm...
352
353
354
355
356
357
358
359
360
                          <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...
361
                      </v-layout>
5b841b043   Neeraj Sharma   fix upload dyanm...
362
363
364
365
                    </v-flex>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
aa8fc5033   Neeraj Sharma   implenment all pa...
366
367
                          <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...
368
                        </v-flex>
aa8fc5033   Neeraj Sharma   implenment all pa...
369
                        <v-flex xs8 sm4 class="ml-3">
5b841b043   Neeraj Sharma   fix upload dyanm...
370
371
372
373
374
375
376
377
378
379
                          <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...
380
                    <v-layout>
f4df757fe   Neeraj Sharma   responsive vie in...
381
382
383
384
385
386
387
388
389
                      <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...
390
391
392
393
394
395
396
397
398
                      </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...
399
400
401
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
6566e8f29   Neeraj Sharma   design and functi...
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
    </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...
420
      showLoader: false,
6566e8f29   Neeraj Sharma   design and functi...
421
422
423
424
425
426
427
      dialog: false,
      dialog1: false,
      valid: true,
      isActive: true,
      newActive: false,
      addclass: [],
      addSection: [],
6566e8f29   Neeraj Sharma   design and functi...
428
429
430
431
      AddUsercredentials: {},
      pagination: {
        rowsPerPage: 15
      },
6566e8f29   Neeraj Sharma   design and functi...
432
433
434
      imageName: "",
      imageUrl: "",
      imageFile: "",
2b0e316ee   Neeraj Sharma   upload mytiple im...
435
      image: [],
5b841b043   Neeraj Sharma   fix upload dyanm...
436
437
      upload: "",
      files: [],
6566e8f29   Neeraj Sharma   design and functi...
438
439
440
441
      titleRules: [v => !!v || " Tilte is required"],
      descriptionRules: [v => !!v || " Description is required"],
      headers: [
        {
5f1d4b444   Neeraj Sharma   fix design and fi...
442
          align: "justify-center",
506be6fd7   Neeraj Sharma   implemet dyamic i...
443
          text: "No",
6566e8f29   Neeraj Sharma   design and functi...
444
445
446
          sortable: false,
          value: "No"
        },
5b841b043   Neeraj Sharma   fix upload dyanm...
447
        { text: "Image", vaue: "image", sortable: false, align: "center" },
6566e8f29   Neeraj Sharma   design and functi...
448
        { text: "Title", value: "title", sortable: false, align: "center" },
5b841b043   Neeraj Sharma   fix upload dyanm...
449
450
451
452
453
454
        {
          text: "Description",
          value: "description",
          sortable: false,
          align: "center"
        },
6566e8f29   Neeraj Sharma   design and functi...
455
456
        { text: "Action", value: "", sortable: false, align: "center" }
      ],
8bb178441   Neeraj Sharma   implemnt api in s...
457
      desserts: [],
6566e8f29   Neeraj Sharma   design and functi...
458
459
460
      editedIndex: -1,
      addNews: {
        title: "",
5b841b043   Neeraj Sharma   fix upload dyanm...
461
        description: ""
6566e8f29   Neeraj Sharma   design and functi...
462
463
464
      },
      editedItem: {
        title: "",
5b841b043   Neeraj Sharma   fix upload dyanm...
465
        description: ""
6566e8f29   Neeraj Sharma   design and functi...
466
467
468
469
      },
      defaultItem: {
        title: "",
        description: ""
aa8fc5033   Neeraj Sharma   implenment all pa...
470
      }
6566e8f29   Neeraj Sharma   design and functi...
471
    }),
6566e8f29   Neeraj Sharma   design and functi...
472
473
    methods: {
      getSections(_id) {
5b841b043   Neeraj Sharma   fix upload dyanm...
474
        console.log("_id", _id);
6566e8f29   Neeraj Sharma   design and functi...
475
476
477
478
479
480
481
482
483
484
485
486
487
488
        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...
489
            console.log("err====>", err);
6566e8f29   Neeraj Sharma   design and functi...
490
491
492
493
494
495
            // this.$router.replace({ path: '/' });
          });
      },
      pickFile() {
        this.$refs.image.click();
      },
6566e8f29   Neeraj Sharma   design and functi...
496
497
498
      onFilePicked(e) {
        // console.log(e)
        const files = e.target.files;
5b841b043   Neeraj Sharma   fix upload dyanm...
499
        /** fetch Image Name **/
6566e8f29   Neeraj Sharma   design and functi...
500
501
502
503
        if (files[0] !== undefined) {
          this.imageName = files[0].name;
          if (this.imageName.lastIndexOf(".") <= 0) {
            return;
5b841b043   Neeraj Sharma   fix upload dyanm...
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
          }
          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...
522
          });
5b841b043   Neeraj Sharma   fix upload dyanm...
523
524
525
526
527
          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...
528
          });
6566e8f29   Neeraj Sharma   design and functi...
529
530
531
532
533
534
535
        } else {
          this.imageName = "";
          this.imageFile = "";
          this.imageUrl = "";
        }
      },
      getNewsList() {
4b169b574   Neeraj Sharma   add loader in all...
536
        this.showLoader = true;
6566e8f29   Neeraj Sharma   design and functi...
537
538
539
540
541
542
543
        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...
544
            this.showLoader = false;
6566e8f29   Neeraj Sharma   design and functi...
545
546
            // console.log("getNewsList=====>",this.desserts)
          })
00e4bc4e1   Neeraj Sharma   fixed auntentication
547
          .catch(error => {
6566e8f29   Neeraj Sharma   design and functi...
548
            // console.log("err====>", err);
4b169b574   Neeraj Sharma   add loader in all...
549
            this.showLoader = false;
aa8fc5033   Neeraj Sharma   implenment all pa...
550
            if (error.response.status === 401) {
a17c68a03   Neeraj Sharma   implement two rou...
551
552
553
554
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
6566e8f29   Neeraj Sharma   design and functi...
555
556
557
          });
      },
      editItem(item) {
8e6d1a7d7   Neeraj Sharma   solve bugs uplaod...
558
        this.files = [];
6566e8f29   Neeraj Sharma   design and functi...
559
560
561
562
563
564
565
566
567
        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...
568
569
570
571
572
573
574
575
576
577
578
579
580
581
      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...
582
              this.text = "Successfully delete Existing News";
6566e8f29   Neeraj Sharma   design and functi...
583
584
585
586
587
588
589
            }
            this.getNewsList();
          })
          .catch(error => {
            // console.log(error);
          });
      },
5b841b043   Neeraj Sharma   fix upload dyanm...
590
591
592
      deleteImage(imageId, newsId) {
        console.log(imageId, newsId);
        let deleteImages = {
79006bdcb   Neeraj Sharma   uplaod images all...
593
594
595
596
597
598
          newsId: newsId,
          imageId: imageId
        };
        http()
          .put("/deleteImages", deleteImages)
          .then(response => {
5b841b043   Neeraj Sharma   fix upload dyanm...
599
            console.log("deleteNews", deleteImages);
79006bdcb   Neeraj Sharma   uplaod images all...
600
601
602
603
            if ((this.snackbar = true)) {
              this.text = "Image deleted Successfully";
            }
            this.getNewsList();
8e6d1a7d7   Neeraj Sharma   solve bugs uplaod...
604
            this.close();
79006bdcb   Neeraj Sharma   uplaod images all...
605
606
607
608
609
          })
          .catch(error => {
            console.log(error);
          });
      },
6566e8f29   Neeraj Sharma   design and functi...
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
      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...
633
634
      submit() {
        if (this.$refs.form.validate()) {
5b841b043   Neeraj Sharma   fix upload dyanm...
635
636
637
638
639
640
641
642
643
644
645
646
647
          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...
648
          }
9a1e18aba   Neeraj Sharma   display static im...
649
          this.loading = true;
6566e8f29   Neeraj Sharma   design and functi...
650
          http()
2b0e316ee   Neeraj Sharma   upload mytiple im...
651
            .post("/createNews", newsData)
6566e8f29   Neeraj Sharma   design and functi...
652
            .then(response => {
0551a0f15   Neeraj Sharma   implemnet functio...
653
654
655
              this.files = [];
              this.snackbar = true;
              this.text = "New News added successfully";
6566e8f29   Neeraj Sharma   design and functi...
656
              this.getNewsList();
506be6fd7   Neeraj Sharma   implemet dyamic i...
657
              this.loading = false;
6566e8f29   Neeraj Sharma   design and functi...
658
659
660
              this.clear();
            })
            .catch(error => {
0551a0f15   Neeraj Sharma   implemnet functio...
661
662
              this.snackbar = true;
              this.text = error.response.data.message;
6566e8f29   Neeraj Sharma   design and functi...
663
664
665
            });
        }
      },
6566e8f29   Neeraj Sharma   design and functi...
666
667
      clear() {
        this.$refs.form.reset();
0551a0f15   Neeraj Sharma   implemnet functio...
668
        this.files = [];
6566e8f29   Neeraj Sharma   design and functi...
669
670
      },
      save() {
5b841b043   Neeraj Sharma   fix upload dyanm...
671
672
673
        let editNews = {
          title: this.editedItem.title,
          description: this.editedItem.description,
a17c68a03   Neeraj Sharma   implement two rou...
674
          newsId: this.editedItem._id
5b841b043   Neeraj Sharma   fix upload dyanm...
675
676
        };
        if (this.files) {
a17c68a03   Neeraj Sharma   implement two rou...
677
678
679
680
681
682
683
          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...
684
          }
a17c68a03   Neeraj Sharma   implement two rou...
685
        }
6566e8f29   Neeraj Sharma   design and functi...
686
687
688
689
690
        http()
          .put("/updateNews", editNews)
          .then(response => {
            // console.log("updateNews",updateNews);
            if ((this.snackbar = true)) {
5f1d4b444   Neeraj Sharma   fix design and fi...
691
              this.text = "Successfully Edit Existing News";
6566e8f29   Neeraj Sharma   design and functi...
692
693
            }
            this.getNewsList();
79006bdcb   Neeraj Sharma   uplaod images all...
694
            this.close();
6566e8f29   Neeraj Sharma   design and functi...
695
696
697
698
          })
          .catch(error => {
            // console.log(error);
          });
aa8fc5033   Neeraj Sharma   implenment all pa...
699
      }
6566e8f29   Neeraj Sharma   design and functi...
700
701
702
    },
    mounted() {
      this.getNewsList();
5b841b043   Neeraj Sharma   fix upload dyanm...
703
      this.editItem;
6566e8f29   Neeraj Sharma   design and functi...
704
    },
a17c68a03   Neeraj Sharma   implement two rou...
705
706
707
708
709
710
711
712
    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...
713
714
715
716
    }
  };
  </script>
  <style scoped>
6566e8f29   Neeraj Sharma   design and functi...
717
  .active {
687e0b929   Neeraj Sharma   add user,attenden...
718
    background-color: gray;
6566e8f29   Neeraj Sharma   design and functi...
719
720
721
722
723
    color: white !important;
  }
  .activebtn {
    color: black !important;
  }
6566e8f29   Neeraj Sharma   design and functi...
724
  </style>