Add inline assign from dashboard, specific battery picker on device, dynamic install rows
- Dashboard: replace Assign link with device dropdown + arrow button for quick inline assignment without leaving the page - Device detail: replace hardcoded 4-row install form with 1 row + '+ Add brand' button that clones rows dynamically - Device detail: add 'Install Specific Battery' card with dropdown of all available batteries (label, brand, size, notes) via new /device/<id>/install-one route - Tests: 4 new acceptance tests covering dashboard quick-assign and install-one, including capacity enforcement on both paths (39 total)
This commit is contained in:
@@ -167,7 +167,18 @@
|
||||
<a class="btn btn-sm btn-secondary" href="{{ url_for('battery_detail', battery_id=b.id) }}">View</a>
|
||||
|
||||
{% if b.is_available() %}
|
||||
<a class="btn btn-sm btn-primary" href="{{ url_for('battery_assign', battery_id=b.id) }}">Assign</a>
|
||||
<select id="qas-{{ b.id }}"
|
||||
style="padding:0.2rem 0.3rem;font-size:0.8rem;border:1px solid #cbd5e1;border-radius:4px;max-width:110px;vertical-align:middle;">
|
||||
<option value="">— assign —</option>
|
||||
{% for d in devices %}
|
||||
<option value="{{ d.id }}"
|
||||
{% if d.installed_count() >= d.battery_slots %}disabled{% endif %}>
|
||||
{{ d.name }} ({{ d.installed_count() }}/{{ d.battery_slots }})
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type="button" class="btn btn-sm btn-primary"
|
||||
onclick="quickAssign('{{ url_for('battery_assign', battery_id=b.id) }}', {{ b.id }})">→</button>
|
||||
{% endif %}
|
||||
|
||||
{% if b.is_installed() %}
|
||||
@@ -249,6 +260,18 @@ function applyFilters() {
|
||||
updateToolbar();
|
||||
}
|
||||
|
||||
function quickAssign(action, batteryId) {
|
||||
var sel = document.getElementById('qas-' + 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);
|
||||
document.body.appendChild(f);
|
||||
f.submit();
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
['filter-status','filter-brand','filter-size','filter-storage'].forEach(function(id) {
|
||||
document.getElementById(id).value = '';
|
||||
|
||||
@@ -30,41 +30,51 @@
|
||||
{% set free_slots = device.battery_slots - device.installed_count() %}
|
||||
<p class="text-muted" style="margin-bottom:0.75rem;">{{ free_slots }} slot(s) free</p>
|
||||
<form method="post" action="{{ url_for('device_install', device_id=device.id) }}">
|
||||
<div style="display:grid;grid-template-columns:1fr auto;gap:0.4rem;max-width:400px;align-items:start;margin-bottom:0.75rem;">
|
||||
<div id="install-grid" style="display:grid;grid-template-columns:1fr auto;gap:0.4rem;max-width:400px;align-items:start;margin-bottom:0.5rem;">
|
||||
<span style="font-weight:600;font-size:0.85rem;color:#64748b;">Brand</span>
|
||||
<span style="font-weight:600;font-size:0.85rem;color:#64748b;">Qty</span>
|
||||
{% for i in range(1, 5) %}
|
||||
<div>
|
||||
<select onchange="brandSelectChanged(this, 'brand-{{ i }}')">
|
||||
<option value="">— select —</option>
|
||||
{% for b in brands|default([]) %}
|
||||
<option value="{{ b }}">{{ b }}</option>
|
||||
{% endfor %}
|
||||
<option value="__new__">➕ New brand…</option>
|
||||
</select>
|
||||
<input type="text" id="brand-{{ i }}" name="brand[]" value=""
|
||||
placeholder="Type brand name"
|
||||
style="display:none;margin-top:0.3rem;padding:0.3rem 0.5rem;">
|
||||
<div class="install-row-pair" style="display:contents;">
|
||||
<div>
|
||||
<select onchange="brandSelectChanged(this)">
|
||||
<option value="">— select —</option>
|
||||
{% for b in brands|default([]) %}
|
||||
<option value="{{ b }}">{{ b }}</option>
|
||||
{% endfor %}
|
||||
<option value="__new__">➕ New brand…</option>
|
||||
</select>
|
||||
<input type="text" name="brand[]" value=""
|
||||
placeholder="Type brand name"
|
||||
style="display:none;margin-top:0.3rem;padding:0.3rem 0.5rem;">
|
||||
</div>
|
||||
<input type="number" name="qty[]" value="0" min="0"
|
||||
style="padding:0.3rem 0.5rem;width:4rem;text-align:center;">
|
||||
</div>
|
||||
<input type="number" name="qty[]" value="0" min="0"
|
||||
style="padding:0.3rem 0.5rem;width:4rem;text-align:center;">
|
||||
{% endfor %}
|
||||
</div>
|
||||
<button type="button" class="btn btn-sm btn-secondary" onclick="addInstallRow()" style="margin-bottom:0.75rem;">+ Add brand</button>
|
||||
<br>
|
||||
<button class="btn btn-primary" type="submit">Install</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
function brandSelectChanged(sel, inputId) {
|
||||
var input = document.getElementById(inputId);
|
||||
if (sel.value === '__new__' || sel.value === '') {
|
||||
input.style.display = sel.value === '__new__' ? '' : 'none';
|
||||
input.value = '';
|
||||
if (sel.value === '__new__') input.focus();
|
||||
function brandSelectChanged(sel) {
|
||||
var input = sel.nextElementSibling;
|
||||
if (sel.value === '__new__') {
|
||||
input.style.display = ''; input.value = ''; input.focus();
|
||||
} else {
|
||||
input.style.display = 'none';
|
||||
input.value = sel.value;
|
||||
input.value = (sel.value === '') ? '' : sel.value;
|
||||
}
|
||||
}
|
||||
function addInstallRow() {
|
||||
var grid = document.getElementById('install-grid');
|
||||
var tmpl = grid.querySelector('.install-row-pair');
|
||||
var clone = tmpl.cloneNode(true);
|
||||
clone.querySelector('select').value = '';
|
||||
clone.querySelector('input[type=text]').style.display = 'none';
|
||||
clone.querySelector('input[type=text]').value = '';
|
||||
clone.querySelector('input[type=number]').value = '0';
|
||||
grid.appendChild(clone);
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -98,6 +108,28 @@ function brandSelectChanged(sel, inputId) {
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>Install Specific Battery</h2>
|
||||
{% if available_batteries %}
|
||||
<form method="post" action="{{ url_for('device_install_one', device_id=device.id) }}">
|
||||
<div class="form-group">
|
||||
<label for="battery_id">Battery</label>
|
||||
<select name="battery_id" id="battery_id">
|
||||
<option value="">— select —</option>
|
||||
{% for b in available_batteries %}
|
||||
<option value="{{ b.id }}">{{ b.label }} — {{ b.brand }}
|
||||
{%- if b.size %} {{ b.size }}{% endif %}
|
||||
{%- if b.notes %} ({{ b.notes }}){% endif %}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Install</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<p class="text-muted">No available batteries.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>Delete Device</h2>
|
||||
<p style="margin-bottom:1rem;" class="text-muted">
|
||||
|
||||
Reference in New Issue
Block a user