Blame view

src/pages/Gallery/gallery.vue 29.8 KB
8bb178441   Neeraj Sharma   implemnt api in s...
1
2
  <template>
    <v-app id="pages-dasboard">
8bb178441   Neeraj Sharma   implemnt api in s...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
      <v-tabs grow slider-color="black">
        <v-tab
          ripple
          @click="activeTab('existing')"
          v-bind:class="{ active: isActive }"
          id="tab"
          class="subheading"
        >Existing Gallery</v-tab>
        <v-tab
          ripple
          @click="activeTab('new')"
          v-bind:class="{ active: newActive }"
          id="tab1"
          User
          class="subheading"
        >Add Gallery</v-tab>
  
        <!-- ****** EDITS ALL Gallery DETAILS ****** -->
  
        <v-tab-item>
          <v-snackbar
            :timeout="timeout"
            :top="y === 'top'"
            :right="x === 'right'"
            :vertical="mode === 'vertical'"
            v-model="snackbar"
            color="success"
          >{{ text }}</v-snackbar>
          <v-dialog v-model="dialog" max-width="1000px" scrollable>
            <v-card flat>
              <v-toolbar class="grey lighten-2" flat>
                <v-spacer></v-spacer>
                <v-toolbar-title>
                  <h3>Edit Gallery</h3>
                </v-toolbar-title>
                <v-spacer></v-spacer>
              </v-toolbar>
a17c68a03   Neeraj Sharma   implement two rou...
40
              <v-card-text style="height:700px;">
8bb178441   Neeraj Sharma   implemnt api in s...
41
42
43
44
45
46
47
48
49
50
                <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 mr-4"
                      >
                        <input
                          type="file"
                          style="display: none"
a17c68a03   Neeraj Sharma   implement two rou...
51
                          ref="editImage"
8bb178441   Neeraj Sharma   implemnt api in s...
52
53
                          accept="image/*"
                          multiple
a17c68a03   Neeraj Sharma   implement two rou...
54
                          @change="editFilePicked"
8bb178441   Neeraj Sharma   implemnt api in s...
55
56
57
58
59
60
61
62
63
                        />
                        <v-layout justify-center>
                          <v-flex
                            xs3
                            v-for="Image in editedItem.imageUrl"
                            :key="Image._id"
                            v-if="editedItem.imageUrl"
                            class="profile-image-wrapper"
                          >
a17c68a03   Neeraj Sharma   implement two rou...
64
65
66
67
68
69
70
                            <img
                              :src="Image.imageLink"
                              height="160"
                              width="160"
                              alt="Gallery"
                              class="pa-2"
                            />
8bb178441   Neeraj Sharma   implemnt api in s...
71
72
73
74
75
76
                            <v-icon
                              class="red edit-profile-icon"
                              dark
                              @click="deleteImage(Image._id,editedItem._id)"
                            >close</v-icon>
                          </v-flex>
a17c68a03   Neeraj Sharma   implement two rou...
77
                          <v-flex v-for="(file, index) in editFiles" :key="index">
8bb178441   Neeraj Sharma   implemnt api in s...
78
79
80
81
82
                            <img :src="file" height="160" width="160" class="pa-2" />
                          </v-flex>
                        </v-layout>
                        <img
                          src="/static/icon/user.png"
a17c68a03   Neeraj Sharma   implement two rou...
83
                          v-if="editedItem.imageUrl == '' && editFiles == ''"
8bb178441   Neeraj Sharma   implemnt api in s...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
                          height="160"
                          width="160"
                          alt="Gallery"
                        />
                      </v-flex>
                    </v-layout>
                    <!-- </v-layout> -->
                    <v-layout>
                      <v-flex xs12 sm12>
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
                            <label class="right">Title:</label>
                          </v-flex>
                          <v-flex xs5 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>
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <v-text-field
                              placeholder="fill your Description"
                              v-model="editedItem.description"
                              type="text"
                              name="email"
                              required
                            ></v-text-field>
                          </v-flex>
                        </v-layout>
                      </v-flex>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Select Class:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-select
                            :items="addclass"
                            label="Select Class"
1571e40b5   Neeraj Sharma   gallery and socia...
132
                            v-model="editedItem.classNum"
8bb178441   Neeraj Sharma   implemnt api in s...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
                            item-text="classNum"
                            item-value="_id"
                            name="Select Class"
                            required
                          ></v-select>
                        </v-flex>
                      </v-layout>
                      <v-flex xs12>
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
                            <label class="right">Add New Images:</label>
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <v-text-field
                              label="Select Image"
