diff --git a/app.py b/app.py index f9f25d0..29c745f 100644 --- a/app.py +++ b/app.py @@ -759,7 +759,7 @@ def create_app(config_object="config"): flash(f"Device '{name}' added.", "success") if parent_device: return redirect(url_for("device_detail", device_id=parent_device.id)) - return redirect(url_for("device_list")) + return redirect(url_for("device_detail", device_id=device.id)) return render_template("device_add.html", device_types=device_types, device_locations=device_locations, @@ -809,11 +809,18 @@ def create_app(config_object="config"): if changed: db.commit() flat_installed = [] + children_avail = {} if device.has_children(): for child in device.children: for b in child.batteries: if b.status == "installed": flat_installed.append((b, child.name, child.id)) + avail_q = db.query(Battery).filter_by(status="available") + if child.battery_size: + avail_q = avail_q.filter( + (Battery.size == child.battery_size) | (Battery.size == None) + ) + children_avail[child.id] = avail_q.order_by(Battery.label).all() return render_template("device_detail.html", device=device, brands=brands, available_batteries=available_batteries, device_types=device_types, @@ -823,7 +830,8 @@ def create_app(config_object="config"): ha_enabled=ha_client.enabled, ha_live_pct=ha_live_pct, logbook_entries=device.logbook_entries, - flat_installed=flat_installed) + flat_installed=flat_installed, + children_avail=children_avail) # ------------------------------------------------------------------ # # Devices — edit diff --git a/templates/device_detail.html b/templates/device_detail.html index 112491a..57a9969 100644 --- a/templates/device_detail.html +++ b/templates/device_detail.html @@ -112,13 +112,79 @@
{% if device.children %}

Sub-components

-
+
{% for child in device.children %} - - {{ child.name }}
- {{ child.installed_count() }}/{{ child.battery_slots }} slots · {{ child.battery_size }}{% if child.ha_entity_id %} · HA{% endif %} -
+ {% set child_free = child.battery_slots - child.installed_count() %} + {% set child_batteries = children_avail.get(child.id, []) %} +
+ + + {{ child.name }} + {{ child.installed_count() }}/{{ child.battery_slots }} slots · {{ child.battery_size }}{% if child.ha_entity_id %} · HA{% endif %} + + + {% if child_free > 0 and child_batteries %}{{ child_batteries|length }} available{% endif %} + View + + +
+ {% if child_free <= 0 %} +

No free slots.

+ {% elif not child_batteries %} +

No compatible batteries available.

+ {% else %} +
+
+ +
+
+ {% for b in child_batteries %} +
+ +
+ {% endfor %} +
+ +
+ + {% endif %} +
+
{% endfor %}
{% else %}