Blame view

src/pages/Course/courseDiscussion.vue 16.2 KB
dea4d2889   Neeraj Sharma   task commited
1
2
  <template>
    <v-container fluid class="body-color">
db965de89   Amber Dev   added dialog pers...
3
      <v-dialog v-model="editDialog" max-width="600px" scrollable persistent>
4dd422bef   Shikha Mishra   change ui of card...
4
        <v-card flat class="Card-style pa-2">
dea4d2889   Neeraj Sharma   task commited
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
          <v-layout>
            <v-flex xs12>
              <label class="title text-xs-center">Edit Course Discussion</label>
              <v-icon size="24" class="right" @click="editDialog = false">cancel</v-icon>
            </v-flex>
          </v-layout>
          <v-card-text>
            <v-form ref="form">
              <v-container fluid>
                <v-layout>
                  <v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center">
                    <v-avatar size="100px" v-if="!editedItem.attachementUrl && !editImageUrl">
                      <img src="/static/icon/user.png" />
                    </v-avatar>
                    <img
                      :src="editedItem.attachementUrl"
                      v-else-if="editedItem.attachementUrl && !editImageUrl"
                      height="150"
                      style="border-radius:50%; width:150px"
                    />
                    <img
                      v-if="editImageUrl"
                      :src="editImageUrl"
                      style="border-radius:50%; width:150px;height:150px"
                    />
                    <input
                      type="file"
                      style="display: none"
                      ref="editDataImage"
                      accept="image/*"
                      @change="onEditFilePicked"
                    />
                  </v-flex>
                </v-layout>
                <v-layout wrap>
                  <v-flex xs12 sm12>
                    <v-layout>
                      <v-flex xs4 sm5 class="pt-4 subheading">
                        <label class="right hidden-xs-only hidden-sm-only">Select Class:</label>
                        <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Class:</label>
                      </v-flex>
                      <v-flex xs8 sm7 class="ml-3">
                        <v-select
                          :items="addclass"
                          v-model="editedItem.classId"
                          item-text="classNum"
                          item-value="_id"
                          name="Select Class"
                          required
                          @change="editGetCourses(editedItem.classId)"
                        ></v-select>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs12 sm12>
                        <v-layout>
                          <v-flex xs4 sm5 class="pt-4 subheading">
                            <label class="right">Select Course:</label>
                          </v-flex>
                          <v-flex xs8 sm7 class="ml-3">
                            <v-select
                              :items="editCourseData"
                              label="Select Course"
                              v-model="editedItem.courseId"
                              item-text="courseName"
                              item-value="_id"
                              required
                              class="ml-2"
                            ></v-select>
                          </v-flex>
                        </v-layout>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs4 sm5 class="pt-4 subheading">
                        <label class="right">Subject:</label>
                      </v-flex>
                      <v-flex xs8 sm7 class="ml-3">
                        <v-text-field v-model="editedItem.subject" type="text" required></v-text-field>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs4 sm5 class="pt-4 subheading">
                        <label class="right">Description:</label>
                      </v-flex>
                      <v-flex xs8 sm7 class="ml-3">
                        <v-text-field v-model="editedItem.description" type="text" required></v-text-field>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs4 sm5 class="pt-4 subheading">
                        <label class="right hidden-xs-only hidden-sm-only">Upload Image:</label>
                        <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Upload:</label>
                      </v-flex>
                      <v-flex xs8 sm7 class="ml-3">
                        <v-text-field
                          @click="pickEditFile"
                          v-model="editImageName"
                          append-icon="attach_file"
                        ></v-text-field>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                </v-layout>
                <v-layout>
                  <v-flex xs12 sm12 class="px-0 mx-0">
                    <v-layout class="right">
                      <v-btn @click="save" round dark :loading="editLoading" class="add-button">Save</v-btn>
                    </v-layout>
                  </v-flex>
                </v-layout>
              </v-container>
            </v-form>
          </v-card-text>
        </v-card>
      </v-dialog>
      <!-- ****** DIsCUSIION TABLE ****** -->
      <v-toolbar color="transparent" flat>
        <v-spacer></v-spacer>
        <v-flex xs12 sm4 md2>
          <v-select
            small
            :items="addclass"
            label="Select Class"
            v-model="getSelectedData.classId"
            item-text="classNum"
            item-value="_id"
            name="Select Class"
            @change="getCourses(getSelectedData.classId)"
            class="mr-2"
            required
          ></v-select>
        </v-flex>
        <v-flex xs12 sm4 md2>
          <v-select
            :items="courseData"
            label="Select Course"
            v-model="getSelectedData.courseId"
            item-text="courseName"
            item-value="_id"
            required
            class="ml-2"
            @change="getCourseDiscussionTable(getSelectedData.courseId)"
          ></v-select>
        </v-flex>
        <v-card-title class="body-1" v-show="show">
          <v-btn icon large flat @click="displaySearch">
            <v-avatar size="27">
              <img src="/static/icon/search.png" alt="icon" />
            </v-avatar>
          </v-btn>
        </v-card-title>
