Blame view

src/pages/changeStudents/changeStudents.vue 5.43 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
      <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" dark 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>
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
80
81
82
83
84
85
        localStorage.setItem("parentStudentId", this.changeStudent);
        this.$router.replace({ path: "/" });
      },
      getparentStudents() {
        this.showLoader = true;
        http()
          .get("/parentStudentsList")
fa975e45a   Amber Dev   change students d...
86
          .then((response) => {
860da881d   Shikha Mishra   comment all consoles
87
            //   console.log("students - ", response.data.data.students);
fa975e45a   Amber Dev   change students d...
88
89
90
91
92
93
94
95
96
97
98
99
            /* 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
100
            this.studentsData = response.data.data.students;
fa975e45a   Amber Dev   change students d...
101
102
103
104
            /* 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...
105
106
              this.changeStudent = response.data.data.students[0]._id;
            }
860da881d   Shikha Mishra   comment all consoles
107
            //   console.log("indexStatusFalse - ", indexStatusFalse);
fa975e45a   Amber Dev   change students d...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
            /* 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
126
            //   console.log("counter - ", counter);
fa975e45a   Amber Dev   change students d...
127
128
129
130
131
132
133
134
135
136
137
138
139
            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...
140
            localStorage.setItem("parentStudentId", this.changeStudent);
11d037abe   Neeraj Sharma   commit code
141
142
143
144
145
146
            localStorage.setItem(
              "parentClassId",
              response.data.data.students[0].classId
            );
            this.showLoader = false;
          })
fa975e45a   Amber Dev   change students d...
147
          .catch((err) => {
860da881d   Shikha Mishra   comment all consoles
148
            //   console.log("err====>", err);
11d037abe   Neeraj Sharma   commit code
149
            this.showLoader = false;
860da881d   Shikha Mishra   comment all consoles
150
151
152
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
11d037abe   Neeraj Sharma   commit code
153
          });
fa975e45a   Amber Dev   change students d...
154
      },
11d037abe   Neeraj Sharma   commit code
155
156
157
158
    },
    computed: {
      color() {
        return this.loading ? "success" : "error";
fa975e45a   Amber Dev   change students d...
159
160
      },
    },
11d037abe   Neeraj Sharma   commit code
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  };
  </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>