updated to multiple cared on nfc

This commit is contained in:
2026-06-13 10:30:53 +03:00
parent 916e35b22b
commit 61ae9b2431
3 changed files with 136 additions and 48 deletions
+55 -34
View File
@@ -75,14 +75,30 @@
</div>
</div>
<!-- Current authorized UID -->
<!-- Authorized cards list -->
<div class="mb-3">
<div class="small text-secondary mb-1">Authorized card UID</div>
{% if nfc.get('auth_uid') %}
<code id="auth-uid-display" class="fs-6 fw-bold text-success">{{ nfc.get('auth_uid') }}</code>
{% else %}
<span id="auth-uid-display" class="text-danger small"><i class="bi bi-exclamation-triangle me-1"></i>None — no card enrolled yet</span>
{% endif %}
<div class="small text-secondary mb-1">Authorized cards
<span class="badge text-bg-secondary ms-1" id="card-count-badge">{{ (nfc.get('auth_uids') or ([nfc['auth_uid']] if nfc.get('auth_uid') else [])) | length }}/10</span>
</div>
<div id="auth-uid-list">
{% set uids = nfc.get('auth_uids') or ([nfc['auth_uid']] if nfc.get('auth_uid') else []) %}
{% if uids %}
{% for uid in uids %}
<span class="badge text-bg-success font-monospace me-1 mb-1 d-inline-flex align-items-center gap-1">
{{ uid }}
<form method="POST" action="{{ url_for('boards.nfc_remove_card', board_id=board.id) }}" class="d-inline m-0 p-0">
<input type="hidden" name="uid" value="{{ uid }}">
<button type="submit" class="btn btn-sm p-0 border-0 text-white lh-1"
style="background:none;font-size:14px;line-height:1"
onclick="return confirm('Remove card {{ uid }}?')"
title="Remove">&times;</button>
</form>
</span>
{% endfor %}
{% else %}
<span class="text-danger small"><i class="bi bi-exclamation-triangle me-1"></i>None — no card enrolled yet</span>
{% endif %}
</div>
</div>
<!-- Current relay & timeout -->
@@ -187,19 +203,26 @@
<!-- ── Manual Config ────────────────────────────────────────────────── -->
<div class="card border-0 rounded-4">
<div class="card-header bg-transparent fw-semibold pt-3">
<i class="bi bi-sliders me-1 text-warning"></i> Manual Settings
<i class="bi bi-sliders me-1 text-warning"></i> Settings &amp; Add Card
</div>
<div class="card-body">
<form method="POST" action="{{ url_for('boards.nfc_config_save', board_id=board.id) }}">
<div class="row g-3">
<div class="col-12">
<label class="form-label small text-secondary mb-1">Authorized card UID <span class="text-muted">(leave empty to clear authorization)</span></label>
<input type="text" name="auth_uid" id="manual-uid"
class="form-control font-monospace text-uppercase"
placeholder="e.g. 04:AB:CD:EF"
value="{{ nfc.get('auth_uid', '') }}"
maxlength="31"
oninput="this.value=this.value.toUpperCase()">
<label class="form-label small text-secondary mb-1">
Add authorized card UID
<span class="text-muted">(leave empty to only update relay/timeout)</span>
</label>
<div class="input-group">
<input type="text" name="new_uid" id="manual-uid"
class="form-control font-monospace text-uppercase"
placeholder="e.g. 04:AB:CD:EF — max 10 cards"
maxlength="31"
oninput="this.value=this.value.toUpperCase()">
<button type="submit" class="btn btn-success">
<i class="bi bi-plus-circle me-1"></i>Add &amp; Save
</button>
</div>
</div>
<div class="col-sm-6">
<label class="form-label small text-secondary mb-1">Trigger relay</label>
@@ -210,21 +233,15 @@
</select>
</div>
<div class="col-sm-6">
<label class="form-label small text-secondary mb-1">Release delay (ms)</label>
<label class="form-label small text-secondary mb-1">Absent timeout (ms)</label>
<input type="number" name="pulse_ms" class="form-control"
min="0" max="60000" value="{{ nfc.get('pulse_ms', 0) }}">
<div class="form-text">Relay turns off this many ms after the card is removed (0 = immediately).</div>
<div class="form-text">Relay turns off after card absent this long (0 = use board default 5 s).</div>
</div>
<div class="col-12 d-flex gap-2">
<div class="col-12">
<button type="submit" class="btn btn-primary">
<i class="bi bi-floppy me-1"></i>Save config
<i class="bi bi-floppy me-1"></i>Save relay &amp; timeout only
</button>
{% if nfc.get('auth_uid') %}
<button type="submit" class="btn btn-outline-danger"
onclick="document.getElementById('manual-uid').value=''">
<i class="bi bi-x-circle me-1"></i>Clear authorization
</button>
{% endif %}
</div>
</div>
</form>
@@ -272,15 +289,18 @@ function loadStatus() {
if (useBtn) useBtn.disabled = !d.last_uid;
const enrollBtn = document.getElementById('enroll-btn');
if (enrollBtn) enrollBtn.disabled = !d.last_uid;
// authorized UID display
const authEl = document.getElementById('auth-uid-display');
if (authEl) {
if (d.auth_uid) {
authEl.className = 'fs-6 fw-bold text-success';
authEl.textContent = d.auth_uid;
// authorized cards list
const authList = document.getElementById('auth-uid-list');
if (authList) {
const uids = d.auth_uids || (d.auth_uid ? [d.auth_uid] : []);
const countBadge = document.getElementById('card-count-badge');
if (countBadge) countBadge.textContent = uids.length + '/10';
if (uids.length === 0) {
authList.innerHTML = '<span class="text-danger small"><i class="bi bi-exclamation-triangle me-1"></i>None — no card enrolled yet</span>';
} else {
authEl.className = 'text-danger small';
authEl.innerHTML = '<i class="bi bi-exclamation-triangle me-1"></i>None — no card enrolled yet';
authList.innerHTML = uids.map(uid =>
`<span class="badge text-bg-success font-monospace me-1 mb-1">${uid}</span>`
).join('');
}
}
// relay & timeout summary
@@ -307,8 +327,9 @@ function useLastUID() {
if (uid && uid !== '—') {
const manualUid = document.getElementById('manual-uid');
if (manualUid) {
manualUid.value = uid;
manualUid.value = uid.toUpperCase();
manualUid.scrollIntoView({ behavior: 'smooth', block: 'center' });
manualUid.focus();
}
}
}