Blame view

src/pages/Library/eBook.vue 24.9 KB
687e0b929   Neeraj Sharma   add user,attenden...
1
2
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
  <template>
    <v-app id="pages-dasboard">
      <v-tabs grow slider-color="gray">
        <v-tab
          ripple
          @click="activeTab('existing')"
          v-bind:class="{ active: isActive }"
          id="tab"
          class="subheading"
        >Existing E-Books</v-tab>
        <v-tab
          ripple
          @click="activeTab('new')"
          v-bind:class="{ active: newActive }"
          id="tab1"
          User
          class="subheading"
        >Add E-Books</v-tab>
  
        <!-- ****** EDITS ALL NEWS 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 E-Books</h3>
                </v-toolbar-title>
                <v-spacer></v-spacer>
              </v-toolbar>
6c05a9f84   Neeraj Sharma   add functionalit ...
40
              <v-card-text style="height:760px;">
687e0b929   Neeraj Sharma   add user,attenden...
41
42
43
44
45
                <v-form ref="form">
                  <v-container fluid>
                    <v-layout row>
                      <v-flex
                        xs12
6c05a9f84   Neeraj Sharma   add functionalit ...
46
                        class="text-xs-center text-sm-center text-md-center text-lg-center mr-4"
687e0b929   Neeraj Sharma   add user,attenden...
47
48
49
50
51
52
53
                      >
                        <input
                          type="file"
                          style="display: none"
                          ref="image"
                          accept="image/*"
                          multiple
6c05a9f84   Neeraj Sharma   add functionalit ...
54
                          @change="onImagePicked"
687e0b929   Neeraj Sharma   add user,attenden...
55
56
                        />
                        <v-layout justify-center>
6c05a9f84   Neeraj Sharma   add functionalit ...
57
58
59
60
61
62
63
64
65
66
67
68
69
                          <v-flex v-if="files != ''">
                            <img :src="files" height="450" width="500;" />
                          </v-flex>
                        </v-layout>
                        <img
                          v-if="editedItem.coverPhotoUrl && files == '' "
                          :src="editedItem.coverPhotoUrl"
                          height="450"
                          width="500"
                          alt="eBooks"
                          class="pa-2"
                        />
                        <!-- <v-layout justify-center>
687e0b929   Neeraj Sharma   add user,attenden...
70
71
72
73
74
75
76
                          <v-flex
                            xs3
                            v-for="Image in editedItem.newsImageUrl"
                            :key="Image._id"
                            v-if="editedItem.newsImageUrl"
                            class="profile-image-wrapper"
                          >
6c05a9f84   Neeraj Sharma   add functionalit ...
77
                           
687e0b929   Neeraj Sharma   add user,attenden...
78
79
80
81
82
83
84
85
86
                            <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" />
                          </v-flex>
6c05a9f84   Neeraj Sharma   add functionalit ...
87
                        </v-layout>-->
687e0b929   Neeraj Sharma   add user,attenden...
88
89
                        <img
                          src="/static/icon/user.png"
6c05a9f84   Neeraj Sharma   add functionalit ...
90
                          v-if="editedItem.coverPhotoUrl == ''"
687e0b929   Neeraj Sharma   add user,attenden...
91
92
93
94
95
96
                          height="160"
                          width="160"
                          alt="Books"
                        />
                      </v-flex>
                    </v-layout>
687e0b929   Neeraj Sharma   add user,attenden...
97
98
99
100
                    <v-layout>
                      <v-flex xs12 sm12>
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
6c05a9f84   Neeraj Sharma   add functionalit ...
101
                            <label class="right">Name:</label>
687e0b929   Neeraj Sharma   add user,attenden...
102
103
104
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <v-text-field
6c05a9f84   Neeraj Sharma   add functionalit ...
105
106
                              v-model="editedItem.name"
                              placeholder="fill your Name"
687e0b929   Neeraj Sharma   add user,attenden...
107
                              type="text"
