-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_headfunctions.js
282 lines (236 loc) · 8.92 KB
/
script_headfunctions.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
/*
* 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";
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////Methods for all HTML Sites////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////User Functions////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*@desc function check if one User is logged
*/
async function check_logged_User() {
var logged = await get_logged_User();
if (logged[0] != undefined) {
// window.alert("Login Sucess");
}
else {
window.alert("Login failed");
window.location.href = 'http://localhost:3000/index_Login';
}
}
/**
*@desc function to request logged User
*/
async function get_logged_User() {
return new Promise(function (res, rej) {
$.ajax({
url: "/logged_User",
method: "GET",
success: function (result) {
res(result);
},
error: function (err) { console.log(err) }
});
})
}
/**
*@desc function to delete User from "logged_User" Collection
*/
function delete_logged_User() {
return new Promise(function (res, rej) {
$.ajax({
url: "/logged_User",
method: "DELETE",
success: function (result) {
res(result);
window.location.href = 'http://localhost:3000/index_Login';
},
error: function (err) { console.log(err) }
});
})
}
/**
*@desc function to get all stops from a User by using TravellerID to identiefier
*/
async function get_stops_by_UserID(logged_User) {
var idobject = {
id: logged_User
}
return new Promise(function (res, rej) {
$.ajax({
url: "/selected_departures",
method: "GET",
data: idobject,
success: function (result) {
return res(result);
},
error: function (err) { console.log(err) }
});
})
}
/**
*@desc function to get all User Data from "User" Collection by given Traveller ID
*/
async function get_User_by_TravID(TravID) {
var idobject = {
UserID: TravID
}
return new Promise(function (res, rej) {
$.ajax({
url: "/search_by_UserID",
method: "GET",
data: idobject,
success: function (result) {
return res(result);
},
error: function (err) { console.log(err) }
});
})
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////DB Funktionen/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*@desc function to set Markers at given stops position, creates another Marker when departure is marked as infected
*/
async function set_Markers_at_stop_positions(stops_from_User) {
for (var i = 0; i < stops_from_User.length; i++) {
var stop_data = await get_stop_data(stops_from_User[i].stop_id);
var stop_coordinates = get_stop_coordinates(stop_data);
if (stops_from_User[i].infection_risk == "yes") {
L.marker(stop_coordinates, { icon: redIcon }).addTo(map).bindPopup("Name: " + stop_data[0].name + "<br>" + "Type: " + stop_data[0].type + "<br>" + "ID: " + stop_data[0].id);
}
else {
L.marker(stop_coordinates, { icon: greenIcon }).addTo(map).bindPopup("Name: " + stop_data[0].name + "<br>" + "Type: " + stop_data[0].type + "<br>" + "ID: " + stop_data[0].id);
}
}
}
/**
*@desc function to get one Stop by ID from "all_busstops_and_Departures" Collection
*/
function get_one_stop_with_ID(idobject) {
return new Promise(function (res, rej) {
$.ajax({
url: "/all_busstops_and_departures",
method: "GET",
data: idobject,
success: function (result) {
res(result);
},
error: function (err) { console.log(err) }
});
})
}
/**
*@desc function to check if Collection "all_busstops_and_departures" is Empty
*/
async function Coll_all_busstops_and_Departures_isEmpty() {
//console.log("testhead")
return $.ajax({
url: "/is_empty_all_busstops_and_departures",
method: "GET",
success: function (result) {
return result;
},
error: function (err) { console.log(err) }
});
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////alles weitere/////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*@desc change values of an array
*/
function change(array) {
var temp;
temp = array[0];
array[0] = array[1];
array[1] = temp;
return array;
}
/**
*@desc function to abbreviate time string
*/
function convert_time(time) {
var str = time;
var time_pos_begin = str.indexOf("T");
var time_pos_end = str.lastIndexOf(":");
var time_short = str.slice(time_pos_begin + 1, time_pos_end - 3)
return time_short;
}
/**
*@desc function to clean rows of all tables
*/
function clean_tables() {
$(".rt2").html(" ");
}
/**
*@desc function to return stop coordinates as array from given stop data
*/
function get_stop_coordinates(stop_data) {
var coor = [stop_data[0].lat, stop_data[0].lng];
return coor;
}
/**
*@desc function to get stop data, creates a object for async db Function
*/
async function get_stop_data(id) {
var idobject = {
id: id,
}
var stop = await get_one_stop_with_ID(idobject);
return stop;
}
/**
*@desc declaration of Green Marker for Leafleat Map
*@Source https://github.com/pointhi/leaflet-color-markers/tree/master/img
*/
var greenIcon = new L.Icon({
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-green.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
/**
*@desc declaration of Red Marker for Leafleat Map
*@Source https://github.com/pointhi/leaflet-color-markers/tree/master/img
*/
var redIcon = new L.Icon({
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});