Add delete with confirmation for trips and dashcam

- Confirmation modal in server base.html (window.confirmDelete promise helper)
- Trip delete: trash button in Replay column (server-only via data-deletable on
  trip-list div), DELETE /api/v1/portal/trip/<id>, removes computed trip only
  (raw tracking_points kept)
- Dashcam delete: trash button next to download, DELETE /api/v1/portal/dashcam/<id>,
  removes from DB + disk (best-effort file removal)
- history.js: delete button gated on data-deletable='1' attribute; click handler
  intercepts before replay logic
- db.py: delete_trip(), delete_dashcam_file() helpers

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-10 04:40:22 -04:00
co-authored by Copilot
parent a13d74e18e
commit 7aa9ffda16
7 changed files with 151 additions and 6 deletions
+21
View File
@@ -348,6 +348,27 @@ def get_dashcam_file(device_id, file_id):
return {"id": r[0], "relative_path": r[1], "size_bytes": r[2], "uploaded_at": r[3].isoformat(), "storage_path": r[4]}
def delete_trip(device_id, trip_id):
"""Delete a computed trip record. Raw tracking_points are NOT removed."""
with get_cursor(commit=True) as cur:
cur.execute(
"DELETE FROM trips WHERE id = %s AND device_id = %s RETURNING id",
(trip_id, device_id),
)
return cur.fetchone() is not None
def delete_dashcam_file(device_id, file_id):
"""Delete dashcam file from DB and disk. Returns storage_path if deleted, None if not found."""
with get_cursor(commit=True) as cur:
cur.execute(
"DELETE FROM dashcam_files WHERE id = %s AND device_id = %s RETURNING storage_path",
(file_id, device_id),
)
row = cur.fetchone()
return row[0] if row else None
def get_overview_stats(device_id):
with get_cursor() as cur:
cur.execute(