From 3aabd47571bbfd981573c7954d7aabfabd7de606 Mon Sep 17 00:00:00 2001 From: cproudlock Date: Sat, 16 May 2026 15:58:31 -0400 Subject: [PATCH] imaging dashboard: add Clear all button + endpoint New /imaging/delete_all endpoint wipes every per-bay JSON in IMAGING_DIR via imaging_status.delete_all_sessions(). Template adds "Clear all" outline-danger button next to the count badge, gated on sessions list non-empty, with confirm() prompt naming the count. Deployed via scp + systemctl restart pxe-webapp on 172.16.9.1. Co-Authored-By: Claude Opus 4.7 (1M context) --- webapp/app.py | 8 ++++++++ webapp/services/imaging_status.py | 15 +++++++++++++++ webapp/templates/imaging.html | 11 ++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/webapp/app.py b/webapp/app.py index c17ab03..44fbbc4 100644 --- a/webapp/app.py +++ b/webapp/app.py @@ -496,6 +496,14 @@ def imaging_delete_session(serial): return redirect(url_for("imaging_dashboard")) +@app.route("/imaging/delete_all", methods=["POST"]) +def imaging_delete_all(): + n = imaging_status.delete_all_sessions() + audit("IMAGING_DELETE_ALL", str(n)) + flash(f"Cleared {n} imaging session(s).", "success") + return redirect(url_for("imaging_dashboard")) + + @app.route("/imaging//laps", methods=["POST"]) def imaging_set_laps(serial): """Save (or clear with empty value) the LAPS password for a bay so it diff --git a/webapp/services/imaging_status.py b/webapp/services/imaging_status.py index b311144..1c0240d 100644 --- a/webapp/services/imaging_status.py +++ b/webapp/services/imaging_status.py @@ -169,3 +169,18 @@ def delete_session(serial: str) -> bool: return True except OSError: return False + + +def delete_all_sessions() -> int: + """Wipe every per-bay JSON in IMAGING_DIR. Returns count removed.""" + _ensure_dir() + removed = 0 + for fn in os.listdir(config.IMAGING_DIR): + if not fn.endswith(".json"): + continue + try: + os.unlink(os.path.join(config.IMAGING_DIR, fn)) + removed += 1 + except OSError: + pass + return removed diff --git a/webapp/templates/imaging.html b/webapp/templates/imaging.html index 6831ef1..a72576b 100644 --- a/webapp/templates/imaging.html +++ b/webapp/templates/imaging.html @@ -23,7 +23,16 @@ window.addEventListener('DOMContentLoaded', scheduleImagingReload);

Imaging Progress

Auto-refresh 15s. POST updates from imaging clients arrive at /imaging/status. - {{ sessions|length }}/{{ sessions|length }} +
+ {{ sessions|length }}/{{ sessions|length }} + {% if sessions %} +
+ +
+ {% endif %} +