Files
led-controller/web/static/zone-devices-panel.js
jimmyandClaude Opus 5.5 a560a1a72b 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>
2026-11-04 20:47:00 +13:00

133 lines
4.2 KiB
JavaScript

/**
* Scrollable device/group list with a fixed add row (dropdown + button) below.
* Used by group and zone edit modals.
*/
function prepareZoneDevicesPanel(containerEl) {
if (!containerEl) return null;
let listEl = containerEl.querySelector('.zone-devices-list');
let addSlot = containerEl.querySelector('.zone-devices-add-slot');
if (!listEl) {
containerEl.innerHTML = '';
containerEl.classList.add('zone-devices-panel');
listEl = document.createElement('div');
listEl.className = 'zone-devices-list';
addSlot = document.createElement('div');
addSlot.className = 'zone-devices-add-slot';
containerEl.appendChild(listEl);
containerEl.appendChild(addSlot);
} else {
listEl.innerHTML = '';
addSlot.innerHTML = '';
}
return { listEl, addSlot };
}
/**
* Search field + scrollable filtered list for picking an item to add.
*/
function createSearchableAddPicker({
entries,
excludeIds,
labelFor,
searchTextFor,
onPick,
actionFor,
placeholder = 'Search…',
emptyMessage = 'No matches.',
noItemsMessage = 'Nothing to add.',
}) {
const wrap = document.createElement('div');
wrap.className = 'zone-device-add-picker';
const excluded = excludeIds || new Set();
const available = (entries || []).filter(([id]) => !excluded.has(id));
if (!available.length) {
const empty = document.createElement('span');
empty.className = 'muted-text';
empty.textContent = noItemsMessage;
wrap.appendChild(empty);
return wrap;
}
const search = document.createElement('input');
search.type = 'search';
search.className = 'zone-device-add-search';
search.placeholder = placeholder;
search.setAttribute('aria-label', placeholder);
const results = document.createElement('div');
results.className = 'zone-device-add-results';
results.setAttribute('role', 'listbox');
const filterAvailable = (query) => {
const q = String(query || '').trim().toLowerCase();
return available.filter(([id, item]) => {
if (!q) return true;
const text = searchTextFor(id, item);
return String(text).toLowerCase().includes(q);
});
};
const pickEntry = (id, item) => {
onPick(id, item);
search.value = '';
renderResults('');
};
const renderResults = (query) => {
results.innerHTML = '';
const filtered = filterAvailable(query);
if (!filtered.length) {
const none = document.createElement('div');
none.className = 'zone-device-add-results-empty muted-text';
none.textContent = emptyMessage;
results.appendChild(none);
return;
}
filtered.forEach(([id, item]) => {
const btn = document.createElement('button');
btn.type = 'button';
btn.className = 'zone-device-add-result';
btn.setAttribute('role', 'option');
btn.textContent = labelFor(id, item);
btn.addEventListener('click', () => pickEntry(id, item));
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);
});
};
search.addEventListener('input', () => renderResults(search.value));
search.addEventListener('focus', () => renderResults(search.value));
search.addEventListener('keydown', (event) => {
if (event.key !== 'Enter') return;
const filtered = filterAvailable(search.value);
if (filtered.length === 1) {
event.preventDefault();
pickEntry(filtered[0][0], filtered[0][1]);
}
});
renderResults('');
wrap.appendChild(search);
wrap.appendChild(results);
return wrap;
}
if (typeof window !== 'undefined') {
window.prepareZoneDevicesPanel = prepareZoneDevicesPanel;
window.createSearchableAddPicker = createSearchableAddPicker;
}