Profiles, presets and sequences export and import as main's bundles. Zones carry group_ids, preset_group_ids, sequence_ids, content_kind and brightness; profiles seed rainbow as colour_cycle, and deleting a profile also deletes its sequences. Groups, zones and sequences written by older versions are migrated at boot. /api/audio (status, event stream, start/stop, reset, anchor-bar, devices) maps main's audio detector onto the mic's beat detector. Audio start/stop picks whether mic beats or the BPM clock time sequences; the clock's beats also go to the drivers while the mic is off. /ws now greets from a post-handshake callback (httpd does not call the handler for the upgrade). The web UI is main's, plus v2's outputs editor, list search and hostname/static IP settings; the bridge, Wi-Fi AP and led-tool parts are gone. API tests follow main's behaviour (119 pass on the board). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
123 lines
3.8 KiB
JavaScript
123 lines
3.8 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,
|
|
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));
|
|
results.appendChild(btn);
|
|
});
|
|
};
|
|
|
|
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;
|
|
}
|