Blame view

src/pages/Dashboard/Announcement.vue 18.9 KB
3f7b85167   Amber Dev   added announcements
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  <template>
    <div class="body-color">
      <!-- LOADER -->
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
  
      <!-- SNACKBAR -->
      <v-snackbar
        :timeout="timeout"
        :top="y === 'top'"
        :right="x === 'right'"
        :vertical="mode === 'vertical'"
        v-model="snackbar"
        :color="snackbarColor"
      >
        {{ text }}
        <v-spacer></v-spacer>
        <v-btn flat text @click="snackbar = false">X</v-btn>
      </v-snackbar>
3f7b85167   Amber Dev   added announcements
21
22
      <v-container grid-list-xl class="pt-0">
        <v-layout row class="mt-1">
8ac91bfcd   Amber Dev   added changes to ...
23
          <v-flex xs12 md9>
3f7b85167   Amber Dev   added announcements
24
25
26
27
28
29
            <v-layout column>
              <!-- HEADING -->
              <v-flex>
                <div class="title side-bar-color font-weight-bold">Announcements</div>
                <div class="subheading grey--text lighten-1">General news and announcements</div>
              </v-flex>
3f7b85167   Amber Dev   added announcements
30
31
32
              <!-- DATA TABLE -->
              <v-flex>
                <v-data-table
3a557c5ae   Amber Dev   added reply annou...
33
34
                  :headers="announcementHeaders"
                  :items="announcementsList"
3f7b85167   Amber Dev   added announcements
35
36
                  :pagination.sync="pagination"
                  :search="search"
3a557c5ae   Amber Dev   added reply annou...
37
                  item-key="_id"
3f7b85167   Amber Dev   added announcements
38
39
                >
                  <template slot="items" slot-scope="props">
3a557c5ae   Amber Dev   added reply annou...
40
41
                    <tr
                      class="tr"
c50650743   Amber Dev   added Announcemen...
42
43
                      @click="props.expanded = !props.expanded; selectedAnnoucementId = props.item._id; getDiscussionesThread()"
                      style="cursor: pointer;"
3a557c5ae   Amber Dev   added reply annou...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
                    >
                      <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>
                      <td class="text-xs-center td td-row">{{ props.item.discussionType}}</td>
                      <td class="text-xs-center td td-row">
                        <span>
                          <v-tooltip top>
                            <img
                              slot="activator"
                              style="cursor:pointer; width:25px; height:25px; "
                              class="mr-3"
                              @click="profile(props.item)"
                              src="/static/icon/view.png"
                            />
                            <span>View</span>
                          </v-tooltip>
3a557c5ae   Amber Dev   added reply annou...
64
65
                        </span>
                      </td>
3f7b85167   Amber Dev   added announcements
66
67
                    </tr>
                  </template>
3a557c5ae   Amber Dev   added reply annou...
68
69
70
71
                  <!-- COURSE ANNOUNCEMENTS REPLY FUNCTIONALITY -->
                  <template slot="expand" slot-scope="props">
                    <v-layout>
                      <v-flex xs12 v-for="(annoucementData,i) in annoucementData" :key="i">
8ac91bfcd   Amber Dev   added changes to ...
72
                        <!-- TOPIC HEADING -->
3a557c5ae   Amber Dev   added reply annou...
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
                        <v-card class="elevation-0 grey lighten-3 pa-2" flat>
                          <v-list two-line subheader>
                            <v-list-tile>
                              <v-list-tile-avatar>
                                <v-avatar size="46">
                                  <img
                                    :src="annoucementData.attachementUrl"
                                    v-if="annoucementData.attachementUrl"
                                  />
                                  <img
                                    src="/static/icon/user.png"
                                    v-else-if="!annoucementData.attachementUrl"
                                  />
                                </v-avatar>
                              </v-list-tile-avatar>
                              <v-list-tile-content>
                                <v-list-tile-title>{{ annoucementData.discussionType }}</v-list-tile-title>
                                <!-- <v-list-tile-sub-title>
                    By
                    <span class="info--text">{{ annoucementData.studentId.name }}</span>
                    - {{dates(annoucementData.created ) }}
                                </v-list-tile-sub-title>-->
                              </v-list-tile-content>
                              <v-list-tile-action>
                                <div>
                                  <v-btn
                                    flat
                                    round
                                    dark
                                    class="reply-btn"
                                    @click="showReplyBox = true"
                                  >Reply</v-btn>
                                </div>
                              </v-list-tile-action>
                            </v-list-tile>
                          </v-list>
                        </v-card>
