Add clear asset GPS endpoint + UI

- DELETE /api/assets/{id}/gps: clears lat/lng to NULL
- GET /api/assets/{id}: asset lookup by ID
- GET /api/assets/search?machine_id=: asset lookup by machine ID
- Export & Admin page: Clear Asset GPS card with lookup + confirmation
- Tests: 204 success + 404 not found
This commit is contained in:
Leo
2026-05-22 23:36:40 -04:00
parent ae20c0507f
commit 9794d8076c
3 changed files with 137 additions and 0 deletions
+63
View File
@@ -878,6 +878,17 @@
<a href="/api/export/checkins" class="btn btn-outline" download>📄 Export Check-Ins CSV</a>
</div>
</div>
<div class="card">
<div class="card-title">Clear Asset GPS</div>
<p style="font-size:13px;color:var(--text2);margin-bottom:10px;">
Clear GPS coordinates from an asset. Enter the asset ID or machine ID.
</p>
<div style="display:flex;gap:8px;margin-bottom:10px;">
<input id="clearGpsAssetId" type="text" class="input-field" placeholder="Asset ID or Machine ID" style="flex:1;">
<button class="btn btn-outline btn-sm" onclick="clearAssetGps()">📍 Clear GPS</button>
</div>
<div id="clearGpsResult" style="display:none;"></div>
</div>
<div class="card">
<div class="card-title">Database</div>
<div style="display:flex;flex-wrap:wrap;gap:8px;">
@@ -2110,6 +2121,58 @@ async function confirmResetDb() {
}
}
// ── Clear Asset GPS ──────────────────────────────────────────────────────
async function clearAssetGps() {
const input = document.getElementById('clearGpsAssetId').value.trim();
if (!input) {
showToast('Enter an asset ID or machine ID', true);
return;
}
const resultEl = document.getElementById('clearGpsResult');
resultEl.style.display = 'none';
try {
// Try numeric asset ID first, otherwise search by machine_id
let asset;
const idNum = parseInt(input);
if (!isNaN(idNum) && idNum > 0) {
try {
asset = await api('/api/assets/' + idNum);
} catch (e) {
// Fall through to machine_id search
}
}
if (!asset) {
asset = await api('/api/assets/search?machine_id=' + encodeURIComponent(input));
}
if (!asset || !asset.id) {
resultEl.style.display = '';
resultEl.innerHTML = '<span style="color:var(--red);">Asset not found</span>';
return;
}
const confirmed = await showModal(
'Clear GPS Data',
`<strong>${esc(asset.name)}</strong> (#${asset.id})<br>
Machine ID: ${esc(asset.machine_id)}<br>
Current: lat=${asset.latitude || 'none'}, lng=${asset.longitude || 'none'}<br><br>
Remove GPS coordinates from this asset?`,
'Clear GPS', 'btn-danger'
);
if (!confirmed) return;
await api('/api/assets/' + asset.id + '/gps', { method: 'DELETE' });
resultEl.style.display = '';
resultEl.innerHTML = '<span style="color:var(--green);">✅ GPS data cleared for ' + esc(asset.name) + ' (#' + asset.id + ')</span>';
document.getElementById('clearGpsAssetId').value = '';
showToast('GPS data cleared');
} catch (e) {
resultEl.style.display = '';
resultEl.innerHTML = '<span style="color:var(--red);">' + esc(e.message) + '</span>';
}
}
// ═════════════════════════════════════════════════════════════════════════════
// CANTALOUPE SYNC
// ═════════════════════════════════════════════════════════════════════════════