Channel 11 defaults, ESP-NOW driver config and rig/desktop updates

Moves the controller, bridge and led-driver default ESP-NOW channel to 11 and
updates the led-driver and led-tool submodule pointers. Includes the rest of the
working tree: web UI, desktop and sim-controller changes, API and bridge code,
graphify output, and the .gitea and fixture-driver folders.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Haiku 5.5 committed 2026-11-21 01:19:02 +13:00
1 parent 35207a868a
commit edf35e9c71
280 files changed
+24043 -1756

No files matched your search

+264 -141
View File
@@ -111,9 +111,11 @@
el.hidden = !can(need[0], LEVELS.indexOf(need[1]));
});
var btn = document.getElementById('auth-button');
var label = !state.enabled ? 'Set up users' : state.user ? state.user + ' (' + state.role + ')' : 'Sign in';
if (btn) {
btn.textContent = !state.enabled ? 'Set up users' : state.user ? state.user + ' (' + state.role + ')' : 'Sign in';
btn.textContent = label;
}
renderUsersTab();
}
/* ------------------------------------------------------------ sign in */
@@ -193,148 +195,257 @@
/* ------------------------------------------------------------ users and roles */
function usersAndRoles() {
dialog('Users & roles', function (body) {
body.innerHTML = '<div class="auth-err" id="auth-err"></div><div id="auth-content">Loading…</div>';
var err = body.querySelector('#auth-err');
var content = body.querySelector('#auth-content');
var roles = [];
// The lists of users and roles, drawn into `urHost` (the Users tab of Settings or a dialog).
// Each row opens its editor: the user and role editors are modals in the page.
var urHost = null;
var urRoles = [];
var urUsers = [];
var urEditing = null; // { kind: 'user' | 'role', name: '' when adding }
function req(method, url, data) {
err.textContent = '';
return origFetch(url, {
method: method, credentials: 'same-origin',
headers: data ? { 'Content-Type': 'application/json' } : undefined,
body: data ? JSON.stringify(data) : undefined,
}).then(function (res) {
if (!res.ok) {
return errorText(res).then(function (m) { err.textContent = m; throw new Error(m); });
}
return res.json().catch(function () { return {}; });
});
function byId(id) { return document.getElementById(id); }
function showModal(id) { byId(id).classList.add('active'); }
function hideModal(id) { byId(id).classList.remove('active'); }
function editorError(id, message) {
var p = byId(id + '-error');
p.textContent = message || '';
p.hidden = !message;
}
// One call to the auth API. A failure rejects with the server's message.
function urRequest(method, url, data) {
return origFetch(url, {
method: method, credentials: 'same-origin',
headers: data ? { 'Content-Type': 'application/json' } : undefined,
body: data ? JSON.stringify(data) : undefined,
}).then(function (res) {
if (!res.ok) {
return errorText(res).then(function (m) { throw new Error(m); });
}
function roleOptions(selected) {
return roles.map(function (r) {
return '<option value="' + esc(r.name) + '"' + (r.name === selected ? ' selected' : '') + '>' + esc(r.name) + '</option>';
}).join('');
}
function render(users) {
var userRows = users.map(function (u) {
return '<tr><td>' + esc(u.username) + '</td>' +
'<td><select data-user-role="' + esc(u.username) + '">' + roleOptions(u.role) + '</select></td>' +
'<td class="auth-row"><button data-reset="' + esc(u.username) + '">Set password</button>' +
'<button class="danger" data-delete-user="' + esc(u.username) + '">Delete</button></td></tr>';
}).join('');
var head = '<tr><th>Area</th>' + roles.map(function (r) { return '<th>' + esc(r.name) + '</th>'; }).join('') + '</tr>';
var matrix = AREAS.map(function (a) {
return '<tr><td>' + esc(AREA_LABELS[a]) + '</td>' + roles.map(function (r) {
var lvl = (r.perms && r.perms[a]) || 0;
var locked = r.name === 'admin';
return '<td><select data-perm-role="' + esc(r.name) + '" data-area="' + a + '"' + (locked ? ' disabled' : '') + '>' +
LEVELS.map(function (l, i) { return '<option value="' + i + '"' + (i === lvl ? ' selected' : '') + '>' + l + '</option>'; }).join('') +
'</select></td>';
}).join('') + '</tr>';
}).join('');
content.innerHTML = [
'<h4>Users</h4>',
'<table><tr><th>Username</th><th>Role</th><th></th></tr>' + (userRows || '<tr><td colspan="3">No users yet</td></tr>') + '</table>',
'<div class="auth-row"><input id="new-user" placeholder="username" style="width:140px">',
'<input id="new-pass" type="password" placeholder="password (8+)" style="width:160px">',
'<select id="new-role" style="width:140px">' + roleOptions('guest') + '</select>',
'<button class="primary" id="add-user">Add user</button></div>',
'<h4 style="margin-top:18px">Permissions</h4>',
'<p style="font-size:12px;opacity:.75;margin:4px 0">none: hidden · view: read · control: play, stop, brightness, identify · edit: change anything.</p>',
'<div style="overflow:auto"><table>' + head + matrix + '</table></div>',
'<div class="auth-row"><input id="new-role-name" placeholder="new role name" style="width:180px">',
'<button id="add-role">New role</button><span style="flex:1"></span>',
'<button class="primary" id="save-roles">Save permissions</button></div>',
'<div class="auth-row" style="margin-top:10px">' + roles.filter(function (r) { return !r.builtin; }).map(function (r) {
return '<button class="danger" data-delete-role="' + esc(r.name) + '">Delete role ' + esc(r.name) + '</button>';
}).join(' ') + '</div>',
].join('');
wire();
}
function wire() {
content.querySelectorAll('[data-user-role]').forEach(function (sel) {
sel.onchange = function () {
req('PUT', '/auth/users/' + encodeURIComponent(sel.dataset.userRole), { role: sel.value })
.then(load, function () { load(); });
};
});
content.querySelectorAll('[data-reset]').forEach(function (b) {
b.onclick = function () {
var pw = window.prompt('New password for ' + b.dataset.reset + ' (8 to 128 characters)');
if (pw) {
req('PUT', '/auth/users/' + encodeURIComponent(b.dataset.reset), { password: pw }).then(load, function () {});
}
};
});
content.querySelectorAll('[data-delete-user]').forEach(function (b) {
b.onclick = function () {
if (window.confirm('Delete user ' + b.dataset.deleteUser + '?')) {
req('DELETE', '/auth/users/' + encodeURIComponent(b.dataset.deleteUser)).then(load, function () {});
}
};
});
content.querySelector('#add-user').onclick = function () {
req('POST', '/auth/users', {
username: content.querySelector('#new-user').value.trim(),
password: content.querySelector('#new-pass').value,
role: content.querySelector('#new-role').value,
}).then(load, function () {});
};
content.querySelector('#add-role').onclick = function () {
var name = content.querySelector('#new-role-name').value.trim();
var perms = {};
AREAS.forEach(function (a) { perms[a] = 0; });
req('POST', '/auth/roles', { name: name, perms: perms }).then(load, function () {});
};
content.querySelector('#save-roles').onclick = function () {
var jobs = roles.filter(function (r) { return r.name !== 'admin'; }).map(function (r) {
var perms = {};
AREAS.forEach(function (a) {
var sel = content.querySelector('[data-perm-role="' + r.name + '"][data-area="' + a + '"]');
perms[a] = sel ? parseInt(sel.value, 10) : 0;
});
return req('PUT', '/auth/roles/' + encodeURIComponent(r.name), { perms: perms });
});
Promise.all(jobs).then(function () { toast('Permissions saved'); load(); }, function () { load(); });
};
content.querySelectorAll('[data-delete-role]').forEach(function (b) {
b.onclick = function () {
if (window.confirm('Delete role ' + b.dataset.deleteRole + '?')) {
req('DELETE', '/auth/roles/' + encodeURIComponent(b.dataset.deleteRole)).then(load, function () {});
}
};
});
}
function load() {
Promise.all([req('GET', '/auth/roles'), req('GET', '/auth/users')]).then(function (res) {
try {
roles = res[0];
render(res[1]);
} catch (e) {
err.textContent = 'Could not show users and roles: ' + e.message;
}
}, function () {
if (!err.textContent) {
err.textContent = 'Could not load users and roles';
}
});
}
load();
return res.json().catch(function () { return {}; });
});
}
// The users and roles lists in a dialog, for when there is no Settings window
function openUsersDialog() {
dialog('Users & roles', function (body) { usersAndRoles(body); });
}
// The users and roles lists, drawn into `host` (the Users tab of Settings)
function usersAndRoles(host) {
urHost = host;
host.innerHTML = '<div class="auth-err" id="auth-err"></div><div id="auth-content">Loading…</div>';
var content = host.querySelector('#auth-content');
content.onclick = function (e) {
var b = e.target.closest('button');
if (!b) return;
if (b.id === 'add-user') openUserEditor('');
else if (b.id === 'add-role') openRoleEditor('');
else if (b.dataset.editUser !== undefined) openUserEditor(b.dataset.editUser);
else if (b.dataset.editRole !== undefined) openRoleEditor(b.dataset.editRole);
};
loadLists();
}
function listError(message) {
var err = urHost.querySelector('#auth-err');
if (err) err.textContent = message;
}
function loadLists() {
Promise.all([urRequest('GET', '/auth/roles'), urRequest('GET', '/auth/users')]).then(function (res) {
urRoles = res[0];
urUsers = res[1];
drawLists();
}, function (e) {
urHost.querySelector('#auth-content').innerHTML = '';
listError(e.message || 'Could not load users and roles');
});
}
/* ------------------------------------------------------------ lists */
function drawLists() {
var content = urHost.querySelector('#auth-content');
listError('');
content.innerHTML = [
listHead('Users', 'add-user', 'Add user'),
urUsers.length ? urUsers.map(userRow).join('') : '<p class="muted-text">No users yet, so anyone can edit. Add the first admin to turn sign-in on.</p>',
listHead('Roles', 'add-role', 'New role', 'margin-top:18px;'),
urRoles.map(roleRow).join(''),
].join('');
}
function listHead(title, id, label, style) {
return '<div class="profiles-actions" style="align-items:center;' + (style || '') + '">' +
'<h4 style="margin:0;">' + title + '</h4><span style="flex:1"></span>' +
'<button type="button" class="btn btn-primary btn-small" id="' + id + '">' + label + '</button></div>';
}
// The same row as the device groups list: title and detail on the left, Edit on the right
function listRow(title, meta, attr) {
return '<div class="group-list-row row-inline"><div class="group-list-row-info">' +
'<div class="group-list-row-title">' + esc(title) + '</div>' +
'<div class="group-list-row-meta muted-text">' + esc(meta) + '</div></div>' +
'<div class="group-list-row-actions"><button type="button" class="btn btn-secondary btn-small" ' + attr + '>Edit</button></div></div>';
}
function userRow(u) {
return listRow(u.username, 'Role: ' + (u.role || 'none'), 'data-edit-user="' + esc(u.username) + '"');
}
function roleRow(r) {
var open = AREAS.filter(function (a) { return ((r.perms && r.perms[a]) || 0) > 0; }).length;
var meta = (r.builtin ? 'Built-in · ' : '') + open + ' of ' + AREAS.length + ' areas visible';
return listRow(r.name, meta, 'data-edit-role="' + esc(r.name) + '"');
}
function roleOptions(selected) {
return urRoles.map(function (r) {
return '<option value="' + esc(r.name) + '"' + (r.name === selected ? ' selected' : '') + '>' + esc(r.name) + '</option>';
}).join('');
}
/* ------------------------------------------------------------ user editor */
function openUserEditor(name) {
var u = name ? urUsers.find(function (x) { return x.username === name; }) : null;
urEditing = { kind: 'user', name: u ? u.username : '' };
byId('edit-user-title').textContent = u ? 'Edit user' : 'Add user';
byId('edit-user-name').value = u ? u.username : '';
byId('edit-user-name').readOnly = !!u;
// The first user is the admin, which turns sign-in on; later users start as guests
byId('edit-user-role').innerHTML = roleOptions(u ? u.role : urUsers.length ? 'guest' : 'admin');
byId('edit-user-pass').value = '';
byId('edit-user-pass').required = !u;
byId('edit-user-pass-help').textContent = u ? 'Leave empty to keep the current password.' : '8 to 128 characters.';
byId('edit-user-delete-btn').hidden = !u;
editorError('edit-user', '');
showModal('edit-user-modal');
}
function saveUser(e) {
e.preventDefault();
var name = byId('edit-user-name').value.trim();
var role = byId('edit-user-role').value;
var pw = byId('edit-user-pass').value;
var isNew = !urEditing.name;
var url = '/auth/users/' + encodeURIComponent(urEditing.name);
var job = isNew
? urRequest('POST', '/auth/users', { username: name, password: pw, role: role })
: urRequest('PUT', url, { role: role }).then(function () {
return pw ? urRequest('PUT', url, { password: pw }) : null;
});
job.then(function () {
hideModal('edit-user-modal');
toast(isNew ? 'User added' : 'User saved');
loadLists();
}, function (err) {
editorError('edit-user', err.message);
loadLists();
});
}
async function deleteUser() {
if (!await uiConfirm('Delete user ' + urEditing.name + '?')) return;
urRequest('DELETE', '/auth/users/' + encodeURIComponent(urEditing.name)).then(function () {
hideModal('edit-user-modal');
loadLists();
}, function (err) {
editorError('edit-user', err.message);
});
}
/* ------------------------------------------------------------ role editor */
function openRoleEditor(name) {
var r = name ? urRoles.find(function (x) { return x.name === name; }) : null;
var admin = !!r && r.name === 'admin'; // the admin role's permissions are fixed
urEditing = { kind: 'role', name: r ? r.name : '' };
byId('edit-role-title').textContent = r ? 'Edit role' : 'New role';
byId('edit-role-name').value = r ? r.name : '';
byId('edit-role-name').readOnly = !!r;
byId('edit-role-perms').innerHTML = AREAS.map(function (a) {
var lvl = (r && r.perms && r.perms[a]) || 0;
return '<div class="group-list-row row-inline"><div class="group-list-row-info">' +
'<div class="group-list-row-title">' + esc(AREA_LABELS[a]) + '</div></div>' +
'<div class="group-list-row-actions"><select data-area="' + a + '"' + (admin ? ' disabled' : '') + '>' +
LEVELS.map(function (l, i) { return '<option value="' + i + '"' + (i === lvl ? ' selected' : '') + '>' + l + '</option>'; }).join('') +
'</select></div></div>';
}).join('');
byId('edit-role-save-btn').hidden = admin;
byId('edit-role-delete-btn').hidden = !r || !!r.builtin;
editorError('edit-role', '');
showModal('edit-role-modal');
}
function saveRole(e) {
e.preventDefault();
var name = byId('edit-role-name').value.trim();
var perms = {};
AREAS.forEach(function (a) {
perms[a] = parseInt(byId('edit-role-perms').querySelector('[data-area="' + a + '"]').value, 10);
});
var isNew = !urEditing.name;
var job = isNew
? urRequest('POST', '/auth/roles', { name: name, perms: perms })
: urRequest('PUT', '/auth/roles/' + encodeURIComponent(urEditing.name), { perms: perms });
job.then(function () {
hideModal('edit-role-modal');
toast(isNew ? 'Role added' : 'Permissions saved');
loadLists();
}, function (err) {
editorError('edit-role', err.message);
});
}
async function deleteRole() {
if (!await uiConfirm('Delete role ' + urEditing.name + '?')) return;
urRequest('DELETE', '/auth/roles/' + encodeURIComponent(urEditing.name)).then(function () {
hideModal('edit-role-modal');
loadLists();
}, function (err) {
editorError('edit-role', err.message);
});
}
// Wired once: the editors are modals in the page, opened from the lists
function wireEditors() {
byId('edit-user-form').addEventListener('submit', saveUser);
byId('edit-user-delete-btn').addEventListener('click', deleteUser);
byId('edit-user-close-btn').addEventListener('click', function () { hideModal('edit-user-modal'); });
byId('edit-role-form').addEventListener('submit', saveRole);
byId('edit-role-delete-btn').addEventListener('click', deleteRole);
byId('edit-role-close-btn').addEventListener('click', function () { hideModal('edit-role-modal'); });
}
/* ------------------------------------------------------------ header button */
function accountMenu() {
dialog(state.user ? 'Signed in as ' + state.user : 'Users', function (body, close) {
if (window.openSettingsTab) {
window.openSettingsTab('users');
return;
}
dialog(state.user ? 'Signed in as ' + state.user : 'Users', buildAccount);
}
// The Users tab of Settings: the same actions, drawn in the tab
function renderUsersTab() {
var body = document.getElementById('settings-users-body');
if (body) {
buildAccount(body, renderUsersTab, true);
if (can('users', AREA_EDIT_LEVEL)) {
var roles = document.createElement('div');
roles.className = 'settings-roles';
body.appendChild(roles);
usersAndRoles(roles);
}
}
}
function buildAccount(body, close, inline) {
{
var rows = [];
if (!state.enabled) {
rows.push('<p style="font-size:13px;opacity:.85">No users yet, so anyone can edit. Create the first admin to turn sign-in on.</p>');
@@ -347,7 +458,7 @@
rows.push('<button id="auth-do-pass">Change password</button>');
rows.push('<button id="auth-do-out">Sign out</button>');
}
if (can('users', AREA_EDIT_LEVEL)) {
if (!inline && can('users', AREA_EDIT_LEVEL)) {
rows.push('<button id="auth-do-users">Users &amp; roles</button>');
}
rows.push('<button id="auth-do-close">Close</button></div>');
@@ -356,15 +467,20 @@
bind('auth-do-login', askLogin);
bind('auth-do-pass', changePassword);
bind('auth-do-out', signOut);
bind('auth-do-users', usersAndRoles);
body.querySelector('#auth-do-close').onclick = close;
});
bind('auth-do-users', openUsersDialog);
if (inline) {
body.querySelector('#auth-do-close').remove();
body.insertAdjacentHTML('afterbegin', '<p style="font-size:13px;opacity:.85">' + (state.user ? 'Signed in as ' + esc(state.user) + ' (' + esc(state.role) + ').' : state.enabled ? 'Not signed in.' : '') + '</p>');
} else {
body.querySelector('#auth-do-close').onclick = close;
}
}
}
var AREA_EDIT_LEVEL = 3;
function addHeaderButton() {
// Beside the Menu button, which stays visible; the header actions inside the menu are hidden until it opens
// The button itself stays hidden; its click opens the Users tab of Settings
var menu = document.getElementById('main-menu-btn');
var host = menu ? menu.parentElement : document.querySelector('header');
if (!host || document.getElementById('auth-button')) {
@@ -376,7 +492,13 @@
btn.className = 'auth-button';
btn.title = 'Sign in, change password, users and roles';
btn.onclick = accountMenu;
btn.hidden = true;
host.insertBefore(btn, menu || host.firstChild);
document.addEventListener('settings-tab', function (e) {
if (e.detail === 'users') {
renderUsersTab();
}
});
applyPerms();
}
@@ -407,12 +529,13 @@
function start() {
injectStyle();
wireEditors();
addHeaderButton();
refresh();
window.authPerms = {
can: can,
refresh: refresh,
usersAndRoles: usersAndRoles,
usersAndRoles: openUsersDialog,
};
}