Commit f9b486fe1c384e04584aa74447d02320937798ce
1 parent
6fe35f887d
Exists in
master
and in
3 other branches
implemrent all task
Showing
3 changed files
with
127 additions
and
18 deletions
Show diff stats
src/Services/http.js
1 | import axios from 'axios' | 1 | import axios from 'axios' |
2 | import store from '@/store/store' | 2 | import store from '@/store/store' |
3 | 3 | ||
4 | export default () => { | 4 | export default () => { |
5 | return axios.create({ | 5 | return axios.create({ |
6 | // baseURL: 'http://192.168.0.108:3002/v1', | 6 | // baseURL: 'http://192.168.2.221:3002/v1', |
7 | baseURL: 'http://13.234.251.173:8001/v1', | 7 | baseURL: 'http://13.234.251.173:8001/v1', |
8 | headers: { | 8 | headers: { |
9 | Authorization: `Bearer ${store.state.token}` | 9 | Authorization: `Bearer ${store.state.token}` |
10 | } | 10 | } |
11 | }) | 11 | }) |
12 | } | 12 | } |
src/pages/Administrator/bulkImport.vue
1 | <template> | 1 | <template> |
2 | <v-container fluid grid-list-md> | 2 | <v-container fluid grid-list-md> |
3 | <v-card flat> | 3 | <v-card flat> |
4 | <v-toolbar class="fixcolors" dark flat> | 4 | <v-toolbar class="fixcolors" dark flat> |
5 | <v-spacer></v-spacer> | 5 | <v-spacer></v-spacer> |
6 | <v-toolbar-title>Import</v-toolbar-title> | 6 | <v-toolbar-title>Import</v-toolbar-title> |
7 | <v-spacer></v-spacer> | 7 | <v-spacer></v-spacer> |
8 | </v-toolbar> | 8 | </v-toolbar> |
9 | <v-container fluid> | 9 | <v-container fluid> |
10 | <v-layout> | 10 | <v-layout> |
11 | <v-flex xs12> | 11 | <v-flex xs12> |
12 | <v-layout wrap> | 12 | <v-layout wrap> |
13 | <v-flex xs6 sm5 lg2 class="pt-4"> | 13 | <v-flex xs6 sm5 lg2 class="pt-4"> |
14 | <label class="title right">Add Teacher:</label> | 14 | <label class="title right">Add Teacher:</label> |
15 | </v-flex> | 15 | </v-flex> |
16 | <v-flex xs12 sm6 lg3> | 16 | <v-flex xs12 sm6 lg3> |
17 | <v-text-field v-model="teacherFileName" placeholder="Choose file" :disabled="true"></v-text-field> | 17 | <v-text-field v-model="teacherFileName" placeholder="Choose file" :disabled="true"></v-text-field> |
18 | <input | 18 | <input |
19 | type="file" | 19 | type="file" |
20 | style="display: none" | 20 | style="display: none" |
21 | ref="file" | 21 | ref="file" |
22 | @change="convertFile" | 22 | @change="convertFile" |
23 | id="fileInput" | 23 | id="fileInput" |
24 | /> | 24 | /> |
25 | </v-flex> | 25 | </v-flex> |
26 | <v-flex xs6 sm4 lg2 class="mt-1"> | 26 | <v-flex xs6 sm4 lg2 class="mt-1"> |
27 | <v-btn class="grey" dark block @click="pickFile"> | 27 | <v-btn class="grey" dark block @click="pickFile"> |
28 | <v-icon small class="pr-1">refresh</v-icon>Upload | 28 | <v-icon small class="pr-1">refresh</v-icon>Upload |
29 | </v-btn> | 29 | </v-btn> |
30 | </v-flex> | 30 | </v-flex> |
31 | <v-flex xs6 sm4 lg2 class="mt-1"> | 31 | <v-flex xs6 sm4 lg2 class="mt-1"> |
32 | <v-btn class="grey" dark block @click="importTeacher()" :loading="loading">import</v-btn> | 32 | <v-btn class="grey" dark block @click="importTeacher()" :loading="loading">import</v-btn> |
33 | </v-flex> | 33 | </v-flex> |
34 | <v-flex xs12 sm4 lg2 class="mt-1"> | 34 | <v-flex xs12 sm4 lg2 class="mt-1"> |
35 | <download-csv :data="teacherData"> | 35 | <download-csv :data="teacherData"> |
36 | <v-btn class="blue lighten-2" dark block> | 36 | <v-btn class="blue lighten-2" dark block> |
37 | <v-icon small class="pr-1">archive</v-icon>sample download | 37 | <v-icon small class="pr-1">archive</v-icon>sample download |
38 | </v-btn> | 38 | </v-btn> |
39 | </download-csv> | 39 | </download-csv> |
40 | </v-flex> | 40 | </v-flex> |
41 | </v-layout> | 41 | </v-layout> |
42 | </v-flex> | 42 | </v-flex> |
43 | </v-layout> | 43 | </v-layout> |
44 | <v-layout> | 44 | <v-layout> |
45 | <v-flex xs12> | 45 | <v-flex xs12> |
46 | <v-layout wrap> | 46 | <v-layout wrap> |
47 | <v-flex xs6 sm5 lg2 class="pt-4"> | 47 | <v-flex xs6 sm5 lg2 class="pt-4"> |
48 | <label class="title right">Add Parent:</label> | 48 | <label class="title right">Add Parent:</label> |
49 | </v-flex> | 49 | </v-flex> |
50 | <v-flex xs12 sm6 lg3> | 50 | <v-flex xs12 sm6 lg3> |
51 | <v-text-field v-model="parentFileName" placeholder="Choose file" :disabled="true"></v-text-field> | 51 | <v-text-field v-model="parentFileName" placeholder="Choose file" :disabled="true"></v-text-field> |
52 | <input | 52 | <input |
53 | type="file" | 53 | type="file" |
54 | style="display: none" | 54 | style="display: none" |
55 | ref="parentfile" | 55 | ref="parentfile" |
56 | @change="parentFile" | 56 | @change="parentFile" |
57 | id="parentInput" | 57 | id="parentInput" |
58 | /> | 58 | /> |
59 | </v-flex> | 59 | </v-flex> |
60 | <v-flex xs6 sm4 lg2 class="mt-1"> | 60 | <v-flex xs6 sm4 lg2 class="mt-1"> |
61 | <v-btn class="grey" dark block @click="pickParentFile"> | 61 | <v-btn class="grey" dark block @click="pickParentFile"> |
62 | <v-icon small class="pr-1">refresh</v-icon>Upload | 62 | <v-icon small class="pr-1">refresh</v-icon>Upload |
63 | </v-btn> | 63 | </v-btn> |
64 | </v-flex> | 64 | </v-flex> |
65 | <v-flex xs6 sm4 lg2 class="mt-1" @click="importParent"> | 65 | <v-flex xs6 sm4 lg2 class="mt-1" @click="importParent"> |
66 | <v-btn class="grey" dark block>import</v-btn> | 66 | <v-btn class="grey" dark block>import</v-btn> |
67 | </v-flex> | 67 | </v-flex> |
68 | <v-flex xs12 sm4 lg2 class="mt-1"> | 68 | <v-flex xs12 sm4 lg2 class="mt-1"> |
69 | <download-csv :data="parentData"> | 69 | <download-csv :data="parentData"> |
70 | <v-btn class="blue lighten-2" dark block> | 70 | <v-btn class="blue lighten-2" dark block> |
71 | <v-icon small class="pr-1">archive</v-icon>sample download | 71 | <v-icon small class="pr-1">archive</v-icon>sample download |
72 | </v-btn> | 72 | </v-btn> |
73 | </download-csv> | 73 | </download-csv> |
74 | </v-flex> | 74 | </v-flex> |
75 | </v-layout> | 75 | </v-layout> |
76 | </v-flex> | 76 | </v-flex> |
77 | </v-layout> | 77 | </v-layout> |
78 | <v-layout> | 78 | <v-layout> |
79 | <v-flex xs12> | 79 | <v-flex xs12> |
80 | <v-layout wrap> | 80 | <v-layout wrap> |
81 | <v-flex xs6 sm5 lg2 class="pt-4"> | 81 | <v-flex xs6 sm5 lg2 class="pt-4"> |
82 | <label class="title right">Add User:</label> | 82 | <label class="title right">Add User:</label> |
83 | </v-flex> | 83 | </v-flex> |
84 | <v-flex xs12 sm6 lg3> | 84 | <v-flex xs12 sm6 lg3> |
85 | <v-text-field placeholder="Choose file" v-model="userFileName" :disabled="true"></v-text-field> | 85 | <v-text-field placeholder="Choose file" v-model="userFileName" :disabled="true"></v-text-field> |
86 | <input | 86 | <input |
87 | type="file" | 87 | type="file" |
88 | style="display: none" | 88 | style="display: none" |
89 | ref="userfile" | 89 | ref="userfile" |
90 | @change="userFile" | 90 | @change="userFile" |
91 | id="userInput" | 91 | id="userInput" |
92 | /> | 92 | /> |
93 | </v-flex> | 93 | </v-flex> |
94 | <v-flex xs6 sm4 lg2 class="mt-1"> | 94 | <v-flex xs6 sm4 lg2 class="mt-1"> |
95 | <v-btn class="grey" dark block @click="pickUserFile"> | 95 | <v-btn class="grey" dark block @click="pickUserFile"> |
96 | <v-icon small class="pr-1">refresh</v-icon>Upload | 96 | <v-icon small class="pr-1">refresh</v-icon>Upload |
97 | </v-btn> | 97 | </v-btn> |
98 | </v-flex> | 98 | </v-flex> |
99 | <v-flex xs6 sm4 lg2 class="mt-1"> | 99 | <v-flex xs6 sm4 lg2 class="mt-1"> |
100 | <v-btn class="grey" dark block @click="importUser">import</v-btn> | 100 | <v-btn class="grey" dark block @click="importUser">import</v-btn> |
101 | </v-flex> | 101 | </v-flex> |
102 | <v-flex xs12 sm4 lg2 class="mt-1"> | 102 | <v-flex xs12 sm4 lg2 class="mt-1"> |
103 | <download-csv :data="userData"> | 103 | <download-csv :data="userData"> |
104 | <v-btn class="blue lighten-2" dark block> | 104 | <v-btn class="blue lighten-2" dark block> |
105 | <v-icon small class="pr-1">archive</v-icon>sample download | 105 | <v-icon small class="pr-1">archive</v-icon>sample download |
106 | </v-btn> | 106 | </v-btn> |
107 | </download-csv> | 107 | </download-csv> |
108 | </v-flex> | 108 | </v-flex> |
109 | </v-layout> | 109 | </v-layout> |
110 | </v-flex> | 110 | </v-flex> |
111 | </v-layout> | 111 | </v-layout> |
112 | <v-layout> | 112 | <v-layout> |
113 | <v-flex xs12> | 113 | <v-flex xs12> |
114 | <v-layout wrap> | 114 | <v-layout wrap> |
115 | <v-flex xs6 sm5 lg2 class="pt-4"> | 115 | <v-flex xs6 sm5 lg2 class="pt-4"> |
116 | <label class="title right">Add Book:</label> | 116 | <label class="title right">Add Book:</label> |
117 | </v-flex> | 117 | </v-flex> |
118 | <v-flex xs12 sm6 lg3> | 118 | <v-flex xs12 sm6 lg3> |
119 | <v-text-field placeholder="Choose file" v-model="bookFileName" :disabled="true"></v-text-field> | 119 | <v-text-field placeholder="Choose file" v-model="bookFileName" :disabled="true"></v-text-field> |
120 | <input | 120 | <input |
121 | type="file" | 121 | type="file" |
122 | style="display: none" | 122 | style="display: none" |
123 | ref="bookfile" | 123 | ref="bookfile" |
124 | @change="bookFile" | 124 | @change="bookFile" |
125 | id="bookInput" | 125 | id="bookInput" |
126 | /> | 126 | /> |
127 | </v-flex> | 127 | </v-flex> |
128 | <v-flex xs6 sm4 lg2 class="mt-1"> | 128 | <v-flex xs6 sm4 lg2 class="mt-1"> |
129 | <v-btn class="grey" dark block @click="pickBookFile"> | 129 | <v-btn class="grey" dark block @click="pickBookFile"> |
130 | <v-icon small class="pr-1">refresh</v-icon>Upload | 130 | <v-icon small class="pr-1">refresh</v-icon>Upload |
131 | </v-btn> | 131 | </v-btn> |
132 | </v-flex> | 132 | </v-flex> |
133 | <v-flex xs6 sm4 lg2 class="mt-1"> | 133 | <v-flex xs6 sm4 lg2 class="mt-1"> |
134 | <v-btn class="grey" dark block @click="importBook">import</v-btn> | 134 | <v-btn class="grey" dark block @click="importBook">import</v-btn> |
135 | </v-flex> | 135 | </v-flex> |
136 | <v-flex xs12 sm4 lg2 class="mt-1"> | 136 | <v-flex xs12 sm4 lg2 class="mt-1"> |
137 | <download-csv :data="bookData"> | 137 | <download-csv :data="bookData"> |
138 | <v-btn class="blue lighten-2" dark block> | 138 | <v-btn class="blue lighten-2" dark block> |
139 | <v-icon small class="pr-1">archive</v-icon>sample download | 139 | <v-icon small class="pr-1">archive</v-icon>sample download |
140 | </v-btn> | 140 | </v-btn> |
141 | </download-csv> | 141 | </download-csv> |
142 | </v-flex> | 142 | </v-flex> |
143 | </v-layout> | 143 | </v-layout> |
144 | </v-flex> | 144 | </v-flex> |
145 | </v-layout> | 145 | </v-layout> |
146 | <v-layout> | 146 | <v-layout> |
147 | <v-flex xs12> | 147 | <v-flex xs12> |
148 | <v-layout wrap> | 148 | <v-layout wrap> |
149 | <v-flex xs6 sm5 lg2 class="pt-4"> | 149 | <v-flex xs6 sm5 lg2 class="pt-4"> |
150 | <label class="title right">Add Student:</label> | 150 | <label class="title right">Add Student:</label> |
151 | </v-flex> | 151 | </v-flex> |
152 | <v-flex xs12 sm6 lg3> | 152 | <v-flex xs12 sm6 lg3> |
153 | <v-text-field placeholder="Choose file" :disabled="true"></v-text-field> | 153 | <v-text-field placeholder="Choose file" v-model="bookStudentName" :disabled="true"></v-text-field> |
154 | <input | ||
155 | type="file" | ||
156 | style="display: none" | ||
157 | ref="studentfile" | ||
158 | @change="studentFile" | ||
159 | id="studentInput" | ||
160 | /> | ||
154 | </v-flex> | 161 | </v-flex> |
155 | <v-flex xs6 sm4 lg2 class="mt-1"> | 162 | <v-flex xs6 sm4 lg2 class="mt-1"> |
156 | <v-btn class="grey" dark block> | 163 | <v-btn class="grey" dark block @click="pickStudentFile"> |
157 | <v-icon small class="pr-1">refresh</v-icon>Upload | 164 | <v-icon small class="pr-1">refresh</v-icon>Upload |
158 | </v-btn> | 165 | </v-btn> |
159 | </v-flex> | 166 | </v-flex> |
160 | <v-flex xs6 sm4 lg2 class="mt-1"> | 167 | <v-flex xs6 sm4 lg2 class="mt-1"> |
161 | <v-btn class="grey" dark block>import</v-btn> | 168 | <v-btn class="grey" dark block @click="importStudent()">import</v-btn> |
162 | </v-flex> | 169 | </v-flex> |
163 | <v-flex xs12 sm4 lg2 class="mt-1"> | 170 | <v-flex xs12 sm4 lg2 class="mt-1"> |
164 | <download-csv :data="studentData"> | 171 | <download-csv :data="studentData"> |
165 | <v-btn class="blue lighten-2" dark block> | 172 | <v-btn class="blue lighten-2" dark block> |
166 | <v-icon small class="pr-1">archive</v-icon>sample download | 173 | <v-icon small class="pr-1">archive</v-icon>sample download |
167 | </v-btn> | 174 | </v-btn> |
168 | </download-csv> | 175 | </download-csv> |
169 | </v-flex> | 176 | </v-flex> |
170 | </v-layout> | 177 | </v-layout> |
171 | </v-flex> | 178 | </v-flex> |
172 | </v-layout> | 179 | </v-layout> |
173 | <v-layout> | 180 | <!-- <v-layout> |
174 | <v-flex xs12> | 181 | <v-flex xs12> |
175 | <v-layout wrap> | 182 | <v-layout wrap> |
176 | <v-flex xs9 sm5 lg2 class="pt-4"> | 183 | <v-flex xs9 sm5 lg2 class="pt-4"> |
177 | <label class="title right">Students & Parents:</label> | 184 | <label class="title right">Students & Parents:</label> |
178 | </v-flex> | 185 | </v-flex> |
179 | <v-flex xs12 sm6 lg3> | 186 | <v-flex xs12 sm6 lg3> |
180 | <v-text-field placeholder="Choose file" :disabled="true"></v-text-field> | 187 | <v-text-field placeholder="Choose file" :disabled="true"></v-text-field> |
181 | </v-flex> | 188 | </v-flex> |
182 | <v-flex xs6 sm4 lg2 class="mt-1"> | 189 | <v-flex xs6 sm4 lg2 class="mt-1"> |
183 | <v-btn class="grey" dark block> | 190 | <v-btn class="grey" dark block> |
184 | <v-icon small class="pr-1">refresh</v-icon>Upload | 191 | <v-icon small class="pr-1">refresh</v-icon>Upload |
185 | </v-btn> | 192 | </v-btn> |
186 | </v-flex> | 193 | </v-flex> |
187 | <v-flex xs6 sm4 lg2 class="mt-1"> | 194 | <v-flex xs6 sm4 lg2 class="mt-1"> |
188 | <v-btn class="grey" dark block>import</v-btn> | 195 | <v-btn class="grey" dark block>import</v-btn> |
189 | </v-flex> | 196 | </v-flex> |
190 | <v-flex xs12 sm4 lg2 class="mt-1"> | 197 | <v-flex xs12 sm4 lg2 class="mt-1"> |
191 | <v-btn class="blue lighten-2" dark block> | 198 | <v-btn class="blue lighten-2" dark block> |
192 | <v-icon small class="pr-1">archive</v-icon>sample download | 199 | <v-icon small class="pr-1">archive</v-icon>sample download |
193 | </v-btn> | 200 | </v-btn> |
194 | </v-flex> | 201 | </v-flex> |
195 | </v-layout> | 202 | </v-layout> |
196 | </v-flex> | 203 | </v-flex> |
197 | </v-layout> | 204 | </v-layout>--> |
198 | </v-container> | 205 | </v-container> |
199 | </v-card> | 206 | </v-card> |
207 | <v-snackbar | ||
208 | :timeout="timeout" | ||
209 | :top="y === 'top'" | ||
210 | :right="x === 'right'" | ||
211 | :vertical="mode === 'vertical'" | ||
212 | v-model="snackbar" | ||
213 | :color= color | ||
214 | >{{ text }}</v-snackbar> | ||
200 | </v-container> | 215 | </v-container> |
201 | </template> | 216 | </template> |
202 | 217 | ||
203 | 218 | ||
204 | <script> | 219 | <script> |
205 | import http from "@/Services/http.js"; | 220 | import http from "@/Services/http.js"; |
206 | import moment from "moment"; | 221 | import moment from "moment"; |
207 | import teacherData from "@/script/teachers.js"; | 222 | import teacherData from "@/script/teachers.js"; |
208 | import studentData from "@/script/students.js"; | 223 | import studentData from "@/script/students.js"; |
209 | import parentData from "@/script/parents.js"; | 224 | import parentData from "@/script/parents.js"; |
210 | import userData from "@/script/users.js"; | 225 | import userData from "@/script/users.js"; |
211 | import bookData from "@/script/books.js"; | 226 | import bookData from "@/script/books.js"; |
212 | 227 | ||
213 | export default { | 228 | export default { |
214 | data: () => ({ | 229 | data: () => ({ |
230 | loading: false, | ||
231 | snackbar: false, | ||
232 | y: "top", | ||
233 | x: "right", | ||
234 | mode: "", | ||
235 | timeout: 3000, | ||
236 | text: "", | ||
237 | color: "", | ||
215 | teacherData: [], | 238 | teacherData: [], |
216 | studentData: [], | 239 | studentData: [], |
217 | parentData: [], | 240 | parentData: [], |
218 | userData: [], | 241 | userData: [], |
219 | bookData: [], | 242 | bookData: [], |
220 | teacherFileJson: [], | 243 | teacherFileJson: [], |
221 | parentFileJson: [], | 244 | parentFileJson: [], |
222 | userFileJson: [], | 245 | userFileJson: [], |
223 | bookFileJson: [], | 246 | bookFileJson: [], |
247 | studentFileJson: [], | ||
224 | teacherFileName: "", | 248 | teacherFileName: "", |
225 | parentFileName: "", | 249 | parentFileName: "", |
226 | userFileName: "", | 250 | userFileName: "", |
227 | bookFileName: "", | 251 | bookFileName: "", |
228 | token: "", | 252 | bookStudentName: "", |
229 | loading: false | 253 | token: "" |
230 | }), | 254 | }), |
231 | methods: { | 255 | methods: { |
232 | pickFile() { | 256 | pickFile() { |
233 | this.$refs.file.click(); | 257 | this.$refs.file.click(); |
234 | }, | 258 | }, |
235 | pickParentFile() { | 259 | pickParentFile() { |
236 | this.$refs.parentfile.click(); | 260 | this.$refs.parentfile.click(); |
237 | }, | 261 | }, |
238 | pickUserFile() { | 262 | pickUserFile() { |
239 | this.$refs.userfile.click(); | 263 | this.$refs.userfile.click(); |
240 | }, | 264 | }, |
241 | pickBookFile() { | 265 | pickBookFile() { |
242 | this.$refs.bookfile.click(); | 266 | this.$refs.bookfile.click(); |
243 | }, | 267 | }, |
268 | pickStudentFile() { | ||
269 | this.$refs.studentfile.click(); | ||
270 | }, | ||
244 | convertFile() { | 271 | convertFile() { |
245 | const input = document.getElementById("fileInput"); | 272 | const input = document.getElementById("fileInput"); |
246 | const reader = new FileReader(); | 273 | const reader = new FileReader(); |
247 | reader.onload = () => { | 274 | reader.onload = () => { |
248 | let text = reader.result; | 275 | let text = reader.result; |
249 | //convert text to json here | 276 | //convert text to json here |
250 | var json = this.csvJSON(text); | 277 | var json = this.csvJSON(text); |
251 | // console.log("CSV: ", json); | ||
252 | }; | 278 | }; |
253 | reader.readAsText(input.files[0]); | 279 | reader.readAsText(input.files[0]); |
254 | // console.log("input.files[0]", input.files[0].name); | ||
255 | this.teacherFileName = input.files[0].name; | 280 | this.teacherFileName = input.files[0].name; |
256 | }, | 281 | }, |
257 | parentFile() { | 282 | parentFile() { |
258 | const input = document.getElementById("parentInput"); | 283 | const input = document.getElementById("parentInput"); |
259 | const reader = new FileReader(); | 284 | const reader = new FileReader(); |
260 | reader.onload = () => { | 285 | reader.onload = () => { |
261 | let text = reader.result; | 286 | let text = reader.result; |
262 | //convert text to json here | 287 | //convert text to json here |
263 | var json = this.csvParentJSON(text); | 288 | var json = this.csvParentJSON(text); |
264 | // console.log("CSV: ", json); | ||
265 | }; | 289 | }; |
266 | reader.readAsText(input.files[0]); | 290 | reader.readAsText(input.files[0]); |
267 | // console.log("input.files[0]", input.files[0].name); | ||
268 | this.parentFileName = input.files[0].name; | 291 | this.parentFileName = input.files[0].name; |
269 | }, | 292 | }, |
270 | userFile() { | 293 | userFile() { |
271 | const input = document.getElementById("userInput"); | 294 | const input = document.getElementById("userInput"); |
272 | const reader = new FileReader(); | 295 | const reader = new FileReader(); |
273 | reader.onload = () => { | 296 | reader.onload = () => { |
274 | let text = reader.result; | 297 | let text = reader.result; |
275 | //convert text to json here | 298 | //convert text to json here |
276 | var json = this.csvUserJSON(text); | 299 | var json = this.csvUserJSON(text); |
277 | // console.log("CSV: ", json); | ||
278 | }; | 300 | }; |
279 | reader.readAsText(input.files[0]); | 301 | reader.readAsText(input.files[0]); |
280 | // console.log("input.files[0]", input.files[0].name); | ||
281 | this.userFileName = input.files[0].name; | 302 | this.userFileName = input.files[0].name; |
282 | }, | 303 | }, |
283 | bookFile() { | 304 | bookFile() { |
284 | const input = document.getElementById("bookInput"); | 305 | const input = document.getElementById("bookInput"); |
285 | const reader = new FileReader(); | 306 | const reader = new FileReader(); |
286 | reader.onload = () => { | 307 | reader.onload = () => { |
287 | let text = reader.result; | 308 | let text = reader.result; |
288 | //convert text to json here | 309 | //convert text to json here |
289 | var json = this.csvBookJSON(text); | 310 | var json = this.csvBookJSON(text); |
290 | // console.log("CSV: ", json); | ||
291 | }; | 311 | }; |
292 | reader.readAsText(input.files[0]); | 312 | reader.readAsText(input.files[0]); |
293 | // console.log("input.files[0]", input.files[0].name); | ||
294 | this.bookFileName = input.files[0].name; | 313 | this.bookFileName = input.files[0].name; |
295 | }, | 314 | }, |
315 | studentFile() { | ||
316 | const input = document.getElementById("studentInput"); | ||
317 | const reader = new FileReader(); | ||
318 | reader.onload = () => { | ||
319 | let text = reader.result; | ||
320 | //convert text to json here | ||
321 | var json = this.csvStudentJSON(text); | ||
322 | }; | ||
323 | reader.readAsText(input.files[0]); | ||
324 | this.bookStudentName = input.files[0].name; | ||
325 | }, | ||
296 | csvJSON(csv) { | 326 | csvJSON(csv) { |
297 | var lines = csv.split("\n"); | 327 | var lines = csv.split("\n"); |
298 | 328 | ||
299 | var result = []; | 329 | var result = []; |
300 | var headers = lines[0].split(","); | 330 | var headers = lines[0].split(","); |
301 | 331 | ||
302 | for (var i = 1; i < lines.length; i++) { | 332 | for (var i = 1; i < lines.length; i++) { |
303 | var obj = {}; | 333 | var obj = {}; |
304 | var currentline = lines[i].split(","); | 334 | var currentline = lines[i].split(","); |
305 | 335 | ||
306 | for (var j = 0; j < headers.length; j++) { | 336 | for (var j = 0; j < headers.length; j++) { |
307 | obj[headers[j]] = currentline[j]; | 337 | obj[headers[j]] = currentline[j]; |
308 | } | 338 | } |
309 | console.log("obj", obj); | ||
310 | this.teacherFileJson.push(obj); | 339 | this.teacherFileJson.push(obj); |
311 | } | 340 | } |
312 | }, | 341 | }, |
313 | csvParentJSON(csvParent) { | 342 | csvParentJSON(csvParent) { |
314 | var lines = csvParent.split("\n"); | 343 | var lines = csvParent.split("\n"); |
315 | 344 | ||
316 | var result = []; | 345 | var result = []; |
317 | 346 | ||
318 | var headers = lines[0].split(","); | 347 | var headers = lines[0].split(","); |
319 | 348 | ||
320 | for (var i = 1; i < lines.length; i++) { | 349 | for (var i = 1; i < lines.length; i++) { |
321 | var obj = {}; | 350 | var obj = {}; |
322 | var currentline = lines[i].split(","); | 351 | var currentline = lines[i].split(","); |
323 | 352 | ||
324 | for (var j = 0; j < headers.length; j++) { | 353 | for (var j = 0; j < headers.length; j++) { |
325 | obj[headers[j]] = currentline[j]; | 354 | obj[headers[j]] = currentline[j]; |
326 | } | 355 | } |
327 | |||
328 | this.parentFileJson.push(obj); | 356 | this.parentFileJson.push(obj); |
329 | } | 357 | } |
330 | }, | 358 | }, |
331 | csvUserJSON(cvsUser) { | 359 | csvUserJSON(cvsUser) { |
332 | var lines = cvsUser.split("\n"); | 360 | var lines = cvsUser.split("\n"); |
333 | 361 | ||
334 | var result = []; | 362 | var result = []; |
335 | 363 | ||
336 | var headers = lines[0].split(","); | 364 | var headers = lines[0].split(","); |
337 | 365 | ||
338 | for (var i = 1; i < lines.length; i++) { | 366 | for (var i = 1; i < lines.length; i++) { |
339 | var obj = {}; | 367 | var obj = {}; |
340 | var currentline = lines[i].split(","); | 368 | var currentline = lines[i].split(","); |
341 | 369 | ||
342 | for (var j = 0; j < headers.length; j++) { | 370 | for (var j = 0; j < headers.length; j++) { |
343 | obj[headers[j]] = currentline[j]; | 371 | obj[headers[j]] = currentline[j]; |
344 | } | 372 | } |
345 | 373 | ||
346 | this.userFileJson.push(obj); | 374 | this.userFileJson.push(obj); |
347 | } | 375 | } |
348 | }, | 376 | }, |
349 | csvBookJSON(cvsBook) { | 377 | csvBookJSON(cvsBook) { |
350 | var lines = cvsBook.split("\n"); | 378 | var lines = cvsBook.split("\n"); |
351 | 379 | ||
352 | var result = []; | 380 | var result = []; |
353 | 381 | ||
354 | var headers = lines[0].split(","); | 382 | var headers = lines[0].split(","); |
355 | 383 | ||
356 | for (var i = 1; i < lines.length; i++) { | 384 | for (var i = 1; i < lines.length; i++) { |
357 | var obj = {}; | 385 | var obj = {}; |
358 | var currentline = lines[i].split(","); | 386 | var currentline = lines[i].split(","); |
359 | 387 | ||
360 | for (var j = 0; j < headers.length; j++) { | 388 | for (var j = 0; j < headers.length; j++) { |
361 | obj[headers[j]] = currentline[j]; | 389 | obj[headers[j]] = currentline[j]; |
362 | } | 390 | } |
363 | 391 | ||
364 | this.bookFileJson.push(obj); | 392 | this.bookFileJson.push(obj); |
365 | } | 393 | } |
366 | }, | 394 | }, |
395 | csvStudentJSON(cvsBook) { | ||
396 | var lines = cvsBook.split("\n"); | ||
397 | |||
398 | var result = []; | ||
399 | |||
400 | var headers = lines[0].split(","); | ||
401 | |||
402 | for (var i = 1; i < lines.length; i++) { | ||
403 | var obj = {}; | ||
404 | var currentline = lines[i].split(","); | ||
405 | |||
406 | for (var j = 0; j < headers.length; j++) { | ||
407 | obj[headers[j]] = currentline[j]; | ||
408 | } | ||
409 | this.studentFileJson.push(obj); | ||
410 | } | ||
411 | }, | ||
367 | importTeacher() { | 412 | importTeacher() { |
368 | this.loading = true; | 413 | this.loading = true; |
369 | var teacherfile = {}; | 414 | var teacherfile = {}; |
370 | teacherfile.teacherData = this.teacherFileJson; | 415 | teacherfile.teacherData = this.teacherFileJson; |
371 | http() | 416 | http() |
372 | .post("/importTeacherData", teacherfile, { | 417 | .post("/importTeacherData", teacherfile, { |
373 | headers: { Authorization: "Bearer " + this.token } | 418 | headers: { Authorization: "Bearer " + this.token } |
374 | }) | 419 | }) |
375 | .then(response => { | 420 | .then(response => { |
376 | this.snackbar = true; | 421 | this.snackbar = true; |
377 | this.text = response.data.message; | 422 | this.text = response.data.message; |
423 | this.color = "green"; | ||
378 | this.loading = false; | 424 | this.loading = false; |
379 | }) | 425 | }) |
380 | .catch(error => { | 426 | .catch(error => { |
381 | this.snackbar = true; | 427 | this.snackbar = true; |
382 | this.text = error.response.data.message; | 428 | this.text = error.response.data.message; |
429 | this.color = "red"; | ||
383 | this.loading = false; | 430 | this.loading = false; |
384 | }); | 431 | }); |
385 | }, | 432 | }, |
386 | importParent() { | 433 | importParent() { |
387 | this.loading = true; | 434 | this.loading = true; |
388 | var parentfile = {}; | 435 | var parentfile = {}; |
389 | parentfile.parentData = this.parentFileJson; | 436 | parentfile.parentData = this.parentFileJson; |
390 | http() | 437 | http() |
391 | .post("/importParentData", parentfile, { | 438 | .post("/importParentData", parentfile, { |
392 | headers: { Authorization: "Bearer " + this.token } | 439 | headers: { Authorization: "Bearer " + this.token } |
393 | }) | 440 | }) |
394 | .then(response => { | 441 | .then(response => { |
395 | this.snackbar = true; | 442 | this.snackbar = true; |
396 | this.text = response.data.message; | 443 | this.text = response.data.message; |
444 | this.color = "green"; | ||
397 | this.loading = false; | 445 | this.loading = false; |
398 | }) | 446 | }) |
399 | .catch(error => { | 447 | .catch(error => { |
400 | this.snackbar = true; | 448 | this.snackbar = true; |
401 | this.text = error.response.data.message; | 449 | this.text = error.response.data.message; |
402 | this.loading = false; | 450 | this.loading = false; |
451 | this.color = "red"; | ||
403 | }); | 452 | }); |
404 | }, | 453 | }, |
405 | importUser() { | 454 | importUser() { |
406 | this.loading = true; | 455 | this.loading = true; |
407 | var userfile = {}; | 456 | var userfile = {}; |
408 | userfile.userData = this.userFileJson; | 457 | userfile.userData = this.userFileJson; |
409 | http() | 458 | http() |
410 | .post("/importUserData", userfile, { | 459 | .post("/importUserData", userfile, { |
411 | headers: { Authorization: "Bearer " + this.token } | 460 | headers: { Authorization: "Bearer " + this.token } |
412 | }) | 461 | }) |
413 | .then(response => { | 462 | .then(response => { |
414 | this.snackbar = true; | 463 | this.snackbar = true; |
415 | this.text = response.data.message; | 464 | this.text = response.data.message; |
465 | this.color = "green"; | ||
416 | this.loading = false; | 466 | this.loading = false; |
417 | }) | 467 | }) |
418 | .catch(error => { | 468 | .catch(error => { |
419 | this.snackbar = true; | 469 | this.snackbar = true; |
420 | this.text = error.response.data.message; | 470 | this.text = error.response.data.message; |
421 | this.loading = false; | 471 | this.loading = false; |
472 | this.color = "red"; | ||
422 | }); | 473 | }); |
423 | }, | 474 | }, |
424 | importBook() { | 475 | importBook() { |
425 | this.loading = true; | 476 | this.loading = true; |
426 | var bookfile = {}; | 477 | var bookfile = {}; |
427 | bookfile.bookData = this.bookFileJson; | 478 | bookfile.bookData = this.bookFileJson; |
428 | http() | 479 | http() |
429 | .post("/importBookData", bookfile, { | 480 | .post("/importBookData", bookfile, { |
430 | headers: { Authorization: "Bearer " + this.token } | 481 | headers: { Authorization: "Bearer " + this.token } |
431 | }) | 482 | }) |
432 | .then(response => { | 483 | .then(response => { |
433 | this.snackbar = true; | 484 | this.snackbar = true; |
434 | this.text = response.data.message; | 485 | this.text = response.data.message; |
486 | this.color = "green"; | ||
487 | this.loading = false; | ||
488 | }) | ||
489 | .catch(error => { | ||
490 | this.snackbar = true; | ||
491 | this.text = error.response.data.message; | ||
492 | this.color = "red"; | ||
493 | this.loading = false; | ||
494 | }); | ||
495 | }, | ||
496 | importStudent() { | ||
497 | this.loading = true; | ||
498 | var studentfile = {}; | ||
499 | studentfile.studentData = this.studentFileJson; | ||
500 | http() | ||
501 | .post("/importStudentData", studentfile, { | ||
502 | headers: { Authorization: "Bearer " + this.token } | ||
503 | }) | ||
504 | .then(response => { | ||
505 | this.snackbar = true; | ||
506 | this.text = response.data.message; | ||
507 | this.color = "green"; | ||
435 | this.loading = false; | 508 | this.loading = false; |
436 | }) | 509 | }) |
437 | .catch(error => { | 510 | .catch(error => { |
438 | this.snackbar = true; | 511 | this.snackbar = true; |
439 | this.text = error.response.data.message; | 512 | this.text = error.response.data.message; |
513 | this.color = "red"; | ||
440 | this.loading = false; | 514 | this.loading = false; |
441 | }); | 515 | }); |
442 | } | 516 | } |
443 | }, | 517 | }, |
444 | mounted() { | 518 | mounted() { |
445 | this.token = this.$store.state.token; | 519 | this.token = this.$store.state.token; |
520 | |||
446 | /** TEACHERS SAMPLE CSV */ | 521 | /** TEACHERS SAMPLE CSV */ |
447 | const getTeacherData = teacherData(); | 522 | const getTeacherData = teacherData(); |
448 | this.teacherData = getTeacherData; | 523 | this.teacherData = getTeacherData; |
449 | 524 | ||
450 | /** STUDENTS SAMPLE CSV */ | 525 | /** STUDENTS SAMPLE CSV */ |
451 | const getstudentData = studentData(); | 526 | const getstudentData = studentData(); |
452 | this.studentData = getstudentData; | 527 | this.studentData = getstudentData; |
453 | 528 | ||
454 | /** PARENTS SAMPLE CSV */ | 529 | /** PARENTS SAMPLE CSV */ |
455 | const getparentData = parentData(); | 530 | const getparentData = parentData(); |
456 | this.parentData = getparentData; | 531 | this.parentData = getparentData; |
457 | 532 | ||
458 | /** USERS SAMPLE CSV */ | 533 | /** USERS SAMPLE CSV */ |
459 | const getUserData = userData(); | 534 | const getUserData = userData(); |
460 | this.userData = getUserData; | 535 | this.userData = getUserData; |
src/script/students.js
1 | export default () => { | 1 | export default () => { |
2 | 2 | ||
3 | const students = [{ | 3 | const students = [{ |
4 | "name": "Rishav Singla", | 4 | "name": "Rishav Singla", |
5 | "email": "rsingla.rishu@gmail.com", | 5 | "email": "rsingla.rishu@gmail.com", |
6 | "className": "1", | ||
7 | "sectionName": "A", | ||
6 | "rollNo": "1", | 8 | "rollNo": "1", |
7 | "dob": "1993-10-08", | 9 | "dob": "1993-10-08", |
8 | "gender": "Male", | 10 | "gender": "Male", |
9 | "bloodGroup": "A+", | 11 | "bloodGroup": "A+", |
10 | "mobile": "9914092452", | 12 | "mobile": "9914092452", |
13 | "height": "5'11", | ||
14 | "medicalNotes": "No", | ||
11 | "city": "Chandigarh", | 15 | "city": "Chandigarh", |
12 | "country": "India", | 16 | "country": "India", |
13 | "presentAddress": "Mohali Sector ", | 17 | "presentAddress": "Mohali Sector ", |
14 | "state": "Punjab", | 18 | "state": "Punjab", |
19 | "allergies": "No", | ||
20 | "establishmentYear": "2019", | ||
21 | "fatherCellNo": "09988772222", | ||
22 | "fatherName": "Raj", | ||
23 | "parentEmail": "rajkumar123@gmail.com", | ||
24 | "motherCellNo": "8877112266", | ||
25 | "motherName": "Simran", | ||
26 | "permanentAddress": "Mohali", | ||
27 | "pincode": "160062", | ||
28 | "presentAddress": "Mohali Sector ", | ||
29 | "role": 4, | ||
30 | "rollNo": "1", | ||
31 | "weight": "72" | ||
15 | }, | 32 | }, |
16 | { | 33 | { |
17 | "name": "Shubham Chugh", | 34 | "name": "Shubham Chugh", |
18 | "email": "shubham@theideazfactory.com", | 35 | "email": "shubham@theideazfactory.com", |
36 | "className": "10", | ||
37 | "sectionName": "A", | ||
19 | "rollNo": "2", | 38 | "rollNo": "2", |
20 | "dob": "1994-05-29", | 39 | "dob": "1994-05-29", |
21 | "gender": "Male", | 40 | "gender": "Male", |
22 | "bloodGroup": "A+", | 41 | "bloodGroup": "A+", |
23 | "mobile": "8077362128", | 42 | "mobile": "8077362128", |
43 | "height": "5'8", | ||
44 | "medicalNotes": "No", | ||
45 | "motherCellNo": "7878654323", | ||
24 | "city": "Chandigarh", | 46 | "city": "Chandigarh", |
25 | "country": "India", | 47 | "country": "India", |
26 | "presentAddress": "#1571, ground floor, sector 7C", | 48 | "presentAddress": "#1571, ground floor, sector 7C", |
27 | "state": "Chandigarh", | 49 | "state": "Chandigarh", |
50 | "allergies": "No", | ||
51 | "establishmentYear": "2019", | ||
52 | "parentEmail": "SureshKumar321@gmail.com", | ||
53 | "fatherCellNo": "09898787865", | ||
54 | "fatherName": "Suresh Kumar", | ||
55 | "motherName": "Shinki", | ||
56 | "permanentAddress": "Sector 43 Chandigarh", | ||
57 | "pincode": " 160036", | ||
58 | "presentAddress": "Sector 43 Chandigarh", | ||
59 | "role": 4, | ||
60 | "rollNo": "2", | ||
61 | "weight": "70" | ||
28 | }, | 62 | }, |
29 | ] | 63 | ] |
30 | return students; | 64 | return students; |
31 | } | 65 | } |