Add device charge-all route, last-charged column, and CSRF fix for quick-assign

This commit is contained in:
2026-06-05 20:08:19 -05:00
parent de986a9305
commit 55ce963d79
4 changed files with 135 additions and 19 deletions
+7 -3
View File
@@ -324,6 +324,7 @@
</div>
<script>
var CSRF_TOKEN = '{{ csrf_token() }}';
var selectAll = document.getElementById('select-all');
var toolbar = document.getElementById('bulk-toolbar');
var countEl = document.getElementById('selected-count');
@@ -471,9 +472,12 @@ function quickAssign(action, batteryId) {
if (!sel.value) { sel.focus(); return; }
var f = document.createElement('form');
f.method = 'post'; f.action = action;
var inp = document.createElement('input');
inp.type = 'hidden'; inp.name = 'device_id'; inp.value = sel.value;
f.appendChild(inp);
var deviceInp = document.createElement('input');
deviceInp.type = 'hidden'; deviceInp.name = 'device_id'; deviceInp.value = sel.value;
f.appendChild(deviceInp);
var csrfInp = document.createElement('input');
csrfInp.type = 'hidden'; csrfInp.name = 'csrf_token'; csrfInp.value = CSRF_TOKEN;
f.appendChild(csrfInp);
document.body.appendChild(f);
f.submit();
}
+28 -1
View File
@@ -166,7 +166,7 @@ function addInstallRow() {
<div class="table-wrap">
<table class="responsive-table">
<thead>
<tr><th>Label</th><th>Brand</th>{% if ha_enabled %}<th>Bat %</th>{% endif %}<th>Notes</th><th>Actions</th></tr>
<tr><th>Label</th><th>Brand</th>{% if ha_enabled %}<th>Bat %</th>{% endif %}<th>Last Charged</th><th>Notes</th><th>Actions</th></tr>
</thead>
<tbody>
{% for b in installed %}
@@ -182,6 +182,7 @@ function addInstallRow() {
{% else %}—{% endif %}
</td>
{% endif %}
<td data-label="Last Charged" class="text-muted">{{ b.charge_logs[-1].charged_date if b.charge_logs else '—' }}</td>
<td data-label="Notes" class="text-muted">{{ b.notes or '—' }}</td>
<td data-label="Actions">
<form class="inline" method="post" action="{{ url_for('battery_unassign', battery_id=b.id) }}">
@@ -209,6 +210,32 @@ function addInstallRow() {
{% endif %}
</div>
{% if installed %}
<div class="card">
<h2>Charge All Installed Batteries</h2>
<form method="post" action="{{ url_for('device_charge_all', device_id=device.id) }}"
style="display:flex;gap:0.5rem;flex-wrap:wrap;align-items:flex-end;">
<div class="form-group" style="margin:0;flex:1;min-width:140px;">
<label>Date</label>
<input type="date" name="charged_date" required>
</div>
<div class="form-group" style="margin:0;align-self:flex-end;padding-bottom:1rem;">
<label style="display:flex;align-items:center;gap:0.4rem;font-weight:normal;cursor:pointer;">
<input type="checkbox" name="increment_cycles" value="1" checked>
Increment charge cycles
</label>
</div>
<div class="form-group" style="margin:0;flex:2;min-width:160px;">
<label>Notes (optional)</label>
<input type="text" name="notes" placeholder="e.g. overnight charge">
</div>
<div style="padding-bottom:1rem;">
<button class="btn btn-primary" type="submit">Log Charge for All</button>
</div>
</form>
</div>
{% endif %}
<div class="card">
<h2>Install Specific Batteries{% if device.battery_size %} <small class="text-muted" style="font-weight:normal;font-size:0.8rem;">({{ device.battery_size }} only)</small>{% endif %}</h2>
{% if available_batteries %}