feat(signage): Slides library, widgets placed on the preview, blank slides, slide editor rework

- Slides library (Alembic 0044, /api/signage/library): slides kept with a name and a
  description, added to playlists as copies ("Add a slide" → Your slides, "Keep in Slides"),
  or shown alone as a screen's default (device config `slide`, played as "slide:<id>",
  also as a schedule's fallback). Signage → Slides: gallery + a two-pane editor.
- Widgets moved and sized by hand on the preview (WidgetCanvas: handles, snapping, arrow
  keys): position/size "custom" with a box the TV draws the same; alignment per widget.
- Blank slides (background + widgets); menu boards narrower and placed left/centre/right.
- Slide editor reworked: name | show, transition effect | seconds; sections; text look on
  one row with ready colours; one card per widget, settings on one row.
- Questions inside the page (@xenia/ui ConfirmDialog/useConfirm), Switch boxed, Segmented
  fill; the timeline's drop line; schedule lines run on weekdays or smart days, not both;
  the playlist editor stays within 1080p with a long timeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 07:53:27 +02:00
co-authored by Claude Opus 5.5
parent 60e6a16217
commit 83551714f7
46 changed files with 1934 additions and 431 deletions
@@ -1,77 +1,130 @@
// The widgets of a text or menu slide (plan step 5.6b): logo, name, date, clock, message of the
// day, QR code, weather; each in a corner or a bar, small / medium / large, with its own options.
// The widgets of a text, menu or blank slide (plan step 5.6b; reworked 2026-11-21): logo, name,
// date, clock, message of the day, QR code, weather. Each in its own card: its name first, then
// its settings on one row (where, size, alignment, its own options). Where / size read "Custom"
// once it was moved or sized by hand on the preview (WidgetCanvas); picking a corner or a bar
// puts it back. The card of the widget picked on the preview is highlighted (the page doesn't
// jump to it: the preview stays in view while you drag).
// Up to 10 (the server's limit).
import { Plus, Trash2 } from 'lucide-react'
import { AlignCenter, AlignLeft, AlignRight, CalendarDays, Clock, CloudSun, ImageIcon, MessageSquare, Plus, QrCode, Store, Trash2 } from 'lucide-react'
import { useTranslation } from '@xenia/i18n'
import { Button, Field, IconButton, Input, Select, Switch } from '@xenia/ui'
import { MediaPick } from './SignageFields'
import { WIDGET_KINDS, WIDGET_POSITIONS } from './signageLogic'
import { Button, Dropdown, Field, IconButton, Input, Segmented, Switch } from '@xenia/ui'
import { MediaPick, Section } from './SignageFields'
import { presetWidget, WIDGET_KINDS, WIDGET_POSITIONS } from './signageLogic'
export default function WidgetsEditor({ widgets = [], onChange, media, onMedia }) {
const ICON = { logo: ImageIcon, name: Store, date: CalendarDays, clock: Clock, message: MessageSquare, qr: QrCode, weather: CloudSun }
export default function WidgetsEditor({ widgets = [], onChange, media, onMedia, selected = null, onSelect }) {
const { t } = useTranslation('manager')
const set = (i, patch) => onChange(widgets.map((w, j) => (j === i ? { ...w, ...patch } : w)))
const add = kind => onChange([...widgets, { kind, position: kind === 'message' ? 'bottom-bar' : 'top-right', size: 'medium' }])
const add = kind => {
onChange([...widgets, { kind, position: kind === 'message' ? 'bottom-bar' : 'top-right', size: 'medium', align: 'auto' }])
onSelect?.(widgets.length)
}
return (
<fieldset className="grid gap-3 rounded-control border border-line p-3" data-testid="signage-widgets">
<legend className="px-1 text-label font-medium text-ink-2">{t('signage.widgets.title')}</legend>
{widgets.length === 0 && <p className="text-caption text-ink-3">{t('signage.widgets.none')}</p>}
{widgets.map((w, i) => (
<div key={i} className="grid gap-2 rounded-control bg-surface-2 p-2" data-testid="signage-widget" data-kind={w.kind}>
<div className="flex flex-wrap items-end gap-2">
<span className="text-label font-medium text-ink min-w-[6rem] pb-2">{t(`signage.widgets.kinds.${w.kind}`)}</span>
<Field label={t('signage.widgets.position')} className="flex-1 min-w-[9rem]">
<Select value={w.position} onChange={e => set(i, { position: e.target.value })} data-testid="signage-widget-position"
options={WIDGET_POSITIONS.map(p => ({ value: p, label: t(`signage.widgets.positions.${p}`) }))} />
</Field>
<Field label={t('signage.widgets.size')}>
<Select value={w.size || 'medium'} onChange={e => set(i, { size: e.target.value })}
options={['small', 'medium', 'large'].map(s => ({ value: s, label: t(`signage.widgets.sizes.${s}`) }))} />
</Field>
<IconButton variant="ghost" label={t('fees.delete')} onClick={() => onChange(widgets.filter((_, j) => j !== i))} data-testid="signage-widget-remove"><Trash2 size={16} /></IconButton>
</div>
{w.kind === 'logo' && (
<MediaPick kind="image" value={w.media_id} entry={media[String(w.media_id)]} testid="signage-widget-logo"
onChange={item => { onMedia(item); set(i, { media_id: item.id }) }} />
)}
{w.kind === 'message' && (
<Field label={t('signage.widgets.ownText')} hint={t('signage.widgets.ownTextHint')}>
<Input value={w.text || ''} maxLength={200} onChange={e => set(i, { text: e.target.value || null })} data-testid="signage-widget-text" />
</Field>
)}
{w.kind === 'date' && (
<Select value={w.date_style || 'long'} onChange={e => set(i, { date_style: e.target.value })} aria-label={t('signage.widgets.kinds.date')}
options={[{ value: 'long', label: t('signage.widgets.dateLong') }, { value: 'short', label: t('signage.widgets.dateShort') }]} />
)}
{w.kind === 'clock' && <Switch checked={!!w.clock_seconds} onChange={on => set(i, { clock_seconds: on })} label={t('signage.widgets.seconds')} />}
{w.kind === 'qr' && (
<div className="grid gap-2 sm:grid-cols-2">
<Field label={t('display.qrTarget')}>
<Select value={w.qr_target || 'ordering'} onChange={e => set(i, { qr_target: e.target.value })}
options={['ordering', 'menu', 'custom'].map(q => ({ value: q, label: t(`display.qrTargets.${q}`) }))} />
<Section title={t('signage.widgets.title')} testid="signage-widgets">
<p className="text-caption text-ink-3 -mt-1">{t(widgets.length ? 'signage.widgets.dragHint' : 'signage.widgets.none')}</p>
{widgets.map((w, i) => {
const Icon = ICON[w.kind] || ImageIcon
const custom = w.position === 'custom'
const on = selected === i
return (
<div key={i} onPointerDown={() => onSelect?.(i)}
className={`grid gap-3 rounded-card border p-4 transition-colors duration-fast ${on ? 'border-accent bg-accent-soft/40 ring-1 ring-accent' : 'border-line bg-surface-2'}`}
data-testid="signage-widget" data-kind={w.kind} data-selected={on ? 'true' : undefined}>
<div className="flex items-center gap-2">
<Icon size={16} className="text-ink-2 shrink-0" aria-hidden="true" />
<span className="text-body font-semibold text-ink">{t(`signage.widgets.kinds.${w.kind}`)}</span>
<span className="flex-1" />
<IconButton size="sm" tone="danger" label={t('fees.delete')} data-testid="signage-widget-remove"
onClick={e => { e.stopPropagation(); onChange(widgets.filter((_, j) => j !== i)); onSelect?.(null) }}><Trash2 size={16} /></IconButton>
</div>
<div className="flex flex-wrap items-end gap-3">
<Field label={t('signage.widgets.position')} className="w-44">
<Dropdown value={w.position} onChange={p => p !== 'custom' && onChange(widgets.map((x, j) => (j === i ? presetWidget(x, p) : x)))}
data-testid="signage-widget-position"
options={[...WIDGET_POSITIONS.map(p => ({ value: p, label: t(`signage.widgets.positions.${p}`) })),
...(custom ? [{ value: 'custom', label: t('signage.widgets.custom') }] : [])]} />
</Field>
{w.qr_target === 'custom' && (
<Field label={t('display.qrUrl')}><Input value={w.qr_url || ''} placeholder="https://" onChange={e => set(i, { qr_url: e.target.value || null })} /></Field>
)}
<Field label={t('display.qrCaption')}><Input value={w.qr_caption || ''} maxLength={80} onChange={e => set(i, { qr_caption: e.target.value || null })} /></Field>
<Field label={t('signage.widgets.size')} className="w-36">
<Dropdown value={custom ? 'custom' : (w.size || 'medium')} disabled={custom} onChange={size => set(i, { size })} data-testid="signage-widget-size"
options={[...['small', 'medium', 'large'].map(s => ({ value: s, label: t(`signage.widgets.sizes.${s}`) })),
...(custom ? [{ value: 'custom', label: t('signage.widgets.custom') }] : [])]} />
</Field>
<Field label={t('signage.widgets.align')}>
<Segmented value={w.align || 'auto'} onChange={align => set(i, { align })} aria-label={t('signage.widgets.align')} data-testid="signage-widget-align"
options={[
{ value: 'auto', label: t('signage.widgets.alignAuto'), testId: 'signage-widget-align-auto' },
{ value: 'left', icon: <AlignLeft size={16} aria-hidden="true" />, ariaLabel: t('signage.aligns.left'), testId: 'signage-widget-align-left' },
{ value: 'center', icon: <AlignCenter size={16} aria-hidden="true" />, ariaLabel: t('signage.aligns.center'), testId: 'signage-widget-align-center' },
{ value: 'right', icon: <AlignRight size={16} aria-hidden="true" />, ariaLabel: t('signage.aligns.right'), testId: 'signage-widget-align-right' },
]} />
</Field>
<KindFields w={w} set={patch => set(i, patch)} media={media} onMedia={onMedia} />
</div>
)}
{w.kind === 'weather' && (
<div className="grid gap-1">
<Select value={String(w.weather_days || 1)} onChange={e => set(i, { weather_days: Number(e.target.value) })} aria-label={t('signage.widgets.weatherDays')}
options={[1, 2, 3].map(n => ({ value: String(n), label: t('signage.widgets.days', { count: n }) }))} />
<p className="text-caption text-ink-3">{t('signage.widgets.weatherNeedsInternet')}</p>
</div>
)}
</div>
))}
{w.kind === 'weather' && <p className="text-caption text-ink-3">{t('signage.widgets.weatherNeedsInternet')}</p>}
</div>
)
})}
{widgets.length < 10 && (
<div className="flex flex-wrap gap-1.5">
{WIDGET_KINDS.map(k => (
<Button key={k} size="sm" variant="secondary" icon={<Plus size={14} />} onClick={() => add(k)} data-testid={`signage-widget-add-${k}`}>
{t(`signage.widgets.kinds.${k}`)}</Button>
))}
<div className="flex flex-wrap items-center gap-1.5">
{WIDGET_KINDS.map(k => {
const Icon = ICON[k]
return (
<Button key={k} size="sm" variant="secondary" icon={<Plus size={14} />} onClick={() => add(k)} data-testid={`signage-widget-add-${k}`}>
<span className="inline-flex items-center gap-1.5"><Icon size={14} aria-hidden="true" />{t(`signage.widgets.kinds.${k}`)}</span>
</Button>
)
})}
</div>
)}
</fieldset>
</Section>
)
}
/** The options only some widgets have, on the same row. */
function KindFields({ w, set, media, onMedia }) {
const { t } = useTranslation('manager')
if (w.kind === 'logo') {
return <MediaPick kind="image" value={w.media_id} entry={media[String(w.media_id)]} testid="signage-widget-logo"
onChange={item => { onMedia(item); set({ media_id: item.id }) }} />
}
if (w.kind === 'message') {
return (
<Field label={t('signage.widgets.ownText')} hint={t('signage.widgets.ownTextHint')} className="flex-1 min-w-[14rem]">
<Input value={w.text || ''} maxLength={200} onChange={e => set({ text: e.target.value || null })} data-testid="signage-widget-text" />
</Field>
)
}
if (w.kind === 'date') {
return (
<Field label={t('signage.widgets.dateStyle')} className="w-56">
<Dropdown value={w.date_style || 'long'} onChange={date_style => set({ date_style })}
options={[{ value: 'long', label: t('signage.widgets.dateLong') }, { value: 'short', label: t('signage.widgets.dateShort') }]} />
</Field>
)
}
if (w.kind === 'clock') {
return <Switch boxed className="w-44" checked={!!w.clock_seconds} onChange={on => set({ clock_seconds: on })} label={t('signage.widgets.seconds')} />
}
if (w.kind === 'qr') {
return (<>
<Field label={t('display.qrTarget')} className="w-48">
<Dropdown value={w.qr_target || 'ordering'} onChange={qr_target => set({ qr_target })}
options={['ordering', 'menu', 'custom'].map(q => ({ value: q, label: t(`display.qrTargets.${q}`) }))} />
</Field>
{w.qr_target === 'custom' && (
<Field label={t('display.qrUrl')} className="flex-1 min-w-[12rem]"><Input value={w.qr_url || ''} placeholder="https://" onChange={e => set({ qr_url: e.target.value || null })} /></Field>
)}
<Field label={t('display.qrCaption')} className="flex-1 min-w-[10rem]"><Input value={w.qr_caption || ''} maxLength={80} onChange={e => set({ qr_caption: e.target.value || null })} /></Field>
</>)
}
if (w.kind === 'weather') {
return (
<Field label={t('signage.widgets.weatherDays')} className="w-48">
<Dropdown value={String(w.weather_days || 1)} onChange={v => set({ weather_days: Number(v) })}
options={[1, 2, 3].map(n => ({ value: String(n), label: t('signage.widgets.days', { count: n }) }))} />
</Field>
)
}
return null
}