Blame view

src/pages/changeStudents/changeStudents.vue 5.67 KB
11d037abe   Neeraj Sharma   commit code
1
2
  <template>
    <v-app id="login">
fa975e45a   Amber Dev   change students d...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
      <!-- 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>
11d037abe   Neeraj Sharma   commit code
21
22
23
      <v-container fluid fill-height>
        <v-layout>
          <v-flex xs12 sm8 md8 lg5 offset-sm2 offset-lg3 class="mt-5">
4dd422bef   Shikha Mishra   change ui of card...
24
            <v-card flat class="Card-style pa-2" id="form">
11d037abe   Neeraj Sharma   commit code
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
              <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>
11d037abe   Neeraj Sharma   commit code
48
49
50
51
52
53
54
55
            </v-card>
          </v-flex>
        </v-layout>
      </v-container>
    </v-app>
  </template>
  <script>
  import http from "@/Services/http.js";
fa975e45a   Amber Dev   change students d...
56
  import AllApiCalls from "@/Services/AllApiCalls.js";
11d037abe   Neeraj Sharma   commit code
57
58
  
  export default {
fa975e45a   Amber Dev   change students d...
59
    mixins: [AllApiCalls],
11d037abe   Neeraj Sharma   commit code
60
61
62
63
64
65
66
67
68
69
    data() {
      return {
        snackbar: false,
        y: "top",
        x: "right",
        mode: "",
        timeout: 4000,
        text: "",
        loading: false,
        valid: false,
610e873a0   Amber Dev   solved bug regard...
70
        changeStudent: "",
fa975e45a   Amber Dev   change students d...
71
        studentsData: [],
11d037abe   Neeraj Sharma   commit code
72
73
74
75
76
77
78
      };
    },
    mounted() {
      this.getparentStudents();
    },
    methods: {
      change() {
11d037abe   Neeraj Sharma   commit code
79
        localStorage.setItem("parentStudentId", this.changeStudent);
019880b6f   Amber Dev   added students list
80
81
82
83
84
85
        /* 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])
          }
        }
11d037abe   Neeraj Sharma   commit code
86
87
88
89
90
91
        this.$router.replace({ path: "/" });
      },
      getparentStudents() {
        this.showLoader = true;
        http()
          .get("/parentStudentsList")
fa975e45a   Amber Dev   change students d...
92
          .then((response) => {
860da881d   Shikha Mishra   comment all consoles
93
            //   console.log("students - ", response.data.data.students);
fa975e45a   Amber Dev   change students d...
94
95
96
97
98
99
100
101
102
103
104
105
            /* 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 */
11d037abe   Neeraj Sharma   commit code
106
            this.studentsData = response.data.data.students;
fa975e45a   Amber Dev   change students d...
107
108
109
110
            /* 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) {
27ec4269c   Amber Dev   added disabled st...
111
112
              this.changeStudent = response.data.data.students[0]._id;
            }
860da881d   Shikha Mishra   comment all consoles
113
            //   console.log("indexStatusFalse - ", indexStatusFalse);
fa975e45a   Amber Dev   change students d...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
            /* 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;
              }
            }
860da881d   Shikha Mishra   comment all consoles
132
            //   console.log("counter - ", counter);
fa975e45a   Amber Dev   change students d...
133
134
135
136
137
138
139
140
141
142
143
144
145
            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;
            }
610e873a0   Amber Dev   solved bug regard...
146
            localStorage.setItem("parentStudentId", this.changeStudent);
11d037abe   Neeraj Sharma   commit code
147
148
149
150
151
152
            localStorage.setItem(
              "parentClassId",
              response.data.data.students[0].classId
            );
            this.showLoader = false;
          })
fa975e45a   Amber Dev   change students d...
153
          .catch((err) => {
860da881d   Shikha Mishra   comment all consoles
154
            //   console.log("err====>", err);
11d037abe   Neeraj Sharma   commit code
155
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
156
157
158
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
11d037abe   Neeraj Sharma   commit code
159
          });
fa975e45a   Amber Dev   change students d...
160
      },
11d037abe   Neeraj Sharma   commit code
161
162
163
164
    },
    computed: {
      color() {
        return this.loading ? "success" : "error";
fa975e45a   Amber Dev   change students d...
165
166
      },
    },
11d037abe   Neeraj Sharma   commit code
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
  };
  </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>