Add clear GPS endpoint + frontend button
- DELETE /api/assets/{id}/gps sets lat/lng to NULL
- Detail view shows 'Clear GPS' button when asset has GPS coords
- Confirmation modal before clearing
- Tests: 204 success + 404 not found
This commit is contained in:
@@ -1249,6 +1249,7 @@
|
||||
</div>
|
||||
<div style="display:flex;gap:8px;margin-bottom:10px;">
|
||||
<button class="btn btn-outline btn-sm" onclick="editAsset()" style="flex:1;">✏️ Edit</button>
|
||||
<button class="btn btn-outline btn-sm" id="detailClearGpsBtn" onclick="clearAssetGps()" style="flex:1;display:none;">📍 Clear GPS</button>
|
||||
<button class="btn btn-danger btn-sm" onclick="deleteAsset()" style="flex:1;">🗑️ Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -3605,6 +3606,14 @@
|
||||
navBtn.style.display = 'none';
|
||||
}
|
||||
|
||||
// Clear GPS button — show when asset has GPS
|
||||
const clearGpsBtn = document.getElementById('detailClearGpsBtn');
|
||||
if (a.latitude != null && a.longitude != null) {
|
||||
clearGpsBtn.style.display = '';
|
||||
} else {
|
||||
clearGpsBtn.style.display = 'none';
|
||||
}
|
||||
|
||||
// Keys + Badges
|
||||
const keys = a.keys || [];
|
||||
const badges = a.badges || (Array.isArray(a.badge_names) ? a.badge_names : []);
|
||||
@@ -3996,6 +4005,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
// ── Clear GPS ──────────────────────────────────────────────────────────
|
||||
async function clearAssetGps() {
|
||||
if (!AppState.currentAssetId) return;
|
||||
const confirmed = await showModal(
|
||||
'Clear GPS Data',
|
||||
'Remove GPS coordinates from this asset?',
|
||||
'Clear GPS'
|
||||
);
|
||||
if (!confirmed) return;
|
||||
try {
|
||||
await api('/api/assets/' + AppState.currentAssetId + '/gps', { method: 'DELETE' });
|
||||
showToast('GPS data cleared');
|
||||
viewAsset(AppState.currentAssetId);
|
||||
} catch (e) {
|
||||
showToast(e.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Delete ────────────────────────────────────────────────────────────
|
||||
async function deleteAsset() {
|
||||
if (!AppState.currentAssetId) return;
|
||||
|
||||
Reference in New Issue
Block a user