change trackpoint format to match server expectation
Sonarqube Scanner / Build and analyze (push) Successful in 1m9s
Sonarqube Scanner / Build and analyze (push) Successful in 1m9s
This commit is contained in:
+68
-25
@@ -56,6 +56,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
formActions: 'editor-form-actions',
|
||||
form: 'editor-form',
|
||||
iconButton: 'editor-icon-button',
|
||||
iconDanger: 'editor-icon-danger',
|
||||
iconRow: 'editor-icon-row',
|
||||
mediaActions: 'editor-media-actions',
|
||||
mediaButton: 'editor-media-button',
|
||||
@@ -127,7 +128,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
}
|
||||
|
||||
function poiTitle(poi) {
|
||||
return text(poi?.title || poi?.name || 'Unbenannte Station');
|
||||
return text(poi?.title || poi?.name || 'Unbenannter Trackpunkt');
|
||||
}
|
||||
|
||||
function apiBase() {
|
||||
@@ -192,7 +193,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
}
|
||||
|
||||
function showPoiView() {
|
||||
setDialogTitle(state.currentPoi ? 'POI bearbeiten' : 'POI hinzufügen');
|
||||
setDialogTitle(state.currentPoi ? 'Trackpunkt bearbeiten' : 'Trackpunkt hinzufügen');
|
||||
setHidden(byId(ids.routeListView), true);
|
||||
setHidden(byId(ids.routeDetailView), true);
|
||||
setHidden(byId(ids.poiFormView), false);
|
||||
@@ -306,9 +307,9 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
return child;
|
||||
}
|
||||
|
||||
function iconButton(label, symbol, action, disabled = false) {
|
||||
function iconButton(label, symbol, action, disabled = false, danger = false) {
|
||||
const button = document.createElement('button');
|
||||
button.className = classes.iconButton;
|
||||
button.className = danger ? `${classes.iconButton} ${classes.iconDanger}` : classes.iconButton;
|
||||
button.dataset.editorAction = action;
|
||||
button.textContent = symbol;
|
||||
button.title = label;
|
||||
@@ -335,6 +336,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
const actions = document.createElement('div');
|
||||
actions.className = classes.iconRow;
|
||||
actions.appendChild(iconButton('Strecke bearbeiten', '✎', 'edit-route'));
|
||||
actions.appendChild(iconButton('Strecke löschen', '×', 'delete-route', false, true));
|
||||
item.append(label, actions);
|
||||
return item;
|
||||
}
|
||||
@@ -353,12 +355,13 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
const title = poiTitle(poi);
|
||||
const label = document.createElement('div');
|
||||
appendText(label, 'strong', title);
|
||||
appendText(label, 'small', `Position ${index + 1}`);
|
||||
appendText(label, 'small', `Trackpunkt ${index + 1}`);
|
||||
const actions = document.createElement('div');
|
||||
actions.className = classes.iconRow;
|
||||
actions.appendChild(iconButton(`${title} nach oben schieben`, '↑', 'move-poi-up', index === 0));
|
||||
actions.appendChild(iconButton(`${title} nach unten schieben`, '↓', 'move-poi-down', index === state.pois.length - 1));
|
||||
actions.appendChild(iconButton(`${title} bearbeiten`, '✎', 'edit-poi'));
|
||||
actions.appendChild(iconButton(`${title} löschen`, '×', 'delete-poi', false, true));
|
||||
item.append(label, actions);
|
||||
return item;
|
||||
}
|
||||
@@ -392,7 +395,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
if (!state.pois.length) {
|
||||
const item = document.createElement('li');
|
||||
item.className = classes.poiItem;
|
||||
appendText(item, 'span', 'Noch keine Stationen angelegt.');
|
||||
appendText(item, 'span', 'Noch keine Trackpunkte angelegt.');
|
||||
list.appendChild(item);
|
||||
return;
|
||||
}
|
||||
@@ -625,7 +628,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
function fillPoiForm(poi) {
|
||||
resetPendingMedia();
|
||||
byId(ids.poiId).value = poiId(poi);
|
||||
byId(ids.poiTitle).value = poiTitle(poi) === 'Unbenannte Station' ? '' : poiTitle(poi);
|
||||
byId(ids.poiTitle).value = poiTitle(poi) === 'Unbenannter Trackpunkt' ? '' : poiTitle(poi);
|
||||
byId(ids.poiDescription).value = text(poi?.description || poi?.text);
|
||||
byId(ids.poiLat).value = text(poi?.lat ?? poi?.latitude);
|
||||
byId(ids.poiLon).value = text(poi?.lon ?? poi?.longitude);
|
||||
@@ -781,7 +784,8 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
const data = new FormData();
|
||||
data.append('name', routePackage.route?.name || 'Unbenannte Strecke');
|
||||
data.append('description', routePackage.route?.description || '');
|
||||
const gpx = new Blob([routePackage.gpx], { type: 'application/gpx+xml' });
|
||||
const uploadGpx = ns.LocalRoutes.gpxForUpload(routePackage);
|
||||
const gpx = new Blob([uploadGpx], { type: 'application/gpx+xml' });
|
||||
data.append('gpx', gpx, safeGpxFilename(routePackage.route?.name));
|
||||
return data;
|
||||
}
|
||||
@@ -899,7 +903,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
const lat = Number(position?.lat);
|
||||
const lon = Number(position?.lon);
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
|
||||
setStatus('Für einen neuen POI muss zuerst eine aktuelle GPS-Position verfügbar sein.', true);
|
||||
setStatus('Für einen neuen Trackpunkt muss zuerst eine aktuelle GPS-Position verfügbar sein.', true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -910,14 +914,14 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
lon,
|
||||
triggerRadiusM: Number.isFinite(accuracy) && accuracy > 0 ? accuracy : 25
|
||||
});
|
||||
byId(ids.poiFormTitle).textContent = state.currentSource === 'local' ? 'GPX-POI hinzufügen' : 'Station hinzufügen';
|
||||
byId(ids.poiFormTitle).textContent = 'Trackpunkt hinzufügen';
|
||||
showPoiView();
|
||||
}
|
||||
|
||||
function editPoi(poi) {
|
||||
state.currentPoi = poi;
|
||||
fillPoiForm(poi);
|
||||
byId(ids.poiFormTitle).textContent = 'Station bearbeiten';
|
||||
byId(ids.poiFormTitle).textContent = 'Trackpunkt bearbeiten';
|
||||
showPoiView();
|
||||
}
|
||||
|
||||
@@ -957,7 +961,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
|
||||
async function saveLocalPoi(values) {
|
||||
if (!Number.isFinite(values.lat) || !Number.isFinite(values.lon)) {
|
||||
throw new TypeError('Für einen GPX-POI sind gültige Breiten- und Längengrade erforderlich.');
|
||||
throw new TypeError('Für einen GPX-Trackpunkt sind gültige Breiten- und Längengrade erforderlich.');
|
||||
}
|
||||
const currentId = Number(byId(ids.poiId).value);
|
||||
const identifier = Number.isSafeInteger(currentId) ? currentId : ns.LocalRoutes.createPoiId();
|
||||
@@ -974,7 +978,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
if (index >= 0) state.pois[index] = savedPoi;
|
||||
else state.pois.push(savedPoi);
|
||||
await persistLocalCurrentRoute();
|
||||
setStatus('GPX-POI und zugehörige JSON-Mediendaten lokal gespeichert.');
|
||||
setStatus('Trackpunkt und zugehörige JSON-Mediendaten lokal gespeichert.');
|
||||
await loadRoute({ id: routeId(state.currentRoute), _source: 'local' });
|
||||
}
|
||||
|
||||
@@ -1007,13 +1011,13 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
const saved = payload.poi || payload;
|
||||
const savedPoiId = poiId(saved) || currentPoiId;
|
||||
if (savedPoiId) await uploadPoiMedia(currentRouteId, savedPoiId);
|
||||
setStatus('Station gespeichert.');
|
||||
setStatus('Trackpunkt gespeichert.');
|
||||
await loadRoute({ id: currentRouteId, _source: 'server' });
|
||||
}
|
||||
|
||||
async function savePoi() {
|
||||
const values = poiFromForm();
|
||||
if (!values.title) throw new Error('Der Titel der Station ist erforderlich.');
|
||||
if (!values.title) throw new Error('Der Titel des Trackpunkts ist erforderlich.');
|
||||
if (state.currentSource === 'local') await saveLocalPoi(values);
|
||||
else await saveServerPoi(values);
|
||||
}
|
||||
@@ -1058,7 +1062,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
async function removeExistingServerMedia(kind, mediaId) {
|
||||
const currentRouteId = routeId(state.currentRoute);
|
||||
const currentPoiId = poiId(state.currentPoi);
|
||||
if (!currentRouteId || !currentPoiId) throw new Error('Der POI ist noch nicht gespeichert.');
|
||||
if (!currentRouteId || !currentPoiId) throw new Error('Der Trackpunkt ist noch nicht gespeichert.');
|
||||
const basePath = `/routes/${encodeURIComponent(currentRouteId)}/pois/${encodeURIComponent(currentPoiId)}`;
|
||||
const updated = { ...state.currentPoi };
|
||||
|
||||
@@ -1119,13 +1123,13 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
await persistLocalCurrentRoute();
|
||||
renderPoiList();
|
||||
showRouteView();
|
||||
setStatus('POI entfernt und lokale Strecke aktualisiert.');
|
||||
setStatus('Trackpunkt entfernt und lokale Strecke aktualisiert.');
|
||||
return;
|
||||
}
|
||||
|
||||
await sendDelete(`/routes/${encodeURIComponent(currentRouteId)}/pois/${encodeURIComponent(currentPoiId)}`);
|
||||
await loadRoute({ id: currentRouteId, _source: 'server' });
|
||||
setStatus('POI entfernt.');
|
||||
setStatus('Trackpunkt entfernt.');
|
||||
}
|
||||
|
||||
function reorderPois(index, offset) {
|
||||
@@ -1148,7 +1152,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
if (!currentRouteId) return;
|
||||
if (state.currentSource === 'local') {
|
||||
await persistLocalCurrentRoute();
|
||||
setStatus('Lokale POI-Reihenfolge gespeichert.');
|
||||
setStatus('Lokale Trackpunkt-Reihenfolge gespeichert.');
|
||||
return;
|
||||
}
|
||||
const jobs = state.pois.map((poi, index) => {
|
||||
@@ -1178,18 +1182,57 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
return state.pois.findIndex(poi => poiId(poi) === item?.dataset.poiId);
|
||||
}
|
||||
|
||||
async function routeListAction(event) {
|
||||
const action = event.target.closest('[data-editor-action]')?.dataset.editorAction;
|
||||
if (action !== 'edit-route') return;
|
||||
await guarded(() => loadRoute(routeForItem(event.target)));
|
||||
async function deleteRouteFromList(route) {
|
||||
const id = routeId(route);
|
||||
if (!id) return;
|
||||
|
||||
if (routeSource(route) === 'local') {
|
||||
ns.LocalRoutes.remove(id);
|
||||
} else {
|
||||
await sendDelete(`/routes/${encodeURIComponent(id)}`);
|
||||
}
|
||||
|
||||
if (routeId(state.currentRoute) === id && state.currentSource === routeSource(route)) {
|
||||
state.currentRoute = null;
|
||||
state.currentSource = null;
|
||||
state.currentPoi = null;
|
||||
state.pois = [];
|
||||
}
|
||||
|
||||
await loadRoutes();
|
||||
showListView();
|
||||
setStatus('Strecke gelöscht.');
|
||||
}
|
||||
|
||||
function poiListAction(event) {
|
||||
async function routeListAction(event) {
|
||||
const control = event.target.closest('[data-editor-action]');
|
||||
const action = control?.dataset.editorAction;
|
||||
const route = routeForItem(event.target);
|
||||
if (!route) return;
|
||||
|
||||
if (action === 'edit-route') {
|
||||
await loadRoute(route);
|
||||
return;
|
||||
}
|
||||
if (action === 'delete-route') await deleteRouteFromList(route);
|
||||
}
|
||||
|
||||
async function deletePoiFromList(poi) {
|
||||
if (!poi) return;
|
||||
state.currentPoi = poi;
|
||||
await deleteCurrentPoi();
|
||||
}
|
||||
|
||||
async function poiListAction(event) {
|
||||
const action = event.target.closest('[data-editor-action]')?.dataset.editorAction;
|
||||
if (action === 'edit-poi') {
|
||||
editPoi(poiForItem(event.target));
|
||||
return;
|
||||
}
|
||||
if (action === 'delete-poi') {
|
||||
await deletePoiFromList(poiForItem(event.target));
|
||||
return;
|
||||
}
|
||||
if (action === 'move-poi-up') {
|
||||
swapPois(poiIndexForItem(event.target), -1);
|
||||
return;
|
||||
@@ -1220,7 +1263,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
|
||||
activate(byId(ids.poiDelete), () => guarded(deleteCurrentPoi));
|
||||
activate(byId(ids.poiCancel), showRouteView);
|
||||
activate(byId(ids.routeList), event => guarded(() => routeListAction(event)));
|
||||
activate(byId(ids.poiList), poiListAction);
|
||||
activate(byId(ids.poiList), event => guarded(() => poiListAction(event)));
|
||||
submit(byId(ids.routeForm), () => guarded(saveRoute));
|
||||
submit(byId(ids.poiForm), () => guarded(savePoi));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user