-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleted.js
350 lines (300 loc) · 8.46 KB
/
deleted.js
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// Add New Student
sendForm() {
console.log('ADD THIS:', this.student);
this.saveStudent('new');
},
showEdit() {
this.edit = false;
console.log('EDIT SEND: ', this.student);
this.saveStudent('edit');
},
saveStudent(type){
var students;
if(localStorage.getItem('dataStudents')){
students = JSON.parse(localStorage.getItem('dataStudents'));
}else{
students = [];
}
// BACKEND
var students2
students2 = this.storedStudentDB;
if(type == 'new'){
// PUSH AND STORE
this.student.created_at = new Date();
this.student.major = this.selectedMajor;
console.log('MAJOR: ', this.selectedMajor);
students.push(this.student);
students2.push(this.student);
localStorage.setItem('dataStudents', JSON.stringify(students));
// POST STUDENT HERE
this.$root.$emit('kirim-add', students);
sweetalert('Added!', 'Student has been added', 'success');
}else if(type == 'edit'){
var index;
for (var i = 0; i < students.length; i++) {
var s = students[i];
var ts = this.student;
if(s.created_at == ts.created_at && s.email == ts.email){
index = i;
}
}
students[index] = this.student;
if (this.selectedMajor == 'Animator') {
this.selectedMajor = 1;
} else if (this.selectedMajor = 'Modeler') {
this.selectedMajor = 2;
} else if (this.selectedMajor = 'Compositor') {
this.selectedMajor = 3;
} else if (this.selectedMajor = 'Programmer') {
this.selectedMajor = 4;
} else {
this.selectedMajor = 1;
}
students[index].major = this.selectedMajor;
// PUT STUDENT HERE
localStorage.setItem('dataStudents', JSON.stringify(students));
this.$root.$emit('kirim-edit', students);
this.$root.$emit('kirim-edit-disini', this.student.characters);
console.log('STUDENT AFTER EDIT: ', this.student);
console.log('CHAR AFTER EDIT: ', this.student.characters);
console.log('CHAR AFTER EDIT: ', this.storedChar);
// this.student.characters = this.storedChar;
sweetalert('Updated!', 'Student has been updated', 'success');
}else{
alert('Error: Save Student type is not defined');
}
// RESET
this.student = _student;
},
addingChar() {
console.log('ADD CHARACTER');
this.addChar = true;
},
addCharSet() {
// var self = this;
for (var i = 0; i < this.storedCharDB.length; i++) {
var char = this.storedCharDB[i].name;
// console.log('KARRRR: ', this.storedCharDB[i].name)
this.student.characters.push({
name: char,
value: 0
});
}
console.log('data student backend char: ', this.student);
},
setAndRender(data, name, key) {
// this stuff undone yet!!!
// POST DATA
var url = this.url.student+ 'create';
},
openUpload() {
document.getElementById("profileIMG").click()
},
onFilePicked(event) {
const files = event.target.files;
const fileReader = new FileReader()
fileReader.onload = (e) => {
this.profilePic = e.target.result
};
fileReader.readAsDataURL(files[0])
this.image = files[0]
console.log(event.target.result)
}
selectedMajor(val) {
var self = this;
// BACKEND DATA
var major_id = null;
if (val == 'Animator' || val == 'animator') {
major_id = 1;
console.log('Major ID: ', major_id);
} else if (val == 'Modeler' || val == 'modeler') {
major_id = 2;
} else if (val == 'Compositor' || val == 'compositor') {
major_id = 3;
} else if (val == 'Programmer' || val == 'programmer') {
major_id = 4;
} else {
major_id = 0;
}
// SEACH SKILL
for (var i=0; i<this.storedSkillDB.length; i++) {
if (major_id == this.storedSkillDB[i].major_id) {
this.selectedListDB = this.storedSkillDB[i];
}
}
console.log('List skill by Major: ', this.selectedListDB);
// ADD SKILL
if (this.selectedListDB.length > 1) {
this.studentDB.skills = null;
this.studentDB.skills = [];
for (var i=0; i<this.selectedListDB.length; i++) {
var skill = this.selectedListDB[i].name;
console.log('Skill nya: ', skill);
this.studentDB.skills.push({
id: skill.id,
name: skill.name,
value: 0
});
}
console.log('Skill Student 1: ', this.studentDB.skills);
} else {
this.studentDB.skills = [{name: this.selectedListDB.name, value: 0}];
console.log('Skill Student 2: ', this.studentDB.skills);
}
// LOCALSTORAGE
// SEARCH SKILLSET
for (var i=0; i<this.storedSkill.length; i++) {
console.log('Cari Major: ', this.storedSkill[i].major)
if (val == this.storedSkill[i].major) {
console.log('Skill dan major ketemu!!!', val);
console.log('Skill dan major ketemu!!!', this.storedSkill);
this.selectedList = this.storedSkill[i].list;
}
}
// ADD SKILLSET
// check created at
if(!this.student.created_at){
this.student.skills = [];
for (var i = 0; i < this.selectedList.length; i++) {
var skill = this.selectedList[i];
// console.log('PRINT SKILL: ', skill)
this.student.skills.push({
id: skill.id,
name: skill.name,
value: 0
});
}
} else {
this.student.skills = [];
for (var i = 0; i < this.selectedList.length; i++) {
var skill = this.selectedList[i];
// console.log('PRINT SKILL: ', skill)
this.student.skills.push({
id: skill.id,
name: skill.name,
value: 0
});
}
}
console.log('SKILL IF MAJOR CHANGE: ', val);
// console.log(this.student)
},
inputValueSkill(val) {
console.log(val)
}
// from worklist.vue ----- localStorage
<template>
<p>From localStorage</p>
<div class="work" v-bind="work" v-for="(work, key) in stored">
<div class="work-show" v-if="work" v-show="!isEditing">
<!-- <img v-bind:src= "work.workPic"> -->
<div class="works-wrapper">
<h3>{{ work.title }}</h3>
<p>{{ work.categori }}</p>
<a v-bind:href="work.website">{{ work.website }}</a>
<div class="option-work">
<img src="../../assets/logo/edit.png" v-on:click="editWork(work, key)">
<img src="../../assets/logo/delete.png" v-on:click="removeWork(work, key)">
</div>
</div>
</div>
<div class="work-show-edit" v-show="isEditing">
<img src="../../assets/work/our.png">
<div class="work-wrapper">
<div class="input-work">
<label>Category:</label>
<input type="text" v-model="work.categori">
</div>
<div class="input-work">
<label>Title:</label>
<input type="text" v-model="work.title">
</div>
<div class="input-work">
<label>Website:</label>
<input type="text" v-model="work.website">
</div>
<div class="button-add">
<button class="edit-work" v-on:click="hideForm">Close</button>
</div>
</div>
</div>
</div>
</template>
// main.js all code
import Vue from 'vue'
import App from './App.vue'
import router from './router'
// import Chartist from './Chartist'
import axios from 'axios'
import VueAxios from 'vue-axios'
import Chart from 'chart.js'
var url = App.data().url;
var data = {
about: null,
founder: null,
skill: null,
character: null,
students: null,
ourwork: null,
login: null
};
Vue.config.productionTip = false
Vue.use(VueAxios, axios);
// IIFE
window.onload = (function(){
getData();
})();
// GET DATA ALL
function getData(){
getAbout();
}
function getAbout(){
Vue.axios.get(url.about).then((response) => {
data.about = response.data;
getFounder();
});
}
function getFounder(){
Vue.axios.get(url.founder).then((response) => {
data.founder = response.data;
getOurwork();
});
}
function getOurwork(){
Vue.axios.get(url.ourwork).then((response) => {
data.ourwork = response.data;
getSkill();
});
}
function getSkill(){
Vue.axios.get(url.skill).then((response) => {
data.skill = response.data;
getCharacter();
});
}
function getCharacter(){
Vue.axios.get(url.character).then((response) => {
data.character = response.data;
getStudent();
});
}
function getStudent(){
Vue.axios.get(url.student).then((response) => {
data.students = response.data;
renderApp();
});
}
// renderApp();
function renderApp(){
var app = new Vue({
router,
data: function(){
return data;
},
mounted(){
// console.clear();
// console.log('INITIAL DATA: ', this.$data);
},
render: h => h(App)
}).$mount('#app')
}