Commit 32fcd6960d80b4b108fbdd93938d480e303c33af

Authored by Amber Dev
1 parent f1f1fb0261

added logout if all students disabled

src/pages/Authentication/Login.vue
... ... @@ -2,14 +2,19 @@
2 2 <v-app id="login">
3 3 <v-content>
4 4 <v-container fluid fill-height>
  5 + <!-- SNACKBAR -->
5 6 <v-snackbar
6 7 :timeout="timeout"
7 8 :top="y === 'top'"
8 9 :right="x === 'right'"
9 10 :vertical="mode === 'vertical'"
10 11 v-model="snackbar"
11   - :color="color"
12   - >{{ text }}</v-snackbar>
  12 + :color="snackbarColor"
  13 + >
  14 + {{ text }}
  15 + <v-spacer></v-spacer>
  16 + <v-btn flat text @click="snackbar = false">X</v-btn>
  17 + </v-snackbar>
13 18 <v-layout align-center justify-center>
14 19 <v-flex xs12 sm10 md5 lg4>
15 20 <img
... ... @@ -82,27 +87,30 @@
82 87  
83 88 <script>
84 89 import http from "@/Services/http.js";
  90 +import AllApiCalls from "@/Services/AllApiCalls.js";
85 91 export default {
  92 + mixins: [AllApiCalls],
86 93 data() {
87 94 return {
88   - snackbar: false,
89   - y: "top",
90   - x: "right",
91   - mode: "",
92   - timeout: 3000,
93   - text: "",
  95 + // snackbar: false,
  96 + // y: "top",
  97 + // x: "right",
  98 + // mode: "",
  99 + // timeout: 3000,
  100 + // text: "",
94 101 append: "",
95 102 e1: true,
96 103 loading: false,
97 104 remember: false,
98 105 valid: false,
99 106 userLogincredentials: {},
100   - nameRules: [v => !!v || "Username is required"],
  107 + nameRules: [(v) => !!v || "Username is required"],
101 108 password: "",
102 109 email: "",
103 110 rules: {
104   - required: value => !!value || "password is Required."
105   - }
  111 + required: (value) => !!value || "password is Required.",
  112 + },
  113 + selectedStudent: {},
106 114 };
107 115 },
108 116 methods: {
... ... @@ -111,7 +119,7 @@ export default {
111 119 this.loading = true;
112 120 var userdata = {
113 121 email: this.userLogincredentials.email,
114   - password: this.userLogincredentials.password
  122 + password: this.userLogincredentials.password,
115 123 };
116 124 if (/^[0-9]{10}$/.test(this.userLogincredentials.email)) {
117 125 userdata.fatherCellNo = this.userLogincredentials.email;
... ... @@ -119,7 +127,7 @@ export default {
119 127 }
120 128 http()
121 129 .post("/schoolLogin", userdata)
122   - .then(response => {
  130 + .then((response) => {
123 131 // console.log("token",response.data.data);
124 132 this.loading = false;
125 133 if (response.data.data.role === "ADMIN") {
... ... @@ -152,10 +160,90 @@ export default {
152 160 this.$store.dispatch("Id", response.data.data.id);
153 161 this.$store.dispatch("Role", response.data.data.role);
154 162 localStorage.setItem("parentStudentId", response.data.data.id);
155   - this.$router.push("/dashboard");
  163 +
  164 + http()
  165 + .get("/parentStudentsList")
  166 + .then((response) => {
  167 + /* set disabled students values */
  168 + console.log("students - ", response.data.data.students);
  169 + /* prepare an array of false status students */
  170 + var indexStatusFalse = [];
  171 + for (var i = 0; i < response.data.data.students.length; i++) {
  172 + if (response.data.data.students[i].status == false) {
  173 + indexStatusFalse.push(i);
  174 + }
  175 + }
  176 + /* introduce a property named disabled in response to make false staus students disbled */
  177 + for (var i = 0; i < indexStatusFalse.length; i++) {
  178 + response.data.data.students[
  179 + indexStatusFalse[i]
  180 + ].disabled = true;
  181 + }
  182 + /* make an array of students */
  183 + this.$store.dispatch(
  184 + "SET_STUDENTS_DATA",
  185 + response.data.data.students
  186 + );
  187 +
  188 + /* counter to keep a track of number of students that are disabled or false */
  189 + var counter = 0;
  190 + /* if zero element of false students list is > 0 then make first student as defalut selected */
  191 + if (indexStatusFalse[0] > 0) {
  192 + this.selectedStudent = response.data.data.students[0]._id;
  193 + }
  194 + console.log("indexStatusFalse - ", indexStatusFalse);
  195 + /* if false student is the first one in the list then see if the next is also false */
  196 + if (indexStatusFalse[0] == 0) {
  197 + if (indexStatusFalse.length > 1) {
  198 + for (var i = 1; i < indexStatusFalse.length; i++) {
  199 + if (indexStatusFalse[i] == i) {
  200 + if (indexStatusFalse[i - 1] == i - 1) {
  201 + counter = i + 1;
  202 + continue;
  203 + }
  204 + } else {
  205 + counter = i;
  206 + break;
  207 + }
  208 + }
  209 + } else {
  210 + counter = 1;
  211 + }
  212 + }
  213 + console.log("counter - ", counter);
  214 + if (counter == response.data.data.students.length) {
  215 + this.seeSnackbar(
  216 + "Your wards have been removed ",
  217 + "warning"
  218 + );
  219 +
  220 + this.$store.dispatch("setToken", null);
  221 + // this.$router.replace({ path: "/" });
  222 + this.$store.dispatch("Id", null);
  223 + // this.$router.replace({ path: "/" });
  224 + } else {
  225 + this.selectedStudent =
  226 + response.data.data.students[counter]._id;
  227 +
  228 + localStorage.setItem(
  229 + "parentStudentId",
  230 + this.selectedStudent
  231 + );
  232 + localStorage.setItem(
  233 + "parentClassId",
  234 + response.data.data.students[counter].classId
  235 + );
  236 + this.$router.push("/dashboard");
  237 + }
  238 + this.showLoader = false;
  239 + })
  240 + .catch((err) => {
  241 + console.log("err====>", err);
  242 + this.showLoader = false;
  243 + });
156 244 }
157 245 })
158   - .catch(error => {
  246 + .catch((error) => {
159 247 if (error.response.data.message) {
160 248 this.text = error.response.data.message;
161 249 this.snackbar = true;
... ... @@ -167,7 +255,7 @@ export default {
167 255 }
168 256 });
169 257 }
170   - }
  258 + },
171 259 },
172 260 mounted() {
173 261 if (this.$store.state.isUserLoggedIn == true) {
... ... @@ -179,8 +267,8 @@ export default {
179 267 computed: {
180 268 color() {
181 269 return this.loading ? "success" : "error";
182   - }
183   - }
  270 + },
  271 + },
184 272 };
185 273 </script>
186 274  
... ...
src/pages/Dashboard/dashboard.vue
... ... @@ -778,6 +778,8 @@ export default {
778 778 activityList: [],
779 779 };
780 780 },
  781 +
  782 +
781 783 methods: {
782 784 test(e) {
783 785 console.log(" test - ", e);
... ... @@ -1008,46 +1010,28 @@ export default {
1008 1010 this.showLoader = false;
1009 1011 });
1010 1012 },
1011   - async getparentStudents() {
1012   - this.showLoader = true;
1013   - var parentStudentsId;
1014   - var classId;
1015   - await http()
1016   - .get("/parentStudentsList")
1017   - .then((response) => {
1018   - this.studentsData = response.data.data;
1019   - localStorage.setItem(
1020   - "parentStudentId",
1021   - this.studentsData.students[0]._id
1022   - );
1023   - localStorage.setItem(
1024   - "parentClassId",
1025   - this.studentsData.students[0].classId
1026   - );
1027   -
1028   - if (localStorage.getItem("parentStudentId") == null) {
1029   - parentStudentsId = response.data.data.students[0].classId;
1030   - classId = response.data.data.students[0]._id;
1031   - }
1032   - if (localStorage.getItem("parentStudentId")) {
1033   - parentStudentsId = localStorage.getItem("parentStudentId");
1034   - classId = localStorage.getItem("parentClassId");
1035   - }
1036   -
1037   - this.showLoader = false;
1038   - })
1039   - .catch((err) => {
1040   - console.log("err====>", err);
1041   - this.showLoader = false;
1042   - });
1043   - await this.getCourses(parentStudentsId, classId);
1044   - await this.getAnnoucementes(classId);
1045   - },
  1013 + // async getparentStudents() {
  1014 + // this.showLoader = true;
  1015 + // await http()
  1016 + // .get("/parentStudentsList")
  1017 + // .then((response) => {
  1018 +
  1019 + // /* set values in local storage */
  1020 + // this.studentsData = response.data.data.students;
  1021 + // this.showLoader = false;
  1022 + // })
  1023 + // .catch((err) => {
  1024 + // console.log("err====>", err);
  1025 + // this.showLoader = false;
  1026 + // });
  1027 + // await this.getCourses(parentStudentsId, classId);
  1028 + // await this.getAnnoucementes(classId);
  1029 + // },
1046 1030 async getCourses(parentStudentsId, classId) {
1047 1031 /* getStudentCourses - to get courseData - defined in GetApis.js*/
1048 1032 await this.getStudentCourses({
1049   - classId: classId,
1050   - studentId: parentStudentsId,
  1033 + classId: localStorage.getItem("parentClassId"),
  1034 + studentId: localStorage.getItem("parentStudentId"),
1051 1035 });
1052 1036 },
1053 1037 getAnnoucementes(classId) {
... ... @@ -1055,7 +1039,7 @@ export default {
1055 1039 http()
1056 1040 .get("/getAnnoucementesList", {
1057 1041 params: {
1058   - classId: classId,
  1042 + classId: localStorage.getItem("parentClassId"),
1059 1043 },
1060 1044 })
1061 1045 .then((response) => {
... ... @@ -1097,6 +1081,7 @@ export default {
1097 1081 });
1098 1082 }
1099 1083 },
  1084 +
1100 1085 },
1101 1086  
1102 1087 mounted() {
... ... @@ -1122,7 +1107,11 @@ export default {
1122 1107 this.token = this.$store.state.token;
1123 1108 } else if (this.$store.state.role === "PARENT") {
1124 1109 this.token = this.$store.state.token;
1125   - await this.getparentStudents();
  1110 + // await this.getparentStudents();
  1111 + this.studentsData = this.$store.getters.GET_STUDENTS_DATA;
  1112 + console.log("students data - ",this.studentsData)
  1113 + await this.getCourses();
  1114 + await this.getAnnoucementes();
1126 1115 }
1127 1116 this.role = this.$store.state.role;
1128 1117  
... ...
src/store/store.js
... ... @@ -17,13 +17,20 @@ export default new Vuex.Store({
17 17 role: null,
18 18 // schoolId: null,
19 19 schoolToken: null,
20   - schoolRole: null
  20 + schoolRole: null,
  21 + studentsData: [],
  22 + },
  23 + getters: {
  24 + GET_STUDENTS_DATA: state => {
  25 + return state.studentsData
  26 + },
  27 +
21 28 },
22 29 // serve as the one and only way to change the state of the data in the state object
23 30 mutations: {
24 31 setToken(state, token) {
25 32 state.token = token
26   - //state.isUserLoggedIn = !!(token)
  33 + //state.isUserLoggedIn = !!(token)
27 34 if (token != null) {
28 35 state.isUserLoggedIn = true
29 36 } else {
... ... @@ -32,7 +39,7 @@ export default new Vuex.Store({
32 39 },
33 40 setSchoolToken(state, schoolToken) {
34 41 state.schoolToken = schoolToken
35   - //state.isUserLoggedIn = !!(token)
  42 + //state.isUserLoggedIn = !!(token)
36 43 if (schoolToken != null) {
37 44 state.isSchoolLoggedIn = true
38 45 } else {
... ... @@ -51,28 +58,48 @@ export default new Vuex.Store({
51 58 setSchoolRole(state, schoolRole) {
52 59 state.schoolRole = schoolRole
53 60 },
  61 + SET_STUDENTS_DATA(state, data) {
  62 + state.studentsData = data
  63 + },
54 64 // SchoolId(state, schoolId) {
55 65 // state.schoolId = schoolId
56 66 // }
57 67 },
58 68 //Action methods are referred to as being "dispatched"
59 69 actions: {
60   - setToken({ commit }, token) {
  70 + setToken({
  71 + commit
  72 + }, token) {
61 73 commit('setToken', token)
62 74 },
63   - setSchoolToken({ commit }, schoolToken) {
  75 + setSchoolToken({
  76 + commit
  77 + }, schoolToken) {
64 78 commit('setSchoolToken', schoolToken)
65 79 },
66   - setUser({ commit }, data) {
  80 + setUser({
  81 + commit
  82 + }, data) {
67 83 commit('setUser', data)
68 84 },
69   - Id({ commit }, id) {
  85 + SET_STUDENTS_DATA({
  86 + commit
  87 + }, data) {
  88 + commit('SET_STUDENTS_DATA', data)
  89 + },
  90 + Id({
  91 + commit
  92 + }, id) {
70 93 commit('Id', id)
71 94 },
72   - Role({ commit }, role) {
  95 + Role({
  96 + commit
  97 + }, role) {
73 98 commit('Role', role)
74 99 },
75   - setSchoolRole({ commit }, schoolRole) {
  100 + setSchoolRole({
  101 + commit
  102 + }, schoolRole) {
76 103 commit('setSchoolRole', schoolRole)
77 104 },
78 105 // SchoolId({ commit }, schoolId) {
... ...