612b79bb4   Amber Dev   made serch auto f...
157
        <v-flex xs8 sm8 md3 lg2 v-if="showSearch">
dea4d2889   Neeraj Sharma   task commited
158
          <v-layout>
01a4a5246   Shikha Mishra   When the modal wa...
159
160
161
162
163
164
165
            <v-text-field
              autofocus
              v-model="search"
              label="Search"
              prepend-inner-icon="search"
              color="primary"
            ></v-text-field>
dea4d2889   Neeraj Sharma   task commited
166
167
168
169
170
171
172
173
174
175
176
            <v-icon @click="closeSearch" color="error">close</v-icon>
          </v-layout>
        </v-flex>
      </v-toolbar>
      <v-data-table
        :headers="headers"
        :items="courseDiscussionData"
        :pagination.sync="pagination"
        :search="search"
      >
        <template slot="items" slot-scope="props">
48defdd99   Neeraj Sharma   fixed task
177
          <tr class="tr row-click" @click="rowCourseDiscussion(props.item._id)">
dea4d2889   Neeraj Sharma   task commited
178
179
180
181
182
183
            <td class="text-xs-center td td-row">
              <v-avatar size="40">
                <img :src="props.item.attachementUrl" v-if="props.item.attachementUrl" />
                <img src="/static/icon/user.png" v-else-if="!props.item.attachementUrl" />
              </v-avatar>
            </td>
48defdd99   Neeraj Sharma   fixed task
184
            <td class="text-xs-center td td-row">{{ props.item.subject }}</td>
dea4d2889   Neeraj Sharma   task commited
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
            <td class="text-xs-center td td-row">{{ props.item.studentId.name}}</td>
            <td class="text-xs-center td td-row">-</td>
            <td class="text-xs-center td td-row">{{ props.item.forumThread.length }}</td>
            <td class="text-xs-center td td-row">
              <span>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:18px; "
                    class="mr-3"
                    @click="editItem(props.item)"
                    src="/static/icon/edit.png"
                  />
                  <span>Edit</span>
                </v-tooltip>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:20px; "
                    class="mr-3"
                    @click="deleteItem(props.item)"
                    src="/static/icon/delete.png"
                  />
                  <span>Delete</span>
                </v-tooltip>
              </span>
            </td>
          </tr>
        </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-snackbar
        :timeout="timeout"
        :top="y === 'top'"
        :right="x === 'right'"
        :vertical="mode === 'vertical'"
        v-model="snackbar"
01a4a5246   Shikha Mishra   When the modal wa...
227
        :color="color"
