Blame view

src/pages/Dashboard/Announcement.vue 18.2 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
23
24
25
26
27
28
29
      <v-container grid-list-xl class="pt-0">
        <v-layout row class="mt-1">
          <v-flex xs8>
            <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
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
                  <!-- COURSE ANNOUNCEMENTS REPLY FUNCTIONALITY -->
                  <template slot="expand" slot-scope="props">
                    <v-layout>
                      <v-flex xs12 v-for="(annoucementData,i) in annoucementData" :key="i">
                        <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>
                        <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>
                        <v-flex
                          xs12
                          class="mt-4 pl-5 mx-auto"
                          v-for="(replyThread,i) in annoucementData.discussionThread"
                          :key="i"
                        >
                          <v-card class="elevation-0 grey lighten-3" flat>
                            <v-list two-line subheader class="grey lighten-3 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
c50650743   Amber Dev   added Announcemen...
157
158
159
160
161
162
163
164
                                    <span
                                      class="info--text"
                                      v-if="replyThread.teacherId"
                                    >{{ replyThread.teacherId.name }}</span>
                                    <span
                                      class="info--text"
                                      v-if="replyThread.studentId"
                                    >{{ replyThread.studentId.name }}</span>
3a557c5ae   Amber Dev   added reply annou...
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
                                    - {{dates(replyThread.created ) }}
                                  </v-list-tile-sub-title>
                                </v-list-tile-content>
                              </v-list-tile>
                            </v-list>
                            <v-list class="pa-2 reply-desc">
                              <v-list-tile-content>
                                <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>
                              </v-list-tile-content>
                            </v-list>
                            <v-list class="grey lighten-4 pa-0">
                              <v-list-tile-action>
                                <v-spacer></v-spacer>
c50650743   Amber Dev   added Announcemen...
195
196
197
                                <div
                                  v-if="replyThread.studentId && replyThread.studentId._id == localStorage.getItem('parentStudentId')"
                                >
3a557c5ae   Amber Dev   added reply annou...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
                                  <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-flex>
                    </v-layout>
                  </template>
3f7b85167   Amber Dev   added announcements
220
221
222
223
224
225
226
227
228
                  <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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
          </v-flex>
  
          <v-spacer></v-spacer>
  
          <!-- COURSES - positioned to the right of the page -->
          <v-flex xs3>
            <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...
263
  import moment from "moment";
3f7b85167   Amber Dev   added announcements
264
265
266
267
  export default {
    mixins: [AllApiCalls],
    data() {
      return {
3f7b85167   Amber Dev   added announcements
268
        // DATA TABLE
c50650743   Amber Dev   added Announcemen...
269
270
        localStorage: localStorage,
        moment: moment,
3f7b85167   Amber Dev   added announcements
271
272
273
274
        search: "",
        pagination: {
          rowsPerPage: 10
        },
3a557c5ae   Amber Dev   added reply annou...
275
        announcementHeaders: [
3f7b85167   Amber Dev   added announcements
276
          {
3a557c5ae   Amber Dev   added reply annou...
277
278
            text: "Image",
            value: "attachementUrl",
3f7b85167   Amber Dev   added announcements
279
            sortable: false,
3a557c5ae   Amber Dev   added reply annou...
280
            align: "center"
3f7b85167   Amber Dev   added announcements
281
282
          },
          {
3a557c5ae   Amber Dev   added reply annou...
283
284
            text: "Discussion Type",
            value: "discussionType",
3f7b85167   Amber Dev   added announcements
285
286
287
            sortable: false,
            align: "center"
          },
3a557c5ae   Amber Dev   added reply annou...
288
          { text: "Action", value: "", sortable: false, align: "center" }
3f7b85167   Amber Dev   added announcements
289
        ],
3a557c5ae   Amber Dev   added reply annou...
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
        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: "",
        editedIndex: -1
3f7b85167   Amber Dev   added announcements
312
313
314
      };
    },
    methods: {
3a557c5ae   Amber Dev   added reply annou...
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
      getAnnoucementes() {
        this.showLoader = true;
        http()
          .get("/getAnnoucementesList", {
            params: {
              courseId: this.$route.query.courseId,
              classId: localStorage.getItem("parentClassId")
            }
          })
          .then(response => {
            this.announcementsList = response.data.data;
            this.showLoader = false;
          })
          .catch(err => {
            console.log("err====>", err);
            this.showLoader = false;
          });
3f7b85167   Amber Dev   added announcements
332
      },
c50650743   Amber Dev   added Announcemen...
333
334
335
336
337
338
339
340
341
342
343
344
345
346
      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",
            query: { courseId: courseId }
          });
        } else {
          this.seeSnackbar("No Data Available", "warning");
        }
      },
