From b62d5a5fc6fccf638eb0ca1e34f9e51af8956a3e Mon Sep 17 00:00:00 2001 From: legop3 Date: Tue, 17 Nov 2026 13:08:11 -0500 Subject: [PATCH] ui betterment --- rover/bootstrap.sh | 1 + rover/install_roverd.sh | 2 + .../components/RoverConfigurationEditor.jsx | 113 ++++++++++++------ .../AdminPanel/AdminPanelContent.jsx | 12 +- webui/src/index.css | 18 +++ 5 files changed, 105 insertions(+), 41 deletions(-) diff --git a/rover/bootstrap.sh b/rover/bootstrap.sh index 3e28b59c..a5e71e35 100755 --- a/rover/bootstrap.sh +++ b/rover/bootstrap.sh @@ -11,6 +11,7 @@ if [[ ! -e /opt/roverd ]]; then git clone https://github.com/legop3/MultiRoombaRover.git /opt/roverd fi [[ -d /opt/roverd/.git ]] || { echo '/opt/roverd must be a repository checkout' >&2; exit 1; } +git -C /opt/roverd pull --ff-only export ROVERD_INITIAL_NAME="$rover_name" ROVERD_INITIAL_SERVER="$server_address" bash /opt/roverd/rover/install_roverd.sh systemctl restart roverd diff --git a/rover/install_roverd.sh b/rover/install_roverd.sh index 1ced7894..ce0cff6c 100755 --- a/rover/install_roverd.sh +++ b/rover/install_roverd.sh @@ -45,6 +45,8 @@ install -D -o root -g root -m 0755 rover/bin/roverd-self-update.sh /usr/local/sb # Keep the running updater on its original inode until it exits. mv -f /usr/local/sbin/roverd-self-update.new /usr/local/sbin/roverd-self-update echo "Registered update checkout at $REPO_ROOT" +# Refuse to report a successful installation with an unusable saved config. +/usr/local/bin/roverd -config /etc/roverd.json -check-config systemctl daemon-reload systemctl enable roverd.service echo 'Installation complete; caller can now restart roverd.' diff --git a/webui/src/admin/components/RoverConfigurationEditor.jsx b/webui/src/admin/components/RoverConfigurationEditor.jsx index 2ce070cb..d1be0ad8 100644 --- a/webui/src/admin/components/RoverConfigurationEditor.jsx +++ b/webui/src/admin/components/RoverConfigurationEditor.jsx @@ -12,33 +12,76 @@ function request(socket, event, payload = {}) { }); } -function fields(schema, prefix = []) { - return Object.entries(schema?.properties || {}).flatMap(([key, child]) => { - const path = [...prefix, key]; - return child.type === 'object' ? fields(child, path) : [{ path, label: path.join(' / ') }]; - }); +function label(key) { return key.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/^./, (c) => c.toUpperCase()); } + +function fieldUI(schema, path = []) { + const ui = { 'ui:title': path.length ? label(path.at(-1)) : '', 'ui:options': { path } }; + if (schema.type === 'string') ui['ui:emptyValue'] = ''; + for (const [key, child] of Object.entries(schema.properties || {})) ui[key] = fieldUI(child, [...path, key]); + return ui; } +function FieldLayout({ id, label: title, children, errors, help, description, schema, uiSchema, registry }) { + const path = uiSchema?.['ui:options']?.path || []; + const object = schema.type === 'object'; + return
+ {!object &&
+ + +
} + {description}{children}{errors}{help} +
; +} + +function ObjectLayout({ title, properties, uiSchema, registry }) { + const path = uiSchema?.['ui:options']?.path || []; + const content =
{properties.map((property) =>
{property.content}
)} + {path.length === 2 && path[0] === 'media' && path[1] !== 'rtspPort' + && } +
; + if (!path.length) return content; + return
+ {title}{content} +
; +} + +// Required boolean properties may be false; HTML required checkboxes may not. +function BooleanInput({ id, value, disabled, readonly, onChange }) { + return onChange(event.target.checked)} className="h-5 w-5 accent-sky-500" />; +} +const widgets = { CheckboxWidget: BooleanInput }; + +const templates = { FieldTemplate: FieldLayout, ObjectFieldTemplate: ObjectLayout }; + function RoverForm({ socket, record, online }) { const [draft, setDraft] = useState(() => structuredClone(record.config)); - const [field, setField] = useState(''); const [busy, setBusy] = useState(false); const [message, setMessage] = useState(''); const [results, setResults] = useState([]); - const options = fields(record.schema); const schema = structuredClone(record.schema); + const uiSchema = fieldUI(schema); for (const category of ['video', 'audioCapture', 'audioPlayback']) { const property = schema.properties?.media?.properties?.[category]?.properties?.profile; const profiles = record.profiles?.[category] || []; - if (property && profiles.length) property.oneOf = profiles.map((profile) => ({ const: profile.id, title: profile.name })); + if (property) { + // Explicit enum/select avoids rendering profile identifiers as free text. + const choices = profiles.map((profile) => ({ id: profile.id, name: profile.name })); + const current = draft.media?.[category]?.profile; + if (current && !choices.some((entry) => entry.id === current)) choices.push({ id: current, name: `${current} (unavailable)` }); + property.enum = choices.map((entry) => entry.id); + uiSchema.media[category].profile['ui:widget'] = 'select'; + uiSchema.media[category].profile['ui:enumNames'] = choices.map((entry) => entry.name); + } } - async function save(all) { + async function save(path) { setBusy(true); setMessage(''); setResults([]); try { - if (all) { - const path = JSON.parse(field); + if (path) { const value = path.reduce((object, key) => object?.[key], draft); if (value === undefined) throw new Error('Selected field has no value'); const response = await request(socket, 'roverManagement:applyField', { path, value }); @@ -57,24 +100,19 @@ function RoverForm({ socket, record, online }) {

{message}

{results.length > 0 && }
-
setDraft(formData)} onSubmit={() => save(false)}> - + setDraft(formData)} onSubmit={() => save()}> +
+ +
- -
- ; } -function MediaProfiles({ socket, record, online }) { - const [category, setCategory] = useState('video'); +function MediaProfiles({ socket, record, online, category, configDirty }) { const [profile, setProfile] = useState({ id: 'custom', name: '', description: '', setup: '', run: '' }); const [message, setMessage] = useState(''); const [busy, setBusy] = useState(false); @@ -90,15 +128,13 @@ function MediaProfiles({ socket, record, online }) { } catch (error) { setMessage(error.message); } finally { setBusy(false); } } - return
- Media profiles and output - + return
{(record.profiles?.[category] || []).map((entry) =>

{entry.name}: {entry.description}

)}

Status: {record.mediaStatus?.[category] || (online ? 'Waiting for status' : 'Offline')}

-

Custom profile

-
+
+ Create or edit custom profile + {configDirty &&

Save configuration changes before saving a custom profile, which restarts the rover.

} +
{['name', 'description', 'setup', 'run'].map((key) =>