687e0b929   Neeraj Sharma   add user,attenden...
108
109
110
111
112
113
114
                            ></v-text-field>
                          </v-flex>
                        </v-layout>
                      </v-flex>
                      <v-flex xs12 sm12>
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
6c05a9f84   Neeraj Sharma   add functionalit ...
115
116
117
118
119
120
121
122
123
124
125
                            <label class="right">Author:</label>
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <v-text-field placeholder="fill your Author" v-model="editedItem.author"></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">Class:</label>
687e0b929   Neeraj Sharma   add user,attenden...
126
127
128
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <v-text-field
6c05a9f84   Neeraj Sharma   add functionalit ...
129
130
131
132
133
                              v-model="editedItem.className"
                              :items="addClass"
                              label="Select Class"
                              item-text="classNum"
                              item-value="_id"
687e0b929   Neeraj Sharma   add user,attenden...
134
135
136
137
                            ></v-text-field>
                          </v-flex>
                        </v-layout>
                      </v-flex>
6c05a9f84   Neeraj Sharma   add functionalit ...
138
                      <v-flex xs12 sm12>
687e0b929   Neeraj Sharma   add user,attenden...
139
140
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
6c05a9f84   Neeraj Sharma   add functionalit ...
141
                            <label class="right">Upload Image:</label>
687e0b929   Neeraj Sharma   add user,attenden...
142
143
144
145
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <v-text-field
                              label="Select Image"
6c05a9f84   Neeraj Sharma   add functionalit ...
146
                              @click="pickImage"
687e0b929   Neeraj Sharma   add user,attenden...
147
148
149
150
151
152
153
                              v-model="imageName"
                              append-icon="attach_file"
                              multiple
                            ></v-text-field>
                          </v-flex>
                        </v-layout>
                      </v-flex>
6c05a9f84   Neeraj Sharma   add functionalit ...
154
155
156
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
                      <v-flex xs12 sm12>
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
                            <label class="right">Upload File:</label>
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <input
                              type="file"
                              style="display: none"
                              ref="file"
                              @change="onFilePicked"
                            />
                            <v-text-field
                              label="Select File"
                              @click="pickFile"
                              v-model="fileName"
                              append-icon="attach_file"
                              multiple
                            ></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">Private:</label>
                          </v-flex>
                          <v-flex xs5 class="ml-3">
                            <v-checkbox v-model="editedItem.private"></v-checkbox>
                          </v-flex>
                        </v-layout>
                      </v-flex>
687e0b929   Neeraj Sharma   add user,attenden...
186
187
188
189
190
191
                    </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>
6c05a9f84   Neeraj Sharma   add functionalit ...
192
                          <v-btn round dark @click="save" :loading="loadingUpadte">Save</v-btn>
687e0b929   Neeraj Sharma   add user,attenden...
193
194
195
196
197
198
199
200
201
202
                        </v-card-actions>
                      </v-flex>
                    </v-layout>
                  </v-container>
                </v-form>
              </v-card-text>
            </v-card>
          </v-dialog>
  
          <!-- ****** PROFILE VIEW ALL NEWS DEATILS ******  -->
ab54b5656   Neeraj Sharma   implement library...
203
204
          <v-dialog v-model="dialog1" max-width="800px" scrollable>
            <v-card style="height: 700px;">
687e0b929   Neeraj Sharma   add user,attenden...
205
206
207
208
209
210
211
212
              <v-toolbar color="grey lighten-2" flat>
                <v-spacer></v-spacer>
                <v-toolbar-title>
                  <h3>E-Books</h3>
                </v-toolbar-title>
                <v-spacer></v-spacer>
                <v-icon @click="close1">close</v-icon>
              </v-toolbar>
687e0b929   Neeraj Sharma   add user,attenden...
213
              <v-card-text>
ab54b5656   Neeraj Sharma   implement library...
214
                <v-container>
687e0b929   Neeraj Sharma   add user,attenden...
215
                  <v-layout wrap>
