Add required battery_size to devices, filter install panels by size
This commit is contained in:
+33
-18
@@ -20,6 +20,13 @@
|
||||
<option value="{{ loc }}">{{ loc }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="filter-battery-size" onchange="applyDeviceFilters()"
|
||||
style="padding:0.25rem 0.5rem;font-size:0.85rem;border:1px solid #cbd5e1;border-radius:4px;">
|
||||
<option value="">Any Size</option>
|
||||
{% for sz in device_battery_sizes|default([]) %}
|
||||
<option value="{{ sz }}">{{ sz }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="filter-fill" onchange="applyDeviceFilters()"
|
||||
style="padding:0.25rem 0.5rem;font-size:0.85rem;border:1px solid #cbd5e1;border-radius:4px;">
|
||||
<option value="">Any Fill</option>
|
||||
@@ -40,6 +47,7 @@
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Size</th>
|
||||
<th>Location</th>
|
||||
<th>Slots</th>
|
||||
<th>Installed</th>
|
||||
@@ -54,11 +62,13 @@
|
||||
{% elif installed >= d.battery_slots %}{% set fill_state = 'full' %}
|
||||
{% else %}{% set fill_state = 'partial' %}{% endif %}
|
||||
<tr data-type="{{ d.device_type or '' }}"
|
||||
data-battery-size="{{ d.battery_size or '' }}"
|
||||
data-location="{{ d.location or '' }}"
|
||||
data-fill="{{ fill_state }}"
|
||||
data-name="{{ d.name|lower }}">
|
||||
<td data-label="Device"><a href="{{ url_for('device_detail', device_id=d.id) }}"><strong>{{ d.name }}</strong></a></td>
|
||||
<td data-label="Type">{{ d.device_type or '—' }}</td>
|
||||
<td data-label="Size">{{ d.battery_size or '—' }}</td>
|
||||
<td data-label="Location">{{ d.location or '—' }}</td>
|
||||
<td data-label="Slots">{{ d.battery_slots }}</td>
|
||||
<td data-label="Installed">
|
||||
@@ -95,7 +105,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="7" class="text-muted" style="text-align:center;padding:1rem;">No devices yet. <a href="{{ url_for('device_add') }}">Add one.</a></td></tr>
|
||||
<tr><td colspan="8" class="text-muted" style="text-align:center;padding:1rem;">No devices yet. <a href="{{ url_for('device_add') }}">Add one.</a></td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -106,27 +116,31 @@
|
||||
|
||||
<script>
|
||||
function applyDeviceFilters() {
|
||||
var typeVal = document.getElementById('filter-type').value;
|
||||
var locationVal = document.getElementById('filter-location').value;
|
||||
var fillVal = document.getElementById('filter-fill').value;
|
||||
var textVal = document.getElementById('filter-device-text').value.toLowerCase();
|
||||
var rows = document.querySelectorAll('tbody tr[data-name]');
|
||||
var visible = 0;
|
||||
var typeVal = document.getElementById('filter-type').value;
|
||||
var batterySizeVal = document.getElementById('filter-battery-size').value;
|
||||
var locationVal = document.getElementById('filter-location').value;
|
||||
var fillVal = document.getElementById('filter-fill').value;
|
||||
var textVal = document.getElementById('filter-device-text').value.toLowerCase();
|
||||
var rows = document.querySelectorAll('tbody tr[data-name]');
|
||||
var visible = 0;
|
||||
rows.forEach(function(row) {
|
||||
var rowType = row.dataset.type || '';
|
||||
var rowLocation = row.dataset.location || '';
|
||||
var rowFill = row.dataset.fill || '';
|
||||
var rowName = row.dataset.name || '';
|
||||
var show = (!typeVal || rowType === typeVal) &&
|
||||
(!locationVal || rowLocation === locationVal) &&
|
||||
(!fillVal || rowFill === fillVal) &&
|
||||
(!textVal || rowName.includes(textVal) ||
|
||||
rowType.toLowerCase().includes(textVal) ||
|
||||
rowLocation.toLowerCase().includes(textVal));
|
||||
var rowType = row.dataset.type || '';
|
||||
var rowBatterySize = row.dataset.batterySize || '';
|
||||
var rowLocation = row.dataset.location || '';
|
||||
var rowFill = row.dataset.fill || '';
|
||||
var rowName = row.dataset.name || '';
|
||||
var show = (!typeVal || rowType === typeVal) &&
|
||||
(!batterySizeVal || rowBatterySize === batterySizeVal) &&
|
||||
(!locationVal || rowLocation === locationVal) &&
|
||||
(!fillVal || rowFill === fillVal) &&
|
||||
(!textVal || rowName.includes(textVal) ||
|
||||
rowType.toLowerCase().includes(textVal) ||
|
||||
rowBatterySize.toLowerCase().includes(textVal) ||
|
||||
rowLocation.toLowerCase().includes(textVal));
|
||||
row.style.display = show ? '' : 'none';
|
||||
if (show) visible++;
|
||||
});
|
||||
var active = typeVal || locationVal || fillVal || textVal;
|
||||
var active = typeVal || batterySizeVal || locationVal || fillVal || textVal;
|
||||
document.getElementById('device-filter-reset').style.display = active ? '' : 'none';
|
||||
document.getElementById('device-filter-count').textContent =
|
||||
active ? (visible + ' of ' + rows.length + ' shown') : '';
|
||||
@@ -134,6 +148,7 @@ function applyDeviceFilters() {
|
||||
|
||||
function resetDeviceFilters() {
|
||||
document.getElementById('filter-type').value = '';
|
||||
document.getElementById('filter-battery-size').value = '';
|
||||
document.getElementById('filter-location').value = '';
|
||||
document.getElementById('filter-fill').value = '';
|
||||
document.getElementById('filter-device-text').value = '';
|
||||
|
||||
Reference in New Issue
Block a user