Blame view

src/pages/Gallery/gallery.vue 30.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
                    <v-flex xs12>
2ddcef1ce   Neeraj Sharma   solve issue empty...
158
159
160
161
162
                      <div
                        v-for="(editImage,index) in editedItem.youTubeLinkUrl"
                        :key="index"
                        v-if="editImage.youTubeLink !=[]"
                      >
a17c68a03   Neeraj Sharma   implement two rou...
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
199
200
201
202
                        <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...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
                    <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...
219
          <v-dialog v-model="dialog1" max-width="940px">
8bb178441   Neeraj Sharma   implemnt api in s...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
            <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...
239
                  <img :src="image.imageLink" alt="Gallery" width="240" height="180" />
8bb178441   Neeraj Sharma   implemnt api in s...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
                </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...
266
267
268
269
270
271
272
                      <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...
273
274
275
276
                          <h5 class="my-1 ml-3">
                            <ul v-for="youTubeLinkUrl in editedItem.youTubeLinkUrl">
                              <li>{{ youTubeLinkUrl.youTubeLink }}</li>
                            </ul>
a17c68a03   Neeraj Sharma   implement two rou...
277
278
279
                          </h5>
                        </v-flex>
                      </v-layout>
8bb178441   Neeraj Sharma   implemnt api in s...
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
                    </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...
304
              <td class="text-xs-center">{{ props.index }}</td>
8bb178441   Neeraj Sharma   implemnt api in s...
305
306
              <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...
307
                  <img :src="image.imageLink" alt="newsImage" width="100" height="70" />
8bb178441   Neeraj Sharma   implemnt api in s...
308
309
310
311
                </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...
312
              <td id="td" class="text-xs-center">
8bb178441   Neeraj Sharma   implemnt api in s...
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
465
466
467
468
                <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...
469
470
                            </v-flex>
                            <v-flex xs2 class="pt-4">
a17c68a03   Neeraj Sharma   implement two rou...
471
                              <v-icon @click="deleteFind(index)" v-if="index !=0 ">cancel</v-icon>
8bb178441   Neeraj Sharma   implemnt api in s...
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
518
519
520
521
                              <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...
522
523
      updates: [{ youTubeLink: "" }],
      youTubeLink: {},
8bb178441   Neeraj Sharma   implemnt api in s...
524
525
526
527
528
529
530
531
532
533
534
      addGallery: {
        youTubeLinkUrl: []
      },
      pagination: {
        rowsPerPage: 15
      },
      imageName: "",
      imageUrl: "",
      imageFile: "",
      image: [],
      upload: "",
a17c68a03   Neeraj Sharma   implement two rou...
535
536
      editImageName: "",
      editFiles: [],
8bb178441   Neeraj Sharma   implemnt api in s...
537
      files: [],
8bb178441   Neeraj Sharma   implemnt api in s...
538
539
540
541
542
543
544
545
      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...
546
          value: "index"
8bb178441   Neeraj Sharma   implemnt api in s...
547
548
549
550
551
552
553
554
555
556
557
558
559
        },
        { 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...
560
561
      editedItem: {},
      index: ""
8bb178441   Neeraj Sharma   implemnt api in s...
562
563
    }),
    methods: {
8bb178441   Neeraj Sharma   implemnt api in s...
564
565
566
      pickFile() {
        this.$refs.image.click();
      },
a17c68a03   Neeraj Sharma   implement two rou...
567
568
569
      editPickFile() {
        this.$refs.editImage.click();
      },
8bb178441   Neeraj Sharma   implemnt api in s...
570
      onFilePicked(e) {
8bb178441   Neeraj Sharma   implemnt api in s...
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
        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...
590
              console.log("uploadImage=======>", this.files);
8bb178441   Neeraj Sharma   implemnt api in s...
591
592
593
594
595
596
597
598
599
600
            });
            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...
601
602
603
604
605
606
607
          });
        } else {
          this.imageName = "";
          this.imageFile = "";
          this.imageUrl = "";
        }
      },
a17c68a03   Neeraj Sharma   implement two rou...
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
639
640
641
642
      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...
643
644
645
646
647
648
649
650
651
652
      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...
653
          .catch(error => {
8bb178441   Neeraj Sharma   implemnt api in s...
654
655
            // console.log("err====>", err);
            this.showLoader = false;
a17c68a03   Neeraj Sharma   implement two rou...
656
657
658
659
660
            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...
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
          });
      },
      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...
676
          galleryId: item._id
8bb178441   Neeraj Sharma   implemnt api in s...
677
678
679
        };
        http()
          .delete(
a17c68a03   Neeraj Sharma   implement two rou...
680
            "/deleteGallery",
8bb178441   Neeraj Sharma   implemnt api in s...
681
            confirm("Are you sure you want to delete this?") && {
a17c68a03   Neeraj Sharma   implement two rou...
682
683
684
685
              params: deleteGallery,
              headers: {
                Authorization: "Bearer " + this.token
              }
8bb178441   Neeraj Sharma   implemnt api in s...
686
687
688
689
            }
          )
          .then(response => {
            if ((this.snackbar = true)) {
2ddcef1ce   Neeraj Sharma   solve issue empty...
690
              this.text = "Successfully delete Existing Gallery";
8bb178441   Neeraj Sharma   implemnt api in s...
691
            }
a17c68a03   Neeraj Sharma   implement two rou...
692
            this.getGalleryList();
8bb178441   Neeraj Sharma   implemnt api in s...
693
694
695
696
697
          })
          .catch(error => {
            // console.log(error);
          });
      },