8ac91bfcd   Amber Dev   added changes to ...
110
                        <!-- REPLY BOX -->
3a557c5ae   Amber Dev   added reply annou...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
                        <v-flex xs12 class="mt-4" v-show="showReplyBox">
                          <v-textarea
                            name="input-7-1"
                            solo
                            label="Label Text"
                            multi-line
                            v-model="replyDescription"
                          ></v-textarea>
                          <v-btn
                            round
                            dark
                            class="open-dialog-button"
                            flat
                            @click="showReplyBox = false"
                          >Cancel</v-btn>
                          <v-btn
                            round
                            dark
                            :loading="loading"
                            class="reply-btn"
                            @click="replyThreadDiscussion()"
                          >Submit</v-btn>
                        </v-flex>
8ac91bfcd   Amber Dev   added changes to ...
134
135
136
137
                        <!-- REPLY THREAD -->
                        <v-layout
                          :class="['mt-4','pl-5','mx-auto',replyThread.teacherId?'justify-start':'justify-end']"
                          v-for="(replyThread,i) in annoucementData.discussionThread.slice().reverse()"
3a557c5ae   Amber Dev   added reply annou...
138
139
                          :key="i"
                        >
8ac91bfcd   Amber Dev   added changes to ...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
                          <v-flex xs12 md7>
                            <v-card class="elevation-0 grey lighten-1" flat>
                              <v-list two-line subheader class="grey lighten-1 pa-1">
                                <v-list-tile>
                                  <v-list-tile-avatar>
                                    <v-avatar size="46">
                                      <img
                                        :src="annoucementData.attachementUrl"
                                        v-if="annoucementData.attachementUrl"
                                      />
                                      <img
                                        src="/static/icon/user.png"
                                        v-else-if="!annoucementData.attachementUrl"
                                      />
                                    </v-avatar>
                                  </v-list-tile-avatar>
                                  <v-list-tile-content>
                                    <v-list-tile-title>Re: {{ annoucementData.discussionType }}</v-list-tile-title>
                                    <v-list-tile-sub-title>
                                      By
                                      <span
                                        class="info--text"
                                        v-if="replyThread.teacherId"
                                      >{{ replyThread.teacherId.name }}</span>
                                      <span
                                        class="info--text"
                                        v-if="replyThread.studentId"
                                      >{{ replyThread.studentId.name }}</span>
                                      - {{dates(replyThread.created ) }}
                                    </v-list-tile-sub-title>
                                  </v-list-tile-content>
                                </v-list-tile>
                              </v-list>
                              <v-list class="pa-2 reply-desc">
3a557c5ae   Amber Dev   added reply annou...
174
                                <v-list-tile-content>
8ac91bfcd   Amber Dev   added changes to ...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
                                  <v-list-tile-title
                                    v-show="replyThread.showDescriptionReplyThread"
                                  >{{ replyThread.description }}</v-list-tile-title>
                                  <v-flex
                                    xs12
                                    sm12
                                    md4
                                    v-show="replyThread.showUpdateReplyThread == true"
                                  >
                                    <v-text-field v-model="replyThread.description"></v-text-field>
                                    <v-btn
                                      flat
                                      round
                                      dark
                                      class="reply-btn right"
                                      @click="updateRelpyThreadDiscussion(replyThread)"
                                    >Save</v-btn>
                                  </v-flex>
3a557c5ae   Amber Dev   added reply annou...
193
                                </v-list-tile-content>
8ac91bfcd   Amber Dev   added changes to ...
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
                              </v-list>
                              <v-list class="grey lighten-4 pa-0">
                                <v-list-tile-action>
                                  <v-spacer></v-spacer>
                                  <div
                                    v-if="replyThread.studentId && replyThread.studentId._id == localStorage.getItem('parentStudentId')"
                                  >
                                    <v-btn
                                      flat
                                      round
                                      dark
                                      class="reply-btn"
                                      @click="deleteRelpyThreadDiscussion(replyThread._id)"
                                    >Delete</v-btn>
                                    <v-btn
                                      flat
                                      round
                                      dark
                                      class="reply-btn mr-4"
                                      @click="showUpdateReplyThreadDiscussion(replyThread)"
                                    >Edit</v-btn>
                                  </div>
                                </v-list-tile-action>
                              </v-list>
                            </v-card>
                          </v-flex>
                        </v-layout>