a17c68a03   Neeraj Sharma   implement two rou...
148
149
                              @click="editPickFile"
                              v-model="editImageName"
8bb178441   Neeraj Sharma   implemnt api in s...
150
151
152
153
154
155
156
                              append-icon="attach_file"
                              multiple
                            ></v-text-field>
                          </v-flex>
                        </v-layout>
                      </v-flex>
                    </v-layout>
a17c68a03   Neeraj Sharma   implement two rou...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
                    <v-flex xs12>
                      <div v-for="(editImage,index) in editedItem.youTubeLinkUrl" :key="index">
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
                            <label class="right">You Tube Link Url:</label>
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <v-text-field
                              v-model="editImage.youTubeLink"
                              type="text"
                              name="link"
                              required
                            ></v-text-field>
                          </v-flex>
                          <v-flex xs2 class="pt-4">
                            <v-icon @click="deleteUrl(index,editImage._id,editedItem._id)">cancel</v-icon>
                          </v-flex>
                        </v-layout>
                      </div>
                    </v-flex>
                    <v-flex xs12>
                      <div v-for="(updateImage,index) in updates" :key="index">
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
                            <label class="right">You Tube Link Url:</label>
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <v-text-field
                              v-model="updateImage.youTubeLink"
                              label="Upload new you tube link url"
                              type="text"
                              name="link"
                              required
                            ></v-text-field>
                          </v-flex>
                          <v-flex xs2 class="pt-4">
                            <v-icon @click="deleteUpdate(index)" v-if="index !=0">cancel</v-icon>
                            <v-icon @click="update">add_circle</v-icon>
                          </v-flex>
                        </v-layout>
                      </div>
                    </v-flex>
8bb178441   Neeraj Sharma   implemnt api in s...
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
                    <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>
                  </v-container>
                </v-form>
              </v-card-text>
            </v-card>
          </v-dialog>
  
          <!-- ****** PROFILE VIEW Gallery ******  -->
1571e40b5   Neeraj Sharma   gallery and socia...
215
          <v-dialog v-model="dialog1" max-width="940px">
8bb178441   Neeraj Sharma   implemnt api in s...
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
            <v-card>
              <v-toolbar color="grey lighten-2" flat>
                <v-spacer></v-spacer>
                <v-toolbar-title>
                  <h3>Gallery</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>
                <v-avatar size="100" v-if="editedItem.imageUrl == ''" class="mt-4 pa-2">
                  <img src="/static/icon/user.png" width="240" height="180" />
                </v-avatar>
                <span
                  v-for="(image,i) in editedItem.imageUrl"
                  :key="i"
                  class="mt-4 pa-2"
                  v-if="editedItem.imageUrl"
                >
a17c68a03   Neeraj Sharma   implement two rou...
235
                  <img :src="image.imageLink" alt="Gallery" width="240" height="180" />
8bb178441   Neeraj Sharma   implemnt api in s...
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-flex>
              <v-card-text>
                <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>
                        </v-flex>
                        <v-flex sm6 xs8>
                          <h5 class="my-1">{{ editedItem.title }}</h5>
                        </v-flex>
                      </v-layout>
                      <v-layout>
                        <v-flex xs5 sm6>
                          <h5 class="right my-1">
                            <b>Description:</b>
                          </h5>
                        </v-flex>
                        <v-flex sm6 xs8>
                          <h5 class="my-1">{{ editedItem.description }}</h5>
                        </v-flex>
                      </v-layout>
a17c68a03   Neeraj Sharma   implement two rou...
262
263
264
265
266
267
268
                      <v-layout>
                        <v-flex xs5 sm6>
                          <h5 class="right my-1">
                            <b>You Tube Link Url:</b>
                          </h5>
                        </v-flex>
                        <v-flex sm6 xs8>
1571e40b5   Neeraj Sharma   gallery and socia...
269
270
271
272
                          <h5 class="my-1 ml-3">
                            <ul v-for="youTubeLinkUrl in editedItem.youTubeLinkUrl">
                              <li>{{ youTubeLinkUrl.youTubeLink }}</li>
                            </ul>
a17c68a03   Neeraj Sharma   implement two rou...
273
274
275
                          </h5>
                        </v-flex>
                      </v-layout>
8bb178441   Neeraj Sharma   implemnt api in s...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
                    </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 Gallery TABLE ****** -->
          <v-data-table
            :headers="headers"
            :items="desserts"
            :pagination.sync="pagination"
            :search="search"
          >
            <template slot="items" slot-scope="props">
