CourseDiscussionForum.vue
11.3 KB
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
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
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
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
227
228
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<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>
<!-- DIALOG TO ADD COURSE DISCUSSION FORUM -->
<v-dialog v-model="addForumDialog" max-width="500" persistent>
<v-card flat class="card-style pa-2" dark>
<v-layout>
<v-flex xs12>
<label class="title text-xs-center">Add Forum</label>
<v-icon size="24" class="right" @click="addForumDialog = false">cancel</v-icon>
</v-flex>
</v-layout>
<v-container fluid>
<v-layout align-center>
<v-flex xs12>
<v-flex xs12 sm12>
<v-form ref="form" v-model="valid" lazy-validation>
<v-layout>
<v-flex
xs12
class="text-xs-center text-sm-center text-md-center text-lg-center"
>
<v-avatar size="100px" v-if="!imageUrl">
<img src="/static/icon/user.png" />
</v-avatar>
<input
type="file"
style="display: none"
ref="image"
accept="image/*"
@change="onFilePicked"
/>
<img
:src="imageData.imageUrl"
height="150"
width="150"
v-if="imageUrl"
style="border-radius:50%; width:200px"
/>
</v-flex>
</v-layout>
<v-layout wrap>
<!-- SUBJECT -->
<v-flex xs12 sm12>
<v-layout>
<v-flex xs4 sm4 class="pt-4 subheading">
<label class="right hidden-xs-only hidden-sm-only">Subject:</label>
<label class="right hidden-lg-only hidden-md-only hidden-xl-only">Subject:</label>
</v-flex>
<v-flex xs8 sm8 class="ml-3">
<v-text-field
v-model="addForumParams.subject"
placeholder="subject"
type="text"
:rules="cantBeEmpty"
required
></v-text-field>
</v-flex>
</v-layout>
</v-flex>
<!-- DESCRIPTION -->
<v-flex xs12 sm12>
<v-layout>
<v-flex xs4 sm4 class="pt-4 subheading">
<label class="right hidden-xs-only hidden-sm-only">Description:</label>
<label
class="right hidden-lg-only hidden-md-only hidden-xl-only"
>Description:</label>
</v-flex>
<v-flex xs8 sm8 class="ml-3">
<v-text-field
v-model="addForumParams.description"
placeholder="Description"
type="text"
:rules="cantBeEmpty"
required
></v-text-field>
</v-flex>
</v-layout>
</v-flex>
<!-- UPLOAD IMAGE -->
<v-flex xs12 sm12>
<v-layout>
<v-flex xs4 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 class="ml-3">
<v-text-field
label="Select Image"
@click="pickFile"
v-model="imageName"
append-icon="attach_file"
></v-text-field>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
<v-layout>
<v-flex xs12 sm12>
<v-layout class="right">
<v-btn @click="submit" round dark :loading="loading" class="add-button">Add</v-btn>
</v-layout>
</v-flex>
</v-layout>
</v-form>
</v-flex>
</v-flex>
</v-layout>
</v-container>
</v-card>
</v-dialog>
<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">Course Discussion Forum</div>
<div class="subheading grey--text lighten-1">General news and announcements</div>
</v-flex>
<!-- ADD DISCUSSION FORUM BUTTON -->
<v-flex>
<div>
<v-btn
fab
dark
class="open-dialog-button hidden-xl-only hidden-md-only hidden-lg-only"
small
@click="addForumDialog = true"
>
<v-icon dark>add</v-icon>
</v-btn>
<v-btn
round
class="open-dialog-button hidden-sm-only hidden-xs-only"
dark
@click="addForumDialog = true"
>
<v-icon class="white--text pr-1" size="20">add</v-icon>Add A New Discussion Topic
</v-btn>
</div>
</v-flex>
<!-- DATA TABLE -->
<v-flex></v-flex>
</v-layout>
<!-- NEXT CHAPTER -->
<!-- <v-flex
class="text-xs-right mt-5"
v-if="indexSelectedChapter < chapterNames.length -1"
@click="showSelectedChapter()"
>
<span style="cursor: pointer;" class="subheading font-weight-bold">
{{chapterNames[indexSelectedChapter + 1]}}
<v-icon class="black--text" style="position:relative; top: 4px;">chevron_right</v-icon>
</span>
</v-flex>-->
<!-- <v-flex class="text-xs-right mt-5" v-else>
<span class="subheading font-weight-bold">Return to chapter one</span>
</v-flex>-->
</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.coursrName}}
</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";
export default {
mixins: [AllApiCalls],
data() {
return {
valid: true,
addForumDialog: false,
addForumParams: {},
// UPLOAD IMAGE
imageName: "",
imageUrl: "",
imageFile: "",
imageData: {}
};
},
methods: {
/* UPLOAD IMAGE */
pickFile() {
this.$refs.image.click();
},
onFilePicked(e) {
// console.log(e)
const files = e.target.files;
this.imageData.upload = e.target.files[0];
if (files[0] !== undefined) {
this.imageName = files[0].name;
if (this.imageName.lastIndexOf(".") <= 0) {
return;
}
const fr = new FileReader();
fr.readAsDataURL(files[0]);
fr.addEventListener("load", () => {
this.imageUrl = fr.result;
this.imageFile = files[0]; // this is an image file that can be sent to server...
this.imageData.imageUrl = URL.createObjectURL(this.imageFile);
});
} else {
this.imageName = "";
this.imageFile = "";
this.imageUrl = "";
}
},
submit() {
if (this.$refs.form.validate()) {
this.addForumParams.classId = localStorage.getItem("parentClassId");
this.addForumParams.courseId = this.$route.query.courseId;
this.addForumParams.studentId = localStorage.getItem("parentStudentId");
if (this.imageUrl) {
var str = this.imageUrl;
const [baseUrl, imageUrl] = str.split(/,/);
this.addForumParams.upload = imageUrl;
}
this.loading = true;
http()
.post("/createCourseDiscussion", this.addForumParams)
.then(response => {
this.snackbar = true;
this.text = "Discussion added successfully";
this.snackbarColor = "green";
this.addForumDialog = false;
this.clear();
this.loading = false;
console.log("response of createCourseDiscussion - ", response);
})
.catch(error => {
this.snackbar = true;
this.text = error.response.data.message;
this.color = "error";
this.loading = false;
});
}
},
clear() {
this.$refs.form.reset();
this.imageUrl = "";
},
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");
}
}
},
async created() {
/* getStudentCourses - to get courseData - defined in GetApis.js*/
await this.getStudentCourses({
classId: localStorage.getItem("parentClassId"),
studentId: localStorage.getItem("parentStudentId")
});
}
};
</script>
<style scoped>
.side-bar-color {
color: #827bfa !important;
/* border-top-right-radius: 74px !important; */
}
.card-border {
border: 1px #bdbdbd solid;
border-radius: 3px;
}
</style>