-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay2.js
197 lines (175 loc) · 5.74 KB
/
Display2.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
function createButton(name, id, list){
var button = document.createElement("input");
button.type = "submit";
button.value = name;
button.id = id;
button.className = 'defaultBut';
if(list['class']){
button.className = list['class'];
}
return button;
}
function createRadioButton(naam, id, name){ //Zou chill zijn als we iets kunne verzinnen voor een betere output.
var radio = document.createElement('input');
radio.type = 'radio';
radio.name = name;
radio.id = id;
var label = document.createElement('label');
label.htmlFor = id;
var description = document.createTextNode(naam);
label.appendChild(description);
return [radio, label];
}
function createGraph(id, points, labels){
var ctx = document.getElementById(id).getContext('2d');
var chart = new Chart(ctx, {
// The type of chart we want to create
type: 'line',
// The data for our dataset
data: {
labels: labels,
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: points,
fill:false,
lineTension: 0
}]
},
// Configuration options go here
options: {}
});
}
function createGraphByTask(task){
var priceHistory = task.getPriceHistory();
var prices = [];
var dates = [];
for(var i = 0; i < priceHistory.length; i++){
prices.push(priceHistory[i][0]);
dates.push(dateToString(priceHistory[i][1]));
}
createGraph("task" + String(task.getId), prices, dates)
}
function createInfo(task){
var price = task.getCurrentPrice();
var lastDate = task.getLastCompletedDate();
var p = document.createElement('p');
p.innerText = "\u20AC"+price;
var p2 = document.createElement('p');
p2.innerText = dateToString(lastDate);
var div = document.createElement('div');
div.appendChild(p);
div.appendChild(p2);
return div
}
function createCanvas(id, role, aria){
var canvas = document.createElement('canvas');
canvas.setAttribute("id", id);
canvas.setAttribute("role", role);
canvas.setAttribute("aria-label", aria)
return canvas;
}
function dateToString(date){
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
return String(day) + "-" + String(month+1) + "-" + String(year)
}
function addEnter(htmlelement){
var p = document.createElement('p');
p.innerText = "\n";
htmlelement.appendChild(p);
}
function makeModal(modalid, id, description){
var modal = document.createElement('div');
modal.id = modalid;
modal.className = 'modal';
var modalcontent = makeModalContent(modalid, id, description);
modal.appendChild(modalcontent);
document.body.appendChild(modal);
return modal;
}
function makeSpan(className, id){
var span = document.createElement('span');
span.className = className;
span.id = id;
span.innerHTML = '×';
return span;
}
function makeModalContent(modalid, task_id, description){
var modalcontent = document.createElement('div');
modalcontent.className = 'modal-content';
modalcontent.appendChild(makeSpan('close', modalid + 'span'));
var tabel = document.createElement('table');
var counter = 0;
var row;
people.forEach(person => {
if(counter % 3 == 0){
row = tabel.insertRow(-1);
}
var cell = row.insertCell(-1);
cell.appendChild(createRadioButton(person.getName(),person.getId(), 'Personbut')[0]);
cell.appendChild(createRadioButton(person.getName(),person.getId(), 'Personbut')[1]);
counter ++;
})
modalcontent.appendChild(tabel);
var p = document.createElement('p');
p.innerText = description;
modalcontent.appendChild(p);
var button = createButton('Helemaal klaar Joh','modalBut', {'class':'redBut'});
modalcontent.appendChild(button);
button.onclick = function(){
modalClick(task_id);
var modal = document.getElementById(modalid);
modal.remove();
}
return modalcontent;
}
function modalClick(taskid){
var task = tasks[taskid];
var prijsid = DB_addPrijs(task.getId(), task.getCurrentPrice(), new Date());
task.setTaskDone(new Date());
var radio = document.getElementsByName('Personbut');
var person_id = false;
radio.forEach(but =>{
if(but.checked){
person_id = but.id;
}
});
if(person_id != false){
DB_addGedaan(person_id, prijsid);
updateTask(task, document.getElementById(task.getId()));
updateLeaderBoard(people);
}
}
function updateTask(task, row){
row.innerHTML = "";
var cell = row.insertCell(-1);
cell.appendChild(createCanvas("task" + String(task.getId()), "img", "aria"+String(task.getName())));
createGraphByTask(task);
var cell2 = row.insertCell(-1);
cell2.appendChild(createInfo(task))
var cell3 = row.insertCell(-1);
var button = createButton("Doe Taak!", "Task"+ task.getId()+"but", {})
cell3.appendChild(button);
task.isTaskEnabled();
button.disabled = !task.isTaskEnabled();
button.onclick = function() {
var modal = makeModal('Task'+task.getId()+'modal',task.getId(), task.getDescription());
var span = document.getElementById('Task'+task.getId()+'modalspan');
modal.style.display = "block";
span.onclick = function() {
modal.remove();
}
}
}
function updateLeaderBoard(people){
var slider = document.getElementById('slider');
slider.innerHTML = '';
var s = "";
people.forEach(person => {
slider.innerHTML += s + String(person.getName()) + ": \u20AC" + String(person.getBalance());
s = ", ";
})
}