Revert "Add clear GPS endpoint + frontend button"
This reverts commit ca77a29d7d.
This commit is contained in:
@@ -1270,24 +1270,6 @@ def delete_asset(asset_id: int):
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
@app.delete("/api/assets/{asset_id}/gps", status_code=204)
|
|
||||||
def clear_asset_gps(asset_id: int):
|
|
||||||
"""Clear GPS coordinates from an asset (sets latitude/longitude to NULL)."""
|
|
||||||
conn = get_db()
|
|
||||||
existing = conn.execute("SELECT id, name FROM assets WHERE id = ?", (asset_id,)).fetchone()
|
|
||||||
if existing is None:
|
|
||||||
conn.close()
|
|
||||||
raise HTTPException(status_code=404, detail="Asset not found")
|
|
||||||
conn.execute(
|
|
||||||
"UPDATE assets SET latitude = NULL, longitude = NULL, updated_at = datetime('now') WHERE id = ?",
|
|
||||||
(asset_id,),
|
|
||||||
)
|
|
||||||
_log_activity(conn, "updated", "asset", asset_id,
|
|
||||||
f"GPS data cleared for '{existing['name']}'")
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
|
|
||||||
# ─── Task 8: POST /api/checkins ─────────────────────────────────────────────
|
# ─── Task 8: POST /api/checkins ─────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1249,7 +1249,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div style="display:flex;gap:8px;margin-bottom:10px;">
|
<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" 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>
|
<button class="btn btn-danger btn-sm" onclick="deleteAsset()" style="flex:1;">🗑️ Delete</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -3606,14 +3605,6 @@
|
|||||||
navBtn.style.display = 'none';
|
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
|
// Keys + Badges
|
||||||
const keys = a.keys || [];
|
const keys = a.keys || [];
|
||||||
const badges = a.badges || (Array.isArray(a.badge_names) ? a.badge_names : []);
|
const badges = a.badges || (Array.isArray(a.badge_names) ? a.badge_names : []);
|
||||||
@@ -4005,24 +3996,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 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 ────────────────────────────────────────────────────────────
|
// ── Delete ────────────────────────────────────────────────────────────
|
||||||
async function deleteAsset() {
|
async function deleteAsset() {
|
||||||
if (!AppState.currentAssetId) return;
|
if (!AppState.currentAssetId) return;
|
||||||
|
|||||||
@@ -432,31 +432,6 @@ class TestDeleteAsset:
|
|||||||
assert response.status_code == 404
|
assert response.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
class TestClearAssetGps:
|
|
||||||
"""Clear GPS endpoint."""
|
|
||||||
|
|
||||||
def test_clear_gps_returns_204(self, client):
|
|
||||||
"""Clear GPS returns 204 and sets lat/lng to null."""
|
|
||||||
r = client.post("/api/assets", json={
|
|
||||||
"machine_id": "GPS001", "name": "Has GPS",
|
|
||||||
"latitude": 28.5, "longitude": -81.3
|
|
||||||
})
|
|
||||||
asset_id = r.json()["id"]
|
|
||||||
response = client.delete(f"/api/assets/{asset_id}/gps")
|
|
||||||
assert response.status_code == 204
|
|
||||||
|
|
||||||
# Verify lat/lng are cleared
|
|
||||||
r2 = client.get(f"/api/assets/{asset_id}")
|
|
||||||
assert r2.status_code == 200
|
|
||||||
data = r2.json()
|
|
||||||
assert data["latitude"] is None
|
|
||||||
assert data["longitude"] is None
|
|
||||||
|
|
||||||
def test_clear_gps_not_found_returns_404(self, client):
|
|
||||||
response = client.delete("/api/assets/99999/gps")
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
# ─── Task 7: GET /api/assets/search?machine_id= ───────────────────────────
|
# ─── Task 7: GET /api/assets/search?machine_id= ───────────────────────────
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user