Blame view
src/pages/Subjects/subjects.vue
14.9 KB
beb598536
|
1 |
<template> |
68d742034
|
2 3 4 5 6 7 8 9 |
<v-container fluid class="body-color"> <!-- ****** EDIT Subject ****** --> <v-dialog v-model="editSubjectDialog" max-width="400px"> <v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Edit Subject</label> <v-icon size="24" class="right" @click="editSubjectDialog = false">cancel</v-icon> |
beb598536
|
10 |
</v-flex> |
68d742034
|
11 12 13 |
</v-layout> <v-container fluid> <v-form ref="formEditSubject" v-model="validEditSubject" lazy-validation> |
46db0a3b5
|
14 |
<v-layout> |
68d742034
|
15 16 |
<v-flex xs4 class="pt-4 subheading"> <label class="right">Class:</label> |
46db0a3b5
|
17 |
</v-flex> |
68d742034
|
18 |
<v-flex xs8 class="ml-3"> |
46db0a3b5
|
19 20 21 |
<v-select :items="classList" label="Select Class" |
68d742034
|
22 |
v-model="addSubject.selectName" |
46db0a3b5
|
23 24 25 |
item-text="classNum" item-value="_id" name="Select Class" |
68d742034
|
26 |
:rules="nameEditSubjectRules" |
46db0a3b5
|
27 28 29 30 |
required ></v-select> </v-flex> </v-layout> |
68d742034
|
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 |
<v-layout> <v-flex xs4 class="pt-4 subheading"> <label class="right">Subject:</label> </v-flex> <v-flex xs8 class="ml-3"> <v-text-field placeholder="fill your Subject" v-model="editedItem.subjectName" :rules="subjectEditNameRules" type="text" name="email" required ></v-text-field> </v-flex> </v-layout> <v-flex xs12 sm12> <v-card-actions> <v-btn round dark @click.native="close" class="clear-button">Cancel</v-btn> <v-spacer></v-spacer> <v-btn round dark @click="save" :loading="editLoading" class="add-button">Save</v-btn> </v-card-actions> </v-flex> </v-form> </v-container> </v-card> </v-dialog> |
beb598536
|
57 |
|
68d742034
|
58 |
<!-- ****** VIEW PROFIL NOTICE BOARD ****** --> |
beb598536
|
59 |
|
68d742034
|
60 |
<v-dialog v-model="viewSubjectDialog" max-width="600px"> |
c8fc8e42e
|
61 |
<v-toolbar flat class="card-style pa-3" dark> |
68d742034
|
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
<v-spacer></v-spacer> <v-toolbar-title> <h3>Subject</h3> </v-toolbar-title> <v-spacer></v-spacer> <v-icon @click="close1">close</v-icon> </v-toolbar> <v-card> <v-card-text> <v-container grid-list-md> <v-layout wrap> <v-flex> <v-layout> <v-flex xs7 sm6> <h5 class="right my-1"> <b>Subject Name:</b> </h5> </v-flex> <v-flex sm6 xs5> <h5 class="my-1">{{ editedItem.subjectName }}</h5> |
beb598536
|
82 83 |
</v-flex> </v-layout> |
68d742034
|
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 |
</v-flex> </v-layout> </v-container> </v-card-text> </v-card> </v-dialog> <!-- ****** EXISTING SUBJECTS TABLE ****** --> <v-toolbar color="transparent" flat> <v-btn fab dark class="open-dialog-button hidden-xl-only hidden-md-only hidden-lg-only" small @click="addSubjectDialog = true" > <v-icon dark>add</v-icon> </v-btn> <v-flex xs1 class="hidden-sm-only hidden-xs-only"> <v-btn round class="open-dialog-button" dark @click="addSubjectDialog = true"> <v-icon class="white--text pr-1" size="20">add</v-icon>Add Subject </v-btn> </v-flex> <v-spacer></v-spacer> <v-flex lg2 md2 xs12 v-show="show"> <v-select :items="classList" label="Select Your Class" v-model="selectClassId" item-text="classNum" item-value="_id" name="Select Class" :rules="nameRules" @change="getClassSubject" class="pl-2" required ></v-select> </v-flex> <v-card-title class="body-1" v-show="show"> <v-btn icon flat @click="displaySearch"> <v-avatar size="27"> |
aa310d61a
|
125 |
<img src="/static/icon/search.png" alt="icon" /> |
68d742034
|
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 |
</v-avatar> </v-btn> </v-card-title> <v-flex xs9 sm9 md2 lg2 xl2 v-show="showSearch"> <v-layout> <v-text-field v-model="search" label="Search" prepend-inner-icon="search" color="primary" style="transition: 0.8s cubic-bezier(0.25, 0.8, 0.25, 1); !important" ></v-text-field> <v-icon @click="closeSearch" color="error">close</v-icon> </v-layout> </v-flex> </v-toolbar> <v-data-table :headers="headers" :items="subjectList.subjects" :pagination.sync="pagination" :search="search" > <template slot="items" slot-scope="props"> <tr class="tr"> <td class="td-row td">{{ props.index + 1 }}</td> <td class="text-xs-center td td-row">{{ props.item.subjectName }}</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)" |
aa310d61a
|
160 |
src="/static/icon/view.png" |
68d742034
|
161 162 163 164 165 166 167 168 169 |
/> <span>View</span> </v-tooltip> <v-tooltip top> <img slot="activator" style="cursor:pointer; width:20px; height:18px; " class="mr-3" @click="editItem(props.item)" |
aa310d61a
|
170 |
src="/static/icon/edit.png" |
68d742034
|
171 172 173 174 175 176 177 178 179 |
/> <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)" |
aa310d61a
|
180 |
src="/static/icon/delete.png" |
68d742034
|
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 |
/> <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> <!-- ****** ADD MULTIPLE Subject ****** --> <v-snackbar :timeout="timeout" :top="y === 'top'" :right="x === 'right'" :vertical="mode === 'vertical'" v-model="snackbar" :color="color" >{{ text }}</v-snackbar> <v-dialog v-model="addSubjectDialog" max-width="400px"> <v-card flat class="card-style pa-2" dark> <v-layout> <v-flex xs12> <label class="title text-xs-center">Add Subject</label> <v-icon size="24" class="right" @click="addSubjectDialog = false">cancel</v-icon> |
beb598536
|
210 |
</v-flex> |
68d742034
|
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 |
</v-layout> <v-container fluid fill-height> <v-layout align-center> <v-flex xs12> <v-form ref="form" v-model="valid" lazy-validation> <v-layout> <v-flex xs4 sm4 class="pt-4 subheading"> <label class="right">Class :</label> </v-flex> <v-flex xs8 sm8 class="ml-3"> <v-select v-model="addSubject.classId" label="Select your class" type="text" :items="classList" item-text="classNum" item-value="_id" :rules="nameRules" required ></v-select> </v-flex> </v-layout> <v-layout> <v-flex xs4 sm4 class="pt-4 subheading"> <label class="right">Subject :</label> </v-flex> <v-flex xs8 sm8 class="ml-3"> <v-text-field v-model="addSubject.subjectName" placeholder="fill your Subject Name" name="name" type="text" :rules="subjectRules" required ></v-text-field> </v-flex> </v-layout> <v-layout> <v-flex xs12 sm12> <v-card-actions> <v-btn @click="clear" round dark class="clear-button">Clear</v-btn> <v-spacer></v-spacer> <v-btn @click="submit" round dark :loading="loading" class="add-button">Add</v-btn> </v-card-actions> </v-flex> </v-layout> </v-form> </v-flex> </v-layout> |
beb598536
|
260 |
</v-container> |
68d742034
|
261 262 |
</v-card> </v-dialog> |
36fc987df
|
263 264 265 |
<div class="loader" v-if="showLoader"> <v-progress-circular indeterminate color="white"></v-progress-circular> </div> |
68d742034
|
266 |
</v-container> |
beb598536
|
267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
</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: "", |
0721aca93
|
281 |
color: "", |
68d742034
|
282 283 |
show: true, showSearch: false, |
fc82ac667
|
284 |
showLoader: false, |
beb598536
|
285 |
loading: false, |
afc98f028
|
286 |
editLoading: false, |
beb598536
|
287 288 |
date: null, search: "", |
68d742034
|
289 290 |
viewSubjectDialog: false, editSubjectDialog: false, |
beb598536
|
291 |
valid: true, |
afc98f028
|
292 |
validEditSubject: true, |
68d742034
|
293 294 295 |
addSubjectDialog: false, // isActive: true, // newActive: false, |
beb598536
|
296 |
gender: ["Male", "Female"], |
beb598536
|
297 |
pagination: { |
68d742034
|
298 |
rowsPerPage: 10 |
beb598536
|
299 |
}, |
46db0a3b5
|
300 301 |
token: "", nameRules: [v => !!v || " Class Name is required"], |
afc98f028
|
302 |
nameEditSubjectRules: [v => !!v || " Class Name is required"], |
46db0a3b5
|
303 |
subjectRules: [v => !!v || " Subject Name is required"], |
39fb2832e
|
304 |
subjectEditNameRules: [v => !!v || " Subject Name is required"], |
beb598536
|
305 306 307 |
headers: [ { text: "No", |
68d742034
|
308 |
align: "", |
beb598536
|
309 310 311 |
sortable: false, value: "No" }, |
fc82ac667
|
312 |
{ |
46db0a3b5
|
313 314 |
text: "Subject Name", value: "subjectName", |
fc82ac667
|
315 316 317 |
sortable: false, align: "center" }, |
beb598536
|
318 319 |
{ text: "Action", value: "", sortable: false, align: "center" } ], |
46db0a3b5
|
320 321 |
subjectList: [], classList: [], |
beb598536
|
322 |
editedIndex: -1, |
46db0a3b5
|
323 324 |
addSubject: {}, selectClassId: "", |
0721aca93
|
325 |
selectClassId: "", |
beb598536
|
326 |
editedItem: { |
46db0a3b5
|
327 |
subjectName: "" |
a17c68a03
|
328 |
} |
beb598536
|
329 |
}), |
beb598536
|
330 331 332 333 |
methods: { pickFile() { this.$refs.image.click(); }, |
beb598536
|
334 |
editItem(item) { |
c8fc8e42e
|
335 |
this.editedIndex = this.subjectList.subjects; |
beb598536
|
336 337 |
this.editedItem = Object.assign({}, item); this.dialog = true; |
c8fc8e42e
|
338 |
this.editSubjectDialog = true; |
beb598536
|
339 340 |
}, profile(item) { |
c8fc8e42e
|
341 |
this.editedIndex = this.subjectList.subjects; |
beb598536
|
342 343 |
this.editedItem = Object.assign({}, item); this.dialog1 = true; |
c8fc8e42e
|
344 |
this.viewSubjectDialog = true; |
beb598536
|
345 346 |
}, deleteItem(item) { |
46db0a3b5
|
347 |
let deleteSubject = { |
0721aca93
|
348 |
classId: this.selectClassId, |
46db0a3b5
|
349 |
subjectId: item._id |
beb598536
|
350 351 352 |
}; http() .delete( |
46db0a3b5
|
353 |
"/deleteSubject", |
beb598536
|
354 |
confirm("Are you sure you want to delete this?") && { |
46db0a3b5
|
355 |
params: deleteSubject |
beb598536
|
356 357 358 |
} ) .then(response => { |
0721aca93
|
359 360 361 |
this.getClassSubject(); this.snackbar = true; this.text = "Successfully delete Existing Subject"; |
beb598536
|
362 363 |
}) .catch(error => { |
c8fc8e42e
|
364 365 366 |
this.snackbar = true; this.text = error.response.data.message; this.color = "error"; |
beb598536
|
367 368 |
}); }, |
beb598536
|
369 |
close() { |
68d742034
|
370 |
this.editSubjectDialog = false; |
beb598536
|
371 372 |
}, close1() { |
68d742034
|
373 |
this.viewSubjectDialog = false; |
beb598536
|
374 375 376 |
}, submit() { if (this.$refs.form.validate()) { |
beb598536
|
377 |
http() |
46db0a3b5
|
378 |
.post("/addSubject", this.addSubject) |
beb598536
|
379 |
.then(response => { |
0721aca93
|
380 381 382 |
this.getClassSubject(); this.snackbar = true; this.text = "New Subject added successfully"; |
beb598536
|
383 |
this.clear(); |
0721aca93
|
384 |
this.color = "green"; |
68d742034
|
385 |
this.addSubjectDialog = false; |
beb598536
|
386 387 388 |
}) .catch(error => { // console.log(error); |
0721aca93
|
389 390 391 |
this.snackbar = true; this.text = error.response.data.message; this.color = "error"; |
beb598536
|
392 393 394 |
}); } }, |
beb598536
|
395 396 397 398 |
clear() { this.$refs.form.reset(); }, save() { |
afc98f028
|
399 400 401 402 403 404 405 406 407 408 409 |
if (this.$refs.formEditSubject.validate()) { let editSubject = { classId: this.addSubject.selectName, subjectId: this.editedItem._id, subjectName: this.editedItem.subjectName }; this.editLoading = true; http() .put("/updateSubject", editSubject) .then(response => { this.snackbar = true; |
46db0a3b5
|
410 |
this.text = "Successfully Edit Existing Subject"; |
afc98f028
|
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
this.editLoading = false; http() .get( "/getParticularClass", { params: { classId: this.selectClassId } }, { headers: { Authorization: "Bearer " + this.token } } ) .then(response => { this.subjectList = response.data.data; this.getClassSubject(); this.snackbar = true; this.color = "green"; this.text = response.data.message; this.close(); }) .catch(err => { console.log("err====>", err); }); }) .catch(error => { this.editLoading = false; // console.log(error); }); } |
beb598536
|
438 |
}, |
0721aca93
|
439 |
getClassSubject() { |
68d742034
|
440 |
this.showLoader = true; |
0721aca93
|
441 |
this.selectClassId = this.selectClassId; |
46db0a3b5
|
442 443 444 445 446 447 448 449 450 451 |
http() .get( "/getParticularClass", { params: { classId: this.selectClassId } }, { headers: { Authorization: "Bearer " + this.token } } ) .then(response => { this.subjectList = response.data.data; |
68d742034
|
452 |
this.showLoader = false; |
46db0a3b5
|
453 454 |
}) .catch(err => { |
68d742034
|
455 |
this.showLoader = false; |
46db0a3b5
|
456 457 458 459 460 461 462 463 464 465 |
}); }, getClass() { http() .get("/getClassesList", { headers: { Authorization: "Bearer " + this.token } }) .then(response => { this.classList = response.data.data; }) |
00e4bc4e1
|
466 |
.catch(error => { |
a17c68a03
|
467 468 469 470 471 |
if (error.response.status === 401) { this.$router.replace({ path: "/" }); this.$store.dispatch("setToken", null); this.$store.dispatch("Id", null); } |
46db0a3b5
|
472 |
}); |
68d742034
|
473 474 475 476 477 478 479 480 |
}, displaySearch() { (this.show = false), (this.showSearch = true); }, closeSearch() { this.showSearch = false; this.show = true; this.search = ""; |
beb598536
|
481 482 483 |
} }, mounted() { |
46db0a3b5
|
484 485 486 |
this.token = this.$store.state.token; // this.getNoticeDataList(); this.getClass(); |
beb598536
|
487 488 |
} }; |
68d742034
|
489 |
</script> |