Add storage location field to battery with dynamic dropdown
Dropdown populated from existing distinct storage locations, with 'New location...' option revealing a text input.
This commit is contained in:
@@ -86,7 +86,13 @@ def create_app(config_object="config"):
|
||||
battery = db.get(Battery, battery_id)
|
||||
if battery is None:
|
||||
abort(404)
|
||||
return render_template("battery_detail.html", battery=battery)
|
||||
storage_locations = [
|
||||
r[0] for r in db.query(Battery.storage_location)
|
||||
.filter(Battery.storage_location.isnot(None))
|
||||
.distinct().order_by(Battery.storage_location).all()
|
||||
]
|
||||
return render_template("battery_detail.html", battery=battery,
|
||||
storage_locations=storage_locations)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Battery — edit notes
|
||||
@@ -114,6 +120,7 @@ def create_app(config_object="config"):
|
||||
battery.tested_date = f.get("tested_date", "").strip() or None
|
||||
battery.charge_cycles = _int("charge_cycles")
|
||||
battery.purchase_date = f.get("purchase_date", "").strip() or None
|
||||
battery.storage_location = f.get("storage_location", "").strip() or None
|
||||
|
||||
db.commit()
|
||||
flash("Details updated.", "success")
|
||||
|
||||
@@ -45,6 +45,7 @@ class Battery(Base):
|
||||
tested_date = Column(String(10), nullable=True) # YYYY-MM-DD of last test
|
||||
charge_cycles = Column(Integer, nullable=True) # number of charge cycles
|
||||
purchase_date = Column(String(10), nullable=True) # YYYY-MM-DD when purchased
|
||||
storage_location = Column(String(100), nullable=True) # where stored when not installed
|
||||
|
||||
device = relationship("Device", back_populates="batteries")
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
{% endif %}
|
||||
{{ meta_row("Charge Cycles", battery.charge_cycles) }}
|
||||
{{ meta_row("Purchase Date", battery.purchase_date) }}
|
||||
{{ meta_row("Storage", battery.storage_location) }}
|
||||
{% if battery.notes %}
|
||||
<tr>
|
||||
<td style="padding:0.3rem 1rem 0.3rem 0;font-weight:600;color:#64748b;border:none;">Notes</td>
|
||||
@@ -142,6 +143,21 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Storage Location</label>
|
||||
<select id="storage-select" onchange="metaSelectChanged(this,'storage_location')">
|
||||
<option value="">— none —</option>
|
||||
{% for loc in storage_locations|default([]) %}
|
||||
<option value="{{ loc }}" {% if battery.storage_location == loc %}selected{% endif %}>{{ loc }}</option>
|
||||
{% endfor %}
|
||||
<option value="__new__" {% if battery.storage_location and battery.storage_location not in storage_locations|default([]) %}selected{% endif %}>➕ New location…</option>
|
||||
</select>
|
||||
<input type="text" id="storage_location" name="storage_location"
|
||||
value="{{ battery.storage_location or '' }}"
|
||||
placeholder="e.g. Drawer 2, Toolbox, Shelf A"
|
||||
style="display:{% if battery.storage_location and battery.storage_location not in storage_locations|default([]) %}''{% else %}none{% endif %};margin-top:0.4rem;">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="notes">Notes</label>
|
||||
<textarea id="notes" name="notes" placeholder="No notes yet…">{{ battery.notes or '' }}</textarea>
|
||||
|
||||
Reference in New Issue
Block a user