feat(backend): KDS settings as device config, zone enforced for kitchen screens, KDS-only API (platform-v2 3.2a)

- KDS manifest: 23 typed settings (prep zone, board, waiting-time minutes and colours,
  behaviour) replacing the KDS page's localStorage settings.
- ConfigField: colour type, "after" ordering (warning < late < flash), groups for the
  manager's dialogs, ".none" text for an empty ref choice.
- routers/kds.py: a KDS device gets only its zone's orders, prints to its zone by default
  and signs waiter messages with its zone/name. New GET /api/kds/context and
  POST /api/kds/orders/{id}/retry-print so the screen never leaves its kds.* scope.
  Unused v1 /items and /items/{id}/status endpoints removed (D-21).
- PATCH /api/devices/me/config: a screen changes its own settings when the signed-in
  person holds core.devices.manage.
- Manager Devices dialogs: settings in sections, colour pickers, "All zones".
- Tests: test_kds_device.py, colour/ordered fields; terminal.mjs scope + zone checks;
  manager.mjs settings sections; stack.mjs detaches the non-LAN network before the
  restart check (one flaky 403).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 18:56:59 +02:00
co-authored by Claude Opus 5.5
parent c24cb72640
commit d5c4400fde
17 changed files with 762 additions and 140 deletions
@@ -1,12 +1,13 @@
// Per-device settings of an app, rendered from its manifest (plan step 3.1a): the
// Per-device settings of an app, rendered from its manifest (plan steps 3.1a, 3.2a): the
// fields come from GET /api/platform/modules → device_app.config, the texts from
// modules:<app>.config.<key>.{label,hint,choices.<value>}. The backend validates them
// (validation.device_config). Used by the pair and edit dialogs of DevicesPage.
// modules:<app>.config.<key>.{label,hint,choices.<value>,none} and section headings from
// modules:<app>.config_groups.<group>. The backend validates them (validation.device_config).
// Used by the pair and edit dialogs of DevicesPage.
import { useEffect, useState } from 'react'
import { useTranslation } from '@xenia/i18n'
import { Field, Input, Select, Switch } from '@xenia/ui'
import client from '../../api/client'
import { configValue, refOptions } from './devicesLogic'
import { configGroups, configValue, refOptions } from './devicesLogic'
export default function DeviceConfigFields({ appKey, fields = [], value, onChange, devices = [], selfId = null }) {
const { t } = useTranslation('manager')
@@ -24,38 +25,59 @@ export default function DeviceConfigFields({ appKey, fields = [], value, onChang
const base = key => `modules:${appKey}.config.${key}`
const set = (f, raw) => onChange({ ...value, [f.key]: configValue(f, raw) })
const control = f => {
const label = t(`${base(f.key)}.label`, { defaultValue: f.key })
const hint = t(`${base(f.key)}.hint`, { defaultValue: '' }) || undefined
const v = value?.[f.key]
if (f.type === 'bool') {
return <Switch key={f.key} checked={!!v} onChange={on => set(f, on)} label={label} description={hint} data-config={f.key} />
}
if (f.choices?.length) {
return (
<Field key={f.key} label={label} hint={hint}>
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
options={f.choices.map(c => ({ value: String(c), label: t(`${base(f.key)}.choices.${c}`, { defaultValue: String(c) }) }))} />
</Field>
)
}
if (f.type === 'ref') {
return (
<Field key={f.key} label={label} hint={hint}>
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
options={[{ value: '', label: t(`${base(f.key)}.none`, { defaultValue: t('devices.form.none') }) },
...refOptions(f, { zones, devices, selfId })]} />
</Field>
)
}
if (f.type === 'color') {
return (
<Field key={f.key} label={label} hint={hint}>
<input type="color" value={v || '#000000'} onChange={e => set(f, e.target.value)} data-config={f.key}
className="h-10 w-16 rounded-control border border-line bg-surface cursor-pointer" />
</Field>
)
}
return (
<Field key={f.key} label={label} hint={hint}>
<Input type={f.type === 'int' ? 'number' : 'text'} value={v ?? ''} min={f.min ?? undefined} max={f.max ?? undefined}
onChange={e => set(f, e.target.value)} data-config={f.key} />
</Field>
)
}
const groups = configGroups(fields)
return (
<div className="grid gap-4" data-testid="device-config">
{fields.map(f => {
const label = t(`${base(f.key)}.label`, { defaultValue: f.key })
const hint = t(`${base(f.key)}.hint`, { defaultValue: '' }) || undefined
const v = value?.[f.key]
if (f.type === 'bool') {
return <Switch key={f.key} checked={!!v} onChange={on => set(f, on)} label={label} description={hint} data-config={f.key} />
}
if (f.choices?.length) {
return (
<Field key={f.key} label={label} hint={hint}>
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
options={f.choices.map(c => ({ value: String(c), label: t(`${base(f.key)}.choices.${c}`, { defaultValue: String(c) }) }))} />
</Field>
)
}
if (f.type === 'ref') {
return (
<Field key={f.key} label={label} hint={hint}>
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
options={[{ value: '', label: t('devices.form.none') }, ...refOptions(f, { zones, devices, selfId })]} />
</Field>
)
}
return (
<Field key={f.key} label={label} hint={hint}>
<Input type={f.type === 'int' ? 'number' : 'text'} value={v ?? ''} min={f.min ?? undefined} max={f.max ?? undefined}
onChange={e => set(f, e.target.value)} data-config={f.key} />
</Field>
)
})}
<div className="grid gap-5" data-testid="device-config">
{groups.map(g => (
<section key={g.group ?? '_'} className="grid gap-4" data-config-group={g.group ?? ''}>
{g.group && groups.length > 1 && g.fields.length > 1 && (
<h3 className="text-label font-semibold text-ink-2 uppercase tracking-wide">
{t(`modules:${appKey}.config_groups.${g.group}`, { defaultValue: g.group })}
</h3>
)}
{g.fields.map(control)}
</section>
))}
</div>
)
}
@@ -72,6 +72,19 @@ export function configValue(field, raw) {
return raw == null ? '' : String(raw)
}
/** Fields in sections, in manifest order of each group's first field: [{group, fields}]
* (fields without a group form their own section, 3.2a). */
export function configGroups(fields = []) {
const out = []
for (const f of fields) {
const g = f.group ?? null
let sec = out.find(s => s.group === g)
if (!sec) { sec = { group: g, fields: [] }; out.push(sec) }
sec.fields.push(f)
}
return out
}
/** Options of a `ref` field: prep zones, or live devices of one app ("devices:<app>"). */
export function refOptions(field, { zones = [], devices = [], selfId = null } = {}) {
if (field.choices_from === 'prep_zones') return zones.map(z => ({ value: String(z.id), label: z.name }))
+9 -1
View File
@@ -1,7 +1,7 @@
// Pure logic of the platform pages (plan steps 2.6c, 2.6d, 2.6e).
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { configInitial, configValue, deviceStatus, deviceUsage, hasRoom, linkTargets, normalizeCode, refOptions } from '../src/pages/platform/devicesLogic.js'
import { configGroups, configInitial, configValue, deviceStatus, deviceUsage, hasRoom, linkTargets, normalizeCode, refOptions } from '../src/pages/platform/devicesLogic.js'
import { moduleState, stoppedBy } from '../src/pages/platform/modulesLogic.js'
import {
approvalState, approvalTarget, canEndSession, canGive, diff, differsFromRole, editorGroups, permLabelKey, resetToRole,
@@ -136,3 +136,11 @@ test('device settings: starting values, typed values, ref options (3.1a)', () =>
assert.deepEqual(refOptions(fields[2], { devices }), [{ value: '1', label: 'Till' }])
assert.deepEqual(refOptions(fields[2], { devices, selfId: 1 }), [])
})
test('config fields in sections, in the order their groups first appear (3.2a)', () => {
const f = (key, group) => ({ key, type: 'bool', default: false, group })
const groups = configGroups([f('zone', 'zone'), f('w', 'board'), f('c', 'age'), f('s', 'board'), f('auto', undefined)])
assert.deepEqual(groups.map(g => [g.group, g.fields.map(x => x.key)]),
[['zone', ['zone']], ['board', ['w', 's']], ['age', ['c']], [null, ['auto']]])
assert.equal(configValue({ type: 'color' }, '#aabbcc'), '#aabbcc')
})