ab54b5656   Neeraj Sharma   implement library...
216
217
                    <v-flex sm12 xs12>
                      <iframe :src="editedItem.fileUrl" height="600" width="100%"></iframe>
687e0b929   Neeraj Sharma   add user,attenden...
218
219
220
221
222
223
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-card-text>
            </v-card>
          </v-dialog>
687e0b929   Neeraj Sharma   add user,attenden...
224
225
226
          <!-- ****** EXISTING-USERS NEWS TABLE ****** -->
          <v-data-table
            :headers="headers"
ab54b5656   Neeraj Sharma   implement library...
227
            :items="eBookData"
687e0b929   Neeraj Sharma   add user,attenden...
228
229
230
231
232
233
            :pagination.sync="pagination"
            :search="search"
          >
            <template slot="items" slot-scope="props">
              <td class="text-xs-center">{{ props.index + 1}}</td>
              <td id="td" class="text-xs-center">
6c05a9f84   Neeraj Sharma   add functionalit ...
234
                <img :src="props.item.coverPhotoUrl" alt="newsImage" width="100" height="70" />
687e0b929   Neeraj Sharma   add user,attenden...
235
              </td>
ab54b5656   Neeraj Sharma   implement library...
236
237
              <td id="td" class="text-xs-center">{{ props.item.name}}</td>
              <td id="td" class="text-xs-center">{{ props.item.author}}</td>
6c05a9f84   Neeraj Sharma   add functionalit ...
238
              <td id="td" class="text-xs-center">{{ props.item.classId.classNum}}</td>
687e0b929   Neeraj Sharma   add user,attenden...
239
240
241
  
              <td class="text-xs-center">
                <span>
495e4037c   Neeraj Sharma   update
242
243
244
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
                  <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>
687e0b929   Neeraj Sharma   add user,attenden...
272
273
274
275
276
277
278
279
280
281
282
                </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>
b8690bbc9   Neeraj Sharma   implement create ...
283
        <!-- ****** ADD MULTIPLE E-BOOK ****** -->
