changeStudents.vue
5.67 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
<template>
<v-app id="login">
<!-- 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>
<v-container fluid fill-height>
<v-layout>
<v-flex xs12 sm8 md8 lg5 offset-sm2 offset-lg3 class="mt-5">
<v-card flat class="Card-style pa-2" id="form">
<v-layout>
<v-flex xs12>
<label class="title text-xs-center">Change Student</label>
</v-flex>
</v-layout>
<v-card-text>
<v-flex xs12 sm8 md8 lg8 offset-sm2>
<v-form class="mt-3">
<v-select
:items="studentsData"
item-text="name"
item-value="_id"
v-model="changeStudent"
label="Students"
></v-select>
</v-form>
</v-flex>
</v-card-text>
<v-card-actions>
<v-flex text-xs-center>
<v-btn round dark :loading="loading" @click="change" class="add-button">Change</v-btn>
</v-flex>
</v-card-actions>
</v-card>
</v-flex>
</v-layout>
</v-container>
</v-app>
</template>
<script>
import http from "@/Services/http.js";
import AllApiCalls from "@/Services/AllApiCalls.js";
export default {
mixins: [AllApiCalls],
data() {
return {
snackbar: false,
y: "top",
x: "right",
mode: "",
timeout: 4000,
text: "",
loading: false,
valid: false,
changeStudent: "",
studentsData: [],
};
},
mounted() {
this.getparentStudents();
},
methods: {
change() {
localStorage.setItem("parentStudentId", this.changeStudent);
/* Look for active student object */
for(var i = 0; i < this.studentsData.length; i++){
if(this.studentsData[i]._id == this.changeStudent){
this.$store.dispatch("SET_ACTIVE_STUDENT",this.studentsData[i])
}
}
this.$router.replace({ path: "/" });
},
getparentStudents() {
this.showLoader = true;
http()
.get("/parentStudentsList")
.then((response) => {
// console.log("students - ", response.data.data.students);
/* prepare an array of false status students */
var indexStatusFalse = [];
for (var i = 0; i < response.data.data.students.length; i++) {
if (response.data.data.students[i].status == false) {
indexStatusFalse.push(i);
}
}
/* introduce a property named disabled in response to make false staus students disbled */
for (var i = 0; i < indexStatusFalse.length; i++) {
response.data.data.students[indexStatusFalse[i]].disabled = true;
}
/* make an array of students to be displayed in select box */
this.studentsData = response.data.data.students;
/* counter to keep a track of number of students that are disabled or false */
var counter = 0;
/* if zero element of false students list is > 0 then make first student as defalut selected */
if (indexStatusFalse[0] > 0) {
this.changeStudent = response.data.data.students[0]._id;
}
// console.log("indexStatusFalse - ", indexStatusFalse);
/* if false student is the first one in the list then see if the next is also false */
if (indexStatusFalse[0] == 0) {
if (indexStatusFalse.length > 1) {
for (var i = 1; i < indexStatusFalse.length; i++) {
if (indexStatusFalse[i] == i) {
if (indexStatusFalse[i - 1] == i - 1) {
counter = i + 1;
continue;
}
} else {
counter = i;
break;
}
}
} else {
counter = 1;
}
}
// console.log("counter - ", counter);
if (counter == response.data.data.students.length) {
this.seeSnackbar(
"Your wards have been removed you will be logged out",
"warning"
);
setTimeout(() => {
this.$store.dispatch("setToken", null);
this.$router.replace({ path: "/" });
this.$store.dispatch("Id", null);
}, 3000);
} else {
this.changeStudent = response.data.data.students[counter]._id;
}
localStorage.setItem("parentStudentId", this.changeStudent);
localStorage.setItem(
"parentClassId",
response.data.data.students[0].classId
);
this.showLoader = false;
})
.catch((err) => {
// console.log("err====>", err);
this.showLoader = false;
this.snackbar = true;
this.color = "error";
this.text = error.response.data.message;
});
},
},
computed: {
color() {
return this.loading ? "success" : "error";
},
},
};
</script>
<style scoped>
img {
position: absolute;
top: 13px;
left: 50px;
}
.v-btn--large {
padding: 0px 74px;
}
@media screen and (max-width: 769px) {
.v-btn--large {
font-size: 14px;
height: 44px;
padding: 0 32px;
}
}
</style>