From 3c2b2dc389a485ddb1927dc1dc31a0c011c336af Mon Sep 17 00:00:00 2001 From: Darek Date: Mon, 13 Apr 2026 09:30:56 -0500 Subject: [PATCH] Add bulk Log Charged action to dashboard toolbar Select multiple batteries, pick a date, and optionally increment charge cycles for all of them in one shot. Reuses the existing bulk-action form and POST /battery/bulk-action route; no new routes or migrations needed. --- app.py | 18 ++++++++++++++++++ templates/dashboard.html | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app.py b/app.py index 230a276..2d17b5c 100644 --- a/app.py +++ b/app.py @@ -470,6 +470,24 @@ def create_app(config_object="config"): db.commit() label = field_name.replace("_", " ").title() flash(f"Set {label} on {n} batter{'y' if n == 1 else 'ies'}.", "success") + elif action == "log_charged": + date_val = request.form.get("charged_date", "").strip() + if not date_val: + flash("Date is required.", "error") + return redirect(url_for("dashboard")) + increment = 1 if request.form.get("increment_cycles") else 0 + for b in batteries: + db.add(ChargeLog(battery_id=b.id, charged_date=date_val, + increment_cycles=increment, notes=None)) + if increment: + b.charge_cycles = (b.charge_cycles or 0) + 1 + db.commit() + flash( + f"Logged charge date {date_val} for " + f"{n} batter{'y' if n == 1 else 'ies'}" + + (" (+cycles)." if increment else "."), + "success", + ) else: flash("Unknown action.", "error") diff --git a/templates/dashboard.html b/templates/dashboard.html index 1eb1563..9fc6f04 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -124,6 +124,16 @@ + + + + +
@@ -349,6 +359,12 @@ document.addEventListener('click', function() { document.getElementById('col-picker-panel').style.display = 'none'; }); +function validateBulkCharge() { + var d = document.getElementById('bulk-charged-date'); + if (!d.value) { d.focus(); return false; } + return true; +} + function bulkStorageChanged(sel) { var text = document.getElementById('bulk-storage-text'); var hidden = document.getElementById('bulk-field-value-storage');