687e0b929   Neeraj Sharma   add user,attenden...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
  
        <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/*"
ab54b5656   Neeraj Sharma   implement library...
309
                          @change="onImagePicked"
687e0b929   Neeraj Sharma   add user,attenden...
310
311
                        />
                        <v-layout justify-center>
6c05a9f84   Neeraj Sharma   add functionalit ...
312
313
                          <v-flex v-if="files != ''">
                            <img :src="files" height="240" width="260px;" />
687e0b929   Neeraj Sharma   add user,attenden...
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
                          </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">Name:</label>
                        </v-flex>
                        <v-flex xs4 class="ml-3">
                          <v-text-field
                            v-model="addEBooks.name"
                            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">Author:</label>
                        </v-flex>
                        <v-flex xs4 class="ml-3">
                          <v-text-field
                            v-model="addEBooks.author"
                            placeholder="fill your Author Name"
                            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">Class:</label>
                        </v-flex>
                        <v-flex xs4 class="ml-3">
                          <v-select
ab54b5656   Neeraj Sharma   implement library...
365
                            v-model="addEBooks.classId"
687e0b929   Neeraj Sharma   add user,attenden...
366
367
                            :items="addClass"
                            label="Select Class"
ab54b5656   Neeraj Sharma   implement library...
368
369
                            item-text="classNum"
                            item-value="_id"
687e0b929   Neeraj Sharma   add user,attenden...
370
371
372
373
374
375
                            :rules="titleRules"
                            required
                          ></v-select>
                        </v-flex>
                      </v-layout>
                    </v-flex>
ab54b5656   Neeraj Sharma   implement library...
376
                    <v-flex xs12>
687e0b929   Neeraj Sharma   add user,attenden...
377
378
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
ab54b5656   Neeraj Sharma   implement library...
379
                          <label class="right">Upload Image:</label>
687e0b929   Neeraj Sharma   add user,attenden...
380
381
382
                        </v-flex>
                        <v-flex xs4 class="ml-3">
                          <v-text-field
ab54b5656   Neeraj Sharma   implement library...
383
384
385
386
387
                            label="Select Image"
                            @click="pickImage"
                            v-model="imageName"
                            append-icon="attach_file"
                            multiple
687e0b929   Neeraj Sharma   add user,attenden...
388
389
390
                          ></v-text-field>
                        </v-flex>
                      </v-layout>
ab54b5656   Neeraj Sharma   implement library...
391
                    </v-flex>
687e0b929   Neeraj Sharma   add user,attenden...
392
393
394
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
ab54b5656   Neeraj Sharma   implement library...
395
                          <label class="right">Upload File:</label>
687e0b929   Neeraj Sharma   add user,attenden...
396
397
                        </v-flex>
                        <v-flex xs4 class="ml-3">
ab54b5656   Neeraj Sharma   implement library...
398
                          <input type="file" style="display: none" ref="file" @change="onFilePicked" />
687e0b929   Neeraj Sharma   add user,attenden...
399
                          <v-text-field
6c05a9f84   Neeraj Sharma   add functionalit ...
400
                            label="Select File"
687e0b929   Neeraj Sharma   add user,attenden...
401
                            @click="pickFile"
ab54b5656   Neeraj Sharma   implement library...
402
                            v-model="fileName"
687e0b929   Neeraj Sharma   add user,attenden...
403
404
405
406
407
408
                            append-icon="attach_file"
                            multiple
                          ></v-text-field>
                        </v-flex>
                      </v-layout>
                    </v-flex>
ab54b5656   Neeraj Sharma   implement library...
409
410
411
412
413
414
415
416
417
418
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs4 class="pt-3 subheading">
                          <label class="right">Private:</label>
                        </v-flex>
                        <v-flex xs4 class="ml-3">
                          <v-checkbox v-model="addEBooks.private"></v-checkbox>
                        </v-flex>
                      </v-layout>
                    </v-flex>
687e0b929   Neeraj Sharma   add user,attenden...
419
                    <v-layout>
ab54b5656   Neeraj Sharma   implement library...
420
                      <v-flex xs12 sm7 offset-sm2>
687e0b929   Neeraj Sharma   add user,attenden...
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
                        <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,
6c05a9f84   Neeraj Sharma   add functionalit ...
454
      loadingUpadte: false,
687e0b929   Neeraj Sharma   add user,attenden...
455
456
457
458
459
460
461
462
      date: null,
      search: "",
      showLoader: false,
      dialog: false,
      dialog1: false,
      valid: true,
      isActive: true,
      newActive: false,
ab54b5656   Neeraj Sharma   implement library...
463
      addClass: [],
687e0b929   Neeraj Sharma   add user,attenden...
464
465
466
467
468
469
      addSection: [],
      AddUsercredentials: {},
      pagination: {
        rowsPerPage: 15
      },
      imageName: "",
ab54b5656   Neeraj Sharma   implement library...
470
      fileName: "",
687e0b929   Neeraj Sharma   add user,attenden...
471
472
473
474
      imageUrl: "",
      imageFile: "",
      image: [],
      upload: "",
ab54b5656   Neeraj Sharma   implement library...
475
476
      files: "",
      anyFile: "",
687e0b929   Neeraj Sharma   add user,attenden...
477
478
479
480
481
482
483
484
485
      titleRules: [v => !!v || " Tilte is required"],
      descriptionRules: [v => !!v || " Description is required"],
      headers: [
        {
          align: "justify-center",
          text: "No",
          sortable: false,
          value: "No"
        },
ab54b5656   Neeraj Sharma   implement library...
486
487
488
        { text: "Photo", vaue: "fileUrl", sortable: false, align: "center" },
        { text: "Name", vaue: "name", sortable: false, align: "center" },
        { text: "Author", value: "author", sortable: false, align: "center" },
687e0b929   Neeraj Sharma   add user,attenden...
489
        {
ab54b5656   Neeraj Sharma   implement library...
490
491
          text: "Class",
          value: "classId",
687e0b929   Neeraj Sharma   add user,attenden...
492
493
494
495
496
          sortable: false,
          align: "center"
        },
        { text: "Action", value: "", sortable: false, align: "center" }
      ],
ab54b5656   Neeraj Sharma   implement library...
497
      eBookData: [],
687e0b929   Neeraj Sharma   add user,attenden...
498
      editedIndex: -1,
ab54b5656   Neeraj Sharma   implement library...
499
500
501
502
503
      addEBooks: {
        private: false
      },
      editedItem: {},
      token: ""
687e0b929   Neeraj Sharma   add user,attenden...
504
505
    }),
    methods: {
ab54b5656   Neeraj Sharma   implement library...
506
      pickImage() {
687e0b929   Neeraj Sharma   add user,attenden...
507
508
        this.$refs.image.click();
      },
ab54b5656   Neeraj Sharma   implement library...
509
510
511
512
      pickFile() {
        this.$refs.file.click();
      },
      onImagePicked(e) {
687e0b929   Neeraj Sharma   add user,attenden...
513
514
515
516
517
518
519
520
        // console.log(e)
        const files = e.target.files;
        /** fetch Image Name **/
        if (files[0] !== undefined) {
          this.imageName = files[0].name;
          if (this.imageName.lastIndexOf(".") <= 0) {
            return;
          }
687e0b929   Neeraj Sharma   add user,attenden...
521
          /** Select many image and showing many image add to news card **/
687e0b929   Neeraj Sharma   add user,attenden...
522
523
524
          const fr = new FileReader();
          fr.readAsDataURL(files[0]);
          fr.addEventListener("load", () => {
ab54b5656   Neeraj Sharma   implement library...
525
            this.files = fr.result;
687e0b929   Neeraj Sharma   add user,attenden...
526
527
528
529
          });
        } else {
          this.imageName = "";
          this.imageFile = "";
ab54b5656   Neeraj Sharma   implement library...
530
          this.files = "";
687e0b929   Neeraj Sharma   add user,attenden...
531
532
533
          this.imageUrl = "";
        }
      },