dea4d2889   Neeraj Sharma   task commited
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
      >{{ text }}</v-snackbar>
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
    </v-container>
  </template>
  
  <script>
  import http from "@/Services/http.js";
  import moment from "moment";
  
  export default {
    data: () => ({
      snackbar: false,
      y: "top",
      x: "right",
      mode: "",
      timeout: 3000,
      text: "",
01a4a5246   Shikha Mishra   When the modal wa...
247
      color: "",
dea4d2889   Neeraj Sharma   task commited
248
249
250
251
252
253
254
255
      show: true,
      showSearch: false,
      showLoader: false,
      loading: false,
      date: null,
      search: "",
      addclass: [],
      pagination: {
01a4a5246   Shikha Mishra   When the modal wa...
256
        rowsPerPage: 10,
dea4d2889   Neeraj Sharma   task commited
257
258
259
260
261
262
      },
      headers: [
        {
          text: "Image",
          value: "subjattachementUrlect",
          sortable: false,
01a4a5246   Shikha Mishra   When the modal wa...
263
          align: "center",
dea4d2889   Neeraj Sharma   task commited
264
265
266
267
268
        },
        {
          text: "Discussion",
          value: "subject",
          sortable: false,
01a4a5246   Shikha Mishra   When the modal wa...
269
          align: "center",
dea4d2889   Neeraj Sharma   task commited
270
271
272
273
274
275
        },
        { text: "Started", value: "studentId", sortable: false, align: "center" },
        {
          text: "Last Post",
          value: "forumThread",
          sortable: false,
01a4a5246   Shikha Mishra   When the modal wa...
276
          align: "center",
dea4d2889   Neeraj Sharma   task commited
277
278
        },
        { text: "replies", value: "email", sortable: false, align: "center" },
01a4a5246   Shikha Mishra   When the modal wa...
279
        { text: "Action", value: "", sortable: false, align: "center" },
dea4d2889   Neeraj Sharma   task commited
280
281
282
283
      ],
      token: "",
      selectStudents: {
        select: "",
01a4a5246   Shikha Mishra   When the modal wa...
284
        selectSection: "",
dea4d2889   Neeraj Sharma   task commited
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
      },
  
      role: "",
      schoolRole: "",
      menu: false,
      valid: true,
  
      getSelectedData: {},
      courseDiscussionData: [],
      courseData: [],
      editCourseData: [],
      addSection: [],
      editedItem: {},
      editDialog: false,
      editedIndex: -1,
      editiImageFile: "",
      editImageName: "",
      editImageUrl: "",
01a4a5246   Shikha Mishra   When the modal wa...
303
304
      editLoading: false,
      showData: false,
dea4d2889   Neeraj Sharma   task commited
305
306
307
308
309
310
311
312
313
    }),
    methods: {
      // save(date) {
      //   this.$refs.menu.save(date);
      // },
      pickEditFile() {
        this.$refs.editDataImage.click();
      },
      onEditFilePicked(e) {
860da881d   Shikha Mishra   comment all consoles
314
        //   console.log(e);
dea4d2889   Neeraj Sharma   task commited
315
316
317
        const files = e.target.files;
        if (files[0] !== undefined) {
          this.editImageName = files[0].name;
860da881d   Shikha Mishra   comment all consoles
318
          // console.log("this.editImageName", this.editImageName);
dea4d2889   Neeraj Sharma   task commited
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
  
          if (this.editImageName.lastIndexOf(".") <= 0) {
            return;
          }
          const fr = new FileReader();
          fr.readAsDataURL(files[0]);
          fr.addEventListener("load", () => {
            this.editImageUrl = fr.result;
            this.editiImageFile = files[0]; // this is an image file that can be sent to server...
          });
        } else {
          this.editImageName = "";
          this.editiImageFile = "";
        }
      },
      getAllClass() {
        http()
          .get("/getClassesList", {
01a4a5246   Shikha Mishra   When the modal wa...
337
            headers: { Authorization: "Bearer " + this.token },
dea4d2889   Neeraj Sharma   task commited
338
          })
01a4a5246   Shikha Mishra   When the modal wa...
339
          .then((response) => {
dea4d2889   Neeraj Sharma   task commited
340
341
            this.addclass = response.data.data;
          })
01a4a5246   Shikha Mishra   When the modal wa...
342
          .catch((error) => {
dea4d2889   Neeraj Sharma   task commited
343
344
345
346
347
348
349
350
351
            // console.log("err====>", err);
            // this.$router.replace({ path: "/" });
          });
      },
      getCourses(classId) {
        this.showLoader = true;
        http()
          .get("/getCourseesList", {
            params: {
01a4a5246   Shikha Mishra   When the modal wa...
352
353
              classId: classId,
            },
dea4d2889   Neeraj Sharma   task commited
354
          })
01a4a5246   Shikha Mishra   When the modal wa...
355
          .then((response) => {
dea4d2889   Neeraj Sharma   task commited
356
357
358
            this.courseData = response.data.data;
            this.showLoader = false;
          })
01a4a5246   Shikha Mishra   When the modal wa...
359
          .catch((err) => {
860da881d   Shikha Mishra   comment all consoles
360
            //   console.log("err====>", err);
dea4d2889   Neeraj Sharma   task commited
361
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
362
363
364
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
dea4d2889   Neeraj Sharma   task commited
365
366
367
368
369
370
371
          });
      },
      editGetCourses(classId) {
        this.showLoader = true;
        http()
          .get("/getCourseesList", {
            params: {
01a4a5246   Shikha Mishra   When the modal wa...
372
373
              classId: classId,
            },
dea4d2889   Neeraj Sharma   task commited
374
          })
01a4a5246   Shikha Mishra   When the modal wa...
375
          .then((response) => {
dea4d2889   Neeraj Sharma   task commited
376
377
378
            this.editCourseData = response.data.data;
            this.showLoader = false;
          })
01a4a5246   Shikha Mishra   When the modal wa...
379
          .catch((err) => {
860da881d   Shikha Mishra   comment all consoles
380
            //   console.log("err====>", err);
dea4d2889   Neeraj Sharma   task commited
381
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
382
383
384
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
dea4d2889   Neeraj Sharma   task commited
385
386
387
388
389
390
391
392
393
          });
      },
      getCourseDiscussionTable(id) {
        // console.log("id", this.getSelectedData.courseId);
        this.showLoader = true;
        http()
          .get("/getCourseDiscussionesList", {
            params: {
              classId: this.getSelectedData.classId,
01a4a5246   Shikha Mishra   When the modal wa...
394
395
              courseId: id,
            },
dea4d2889   Neeraj Sharma   task commited
396
          })
01a4a5246   Shikha Mishra   When the modal wa...
397
          .then((response) => {
dea4d2889   Neeraj Sharma   task commited
398
399
            //   console.log("response", response.data.data);
            this.courseDiscussionData = response.data.data;
01a4a5246   Shikha Mishra   When the modal wa...
400
401
402
403
404
405
406
407
            if (this.courseDiscussionData.length === 0) {
              this.showLoader = false;
              this.snackbar = true;
              this.text = "Data not found!";
              this.color = "error";
              return;
            }
            this.showData = true;
dea4d2889   Neeraj Sharma   task commited
408
409
            this.showLoader = false;
          })
01a4a5246   Shikha Mishra   When the modal wa...
410
          .catch((error) => {
860da881d   Shikha Mishra   comment all consoles
411
            //   console.log("err====>", error);
dea4d2889   Neeraj Sharma   task commited
412
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
413
414
415
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
dea4d2889   Neeraj Sharma   task commited
416
417
          });
      },
48defdd99   Neeraj Sharma   fixed task
418
      rowCourseDiscussion(id) {
a8bd267e9   Amber Dev   added course disc...
419
        this.$router.push({
48defdd99   Neeraj Sharma   fixed task
420
          name: "Course Discussiones Fourm",
01a4a5246   Shikha Mishra   When the modal wa...
421
          params: { discussionId: id },
48defdd99   Neeraj Sharma   fixed task
422
423
        });
      },
dea4d2889   Neeraj Sharma   task commited
424
425
426
427
428
429
      editItem(item) {
        this.editedIndex = this.courseDiscussionData.indexOf(item);
        this.editedItem = Object.assign({}, item);
        this.editDialog = true;
      },
      save() {
860da881d   Shikha Mishra   comment all consoles
430
        //   console.log("this.editedItem", this.editedItem);
dea4d2889   Neeraj Sharma   task commited
431
432
433
434
435
        let editCourseDiscuss = {
          courseDiscussionId: this.editedItem._id,
          courseId: this.editedItem.courseId,
          studentId: this.editedItem.studentId._id,
          subject: this.editedItem.subject,
01a4a5246   Shikha Mishra   When the modal wa...
436
          description: this.editedItem.description,
dea4d2889   Neeraj Sharma   task commited
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
        };
        if (this.editedItem.classId._id) {
          editCourseDiscuss.classId = this.editedItem.classId._id;
        }
        if (!this.editedItem.classId._id) {
          editCourseDiscuss.classId = this.editedItem.classId;
        }
        if (this.editImageUrl) {
          var str = this.editImageUrl;
          const [baseUrl, editImageUrl] = str.split(/,/);
          editCourse.upload = editImageUrl;
        }
        this.editLoading = true;
        http()
          .put("/updateCourseDiscussion", editCourseDiscuss)
01a4a5246   Shikha Mishra   When the modal wa...
452
          .then((response) => {
dea4d2889   Neeraj Sharma   task commited
453
454
455
456
457
458
459
460
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
            this.imageUrl = "";
            this.getCourseDiscussionTable();
            this.editDialog = false;
            this.editLoading = false;
          })
01a4a5246   Shikha Mishra   When the modal wa...
461
          .catch((error) => {
dea4d2889   Neeraj Sharma   task commited
462
463
464
465
466
467
468
469
            this.editLoading = false;
            this.snackbar = true;
            this.text = error.response.data.statusText;
            this.color = "error";
          });
      },
      deleteItem(item) {
        let deleteCourseDiscussion = {
01a4a5246   Shikha Mishra   When the modal wa...
470
          courseDiscussionId: item._id,
dea4d2889   Neeraj Sharma   task commited
471
472
473
474
475
        };
        http()
          .delete(
            "/deleteCourseDiscussion",
            confirm("Are you sure you want to delete this?") && {
01a4a5246   Shikha Mishra   When the modal wa...
476
              params: deleteCourseDiscussion,
dea4d2889   Neeraj Sharma   task commited
477
478
            }
          )
01a4a5246   Shikha Mishra   When the modal wa...
479
          .then((response) => {
dea4d2889   Neeraj Sharma   task commited
480
481
482
483
484
            this.snackbar = true;
            this.text = response.data.message;
            this.color = "green";
            this.getCourseDiscussionTable();
          })
01a4a5246   Shikha Mishra   When the modal wa...
485
          .catch((error) => {
dea4d2889   Neeraj Sharma   task commited
486
487
488
489
490
491
492
493
494
495
496
497
498
            this.snackbar = true;
            this.text = error.response.data.message;
            this.color = "error";
          });
      },
      displaySearch() {
        this.show = false;
        this.showSearch = true;
      },
      closeSearch() {
        this.showSearch = false;
        this.show = true;
        this.search = "";
01a4a5246   Shikha Mishra   When the modal wa...
499
      },
dea4d2889   Neeraj Sharma   task commited
500
501
502
503
504
505
    },
    mounted() {
      // this.getStudentList();
      this.token = this.$store.state.token;
      this.role = this.$store.state.role;
      this.getAllClass();
01a4a5246   Shikha Mishra   When the modal wa...
506
    },
dea4d2889   Neeraj Sharma   task commited
507
  };
48defdd99   Neeraj Sharma   fixed task
508
509
510
511
512
513
514
  </script>
  
  <style>
  .row-click {
    cursor: pointer !important;
  }
  </style>