feat(ui): Edit mode Menu on desktop, device groups and Identify

Sequences, Settings and Audio only show in Edit mode. On wide screens the Edit
mode actions and Run mode move into the Menu.

Edit device gets a Groups checklist. The Devices list and Edit device group
show names without addresses, and every device in Edit device group, in the
group or in the list to add from, gets an Identify button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-11-04 20:47:00 +13:00
1 parent 24d3c1149d
commit a560a1a72b
8 files changed
+181 -91

No files matched your search

+98 -36
View File
@@ -463,6 +463,32 @@ async function createDeviceFromModal() {
}
}
function createDeviceIdentifyButton(devId) {
const identifyBtn = document.createElement('button');
identifyBtn.className = 'btn btn-primary btn-small';
identifyBtn.type = 'button';
identifyBtn.textContent = 'Identify';
identifyBtn.title = 'Red blink at 10 Hz (~50% brightness) for 2 s, then off (not saved as a preset)';
identifyBtn.addEventListener('click', async () => {
try {
const res = await fetch(`/devices/${encodeURIComponent(devId)}/identify`, {
method: 'POST',
credentials: 'same-origin',
headers: { Accept: 'application/json' },
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
alert(data.error || 'Identify failed');
return;
}
} catch (err) {
console.error(err);
alert('Identify failed');
}
});
return identifyBtn;
}
function renderDevicesList(devices) {
const container = document.getElementById('devices-list-modal');
if (!container) return;
@@ -477,10 +503,8 @@ function renderDevicesList(devices) {
}
ids.forEach((devId) => {
const dev = devices[devId];
const t = (dev && dev.type) || 'led';
const tr = (dev && dev.transport) || 'espnow';
const addrRaw = (dev && dev.address) != null ? String(dev.address).trim() : '';
const addrDisplay = addrRaw || '—';
const row = document.createElement('div');
row.className = 'profiles-row';
@@ -514,43 +538,12 @@ function renderDevicesList(devices) {
label.style.flex = '1';
label.style.minWidth = '100px';
const macEl = document.createElement('code');
macEl.className = 'device-row-mac';
macEl.textContent = devId;
macEl.title = 'MAC (registry id)';
const meta = document.createElement('span');
meta.className = 'muted-text';
meta.style.fontSize = '0.85em';
meta.textContent = `${t} · ${tr} · ${addrDisplay}`;
const editBtn = document.createElement('button');
editBtn.className = 'btn btn-secondary btn-small';
editBtn.textContent = 'Edit';
editBtn.addEventListener('click', () => openEditDeviceModal(devId, dev));
const identifyBtn = document.createElement('button');
identifyBtn.className = 'btn btn-primary btn-small';
identifyBtn.type = 'button';
identifyBtn.textContent = 'Identify';
identifyBtn.title = 'Red blink at 10 Hz (~50% brightness) for 2 s, then off (not saved as a preset)';
identifyBtn.addEventListener('click', async () => {
try {
const res = await fetch(`/devices/${encodeURIComponent(devId)}/identify`, {
method: 'POST',
credentials: 'same-origin',
headers: { Accept: 'application/json' },
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
alert(data.error || 'Identify failed');
return;
}
} catch (err) {
console.error(err);
alert('Identify failed');
}
});
const identifyBtn = createDeviceIdentifyButton(devId);
const deleteBtn = document.createElement('button');
deleteBtn.className = 'btn btn-secondary btn-small';
@@ -572,8 +565,6 @@ function renderDevicesList(devices) {
row.appendChild(dot);
row.appendChild(label);
row.appendChild(macEl);
row.appendChild(meta);
row.appendChild(editBtn);
row.appendChild(identifyBtn);
row.appendChild(deleteBtn);
@@ -661,9 +652,78 @@ function openEditDeviceModal(devId, dev) {
obr.value = String(bv);
if (obv) obv.textContent = String(bv);
}
void renderEditDeviceGroups(devId);
modal.classList.add('active');
}
/** One checkbox per group in the edit modal, ticked when the group lists this device. */
async function renderEditDeviceGroups(devId) {
const listEl = document.getElementById('edit-device-groups');
if (!listEl) return;
listEl.innerHTML = '';
const groups = await fetchGroupsMap();
const idInput = document.getElementById('edit-device-id');
if (!idInput || idInput.value !== devId) return;
listEl.innerHTML = '';
const entries = Object.entries(groups).sort(([a, ga], [b, gb]) =>
String((ga && ga.name) || a).localeCompare(String((gb && gb.name) || b)),
);
if (!entries.length) {
const empty = document.createElement('span');
empty.className = 'muted-text';
empty.textContent = 'No groups yet. Add one under Groups.';
listEl.appendChild(empty);
return;
}
entries.forEach(([gid, g]) => {
const lbl = document.createElement('label');
lbl.style.cssText =
'display:flex;align-items:center;justify-content:flex-start;gap:0.5rem;margin:0.25rem 0;font-weight:normal;';
const cb = document.createElement('input');
cb.type = 'checkbox';
cb.style.cssText = 'width:auto;flex:none;margin:0;';
cb.value = gid;
cb.checked = Array.isArray(g && g.devices) && g.devices.includes(devId);
const name = document.createElement('span');
name.textContent = (g && g.name) || gid;
lbl.appendChild(cb);
lbl.appendChild(name);
listEl.appendChild(lbl);
});
}
/** Add the device to the ticked groups and take it out of the rest; only changed groups are sent. */
async function saveEditDeviceGroups(devId) {
const boxes = document.querySelectorAll('#edit-device-groups input[type="checkbox"]');
if (!boxes.length) return true;
// Fresh copies, so a member added elsewhere since the modal opened is kept.
const groups = await fetchGroupsMap();
try {
for (const cb of boxes) {
const g = groups[cb.value];
if (!g) throw new Error(`Group ${cb.value} not found`);
const devices = Array.isArray(g.devices) ? g.devices : [];
if (devices.includes(devId) === cb.checked) continue;
const res = await fetch(`/groups/${encodeURIComponent(cb.value)}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
devices: cb.checked ? [...devices, devId] : devices.filter((mac) => mac !== devId),
}),
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
throw new Error(data.error || `Group ${cb.value} not saved`);
}
}
return true;
} catch (e) {
console.error('saveEditDeviceGroups:', e);
alert(e.message || 'Failed to update groups');
return false;
}
}
async function updateDevice(devId, payload) {
try {
const res = await fetch(`/devices/${encodeURIComponent(devId)}`, {
@@ -829,6 +889,8 @@ document.addEventListener('DOMContentLoaded', () => {
if (!devId) return;
const ok = await updateDevice(devId, payload);
if (!ok) return;
// Before the brightness push: a driver's brightness includes its groups' factors.
if (!(await saveEditDeviceGroups(devId))) return;
try {
const brRes = await fetch(`/devices/${encodeURIComponent(devId)}/brightness`, {
method: 'POST',