1571e40b5   Neeraj Sharma   gallery and socia...
300
              <td class="text-xs-center">{{ props.index }}</td>
8bb178441   Neeraj Sharma   implemnt api in s...
301
302
              <td id="td" class="text-xs-center">
                <span v-for="(image,_id) in props.item.imageUrl" class="pa-2">
a17c68a03   Neeraj Sharma   implement two rou...
303
                  <img :src="image.imageLink" alt="newsImage" width="100" height="70" />
8bb178441   Neeraj Sharma   implemnt api in s...
304
305
306
307
                </span>
              </td>
              <td id="td" class="text-xs-center">{{ props.item.title}}</td>
              <td id="td" class="text-xs-center">{{ props.item.description}}</td>
a17c68a03   Neeraj Sharma   implement two rou...
308
              <td id="td" class="text-xs-center">
8bb178441   Neeraj Sharma   implemnt api in s...
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
                <span>
                  <img
                    style="cursor:pointer; width:25px; height:18px; "
                    class="mr-5"
                    @click="profile(props.item)"
                    src="/static/icon/eye1.png"
                  />
                  <img
                    style="cursor:pointer; width:20px; height:18px; "
                    class="mr-5"
                    @click="editItem(props.item)"
                    src="/static/icon/edit1.png"
                  />
                  <img
                    style="cursor:pointer;width:20px; height:20px; "
                    class="mr-5"
                    @click="deleteItem(props.item)"
                    src="/static/icon/delete1.png"
                  />
                </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 Gallery Data ****** -->
  
        <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
                        xs12
                        class="text-xs-center text-sm-center text-md-center text-lg-center my-4 mr-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="160" width="160px;" />
                          </v-flex>
                        </v-layout>
                        <img
                          src="/static/icon/user.png"
                          v-if="files ==''"
                          height="140"
                          width="180px;"
                        />
                      </v-flex>
                    </v-layout>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Title:</label>
                        </v-flex>
                        <v-flex xs4 class="ml-3">
                          <v-text-field
                            v-model="addGallery.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 xs4 class="ml-3">
                          <v-text-field
                            placeholder="fill your Description"
                            :rules="descriptionRules"
                            v-model="addGallery.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">Select Class:</label>
                        </v-flex>
                        <v-flex xs4 class="ml-3">
                          <v-select
                            :items="addclass"
                            label="Select Class"
                            v-model="addGallery.classNum"
                            item-text="classNum"
                            item-value="_id"
                            name="Select Class"
                            required
                          ></v-select>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Uplaod Image:</label>
                        </v-flex>
                        <v-flex xs4 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 xs12>
                        <div v-for="(youTubeLink,index) in finds" :key="index">
                          <v-layout>
                            <v-flex xs4 class="pt-4 subheading">
                              <label class="right">You Tube Link Url:</label>
                            </v-flex>
                            <v-flex xs4 class="ml-3">
                              <v-text-field
                                placeholder="fill your youtube link"
                                v-model="youTubeLink.value"
                                type="text"
                                name="link"
                                required
                              ></v-text-field>
8bb178441   Neeraj Sharma   implemnt api in s...
465
466
                            </v-flex>
                            <v-flex xs2 class="pt-4">
a17c68a03   Neeraj Sharma   implement two rou...
467
                              <v-icon @click="deleteFind(index)" v-if="index !=0 ">cancel</v-icon>
8bb178441   Neeraj Sharma   implemnt api in s...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
                              <v-icon @click="addFind">add_circle</v-icon>
                            </v-flex>
                          </v-layout>
                        </div>
                      </v-flex>
                      <v-flex xs12 sm6 offset-sm3>
                        <v-card-actions>
                          <v-btn @click="clear" round dark>clear</v-btn>
                          <v-spacer></v-spacer>
                          <v-btn @click="submit" round dark :loading="loading">Add</v-btn>
                        </v-card-actions>
                      </v-flex>
                    </v-layout>
                  </v-container>
                </v-form>
              </v-card>
            </v-flex>
          </v-container>
        </v-tab-item>
      </v-tabs>
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
    </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: "",
      showLoader: false,
      dialog: false,
      dialog1: false,
      valid: true,
      isActive: true,
      newActive: false,
      addclass: [],
      addSection: [],
      finds: [{ value: "" }],
a17c68a03   Neeraj Sharma   implement two rou...
518
519
      updates: [{ youTubeLink: "" }],
      youTubeLink: {},
