update editor and add tests
This commit is contained in:
+13
-1
@@ -1,11 +1,23 @@
|
||||
(function (ns, $) {
|
||||
'use strict';
|
||||
|
||||
function request(path) {
|
||||
return $.ajax({ url: ns.Config.apiBase + path, method: 'GET', dataType: 'json', cache: false });
|
||||
}
|
||||
|
||||
function routeQuery(position) {
|
||||
const params = new URLSearchParams({ activatedOnly: 'true' });
|
||||
if (position) {
|
||||
params.set('lat', String(position.lat));
|
||||
params.set('lon', String(position.lon));
|
||||
params.set('radiusKm', String(ns.Config.routeRadiusKm));
|
||||
}
|
||||
return `/routes?${params.toString()}`;
|
||||
}
|
||||
|
||||
ns.Api = {
|
||||
health: () => request('/health'),
|
||||
routes: position => request('/routes' + (position ? `?lat=${encodeURIComponent(position.lat)}&lon=${encodeURIComponent(position.lon)}&radiusKm=${ns.Config.routeRadiusKm}` : '')),
|
||||
routes: position => request(routeQuery(position)),
|
||||
route: id => request(`/routes/${encodeURIComponent(id)}`)
|
||||
};
|
||||
}(globalThis.Wegwichtel, globalThis.jQuery));
|
||||
|
||||
Reference in New Issue
Block a user