3a557c5ae   Amber Dev   added reply annou...
221
222
223
                      </v-flex>
                    </v-layout>
                  </template>
3f7b85167   Amber Dev   added announcements
224
225
226
227
228
229
230
231
232
                  <v-alert
                    slot="no-results"
                    :value="true"
                    color="error"
                    icon="warning"
                  >Your search for "{{ search }}" found no results.</v-alert>
                </v-data-table>
              </v-flex>
            </v-layout>
3f7b85167   Amber Dev   added announcements
233
234
235
236
237
          </v-flex>
  
          <v-spacer></v-spacer>
  
          <!-- COURSES - positioned to the right of the page -->
8ac91bfcd   Amber Dev   added changes to ...
238
          <v-flex xs12 md3>
3f7b85167   Amber Dev   added announcements
239
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
266
            <v-card class="elevation-0 card-border" height="100%">
              <v-container class="pt-0">
                <div class="side-bar-color font-weight-bold title">Courses</div>
  
                <div v-for="(course,index) in courseData">
                  <v-btn
                    flat
                    class="subheading text-xs-start justify-left"
                    style="cursor: pointer;"
                    block
                    @click="routeToCourseDetails(course._id)"
                  >
                    <div style="width: 100%;text-align: left;">
                      <v-icon style="color: red;padding-bottom: 3px;" size="15">play_arrow</v-icon>
                      {{course.courseName}}
                    </div>
                  </v-btn>
                </div>
              </v-container>
            </v-card>
          </v-flex>
        </v-layout>
      </v-container>
    </div>
  </template>
  <script>
  import AllApiCalls from "@/Services/AllApiCalls.js";
  import http from "@/Services/http.js";
c50650743   Amber Dev   added Announcemen...
267
  import moment from "moment";