3a557c5ae   Amber Dev   added reply annou...
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
      // COURSE ANNOUNCEMENTS REPLY FUNCTONALITY
      dates: function(date) {
        return moment(date).format("MMMM DD, YYYY hh:mm A");
      },
      getDiscussionesThread() {
        // console.log("id", this.getSelectedData.courseId);
        this.showLoader = true;
        http()
          .get("/getParticularAnnoucement", {
            params: {
              annoucementId: this.selectedAnnoucementId
            }
          })
          .then(response => {
            //   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;
          })
          .catch(error => {
            console.log("err====>", error);
            this.showLoader = false;
3f7b85167   Amber Dev   added announcements
386
          });
3f7b85167   Amber Dev   added announcements
387
      },
3a557c5ae   Amber Dev   added reply annou...
388
389
390
      replyThreadDiscussion() {
        this.showLoader = true;
        var payloadData = {
c50650743   Amber Dev   added Announcemen...
391
392
          annoucementId: this.selectedAnnoucementId,
          studentId: localStorage.getItem("parentStudentId"),
3a557c5ae   Amber Dev   added reply annou...
393
394
395
396
397
          description: this.replyDescription
        };
        http()
          .put("/replyThread", payloadData)
          .then(response => {
3a557c5ae   Amber Dev   added reply annou...
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
            this.showLoader = false;
            this.getDiscussionesThread();
          })
          .catch(error => {
            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
425
          }
3a557c5ae   Amber Dev   added reply annou...
426
          arrayOfannoucementData.push(this.annoucementData[i]);
3f7b85167   Amber Dev   added announcements
427
        }
3a557c5ae   Amber Dev   added reply annou...
428
        this.annoucementData = arrayOfannoucementData;
3f7b85167   Amber Dev   added announcements
429
      },
3a557c5ae   Amber Dev   added reply annou...
430
431
432
433
      updateRelpyThreadDiscussion(replyThread) {
        this.showLoader = true;
        var payloadData = {
          discussionThreadId: replyThread._id,
c50650743   Amber Dev   added Announcemen...
434
435
          annoucementId: this.selectedAnnoucementId,
          studentId: localStorage.getItem("parentStudentId"),
3a557c5ae   Amber Dev   added reply annou...
436
437
438
439
440
441
442
443
444
445
446
          description: replyThread.description
        };
        http()
          .put("/updateThread", payloadData)
          .then(response => {
            this.showLoader = false;
            this.getDiscussionesThread();
          })
          .catch(error => {
            this.showLoader = false;
          });
3f7b85167   Amber Dev   added announcements
447
      },
3a557c5ae   Amber Dev   added reply annou...
448
449
450
451
      deleteRelpyThreadDiscussion(id) {
        this.showLoader = true;
        var payloadData = {
          discussionThreadId: id,
c50650743   Amber Dev   added Announcemen...
452
          annoucementId: this.selectedAnnoucementId
3a557c5ae   Amber Dev   added reply annou...
453
454
455
456
457
458
459
460
461
462
463
464
        };
        http()
          .put(
            "/deleteThread",
            confirm("Are you sure you want to delete this?") && payloadData
          )
          .then(response => {
            this.showLoader = false;
            this.getDiscussionesThread();
          })
          .catch(error => {
            this.showLoader = false;
3f7b85167   Amber Dev   added announcements
465
          });
3f7b85167   Amber Dev   added announcements
466
467
468
469
470
471
472
473
      }
    },
    async created() {
      /* getStudentCourses - to get courseData - defined in GetApis.js*/
      await this.getStudentCourses({
        classId: localStorage.getItem("parentClassId"),
        studentId: localStorage.getItem("parentStudentId")
      });
3a557c5ae   Amber Dev   added reply annou...
474
475
      /* getAnnoucementesList - to populate the data table */
      this.getAnnoucementes();
3f7b85167   Amber Dev   added announcements
476
477
478
479
480
481
482
483
484
485
486
487
    }
  };
  </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...
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
  
  /* 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
506
  </style>