a17c68a03   Neeraj Sharma   implement two rou...
698
699
      deleteImage(imageId, id) {
        console.log("imageId", imageId, "id", id);
8bb178441   Neeraj Sharma   implemnt api in s...
700
        let deleteImages = {
a17c68a03   Neeraj Sharma   implement two rou...
701
          galleryId: id,
8bb178441   Neeraj Sharma   implemnt api in s...
702
703
704
          imageId: imageId
        };
        http()
a17c68a03   Neeraj Sharma   implement two rou...
705
          .put("/deleteImage", deleteImages)
8bb178441   Neeraj Sharma   implemnt api in s...
706
          .then(response => {
a17c68a03   Neeraj Sharma   implement two rou...
707
708
709
            this.snackbar = true;
            this.text = response.data.message;
            this.getGalleryList();
8bb178441   Neeraj Sharma   implemnt api in s...
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
737
738
739
740
            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...
741
742
743
        for (let i = 0; i < this.finds.length; i++) {
          this.addGallery.youTubeLinkUrl.push(this.finds[i].value);
        }
8bb178441   Neeraj Sharma   implemnt api in s...
744
745
746
747
748
749
750
751
752
753
754
        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;
            }
          }
2ddcef1ce   Neeraj Sharma   solve issue empty...
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
          if (this.addGallery.youTubeLinkUrl == "") {
            var galleryData = {
              classId: this.addGallery.classNum,
              title: this.addGallery.title,
              description: this.addGallery.description,
              upload: this.addGallery.upload
            };
            http()
              .post("/createGallery", galleryData)
              .then(response => {
                this.getGalleryList();
                this.loading = false;
                this.snackbar = true;
                this.text = response.data.message;
                this.clear();
                this.files = "";
              })
              .catch(error => {
                if ((this.snackbar = true)) {
                  this.text = error.response.data.message;
                }
              });
          } else if (this.addGallery.youTubeLinkUrl) {
            http()
              .post("/createGallery", this.addGallery)
              .then(response => {
                this.getGalleryList();
                this.loading = false;
                this.snackbar = true;
                this.text = response.data.message;
                this.clear();
                this.files = "";
              })
              .catch(error => {
                if ((this.snackbar = true)) {
                  this.text = error.response.data.message;
                }
              });
          }
8bb178441   Neeraj Sharma   implemnt api in s...
794
795
796
797
798
799
800
        }
      },
      clear() {
        this.$refs.form.reset();
      },
      save() {
        this.editedItem.gelleryId = this.editedItem._id;
1571e40b5   Neeraj Sharma   gallery and socia...
801
        var linkUrl = [];
a17c68a03   Neeraj Sharma   implement two rou...
802
        for (let i = 0; i < this.updates.length; i++) {
1571e40b5   Neeraj Sharma   gallery and socia...
803
          linkUrl.push(this.updates[i].youTubeLink);
a17c68a03   Neeraj Sharma   implement two rou...
804
        }
1571e40b5   Neeraj Sharma   gallery and socia...
805
        if (this.editFiles) {
8bb178441   Neeraj Sharma   implemnt api in s...
806
807
          var ary = [];
          var imageData = [];
1571e40b5   Neeraj Sharma   gallery and socia...
808
          ary = this.editFiles;
8bb178441   Neeraj Sharma   implemnt api in s...
809
810
811
          for (let i = 0; i < ary.length; i++) {
            const [baseUrl, imageUrl] = ary[i].split(/,/);
            imageData.push(imageUrl);
1571e40b5   Neeraj Sharma   gallery and socia...
812
            this.editedItem.editFiles = imageData;
8bb178441   Neeraj Sharma   implemnt api in s...
813
814
          }
        }
1571e40b5   Neeraj Sharma   gallery and socia...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
        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...
844
845
846
847
848
849
850
851
852
853
854
      },
      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...
855
856
          });
      },
8bb178441   Neeraj Sharma   implemnt api in s...
857
858
859
      addFind: function() {
        this.finds.push({ value: "" });
      },
a17c68a03   Neeraj Sharma   implement two rou...
860
861
862
      update: function() {
        this.updates.push({ youTubeLink: "" });
      },
8bb178441   Neeraj Sharma   implemnt api in s...
863
864
865
      deleteFind: function(index) {
        this.finds.splice(index, 1);
        if (index === 0) this.addFind();
a17c68a03   Neeraj Sharma   implement two rou...
866
867
868
869
870
      },
      deleteUpdate: function(index) {
        this.updates.splice(index, 1);
        if (index === 0) this.update();
      },
1571e40b5   Neeraj Sharma   gallery and socia...
871
      deleteUrl: function(index, youTubelinkId, id) {
a17c68a03   Neeraj Sharma   implement two rou...
872
873
        this.editedItem.youTubeLinkUrl.splice(index, 1);
        if (index === 0) this.update();
a17c68a03   Neeraj Sharma   implement two rou...
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
        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...
889
890
891
892
893
894
      }
    },
    mounted() {
      this.token = this.$store.state.token;
      this.getAllClasses();
      this.getGalleryList();
1571e40b5   Neeraj Sharma   gallery and socia...
895
      // console.log("index",index);
8bb178441   Neeraj Sharma   implemnt api in s...
896
    },
a17c68a03   Neeraj Sharma   implement two rou...
897
898
899
900
901
902
903
904
    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...
905
906
907
908
    }
  };
  </script>
  <style scoped>
8bb178441   Neeraj Sharma   implemnt api in s...
909
910
911
  #td {
    border: 1px solid #dddddd;
    text-align: left;
a17c68a03   Neeraj Sharma   implement two rou...
912
913
    padding: 2px 0px;
    max-width: 200px;
8bb178441   Neeraj Sharma   implemnt api in s...
914
915
916
917
918
919
920
921
  }
  .active {
    background-color: black;
    color: white !important;
  }
  .activebtn {
    color: black !important;
  }
8bb178441   Neeraj Sharma   implemnt api in s...
922
  </style>