3f7b85167   Amber Dev   added announcements
268
269
270
271
  export default {
    mixins: [AllApiCalls],
    data() {
      return {
3f7b85167   Amber Dev   added announcements
272
        // DATA TABLE
c50650743   Amber Dev   added Announcemen...
273
274
        localStorage: localStorage,
        moment: moment,
3f7b85167   Amber Dev   added announcements
275
276
        search: "",
        pagination: {
860da881d   Shikha Mishra   comment all consoles
277
          rowsPerPage: 10,
3f7b85167   Amber Dev   added announcements
278
        },
3a557c5ae   Amber Dev   added reply annou...
279
        announcementHeaders: [
3f7b85167   Amber Dev   added announcements
280
          {
3a557c5ae   Amber Dev   added reply annou...
281
282
            text: "Image",
            value: "attachementUrl",
3f7b85167   Amber Dev   added announcements
283
            sortable: false,
860da881d   Shikha Mishra   comment all consoles
284
            align: "center",
3f7b85167   Amber Dev   added announcements
285
286
          },
          {
3a557c5ae   Amber Dev   added reply annou...
287
288
            text: "Discussion Type",
            value: "discussionType",
3f7b85167   Amber Dev   added announcements
289
            sortable: false,
860da881d   Shikha Mishra   comment all consoles
290
            align: "center",
3f7b85167   Amber Dev   added announcements
291
          },
860da881d   Shikha Mishra   comment all consoles
292
          { text: "Action", value: "", sortable: false, align: "center" },
3f7b85167   Amber Dev   added announcements
293
        ],
3a557c5ae   Amber Dev   added reply annou...
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
        announcementsList: [],
        selectedAnnoucementId: "",
  
        // COURSE ANNOUNCEMENTS REPLY FUNCTONALITY
        snackbar: false,
        y: "top",
        x: "right",
        mode: "",
        timeout: 3000,
        text: "",
        showLoader: false,
        loading: false,
        date: null,
        token: "",
        role: "",
        schoolRole: "",
        menu: false,
        annoucementData: {},
        showReplyBox: false,
        replyDescription: "",
        loginId: "",
860da881d   Shikha Mishra   comment all consoles
315
        editedIndex: -1,
3f7b85167   Amber Dev   added announcements
316
317
318
      };
    },
    methods: {
3a557c5ae   Amber Dev   added reply annou...
319
320
321
322
323
324
      getAnnoucementes() {
        this.showLoader = true;
        http()
          .get("/getAnnoucementesList", {
            params: {
              courseId: this.$route.query.courseId,
860da881d   Shikha Mishra   comment all consoles
325
326
              classId: localStorage.getItem("parentClassId"),
            },
3a557c5ae   Amber Dev   added reply annou...
327
          })
860da881d   Shikha Mishra   comment all consoles
328
          .then((response) => {
3a557c5ae   Amber Dev   added reply annou...
329
330
331
            this.announcementsList = response.data.data;
            this.showLoader = false;
          })
860da881d   Shikha Mishra   comment all consoles
332
333
          .catch((err) => {
            //   console.log("err====>", err);
3a557c5ae   Amber Dev   added reply annou...
334
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
335
336
337
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
3a557c5ae   Amber Dev   added reply annou...
338
          });
3f7b85167   Amber Dev   added announcements
339
      },
c50650743   Amber Dev   added Announcemen...
340
341
342
343
344
345
346
347
      async routeToCourseDetails(courseId) {
        /* getParticularCourseDetail- To get courseDetail - defined in GetApis.js*/
        let response = await this.getParticularCourseDetail(courseId);
  
        /* If the response is null then dont route */
        if (response.data.data.length > 0) {
          this.$router.push({
            name: "Course Details",
860da881d   Shikha Mishra   comment all consoles
348
            query: { courseId: courseId },
c50650743   Amber Dev   added Announcemen...
349
350
351
352
353
          });
        } else {
          this.seeSnackbar("No Data Available", "warning");
        }
      },
3a557c5ae   Amber Dev   added reply annou...
354
      // COURSE ANNOUNCEMENTS REPLY FUNCTONALITY
860da881d   Shikha Mishra   comment all consoles
355
      dates: function (date) {
3a557c5ae   Amber Dev   added reply annou...
356
357
358
359
360
361
362
363
        return moment(date).format("MMMM DD, YYYY hh:mm A");
      },
      getDiscussionesThread() {
        // console.log("id", this.getSelectedData.courseId);
        this.showLoader = true;
        http()
          .get("/getParticularAnnoucement", {
            params: {
860da881d   Shikha Mishra   comment all consoles
364
365
              annoucementId: this.selectedAnnoucementId,
            },
3a557c5ae   Amber Dev   added reply annou...
366
          })
860da881d   Shikha Mishra   comment all consoles
367
          .then((response) => {
3a557c5ae   Amber Dev   added reply annou...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
            //   console.log("response", response.data.data);
            this.annoucementData = response.data.data;
            // console.log("response", this.annoucementData);
            for (let i = 0; i < this.annoucementData.length; i++) {
              for (
                let j = 0;
                j < this.annoucementData[i].discussionThread.length;
                j++
              ) {
                if (this.annoucementData[i].discussionThread[j]) {
                  this.annoucementData[i].discussionThread[
                    j
                  ].showUpdateReplyThread = false;
                  this.annoucementData[i].discussionThread[
                    j
                  ].showDescriptionReplyThread = true;
                }
              }
            }
            this.showLoader = false;
            this.showReplyBox = false;
          })
860da881d   Shikha Mishra   comment all consoles
390
391
          .catch((error) => {
            //   console.log("err====>", error);
3a557c5ae   Amber Dev   added reply annou...
392
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
393
394
395
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
3f7b85167   Amber Dev   added announcements
396
          });
3f7b85167   Amber Dev   added announcements
397
      },
3a557c5ae   Amber Dev   added reply annou...
398
399
400
      replyThreadDiscussion() {
        this.showLoader = true;
        var payloadData = {
c50650743   Amber Dev   added Announcemen...
401
402
          annoucementId: this.selectedAnnoucementId,
          studentId: localStorage.getItem("parentStudentId"),
860da881d   Shikha Mishra   comment all consoles
403
          description: this.replyDescription,
3a557c5ae   Amber Dev   added reply annou...
404
405
406
        };
        http()
          .put("/replyThread", payloadData)
860da881d   Shikha Mishra   comment all consoles
407
          .then((response) => {
3a557c5ae   Amber Dev   added reply annou...
408
409
410
            this.showLoader = false;
            this.getDiscussionesThread();
          })
860da881d   Shikha Mishra   comment all consoles
411
          .catch((error) => {
3a557c5ae   Amber Dev   added reply annou...
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
            this.showLoader = false;
          });
      },
      showUpdateReplyThreadDiscussion(item) {
        this.editedIndex = this.annoucementData.indexOf(item);
        var editedItem = Object.assign({}, item);
        var arrayOfannoucementData = [];
        for (let i = 0; i < this.annoucementData.length; i++) {
          for (
            let j = 0;
            j < this.annoucementData[i].discussionThread.length;
            j++
          ) {
            if (
              editedItem._id == this.annoucementData[i].discussionThread[j]._id
            ) {
              this.annoucementData[i].discussionThread[
                j
              ].showUpdateReplyThread = true;
              this.annoucementData[i].discussionThread[
                j
              ].showDescriptionReplyThread = false;
            }
3f7b85167   Amber Dev   added announcements
435
          }
3a557c5ae   Amber Dev   added reply annou...
436
          arrayOfannoucementData.push(this.annoucementData[i]);
3f7b85167   Amber Dev   added announcements
437
        }
3a557c5ae   Amber Dev   added reply annou...
438
        this.annoucementData = arrayOfannoucementData;
3f7b85167   Amber Dev   added announcements
439
      },
3a557c5ae   Amber Dev   added reply annou...
440
441
442
443
      updateRelpyThreadDiscussion(replyThread) {
        this.showLoader = true;
        var payloadData = {
          discussionThreadId: replyThread._id,
c50650743   Amber Dev   added Announcemen...
444
445
          annoucementId: this.selectedAnnoucementId,
          studentId: localStorage.getItem("parentStudentId"),
860da881d   Shikha Mishra   comment all consoles
446
          description: replyThread.description,
3a557c5ae   Amber Dev   added reply annou...
447
448
449
        };
        http()
          .put("/updateThread", payloadData)
860da881d   Shikha Mishra   comment all consoles
450
          .then((response) => {
3a557c5ae   Amber Dev   added reply annou...
451
452
453
            this.showLoader = false;
            this.getDiscussionesThread();
          })
860da881d   Shikha Mishra   comment all consoles
454
          .catch((error) => {
3a557c5ae   Amber Dev   added reply annou...
455
456
            this.showLoader = false;
          });
3f7b85167   Amber Dev   added announcements
457
      },
3a557c5ae   Amber Dev   added reply annou...
458
459
460
461
      deleteRelpyThreadDiscussion(id) {
        this.showLoader = true;
        var payloadData = {
          discussionThreadId: id,
860da881d   Shikha Mishra   comment all consoles
462
          annoucementId: this.selectedAnnoucementId,
3a557c5ae   Amber Dev   added reply annou...
463
464
465
466
467
468
        };
        http()
          .put(
            "/deleteThread",
            confirm("Are you sure you want to delete this?") && payloadData
          )
860da881d   Shikha Mishra   comment all consoles
469
          .then((response) => {
3a557c5ae   Amber Dev   added reply annou...
470
471
472
            this.showLoader = false;
            this.getDiscussionesThread();
          })
860da881d   Shikha Mishra   comment all consoles
473
          .catch((error) => {
3a557c5ae   Amber Dev   added reply annou...
474
            this.showLoader = false;
3f7b85167   Amber Dev   added announcements
475
          });
860da881d   Shikha Mishra   comment all consoles
476
      },
3f7b85167   Amber Dev   added announcements
477
478
479
480
481
    },
    async created() {
      /* getStudentCourses - to get courseData - defined in GetApis.js*/
      await this.getStudentCourses({
        classId: localStorage.getItem("parentClassId"),
860da881d   Shikha Mishra   comment all consoles
482
        studentId: localStorage.getItem("parentStudentId"),
3f7b85167   Amber Dev   added announcements
483
      });
3a557c5ae   Amber Dev   added reply annou...
484
485
      /* getAnnoucementesList - to populate the data table */
      this.getAnnoucementes();
860da881d   Shikha Mishra   comment all consoles
486
    },
3f7b85167   Amber Dev   added announcements
487
488
489
490
491
492
493
494
495
496
497
  };
  </script>
  <style scoped>
  .side-bar-color {
    color: #827bfa !important;
    /* border-top-right-radius: 74px !important; */
  }
  .card-border {
    border: 1px #bdbdbd solid;
    border-radius: 3px;
  }
c50650743   Amber Dev   added Announcemen...
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
  
  /* ANNOUNCEMENTS REPLY FUNCTIONALITY */
  .reply-desc {
    border: 1px solid #f2f2f2;
  }
  .open-dialog-button {
    background: #827bfa !important;
    border-color: #827bfa !important;
    text-transform: none !important;
  }
  
  .reply-btn {
    background: #feb83c !important;
    border-color: #feb83c !important;
    text-transform: none !important;
    -webkit-box-shadow: none !important;
    box-shadow: none !important;
  }
3f7b85167   Amber Dev   added announcements
516
  </style>