8bb178441   Neeraj Sharma   implemnt api in s...
520
521
522
523
524
525
526
527
528
529
530
      addGallery: {
        youTubeLinkUrl: []
      },
      pagination: {
        rowsPerPage: 15
      },
      imageName: "",
      imageUrl: "",
      imageFile: "",
      image: [],
      upload: "",
a17c68a03   Neeraj Sharma   implement two rou...
531
532
      editImageName: "",
      editFiles: [],
8bb178441   Neeraj Sharma   implemnt api in s...
533
      files: [],
8bb178441   Neeraj Sharma   implemnt api in s...
534
535
536
537
538
539
540
541
      token: "",
      titleRules: [v => !!v || " Tilte is required"],
      descriptionRules: [v => !!v || " Description is required"],
      headers: [
        {
          align: "justify-center",
          text: "No",
          sortable: false,
1571e40b5   Neeraj Sharma   gallery and socia...
542
          value: "index"
8bb178441   Neeraj Sharma   implemnt api in s...
543
544
545
546
547
548
549
550
551
552
553
554
555
        },
        { text: "Image", vaue: "image", sortable: false, align: "center" },
        { text: "Title", value: "title", sortable: false, align: "center" },
        {
          text: "Description",
          value: "description",
          sortable: false,
          align: "center"
        },
        { text: "Action", value: "", sortable: false, align: "center" }
      ],
      desserts: [],
      editedIndex: -1,
1571e40b5   Neeraj Sharma   gallery and socia...
556
557
      editedItem: {},
      index: ""
