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:
1 parent
24d3c1149d
commit
a560a1a72b
8 files changed
+181
-91
No files matched your search
+98
-36
@@ -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',
|
||||
|
||||
@@ -63,11 +63,6 @@ function renderGroupDevicesEditor(containerEl, macRows, devicesMap) {
|
||||
const strong = document.createElement('strong');
|
||||
strong.textContent = row.label || row.mac || '—';
|
||||
label.appendChild(strong);
|
||||
label.appendChild(document.createTextNode(' '));
|
||||
const sub = document.createElement('span');
|
||||
sub.className = 'muted-text';
|
||||
sub.textContent = row.mac || '';
|
||||
label.appendChild(sub);
|
||||
|
||||
const rm = document.createElement('button');
|
||||
rm.type = 'button';
|
||||
@@ -78,6 +73,7 @@ function renderGroupDevicesEditor(containerEl, macRows, devicesMap) {
|
||||
renderGroupDevicesEditor(containerEl, macRows, devicesMap);
|
||||
});
|
||||
div.appendChild(label);
|
||||
if (row.mac) div.appendChild(createDeviceIdentifyButton(row.mac));
|
||||
div.appendChild(rm);
|
||||
listEl.appendChild(div);
|
||||
});
|
||||
@@ -92,7 +88,7 @@ function renderGroupDevicesEditor(containerEl, macRows, devicesMap) {
|
||||
excludeIds: macsInRows,
|
||||
labelFor: (mac, d) => {
|
||||
const labelName = d && d.name ? String(d.name).trim() : '';
|
||||
return labelName ? `${labelName} — ${mac}` : mac;
|
||||
return labelName || mac;
|
||||
},
|
||||
searchTextFor: (mac, d) => {
|
||||
const labelName = d && d.name ? String(d.name).trim() : '';
|
||||
@@ -104,6 +100,7 @@ function renderGroupDevicesEditor(containerEl, macRows, devicesMap) {
|
||||
macRows.push({ mac, label: n });
|
||||
renderGroupDevicesEditor(containerEl, macRows, devicesMap);
|
||||
},
|
||||
actionFor: (mac) => createDeviceIdentifyButton(mac),
|
||||
placeholder: 'Search devices to add…',
|
||||
emptyMessage: 'No devices match your search.',
|
||||
noItemsMessage: 'All devices are already in this group.',
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
}
|
||||
|
||||
// Mobile main menu: forward clicks to existing header buttons
|
||||
// Main menu: forward clicks to existing header buttons
|
||||
if (mainMenuBtn && mainMenuDropdown) {
|
||||
mainMenuBtn.addEventListener('click', () => {
|
||||
mainMenuDropdown.classList.toggle('open');
|
||||
|
||||
+37
-7
@@ -31,12 +31,6 @@ body {
|
||||
align-items: end;
|
||||
}
|
||||
|
||||
.device-row-mac {
|
||||
font-size: 0.82em;
|
||||
color: #b0b0b0;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.device-form-actions {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
@@ -68,7 +62,7 @@ body {
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
/* One header row: zone tabs, the BPM readout, then the buttons (or, on narrow screens, the Menu) */
|
||||
/* One header row: zone tabs, the BPM readout, the buttons, then the Menu (on narrow screens, just the Menu) */
|
||||
header {
|
||||
background-color: #1a1a1a;
|
||||
padding: 0.75rem 1rem;
|
||||
@@ -131,6 +125,23 @@ header h1 {
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
/* Wide screens: the Menu holds the Edit mode actions and Run mode, the header keeps the rest */
|
||||
@media (min-width: 1001px) {
|
||||
.header-actions .edit-mode-only,
|
||||
body.preset-ui-edit #ui-mode-toggle,
|
||||
#main-menu-dropdown > :not(.edit-mode-only):not(.ui-mode-toggle) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.header-menu-mobile {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body.preset-ui-run .header-menu-mobile {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-brightness-control {
|
||||
padding: 0.45rem 0.75rem 0.55rem;
|
||||
border-bottom: 1px solid #333;
|
||||
@@ -1875,6 +1886,25 @@ html.simulated-bpm-mode .seq-switch-toggle-wrap {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.zone-device-add-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
border-bottom: 1px solid #4a4a4a;
|
||||
}
|
||||
|
||||
.zone-device-add-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.zone-device-add-row .zone-device-add-result {
|
||||
flex: 1;
|
||||
width: auto;
|
||||
min-width: 0;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.zone-devices-add {
|
||||
margin-top: 0;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@@ -31,6 +31,7 @@ function createSearchableAddPicker({
|
||||
labelFor,
|
||||
searchTextFor,
|
||||
onPick,
|
||||
actionFor,
|
||||
placeholder = 'Search…',
|
||||
emptyMessage = 'No matches.',
|
||||
noItemsMessage = 'Nothing to add.',
|
||||
@@ -93,7 +94,16 @@ function createSearchableAddPicker({
|
||||
btn.setAttribute('role', 'option');
|
||||
btn.textContent = labelFor(id, item);
|
||||
btn.addEventListener('click', () => pickEntry(id, item));
|
||||
results.appendChild(btn);
|
||||
if (!actionFor) {
|
||||
results.appendChild(btn);
|
||||
return;
|
||||
}
|
||||
const row = document.createElement('div');
|
||||
row.className = 'zone-device-add-row';
|
||||
row.setAttribute('role', 'none');
|
||||
row.appendChild(btn);
|
||||
row.appendChild(actionFor(id, item));
|
||||
results.appendChild(row);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user