-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_indexDoc.js
383 lines (296 loc) · 10.5 KB
/
script_indexDoc.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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/*
* Projektaufgabe, Abgabeterim: 21.09.2020, Geosoft 1, SoSe 2020
* @author {Timo Lietmeyer} matr.Nr.: {459169}
* @author {Judith Bresser} matr.Nr.: {459956}
*/
//**various jshint configs**
// jshint esversion: 8
// jshint browser: true
// jshint node: true
// jshint -W117
// jshint -W083
"use strict";
/**
*@desc creates Leafleat Map
*@param map = object of leafleat map
*
*
*
*/
var layergroup = L.layerGroup();
var t = document.getElementById("geojsontextarea");;
var map = L.map('mapbootstrap', { layers: [layergroup] }).setView([51.9574469, 7.5719975], 13);//7.5719975,51.9574469 51.957, -0.09
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
check_logged_User() //function to check if user is logged
main_indexDocSite() //run main method
/**
*@desc Main Method, set markers at all taken Stops, create Table with all Users and Ratio buttons
*@param all_user_data = Array of Object with data of all Users
*@param data = Array of Object with data of all Users without Doc Users
*
*/
async function main_indexDocSite() {
var all_user_data = await get_all_User();
var data = clean_docs(all_user_data)
create_markers(data)
create_User_Table(data)
create_User_Ratios(data)
}
/**
*@desc create Markers at all Stops, which are in data
*@param data = array of object with all taken stops from all users
*@param stops_from_iten_User = Object with all Stops from User at Postion data[i]
*/
async function create_markers(data) {
for (var i = 0; i < data.length; i++) {
var stops_from_iten_User = await get_stops_by_UserID(data[i].userID);
set_Markers_at_stop_positions(stops_from_iten_User)
}
}
/**
*@desc create ratio buttons from all Users and their IDs
*@param data = array of object with all user data
*@param list = Form of ratio buttons elements (Node List)
*/
function create_User_Ratios(data) {
document.getElementById("radiobuttons_User").innerHTML = "";
var list = document.getElementById("radiobuttons_User");
for (var i = 0; i < data.length; i++) {
var br = document.createElement("br");
var x = document.createElement("INPUT");
var y = document.createElement("LABEL");
y.innerHTML = data[i].Username + "(ID: " + data[i].userID + ")\n";
x.setAttribute(
"type",
"radio",
);
x.setAttribute(
"name",
"value"
);
x.setAttribute(
"value",
data[i].userID
);
list.appendChild(br);
list.appendChild(x);
list.appendChild(y);
}
}
/**
*@desc function to check if one of the User Ratio Buttons is marked, creates Table with taken departures from selected Ratio buttons
*/
function check_User_radios() {
const rbs = document.querySelectorAll('input[name="value"]');
let selectedValue;
for (const rb of rbs) {
if (rb.checked) {
selectedValue = rb.value;
clean_tables()
create_table_with_taken_departures(selectedValue)
break;
}
}
}
/**
*@desc function to check if one of the departure Radios is marked, turn status to 'infected' at marked ratio button
*/
function check_User_radios_all_dep() {
const rbs = document.querySelectorAll('input[name="value"]');
let selectedValue;
for (const rb of rbs) {
if (rb.checked) {
selectedValue = rb.value;
add_every_status_of_all_departures_to_infected(selectedValue)
break;
}
}
}
/**
*@desc creates table with all taken departures from given Traveller
*@param Trav_ID = Object with data from selected User
*@param Trav = all data from given User
*@param user_stop_data = all stops from Trav user
*@param checkbox = Array of numbers to identifier a row in the table
*/
async function create_table_with_taken_departures(Trav_ID) {
var Trav = await get_User_by_TravID(Trav_ID)
var user_stop_data = await get_stops_by_UserID(Trav[0].userID);
var table = document.getElementById("Departure_Table");
var checkbox = []
for (var i = 0; (i < user_stop_data.length); i++) {
var row = table.insertRow(); //insert a row
row.setAttribute("class", "rt2");
var idobject = {
id: user_stop_data[i].stop_id,
}
var departure_data = await get_one_stop_with_ID(idobject)
var line8 = row.insertCell(); //Departure ID
line8.innerHTML = i + 1; //insert cell at the row variable with the distance value on place i of array array_of_objects
checkbox.push(i);
line8.setAttribute("class", "t1");
var line1 = row.insertCell()
line1.innerHTML = departure_data[0].name;
line1.setAttribute("class", "t1"); //insert cell at the row variable with the pointcloud (point 2) value on place i of array array_of_objects
var line2 = row.insertCell();
line2.innerHTML = departure_data[0].type; //insert cell at the row variable with the distance value on place i of array array_of_objects
line2.setAttribute("class", "t1");
var line3 = row.insertCell();
line3.innerHTML = departure_data[0].id; //insert cell at the row variable with the distance value on place i of array array_of_objects
line3.setAttribute("class", "t1");
var line4 = row.insertCell() //Direction
line4.innerHTML = departure_data[0].departures[user_stop_data[i].departure_id].transport.headsign;
line4.setAttribute("class", "t1"); //insert cell at the row variable with the pointcloud (point 2) value on place i of array array_of_objects
var line5 = row.insertCell(); //Line Number
line5.innerHTML = departure_data[0].departures[user_stop_data[i].departure_id].transport.name; //insert cell at the row variable with the distance value on place i of array array_of_objects
line5.setAttribute("class", "t1");
var line6 = row.insertCell(); //Time
line6.innerHTML = convert_time(departure_data[0].departures[user_stop_data[i].departure_id].time); //insert cell at the row variable with the distance value on place i of array array_of_objects
line6.setAttribute("class", "t1");
var line7 = row.insertCell(); //Departure ID
line7.innerHTML = user_stop_data[0].departure_id; //insert cell at the row variable with the distance value on place i of array array_of_objects
line7.setAttribute("class", "t1");
}
create_Departure_Ratios(checkbox, user_stop_data, Trav_ID) //creates Ratio Buttons with Departures
}
/**
*@desc create ratio buttons from departures
*@param checkbox = Array to identifer row
*@param user_stop_data = Object with all Taken Stops from User
*@param Trav_Id = Traveller ID
*/
function create_Departure_Ratios(checkbox, user_stop_data, Trav_Id) {
document.getElementById("radiobuttons_departures").innerHTML = "";
var list = document.getElementById("radiobuttons_departures");
for (var i = 0; i < checkbox.length; i++) {
var br = document.createElement("br");
var x = document.createElement("INPUT");
var y = document.createElement("LABEL");
y.innerHTML = checkbox[i] + 1;
var row_data = {
checkbox: checkbox[i],
stop_id: user_stop_data[i].stop_id,
dep_id: user_stop_data[i].departure_id,
Trav_id: Trav_Id
}
var JSON_row_data = JSON.stringify(row_data) //to save the data in the selected Radio Button
x.setAttribute(
"type",
"radio",
);
x.setAttribute(
"name",
"value_dep_doc"
);
x.setAttribute(
"value",
JSON_row_data
);
list.appendChild(br);
list.appendChild(x);
list.appendChild(y);
}
}
/**
*@desc function to check if one of the departure Ratio Buttons is marked, run another function which add every status to infected from selected departure
*/
function check_Departure_radios() {
const rbs = document.querySelectorAll('input[name="value_dep_doc"]');
let selectedValue;
for (const rb of rbs) {
if (rb.checked) {
selectedValue = rb.value;
selectedValue = JSON.parse(selectedValue)
add_every_status_to_infected(selectedValue)
break;
}
}
}
/**
*@desc function to update every status of given departure to infected at Collection "selected_departures"
*@param Dep_Obj = Object with StopID and Departure ID
*@param begin_time = Variable with Value from textfield with ID "Begin_time"
*@param End_time = Variable with Value from textfield with ID "End_time"
*@param Update_Object = Object with Dep_Object Data, begin and end Time data. For PUT Method
*/
async function add_every_status_to_infected(Dep_Obj) {
var begin_time = document.getElementById("Begin_time").value;
var end_time = document.getElementById("End_time").value;
var Update_Object = {
DepID: Dep_Obj.dep_id,
StopID: Dep_Obj.stop_id,
infection_risk: "yes",
begin_time: begin_time,
end_time: end_time
}
$.ajax({
url: "/selected_departures",
method: "PUT",
data: Update_Object,
success: function (result) {
return result;
},
error: function (err) { console.log(err) }
});
}
/**
*@desc function to update every status of all departures of selected User to infected at Collection "selected_departures"
*@param Trav_ID = selected Traveller ID
*/
async function add_every_status_of_all_departures_to_infected(Trav_ID) {
var Trav = await get_User_by_TravID(Trav_ID)
var user_stop_data = await get_stops_by_UserID(Trav[0].userID);
for (var i = 0; i < user_stop_data.length; i++) {
var infec_dep = {
stop_id: user_stop_data[i].stop_id,
dep_id: user_stop_data[i].departure_id,
}
add_every_status_to_infected(infec_dep)
}
}
/**
*@desc creates table with all Users and their ID
*@param only_user = data with all User and their IDs
*/
function create_User_Table(only_user) {
var table = document.getElementById("User_Table");
for (var i = 0; (i < only_user.length); i++) {
var row = table.insertRow(); //insert a row
row.setAttribute("class", "rt1");
var line1 = row.insertCell()
line1.innerHTML = only_user[i].Username;
line1.setAttribute("class", "t1");
var line2 = row.insertCell();
line2.innerHTML = only_user[i].userID;
line2.setAttribute("class", "t1");
}
}
/**
*@desc function to delete Users with role "doctor" from given data
*/
function clean_docs(data) {
var User = [];
for (var i = 0; i < data.length; i++) {
if (data[i].role == "traveller") {
User.push(data[i])
}
}
return User;
}
/**
*@desc function to request all User from Collection "User"
*/
async function get_all_User() {
return new Promise(function (res, rej) {
$.ajax({
url: "/User",
method: "GET",
success: function (result) {
res(result);
},
error: function (err) { console.log(err) }
});
})
}