8bb178441   Neeraj Sharma   implemnt api in s...
558
559
    }),
    methods: {
8bb178441   Neeraj Sharma   implemnt api in s...
560
561
562
      pickFile() {
        this.$refs.image.click();
      },
a17c68a03   Neeraj Sharma   implement two rou...
563
564
565
      editPickFile() {
        this.$refs.editImage.click();
      },
8bb178441   Neeraj Sharma   implemnt api in s...
566
      onFilePicked(e) {
8bb178441   Neeraj Sharma   implemnt api in s...
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
        const files = e.target.files;
        /** fetch Image Name **/
        if (files[0] !== undefined) {
          this.imageName = files[0].name;
          if (this.imageName.lastIndexOf(".") <= 0) {
            return;
          }
          this.files = [];
          // console.log("files", this.files);
          /** Select many image and showing many image add to Gallery 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
                );
              };
a17c68a03   Neeraj Sharma   implement two rou...
586
              console.log("uploadImage=======>", this.files);
8bb178441   Neeraj Sharma   implemnt api in s...
587
588
589
590
591
592
593
594
595
596
            });
            fr.readAsDataURL(file);
            return getResult.then(file => {
              return file;
            });
          });
          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...
8bb178441   Neeraj Sharma   implemnt api in s...
597
598
599
600
601
602
603
          });
        } else {
          this.imageName = "";
          this.imageFile = "";
          this.imageUrl = "";
        }
      },
a17c68a03   Neeraj Sharma   implement two rou...
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
      editFilePicked(e) {
        const files = e.target.files;
        /** fetch Image Name **/
        if (files[0] !== undefined) {
          this.editImageName = files[0].name;
          if (this.editImageName.lastIndexOf(".") <= 0) {
            return;
          }
          /** Select many image and showing many image add to Gallery card **/
          const test = Array.from(files).forEach((file, idx) => {
            const fr = new FileReader();
            const getResult = new Promise(resolve => {
              fr.onload = e => {
                this.editFiles.push(
                  // id: idx,
                  e.target.result
                );
              };
              console.log("uploadImage=======>", this.files);
            });
            fr.readAsDataURL(file);
            return getResult.then(file => {
              return file;
            });
          });
          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...
          // });
        } else {
          this.editImageName = "";
          this.editFiles = "";
        }
      },
8bb178441   Neeraj Sharma   implemnt api in s...
639
640
641
642
643
644
645
646
647
648
      getGalleryList() {
        this.showLoader = true;
        http()
          .get("/getGalleryList", {
            headers: { Authorization: "Bearer " + this.token }
          })
          .then(response => {
            this.desserts = response.data.data;
            this.showLoader = false;
          })
1571e40b5   Neeraj Sharma   gallery and socia...
649
          .catch(error => {
8bb178441   Neeraj Sharma   implemnt api in s...
650
651
            // console.log("err====>", err);
            this.showLoader = false;
a17c68a03   Neeraj Sharma   implement two rou...
652
653
654
655
656
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
8bb178441   Neeraj Sharma   implemnt api in s...
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
          });
      },
      editItem(item) {
        this.files = [];
        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;
      },
      deleteItem(item) {
        let deleteGallery = {
a17c68a03   Neeraj Sharma   implement two rou...
672
          galleryId: item._id
8bb178441   Neeraj Sharma   implemnt api in s...
673
674
675
        };
        http()
          .delete(
a17c68a03   Neeraj Sharma   implement two rou...
676
            "/deleteGallery",
8bb178441   Neeraj Sharma   implemnt api in s...
677
            confirm("Are you sure you want to delete this?") && {
a17c68a03   Neeraj Sharma   implement two rou...
678
679
680
681
              params: deleteGallery,
              headers: {
                Authorization: "Bearer " + this.token
              }
8bb178441   Neeraj Sharma   implemnt api in s...
682
683
684
685
686
687
            }
          )
          .then(response => {
            if ((this.snackbar = true)) {
              this.text = "Successfully delete Existing News";
            }
a17c68a03   Neeraj Sharma   implement two rou...
688
            this.getGalleryList();
8bb178441   Neeraj Sharma   implemnt api in s...
689
690
691
692
693
          })
          .catch(error => {
            // console.log(error);
          });
      },
a17c68a03   Neeraj Sharma   implement two rou...
694
695
      deleteImage(imageId, id) {
        console.log("imageId", imageId, "id", id);
8bb178441   Neeraj Sharma   implemnt api in s...
696
        let deleteImages = {
a17c68a03   Neeraj Sharma   implement two rou...
697
          galleryId: id,
8bb178441   Neeraj Sharma   implemnt api in s...
698
699
700
          imageId: imageId
        };
        http()
a17c68a03   Neeraj Sharma   implement two rou...
701
          .put("/deleteImage", deleteImages)
8bb178441   Neeraj Sharma   implemnt api in s...
702
          .then(response => {
a17c68a03   Neeraj Sharma   implement two rou...
703
704
705
            this.snackbar = true;
            this.text = response.data.message;
            this.getGalleryList();
8bb178441   Neeraj Sharma   implemnt api in s...
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
            this.close();
          })
          .catch(error => {
            console.log(error);
          });
      },
      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;
      },
      submit() {
        this.loading = true;
a17c68a03   Neeraj Sharma   implement two rou...
737
738
739
        for (let i = 0; i < this.finds.length; i++) {
          this.addGallery.youTubeLinkUrl.push(this.finds[i].value);
        }
8bb178441   Neeraj Sharma   implemnt api in s...
740
741
742
743
744
745
746
747
748
749
750
751
752
753
        if (this.$refs.form.validate()) {
          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);
              this.addGallery.upload = imageData;
            }
          }
          http()
            .post("/createGallery", this.addGallery)
            .then(response => {
a17c68a03   Neeraj Sharma   implement two rou...
754
              this.getGalleryList();
8bb178441   Neeraj Sharma   implemnt api in s...
755
756
757
              this.loading = false;
              this.snackbar = true;
              this.text = response.data.message;
8bb178441   Neeraj Sharma   implemnt api in s...
758
              this.clear();
1571e40b5   Neeraj Sharma   gallery and socia...
759
              this.files = "";
8bb178441   Neeraj Sharma   implemnt api in s...
760
761
762
763
764
765
766
767
768
769
770
771
772
            })
            .catch(error => {
              if ((this.snackbar = true)) {
                this.text = error.response.data.message;
              }
            });
        }
      },
      clear() {
        this.$refs.form.reset();
      },
      save() {
        this.editedItem.gelleryId = this.editedItem._id;
1571e40b5   Neeraj Sharma   gallery and socia...
773
        var linkUrl = [];
a17c68a03   Neeraj Sharma   implement two rou...
774
        for (let i = 0; i < this.updates.length; i++) {
1571e40b5   Neeraj Sharma   gallery and socia...
775
          linkUrl.push(this.updates[i].youTubeLink);
a17c68a03   Neeraj Sharma   implement two rou...
776
        }
1571e40b5   Neeraj Sharma   gallery and socia...
777
        if (this.editFiles) {
8bb178441   Neeraj Sharma   implemnt api in s...
778
779
          var ary = [];
          var imageData = [];
1571e40b5   Neeraj Sharma   gallery and socia...
780
          ary = this.editFiles;
8bb178441   Neeraj Sharma   implemnt api in s...
781
782
783
          for (let i = 0; i < ary.length; i++) {
            const [baseUrl, imageUrl] = ary[i].split(/,/);
            imageData.push(imageUrl);
1571e40b5   Neeraj Sharma   gallery and socia...
784
            this.editedItem.editFiles = imageData;
8bb178441   Neeraj Sharma   implemnt api in s...
785
786
          }
        }
1571e40b5   Neeraj Sharma   gallery and socia...
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
        if (linkUrl != "") {
          var updateData = {
            galleryId: this.editedItem._id,
            description: this.editedItem.description,
            classId: this.editedItem.classNum,
            uploadImage: this.editedItem.editFiles,
            title: this.editedItem.title,
            updateYouTubeLinkUrl: linkUrl
          };
        } else if (linkUrl == "") {
          var updateData = {
            galleryId: this.editedItem._id,
            description: this.editedItem.description,
            classId: this.editedItem.classNum,
            uploadImage: this.editedItem.editFiles,
            title: this.editedItem.title
          };
        }
        http()
          .put("/updateGallery", updateData)
          .then(response => {
            this.getGalleryList();
            this.close();
            this.snackbar = true;
            this.text = response.data.message;
          })
          .catch(error => {
            console.log(error);
          });
8bb178441   Neeraj Sharma   implemnt api in s...
816
817
818
819
820
821
822
823
824
825
826
      },
      getAllClasses() {
        http()
          .get("/getClassesList", {
            headers: { Authorization: "Bearer " + this.token }
          })
          .then(response => {
            this.addclass = response.data.data;
          })
          .catch(err => {
            // console.log("err====>", err);
8bb178441   Neeraj Sharma   implemnt api in s...
827
828
          });
      },