6c05a9f84   Neeraj Sharma   add functionalit ...
534
      getEBooksList() {
687e0b929   Neeraj Sharma   add user,attenden...
535
        this.showLoader = true;
687e0b929   Neeraj Sharma   add user,attenden...
536
        http()
ab54b5656   Neeraj Sharma   implement library...
537
538
          .get("/getEBooksList", {
            headers: { Authorization: "Bearer " + this.token }
687e0b929   Neeraj Sharma   add user,attenden...
539
540
          })
          .then(response => {
ab54b5656   Neeraj Sharma   implement library...
541
            this.eBookData = response.data.data;
687e0b929   Neeraj Sharma   add user,attenden...
542
            this.showLoader = false;
687e0b929   Neeraj Sharma   add user,attenden...
543
          })
00e4bc4e1   Neeraj Sharma   fixed auntentication
544
          .catch(error => {
687e0b929   Neeraj Sharma   add user,attenden...
545
546
            // console.log("err====>", err);
            this.showLoader = false;
6c05a9f84   Neeraj Sharma   add functionalit ...
547
548
549
550
551
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
            }
ab54b5656   Neeraj Sharma   implement library...
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
          });
      },
      onFilePicked(e) {
        // console.log(e)
        const files = e.target.files;
        /** fetch Image Name **/
        if (files[0] !== undefined) {
          this.fileName = files[0].name;
          if (this.fileName.lastIndexOf(".") <= 0) {
            return;
          }
          const fr = new FileReader();
          fr.readAsDataURL(files[0]);
          fr.addEventListener("load", () => {
            this.anyFile = fr.result;
            // console.log(" this.anyFile Url", this.anyFile )
687e0b929   Neeraj Sharma   add user,attenden...
568
          });
ab54b5656   Neeraj Sharma   implement library...
569
570
571
572
        } else {
          this.anyFile = "";
          this.fileName = "";
        }
687e0b929   Neeraj Sharma   add user,attenden...
573
574
575
      },
      editItem(item) {
        this.files = [];
ab54b5656   Neeraj Sharma   implement library...
576
        this.editedIndex = this.eBookData.indexOf(item);
687e0b929   Neeraj Sharma   add user,attenden...
577
        this.editedItem = Object.assign({}, item);
6c05a9f84   Neeraj Sharma   add functionalit ...
578
        this.editedItem.className = item.classId.classNum;
687e0b929   Neeraj Sharma   add user,attenden...
579
580
581
        this.dialog = true;
      },
      profile(item) {
ab54b5656   Neeraj Sharma   implement library...
582
        this.editedIndex = this.eBookData.indexOf(item);
687e0b929   Neeraj Sharma   add user,attenden...
583
584
585
586
        this.editedItem = Object.assign({}, item);
        this.dialog1 = true;
      },
      deleteItem(item) {
6c05a9f84   Neeraj Sharma   add functionalit ...
587
588
        let deleteEBooks = {
          ebookId: item._id
687e0b929   Neeraj Sharma   add user,attenden...
589
590
591
        };
        http()
          .delete(
6c05a9f84   Neeraj Sharma   add functionalit ...
592
            "/deleteEBook",
687e0b929   Neeraj Sharma   add user,attenden...
593
            confirm("Are you sure you want to delete this?") && {
6c05a9f84   Neeraj Sharma   add functionalit ...
594
              params: deleteEBooks
687e0b929   Neeraj Sharma   add user,attenden...
595
596
597
            }
          )
          .then(response => {
6c05a9f84   Neeraj Sharma   add functionalit ...
598
599
600
            this.snackbar = true;
            this.text = "Successfully delete Existing News";
            this.getEBooksList();
687e0b929   Neeraj Sharma   add user,attenden...
601
602
          })
          .catch(error => {
6c05a9f84   Neeraj Sharma   add functionalit ...
603
604
            this.snackbar = true;
            this.text = error.response.data.message;
687e0b929   Neeraj Sharma   add user,attenden...
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
          });
      },
      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;
        if (this.$refs.form.validate()) {
687e0b929   Neeraj Sharma   add user,attenden...
633
          if (this.files) {
ab54b5656   Neeraj Sharma   implement library...
634
635
636
637
638
639
640
641
            const [baseUrl, imageUrl] = this.files.split(/,/);
            this.addEBooks.uploadCover = imageUrl;
            // console.log("anyFile.split(/,/)", this.addEBooks.uploadCover);
          }
          if (this.anyFile) {
            const [baseUrl, fileUrl] = this.anyFile.split(/,/);
            this.addEBooks.uploadFile = fileUrl;
            // console.log("anyFile.split(/,/)", this.addEBooks.uploadFile);
687e0b929   Neeraj Sharma   add user,attenden...
642
643
          }
          http()
ab54b5656   Neeraj Sharma   implement library...
644
            .post("/createEBook", this.addEBooks)
687e0b929   Neeraj Sharma   add user,attenden...
645
            .then(response => {
6c05a9f84   Neeraj Sharma   add functionalit ...
646
647
              this.snackbar = true;
              this.text = "New E-Book added successfully";
ab54b5656   Neeraj Sharma   implement library...
648
              this.addEBooks.uploadCover = "";
6c05a9f84   Neeraj Sharma   add functionalit ...
649
650
651
              this.addEBooks.uploadFile = "";
              this.files = "";
              this.getEBooksList();
687e0b929   Neeraj Sharma   add user,attenden...
652
653
654
655
              this.loading = false;
              this.clear();
            })
            .catch(error => {
6c05a9f84   Neeraj Sharma   add functionalit ...
656
657
              this.snackbar = true;
              this.text = error.response.data.message;
687e0b929   Neeraj Sharma   add user,attenden...
658
659
660
661
662
            });
        }
      },
      clear() {
        this.$refs.form.reset();
495e4037c   Neeraj Sharma   update
663
664
        this.addEBooks.uploadCover = "";
        this.files = "";
687e0b929   Neeraj Sharma   add user,attenden...
665
666
      },
      save() {
6c05a9f84   Neeraj Sharma   add functionalit ...
667
668
669
670
671
        this.loadingUpadte = true;
        if (this.files.length > 0) {
          const [baseUrl, imageUrl] = this.files.split(/,/);
          this.editedItem.uploadCover = imageUrl;
          // console.log("anyFile.split(/,/)", this.addEBooks.uploadCover);
687e0b929   Neeraj Sharma   add user,attenden...
672
        }
ab54b5656   Neeraj Sharma   implement library...
673
674
        if (this.anyFile) {
          const [baseUrl, fileUrl] = this.anyFile.split(/,/);
6c05a9f84   Neeraj Sharma   add functionalit ...
675
676
          this.editedItem.uploadFile = fileUrl;
          // console.log("anyFile.split(/,/)", this.addEBooks.uploadFile);
ab54b5656   Neeraj Sharma   implement library...
677
        }
6c05a9f84   Neeraj Sharma   add functionalit ...
678
        this.editedItem.ebookId = this.editedItem._id;
687e0b929   Neeraj Sharma   add user,attenden...
679
        http()
6c05a9f84   Neeraj Sharma   add functionalit ...
680
          .put("/updateEBook", this.editedItem)
687e0b929   Neeraj Sharma   add user,attenden...
681
          .then(response => {
6c05a9f84   Neeraj Sharma   add functionalit ...
682
683
684
685
686
687
688
689
            this.loadingUpadte = false;
            this.snackbar = true;
            this.text = "Successfully Edit Existing E-Book";
            this.getEBooksList();
            this.editedItem.uploadFile = "";
            this.editedItem.uploadCover = "";
            this.anyFile = "";
            this.files = "";
687e0b929   Neeraj Sharma   add user,attenden...
690
691
692
            this.close();
          })
          .catch(error => {
6c05a9f84   Neeraj Sharma   add functionalit ...
693
694
695
            this.loadingUpadte = false;
            this.snackbar = true;
            this.text = error.response.data.message;
687e0b929   Neeraj Sharma   add user,attenden...
696
697
            // console.log(error);
          });
ab54b5656   Neeraj Sharma   implement library...
698
699
700
701
702
703
704
705
706
707
708
709
710
      },
      getAllClass() {
        http()
          .get("/getClassesList", {
            headers: { Authorization: "Bearer " + this.token }
          })
          .then(response => {
            this.addClass = response.data.data;
          })
          .catch(err => {
            // console.log("err====>", err);
            // this.$router.replace({ path: "/" });
          });
687e0b929   Neeraj Sharma   add user,attenden...
711
712
713
      }
    },
    mounted() {
ab54b5656   Neeraj Sharma   implement library...
714
      this.token = this.$store.state.token;
6c05a9f84   Neeraj Sharma   add functionalit ...
715
      this.getEBooksList();
ab54b5656   Neeraj Sharma   implement library...
716
      this.getAllClass();
006544386   Neeraj Sharma   implement task
717
      // this.getBookData();
ab54b5656   Neeraj Sharma   implement library...
718
      // this.editItem;
687e0b929   Neeraj Sharma   add user,attenden...
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
    },
    created() {
      this.$root.$on("app:search", search => {
        this.search = search;
      });
    },
    beforeDestroy() {
      // dont forget to remove the listener
      this.$root.$off("app:search");
    }
  };
  </script>
  <style scoped>
  .active {
    background-color: gray;
    color: white !important;
  }
  .activebtn {
    color: black !important;
  }
  </style>