8bb178441   Neeraj Sharma   implemnt api in s...
829
830
831
      addFind: function() {
        this.finds.push({ value: "" });
      },
a17c68a03   Neeraj Sharma   implement two rou...
832
833
834
      update: function() {
        this.updates.push({ youTubeLink: "" });
      },
8bb178441   Neeraj Sharma   implemnt api in s...
835
836
837
      deleteFind: function(index) {
        this.finds.splice(index, 1);
        if (index === 0) this.addFind();
a17c68a03   Neeraj Sharma   implement two rou...
838
839
840
841
842
      },
      deleteUpdate: function(index) {
        this.updates.splice(index, 1);
        if (index === 0) this.update();
      },
1571e40b5   Neeraj Sharma   gallery and socia...
843
      deleteUrl: function(index, youTubelinkId, id) {
a17c68a03   Neeraj Sharma   implement two rou...
844
845
        this.editedItem.youTubeLinkUrl.splice(index, 1);
        if (index === 0) this.update();
a17c68a03   Neeraj Sharma   implement two rou...
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
        let deleteYouTubeUrl = {
          galleryId: id,
          youTubeId: youTubelinkId
        };
        http()
          .put("/deleteYoutubeLink", deleteYouTubeUrl)
          .then(response => {
            this.snackbar = true;
            this.text = response.data.message;
            this.getGalleryList();
            this.close();
          })
          .catch(error => {
            console.log(error);
          });
8bb178441   Neeraj Sharma   implemnt api in s...
861
862
863
864
865
866
      }
    },
    mounted() {
      this.token = this.$store.state.token;
      this.getAllClasses();
      this.getGalleryList();
1571e40b5   Neeraj Sharma   gallery and socia...
867
      // console.log("index",index);
8bb178441   Neeraj Sharma   implemnt api in s...
868
    },
a17c68a03   Neeraj Sharma   implement two rou...
869
870
871
872
873
874
875
876
    created() {
      this.$root.$on("app:search", search => {
        this.search = search;
      });
    },
    beforeDestroy() {
      // dont forget to remove the listener
      this.$root.$off("app:search");
8bb178441   Neeraj Sharma   implemnt api in s...
877
878
879
880
    }
  };
  </script>
  <style scoped>
8bb178441   Neeraj Sharma   implemnt api in s...
881
882
883
  #td {
    border: 1px solid #dddddd;
    text-align: left;
a17c68a03   Neeraj Sharma   implement two rou...
884
885
    padding: 2px 0px;
    max-width: 200px;
8bb178441   Neeraj Sharma   implemnt api in s...
886
887
888
889
890
891
892
893
  }
  .active {
    background-color: black;
    color: white !important;
  }
  .activebtn {
    color: black !important;
  }
8bb178441   Neeraj Sharma   implemnt api in s...
894
  </style>