feat(manager): the signage editor: playlists, the timeline, slides with a live preview, templates (platform-v2 step 5.6a)
Management → Signage: playlists (name, landscape / portrait, default transition, duplicate, delete with the screens it plays on); the timeline (drag or arrows to reorder, duplicate, remove, on / off, time and when it shows at a glance, a round's total time); a slide's settings (name, seconds or a video to its end, transition, days / hours / dates, the picture or video, fit, text, alignment, font, colour, size, background colour or photo with darkening; a menu board's title, columns and colours) with a live preview drawn by @xenia/signage at 1920 × 1080 and scaled down; new slides empty or from templates (promotion, announcement, happy hour 17-19, welcome, menu board, video); a warning on the slide and its card when a picture or video doesn't fit the playlist's shape. Unit tests (4), e2e signage.mjs builds a playlist in the manager and the TV plays it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,7 @@ import TabsPage from './pages/financials/TabsPage'
|
||||
// Management
|
||||
import ProductsPage from './pages/Management/ProductsPage'
|
||||
import MediaPage from './pages/media/MediaPage'
|
||||
import SignagePage from './pages/signage/SignagePage'
|
||||
import TablesConfigPage from './pages/Management/TablesConfigPage'
|
||||
import StaffPage from './pages/Management/StaffPage'
|
||||
import SessionsPage from './pages/staff/SessionsPage'
|
||||
@@ -163,6 +164,7 @@ export default function App() {
|
||||
{/* ── Management (Headquarters) ── */}
|
||||
<Route path="management/products" element={<ProductsPage />} />
|
||||
<Route path="management/media" element={<MediaPage />} />
|
||||
<Route path="management/signage" element={<SignagePage />} />
|
||||
<Route path="management/tables" element={<TablesConfigPage />} />
|
||||
<Route path="management/staff" element={<StaffPage />} />
|
||||
<Route path="management/sessions" element={<SessionsPage />} />
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// A menu board's settings (plan steps 5.6a, 5.6b): its title, look and background. Which products
|
||||
// it lists and in what order: step 5.6b.
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Field, Input, Select } from '@xenia/ui'
|
||||
import { BackgroundField, ColourField } from './SignageFields'
|
||||
import { TextLook } from './SlideEditor'
|
||||
|
||||
export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [] }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const c = slide.content || {}
|
||||
const setC = patch => onChange({ ...slide, content: { ...c, ...patch } })
|
||||
return (
|
||||
<div className="grid gap-3" data-testid="signage-menu-editor">
|
||||
<Field label={t('signage.title')}><Input value={c.title || ''} maxLength={120} onChange={e => setC({ title: e.target.value })} data-testid="signage-menu-title" /></Field>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Field label={t('signage.columns')}>
|
||||
<Select value={String(c.columns || 2)} onChange={e => setC({ columns: Number(e.target.value) })}
|
||||
options={[1, 2, 3].map(n => ({ value: String(n), label: String(n) }))} data-testid="signage-columns" />
|
||||
</Field>
|
||||
<ColourField label={t('signage.accent')} value={c.accent_colour || '#f59e0b'} onChange={v => setC({ accent_colour: v })} testid="signage-accent" />
|
||||
</div>
|
||||
<TextLook c={c} setC={setC} align={false} />
|
||||
<BackgroundField value={c.background} onChange={background => setC({ background })} media={media} onMedia={onMedia}
|
||||
misfit={misfit.includes(c.background?.media_id)} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
// One playlist (plan step 5.6a): its name, orientation and default transition; the timeline of
|
||||
// slides (drag or arrows to reorder, duplicate, remove, on / off); a slide's settings with a live
|
||||
// preview at the playlist's shape; new slides blank or from a template; a warning on slides whose
|
||||
// picture or video doesn't fit the orientation.
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { AlertTriangle, ArrowDown, ArrowUp, Copy, Film, GripVertical, ImageIcon, LayoutList, Plus, Trash2, Type } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field, IconButton, Input, Select, Spinner } from '@xenia/ui'
|
||||
import * as api from './signageApi'
|
||||
import { mediaEntry, mediaLookup, misfits, moved, slideBody, slideFromTemplate, TEMPLATES, totalSeconds, TRANSITIONS, windowParts } from './signageLogic'
|
||||
import SlideEditor from './SlideEditor'
|
||||
import SlidePreview from './SlidePreview'
|
||||
|
||||
const KIND_ICON = { image: ImageIcon, video: Film, text: Type, menu: LayoutList }
|
||||
|
||||
export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [pl, setPl] = useState(null)
|
||||
const [media, setMedia] = useState({})
|
||||
const [venue, setVenue] = useState(null)
|
||||
const [selected, setSelected] = useState(null)
|
||||
const [draft, setDraft] = useState(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [adding, setAdding] = useState(false)
|
||||
const [confirmDelete, setConfirmDelete] = useState(false)
|
||||
const [dragFrom, setDragFrom] = useState(null)
|
||||
const [name, setName] = useState('')
|
||||
|
||||
const load = useCallback(async (select) => {
|
||||
try {
|
||||
const p = await api.getPlaylist(playlistId)
|
||||
setPl(p)
|
||||
setName(p.name)
|
||||
setMedia(m => ({ ...m, ...p.media }))
|
||||
const want = p.slides.find(s => s.id === select) || null
|
||||
if (select !== undefined) { setSelected(want?.id ?? null); setDraft(want ? structuredClone(want) : null) }
|
||||
return p
|
||||
} catch (err) { toast.error(errorMessage(err, t)); return null }
|
||||
}, [playlistId, t])
|
||||
useEffect(() => {
|
||||
load().then(p => { if (p?.slides?.length) { setSelected(p.slides[0].id); setDraft(structuredClone(p.slides[0])) } })
|
||||
api.previewVenue().then(setVenue).catch(() => {})
|
||||
}, [load])
|
||||
|
||||
const saved = pl?.slides.find(s => s.id === selected)
|
||||
const dirty = useMemo(() => !!(draft && saved && JSON.stringify(slideBody(draft)) !== JSON.stringify(slideBody(saved))), [draft, saved])
|
||||
// a menu board's draft: its products resolved by the server for the preview
|
||||
const menuKey = draft?.kind === 'menu' ? JSON.stringify(draft.content) : null
|
||||
useEffect(() => {
|
||||
if (!menuKey) return undefined
|
||||
const h = setTimeout(() => {
|
||||
api.previewMenu(JSON.parse(menuKey)).then(r => setDraft(d => (d && d.kind === 'menu' ? { ...d, menu: r.menu } : d))).catch(() => {})
|
||||
}, 400)
|
||||
return () => clearTimeout(h)
|
||||
}, [menuKey])
|
||||
|
||||
const bad = useMemo(() => misfits(pl?.slides, media, pl?.orientation), [pl, media])
|
||||
const draftBad = useMemo(() => (draft ? misfits([draft], media, pl?.orientation)[draft.id] || [] : []), [draft, media, pl])
|
||||
if (!pl) return <div className="flex justify-center p-8"><Spinner /></div>
|
||||
|
||||
const run = async (fn, done, select) => {
|
||||
setBusy(true)
|
||||
try { const r = await fn(); if (done) toast.success(done); await load(select === undefined ? selected : select); onChanged?.(); return r }
|
||||
catch (err) { toast.error(errorMessage(err, t)); return null }
|
||||
finally { setBusy(false) }
|
||||
}
|
||||
const pick = s => {
|
||||
if (dirty && !window.confirm(t('signage.discard'))) return
|
||||
setSelected(s.id)
|
||||
setDraft(structuredClone(s))
|
||||
}
|
||||
const reorder = (from, to) => {
|
||||
const ids = moved(pl.slides.map(s => s.id), from, to)
|
||||
setPl(p => ({ ...p, slides: ids.map(id => p.slides.find(s => s.id === id)) }))
|
||||
run(() => api.orderSlides(pl.id, ids))
|
||||
}
|
||||
const savePlaylist = patch => run(() => api.updatePlaylist(pl.id, patch), t('settings.saved'))
|
||||
const addFrom = async tpl => {
|
||||
setAdding(false)
|
||||
const made = await run(() => api.addSlide(pl.id, slideFromTemplate(tpl, t)), t('signage.added'))
|
||||
if (made) { await load(made.id) }
|
||||
}
|
||||
const total = totalSeconds(pl.slides, media)
|
||||
|
||||
return (
|
||||
<div className="grid gap-4" data-testid="signage-playlist" data-id={pl.id}>
|
||||
<header className="flex flex-wrap items-end gap-2">
|
||||
<Field label={t('signage.playlistName')} className="flex-1 min-w-[12rem]">
|
||||
<Input value={name} maxLength={80} onChange={e => setName(e.target.value)} data-testid="signage-playlist-name"
|
||||
onBlur={() => name.trim() && name.trim() !== pl.name && savePlaylist({ name: name.trim() })}
|
||||
onKeyDown={e => { if (e.key === 'Enter') e.currentTarget.blur() }} />
|
||||
</Field>
|
||||
<Field label={t('signage.orientation')}>
|
||||
<Select value={pl.orientation} onChange={e => savePlaylist({ orientation: e.target.value })} data-testid="signage-orientation"
|
||||
options={['landscape', 'portrait'].map(o => ({ value: o, label: t(`signage.orientations.${o}`) }))} />
|
||||
</Field>
|
||||
<Field label={t('signage.defaultTransition')}>
|
||||
<Select value={pl.transition} onChange={e => savePlaylist({ transition: e.target.value })}
|
||||
options={TRANSITIONS.map(x => ({ value: x, label: t(`signage.transitions.${x}`) }))} />
|
||||
</Field>
|
||||
<IconButton variant="secondary" label={t('signage.duplicatePlaylist')} disabled={busy}
|
||||
onClick={() => run(() => api.duplicatePlaylist(pl.id), t('signage.duplicated')).then(() => onChanged?.())}><Copy size={16} /></IconButton>
|
||||
<IconButton variant="ghost" label={t('fees.delete')} disabled={busy} onClick={() => setConfirmDelete(true)} data-testid="signage-playlist-delete"><Trash2 size={16} /></IconButton>
|
||||
</header>
|
||||
<p className="text-label text-ink-3">
|
||||
{t('signage.summary', { count: pl.slides.length, minutes: Math.floor(total / 60), seconds: String(total % 60).padStart(2, '0') })}
|
||||
{pl.screens.length > 0 && <> · {t('signage.playingOn', { names: pl.screens.map(s => s.name).join(', ') })}</>}
|
||||
</p>
|
||||
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(16rem,22rem)_1fr]">
|
||||
{/* the timeline */}
|
||||
<section className="grid gap-2 content-start" aria-label={t('signage.timeline')}>
|
||||
<ol className="grid gap-2" data-testid="signage-timeline">
|
||||
{pl.slides.map((s, i) => {
|
||||
const Icon = KIND_ICON[s.kind] || ImageIcon
|
||||
const parts = windowParts(s)
|
||||
return (
|
||||
<li key={s.id} draggable onDragStart={() => setDragFrom(i)} onDragOver={e => e.preventDefault()}
|
||||
onDrop={() => { if (dragFrom != null) reorder(dragFrom, i); setDragFrom(null) }}
|
||||
data-testid="signage-slide-card" data-id={s.id} data-kind={s.kind}
|
||||
className={`rounded-card border bg-surface flex gap-2 p-2 items-center cursor-pointer transition-colors duration-fast
|
||||
${s.id === selected ? 'border-accent ring-2 ring-accent' : 'border-line hover:border-line-strong'} ${s.enabled ? '' : 'opacity-60'}`}
|
||||
onClick={() => pick(s)}>
|
||||
<GripVertical size={16} className="text-ink-3 shrink-0 cursor-grab" aria-hidden="true" />
|
||||
<div className="w-24 shrink-0 pointer-events-none">
|
||||
<SlidePreview slide={s} media={mediaLookup(media)} venue={venue} orientation={pl.orientation} testid="signage-card-preview" />
|
||||
</div>
|
||||
<div className="grid gap-0.5 min-w-0 flex-1">
|
||||
<span className="text-label font-medium text-ink truncate flex items-center gap-1.5">
|
||||
<Icon size={14} className="text-ink-2 shrink-0" aria-hidden="true" />{s.name || t(`signage.kinds.${s.kind}`)}
|
||||
{bad[s.id] && <AlertTriangle size={14} className="text-warning-ink" aria-label={t('signage.misfit')} data-testid="signage-card-misfit" />}
|
||||
</span>
|
||||
<span className="text-caption text-ink-3">
|
||||
{s.kind === 'video' && s.video_to_end ? t('signage.toTheEnd') : t('signage.seconds', { count: s.duration_s })}
|
||||
{!s.enabled && <> · {t('signage.off')}</>}
|
||||
{parts.map(p => <span key={p.key}> · {p.key === 'days' ? p.params.days.map(d => t(`signage.weekdays.${d}`)).join(' ') : t(`signage.window.${p.key}`, p.params)}</span>)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col" onClick={e => e.stopPropagation()}>
|
||||
<IconButton size="sm" variant="ghost" label={t('display.earlier')} disabled={i === 0 || busy} onClick={() => reorder(i, i - 1)} data-testid="signage-up"><ArrowUp size={14} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('display.later')} disabled={i === pl.slides.length - 1 || busy} onClick={() => reorder(i, i + 1)} data-testid="signage-down"><ArrowDown size={14} /></IconButton>
|
||||
</div>
|
||||
<div className="flex flex-col" onClick={e => e.stopPropagation()}>
|
||||
<IconButton size="sm" variant="ghost" label={t('signage.duplicateSlide')} disabled={busy}
|
||||
onClick={() => run(() => api.duplicateSlide(s.id), t('signage.duplicated'))}><Copy size={14} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('fees.delete')} disabled={busy} data-testid="signage-slide-delete"
|
||||
onClick={() => window.confirm(t('signage.deleteSlide')) && run(() => api.deleteSlide(s.id), t('signage.removed'), s.id === selected ? null : selected)}><Trash2 size={14} /></IconButton>
|
||||
</div>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ol>
|
||||
<Button variant="secondary" icon={<Plus size={16} />} onClick={() => setAdding(true)} data-testid="signage-add-slide">{t('signage.addSlide')}</Button>
|
||||
</section>
|
||||
|
||||
{/* the slide being edited */}
|
||||
<section className="grid gap-4 content-start">
|
||||
{draft ? <>
|
||||
<SlidePreview slide={draft} media={mediaLookup(media)} venue={venue} orientation={pl.orientation} playing
|
||||
className={pl.orientation === 'portrait' ? 'max-w-xs mx-auto w-full' : 'w-full'} />
|
||||
<SlideEditor slide={draft} onChange={setDraft} media={media} onMedia={item => setMedia(m => ({ ...m, [String(item.id)]: mediaEntry(item) }))}
|
||||
misfit={draftBad} />
|
||||
<div className="flex gap-2 items-center sticky bottom-0 bg-canvas py-2">
|
||||
<Button loading={busy} disabled={!dirty} onClick={() => run(() => api.updateSlide(draft.id, slideBody(draft)), t('settings.saved'))}
|
||||
data-testid="signage-slide-save">{t('fees.save')}</Button>
|
||||
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setDraft(structuredClone(saved))}>{t('signage.undo')}</Button>
|
||||
{dirty && <span className="text-label text-ink-3">{t('display.looks.unsaved')}</span>}
|
||||
</div>
|
||||
</> : <p className="text-body text-ink-3 p-6 text-center">{t(pl.slides.length ? 'signage.pickSlide' : 'signage.noSlides')}</p>}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{adding && (
|
||||
<Dialog open size="lg" title={t('signage.addSlide')} onClose={() => setAdding(false)}
|
||||
footer={<Button variant="secondary" onClick={() => setAdding(false)}>{t('fees.cancel')}</Button>}>
|
||||
<div className="grid gap-4" data-testid="signage-add-dialog">
|
||||
<div className="grid gap-2">
|
||||
<span className="text-label font-medium text-ink-2">{t('signage.blank')}</span>
|
||||
<div className="grid gap-2 grid-cols-2 sm:grid-cols-4">
|
||||
{['image', 'video', 'text', 'menu'].map(k => {
|
||||
const Icon = KIND_ICON[k]
|
||||
return (
|
||||
<button key={k} type="button" onClick={() => addFrom({ key: k, kind: k, content: {} })} data-testid={`signage-new-${k}`}
|
||||
className="p-3 rounded-control border border-line bg-surface-2 hover:bg-surface-3 text-left grid gap-1">
|
||||
<Icon size={18} className="text-ink-2" aria-hidden="true" />
|
||||
<span className="text-label font-medium text-ink">{t(`signage.kinds.${k}`)}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<span className="text-label font-medium text-ink-2">{t('signage.templatesTitle')}</span>
|
||||
<div className="grid gap-3 grid-cols-2 sm:grid-cols-3">
|
||||
{TEMPLATES.map(tpl => {
|
||||
const sample = { id: 0, ...slideFromTemplate(tpl, t), enabled: true, menu: { groups: [] } }
|
||||
return (
|
||||
<button key={tpl.key} type="button" onClick={() => addFrom(tpl)} data-testid={`signage-template-${tpl.key}`}
|
||||
className="rounded-control border border-line bg-surface-2 hover:bg-surface-3 text-left overflow-hidden grid">
|
||||
<div className="pointer-events-none"><SlidePreview slide={sample} media={() => null} venue={venue} orientation={pl.orientation} testid="signage-template-preview" /></div>
|
||||
<span className="text-label font-medium text-ink px-2 py-1.5">{t(`signage.templates.${tpl.key}.name`)}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
)}
|
||||
|
||||
{confirmDelete && (
|
||||
<Dialog open size="sm" title={t('signage.deletePlaylistTitle', { name: pl.name })} onClose={() => setConfirmDelete(false)}
|
||||
footer={<>
|
||||
<Button variant="secondary" onClick={() => setConfirmDelete(false)}>{t('fees.cancel')}</Button>
|
||||
<Button variant="danger" loading={busy} data-testid="signage-playlist-delete-confirm"
|
||||
onClick={async () => { try { await api.deletePlaylist(pl.id); setConfirmDelete(false); onDeleted?.() } catch (err) { toast.error(errorMessage(err, t)) } }}>{t('fees.delete')}</Button>
|
||||
</>}>
|
||||
<p className="text-body text-ink-2">{t(pl.screens.length ? 'signage.deletePlaylistUsed' : 'signage.deletePlaylistBody', { names: pl.screens.map(s => s.name).join(', ') })}</p>
|
||||
</Dialog>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// Small editors the signage slide editor is built from (plan step 5.6a): a picture / video from the
|
||||
// library, a colour, a background (colour or photo with darkening).
|
||||
import { useState } from 'react'
|
||||
import { AlertTriangle, Film, ImageIcon, X } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, IconButton, Select } from '@xenia/ui'
|
||||
import MediaPicker from '../media/MediaPicker'
|
||||
|
||||
/** Pick a picture or a video from the library; `entry` is the media map's item for `value`. */
|
||||
export function MediaPick({ kind = 'image', value, entry, onChange, onRemove, misfit, label, testid }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [open, setOpen] = useState(false)
|
||||
return (
|
||||
<div className="grid gap-1.5" data-testid={testid}>
|
||||
{label && <span className="text-label font-medium text-ink-2">{label}</span>}
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-24 h-14 rounded-control border border-line bg-surface-3 overflow-hidden flex items-center justify-center shrink-0">
|
||||
{entry?.thumb ? <img src={entry.thumb} alt="" className="w-full h-full object-cover" />
|
||||
: kind === 'video' ? <Film size={20} className="text-ink-3" aria-hidden="true" /> : <ImageIcon size={20} className="text-ink-3" aria-hidden="true" />}
|
||||
</div>
|
||||
<div className="grid gap-1 min-w-0">
|
||||
{entry && <span className="text-label text-ink truncate" title={entry.name}>{entry.name}</span>}
|
||||
<div className="flex gap-2">
|
||||
<Button size="sm" variant="secondary" onClick={() => setOpen(true)} data-testid={`${testid}-pick`}>
|
||||
{t(value ? 'signage.change' : (kind === 'video' ? 'signage.pickVideo' : 'signage.pickPicture'))}</Button>
|
||||
{value && onRemove && <IconButton size="sm" variant="ghost" label={t('media.removePhoto')} onClick={onRemove}><X size={14} /></IconButton>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{misfit && (
|
||||
<p className="text-caption text-warning-ink flex items-center gap-1.5" data-testid={`${testid}-misfit`}>
|
||||
<AlertTriangle size={14} aria-hidden="true" />{t('signage.misfit')}
|
||||
</p>
|
||||
)}
|
||||
{open && <MediaPicker open kind={kind} selectedId={value} onClose={() => setOpen(false)}
|
||||
onPick={item => { onChange(item); setOpen(false) }} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** A colour the venue chooses for its TV (stored as #rrggbb: data, not a theme colour). */
|
||||
export function ColourField({ label, value, onChange, testid }) {
|
||||
return (
|
||||
<label className="grid gap-1.5 text-label font-medium text-ink-2">
|
||||
{label}
|
||||
<span className="flex items-center gap-2">
|
||||
<input type="color" value={value || '#000000'} onChange={e => onChange(e.target.value)} data-testid={testid}
|
||||
className="w-10 h-10 rounded-control border border-line bg-surface cursor-pointer p-0.5" />
|
||||
<span className="text-caption text-ink-3 font-mono">{value}</span>
|
||||
</span>
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
/** A slide's background: a colour, or a photo (built-in or the venue's) with a darkening slider. */
|
||||
export function BackgroundField({ value, onChange, media, onMedia, misfit, testid = 'signage-bg' }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const bg = value || { kind: 'colour', colour: '#111827', media_id: null, dim: 0, fit: 'cover' }
|
||||
const set = patch => onChange({ ...bg, ...patch })
|
||||
return (
|
||||
<fieldset className="grid gap-3 rounded-control border border-line p-3" data-testid={testid}>
|
||||
<legend className="px-1 text-label font-medium text-ink-2">{t('signage.background')}</legend>
|
||||
<Select value={bg.kind} onChange={e => set({ kind: e.target.value })} aria-label={t('signage.background')} data-testid={`${testid}-kind`}
|
||||
options={[{ value: 'colour', label: t('signage.bgColour') }, { value: 'media', label: t('signage.bgPhoto') }]} />
|
||||
{bg.kind === 'colour'
|
||||
? <ColourField label={t('signage.colour')} value={bg.colour} onChange={colour => set({ colour })} testid={`${testid}-colour`} />
|
||||
: <>
|
||||
<MediaPick kind="image" value={bg.media_id} entry={media?.[String(bg.media_id)]} misfit={misfit} testid={`${testid}-photo`}
|
||||
onChange={item => { onMedia(item); set({ media_id: item.id }) }} onRemove={() => set({ media_id: null })} />
|
||||
<label className="grid gap-1 text-label text-ink-2">
|
||||
{t('signage.dim', { value: bg.dim })}
|
||||
<input type="range" min={0} max={80} step={5} value={bg.dim} onChange={e => set({ dim: Number(e.target.value) })} data-testid={`${testid}-dim`} />
|
||||
</label>
|
||||
<Select value={bg.fit} onChange={e => set({ fit: e.target.value })} aria-label={t('signage.fit')}
|
||||
options={[{ value: 'cover', label: t('signage.fits.cover') }, { value: 'contain', label: t('signage.fits.contain') }]} />
|
||||
</>}
|
||||
</fieldset>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// Signage (plan steps 5.6a-c): the venue's playlists for its TVs. Pick one to edit its timeline
|
||||
// and slides; make a new one for a landscape or a portrait screen. Which screen plays what, the
|
||||
// schedules, the message of the day and the weather's place: the other tabs (5.6c).
|
||||
// Backend: /api/signage (routers/signage.py).
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { Monitor, Plus, Smartphone } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Field, Input, Select, Spinner } from '@xenia/ui'
|
||||
import * as api from './signageApi'
|
||||
import PlaylistEditor from './PlaylistEditor'
|
||||
|
||||
export default function SignagePage() {
|
||||
const { t } = useTranslation('manager')
|
||||
const [list, setList] = useState(null)
|
||||
const [current, setCurrent] = useState(null)
|
||||
const [creating, setCreating] = useState(false)
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try { const l = await api.listPlaylists(); setList(l); return l } catch (err) { toast.error(errorMessage(err, t)); return null }
|
||||
}, [t])
|
||||
useEffect(() => { load().then(l => { if (l?.length) setCurrent(c => c ?? l[0].id) }) }, [load])
|
||||
|
||||
return (
|
||||
<div className="p-4 md:p-6 grid gap-5 max-w-7xl" data-testid="signage-page">
|
||||
<header className="grid gap-1">
|
||||
<h1 className="text-heading font-semibold text-ink">{t('signage.pageTitle')}</h1>
|
||||
<p className="text-body text-ink-2 max-w-3xl">{t('signage.intro')}</p>
|
||||
</header>
|
||||
{!list ? <div className="flex justify-center p-6"><Spinner /></div> : (
|
||||
<div className="grid gap-5 xl:grid-cols-[14rem_1fr]">
|
||||
<nav className="grid gap-2 content-start" aria-label={t('signage.playlists')}>
|
||||
<span className="text-label font-medium text-ink-2">{t('signage.playlists')}</span>
|
||||
<ul className="grid gap-1.5" data-testid="signage-playlists">
|
||||
{list.map(p => {
|
||||
const Icon = p.orientation === 'portrait' ? Smartphone : Monitor
|
||||
return (
|
||||
<li key={p.id}>
|
||||
<button type="button" onClick={() => setCurrent(p.id)} aria-current={p.id === current ? 'true' : undefined}
|
||||
data-testid="signage-playlist-item" data-name={p.name}
|
||||
className={`w-full text-left px-3 py-2 rounded-control border flex items-center gap-2 transition-colors duration-fast
|
||||
${p.id === current ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface hover:bg-surface-2 text-ink'}`}>
|
||||
<Icon size={16} aria-label={t(`signage.orientations.${p.orientation}`)} />
|
||||
<span className="flex-1 min-w-0 truncate text-label font-medium">{p.name}</span>
|
||||
<span className="text-caption text-ink-3">{p.slide_count}</span>
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
<Button variant="secondary" icon={<Plus size={16} />} onClick={() => setCreating(true)} data-testid="signage-new-playlist">{t('signage.newPlaylist')}</Button>
|
||||
</nav>
|
||||
<main className="min-w-0">
|
||||
{current ? <PlaylistEditor key={current} playlistId={current} onChanged={load}
|
||||
onDeleted={() => load().then(l => setCurrent(l?.[0]?.id ?? null))} />
|
||||
: <EmptyState title={t('signage.noPlaylists')} description={t('signage.noPlaylistsHint')} />}
|
||||
</main>
|
||||
</div>
|
||||
)}
|
||||
{creating && <NewPlaylist onClose={() => setCreating(false)} onCreate={async body => {
|
||||
try { const p = await api.createPlaylist(body); setCreating(false); await load(); setCurrent(p.id) } catch (err) { toast.error(errorMessage(err, t)) }
|
||||
}} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function NewPlaylist({ onClose, onCreate }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [name, setName] = useState('')
|
||||
const [orientation, setOrientation] = useState('landscape')
|
||||
return (
|
||||
<Dialog open size="sm" title={t('signage.newPlaylist')} onClose={onClose}
|
||||
footer={<>
|
||||
<Button variant="secondary" onClick={onClose}>{t('fees.cancel')}</Button>
|
||||
<Button disabled={!name.trim()} onClick={() => onCreate({ name: name.trim(), orientation })} data-testid="signage-create-playlist">{t('display.looks.create')}</Button>
|
||||
</>}>
|
||||
<div className="grid gap-3">
|
||||
<Field label={t('signage.playlistName')}>
|
||||
<Input value={name} autoFocus maxLength={80} onChange={e => setName(e.target.value)} placeholder={t('signage.playlistPlaceholder')} data-testid="signage-new-name" />
|
||||
</Field>
|
||||
<Field label={t('signage.orientation')} hint={t('signage.orientationHint')}>
|
||||
<Select value={orientation} onChange={e => setOrientation(e.target.value)} data-testid="signage-new-orientation"
|
||||
options={['landscape', 'portrait'].map(o => ({ value: o, label: t(`signage.orientations.${o}`) }))} />
|
||||
</Field>
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// One slide's settings (plan step 5.6a): its name, time on screen, transition, on / off, when it
|
||||
// may show (days, hours, dates), and what it shows (picture, video, text, menu board's look).
|
||||
// The parent keeps the draft and saves it; the preview follows every change.
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Field, Input, Select, Switch, Textarea } from '@xenia/ui'
|
||||
import { FONT_KEYS, TRANSITIONS } from './signageLogic'
|
||||
import { BackgroundField, ColourField, MediaPick } from './SignageFields'
|
||||
import MenuEditor from './MenuEditor'
|
||||
|
||||
export default function SlideEditor({ slide, onChange, media, onMedia, misfit = [] }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const set = patch => onChange({ ...slide, ...patch })
|
||||
const c = slide.content || {}
|
||||
const setC = patch => set({ content: { ...c, ...patch } })
|
||||
const days = slide.days || []
|
||||
const toggleDay = d => set({ days: days.includes(d) ? days.filter(x => x !== d) : [...days, d].sort() })
|
||||
const bad = id => misfit.includes(id)
|
||||
|
||||
return (
|
||||
<div className="grid gap-5" data-testid="signage-slide-editor" data-kind={slide.kind}>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Field label={t('signage.slideName')} hint={t('signage.slideNameHint')}>
|
||||
<Input value={slide.name || ''} maxLength={80} onChange={e => set({ name: e.target.value })} data-testid="signage-slide-name" />
|
||||
</Field>
|
||||
<div className="flex items-end pb-1">
|
||||
<Switch checked={!!slide.enabled} onChange={on => set({ enabled: on })} label={t('signage.enabled')} data-testid="signage-slide-enabled" />
|
||||
</div>
|
||||
{slide.kind === 'video' && (
|
||||
<div className="sm:col-span-2">
|
||||
<Switch checked={!!slide.video_to_end} onChange={on => set({ video_to_end: on })} label={t('signage.videoToEnd')}
|
||||
description={t('signage.videoToEndHint')} data-testid="signage-video-to-end" />
|
||||
</div>
|
||||
)}
|
||||
{!(slide.kind === 'video' && slide.video_to_end) && (
|
||||
<Field label={t('signage.duration')} hint={slide.kind === 'menu' ? t('signage.durationMenuHint') : undefined}>
|
||||
<Input inputMode="numeric" value={String(slide.duration_s ?? 10)} data-testid="signage-duration"
|
||||
onChange={e => set({ duration_s: Math.min(3600, Number(e.target.value.replace(/\D/g, '')) || 0) })} />
|
||||
</Field>
|
||||
)}
|
||||
<Field label={t('signage.transition')}>
|
||||
<Select value={slide.transition || ''} onChange={e => set({ transition: e.target.value || null })} data-testid="signage-transition"
|
||||
options={[{ value: '', label: t('signage.transitionDefault') }, ...TRANSITIONS.map(x => ({ value: x, label: t(`signage.transitions.${x}`) }))]} />
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<fieldset className="grid gap-3 rounded-control border border-line p-3">
|
||||
<legend className="px-1 text-label font-medium text-ink-2">{t('signage.when')}</legend>
|
||||
<p className="text-caption text-ink-3">{t('signage.whenHint')}</p>
|
||||
<div className="flex flex-wrap gap-1.5" role="group" aria-label={t('signage.days')}>
|
||||
{[0, 1, 2, 3, 4, 5, 6].map(d => (
|
||||
<button key={d} type="button" aria-pressed={days.includes(d)} onClick={() => toggleDay(d)} data-testid={`signage-day-${d}`}
|
||||
className={`px-2.5 py-1 rounded-control border text-label transition-colors duration-fast
|
||||
${days.includes(d) ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface-2 text-ink hover:bg-surface-3'}`}>
|
||||
{t(`signage.weekdays.${d}`)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid gap-3 grid-cols-2">
|
||||
<Field label={t('signage.timeFrom')}><Input type="time" value={slide.time_from || ''} onChange={e => set({ time_from: e.target.value || null })} data-testid="signage-time-from" /></Field>
|
||||
<Field label={t('signage.timeTo')}><Input type="time" value={slide.time_to || ''} onChange={e => set({ time_to: e.target.value || null })} data-testid="signage-time-to" /></Field>
|
||||
<Field label={t('signage.dateFrom')}><Input type="date" value={slide.date_from || ''} onChange={e => set({ date_from: e.target.value || null })} data-testid="signage-date-from" /></Field>
|
||||
<Field label={t('signage.dateTo')}><Input type="date" value={slide.date_to || ''} onChange={e => set({ date_to: e.target.value || null })} data-testid="signage-date-to" /></Field>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
{slide.kind === 'image' && (
|
||||
<div className="grid gap-3">
|
||||
<MediaPick kind="image" label={t('signage.picture')} value={c.media_id} entry={media[String(c.media_id)]} misfit={bad(c.media_id)}
|
||||
onChange={item => { onMedia(item); setC({ media_id: item.id }) }} testid="signage-picture" />
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Field label={t('signage.fit')}>
|
||||
<Select value={c.fit || 'cover'} onChange={e => setC({ fit: e.target.value })}
|
||||
options={[{ value: 'cover', label: t('signage.fits.cover') }, { value: 'contain', label: t('signage.fits.contain') }]} />
|
||||
</Field>
|
||||
<ColourField label={t('signage.around')} value={c.background_colour || '#000000'} onChange={v => setC({ background_colour: v })} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{slide.kind === 'video' && (
|
||||
<div className="grid gap-3">
|
||||
<MediaPick kind="video" label={t('signage.video')} value={c.media_id} entry={media[String(c.media_id)]} misfit={bad(c.media_id)}
|
||||
onChange={item => { onMedia(item); setC({ media_id: item.id }) }} testid="signage-video" />
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<Field label={t('signage.fit')}>
|
||||
<Select value={c.fit || 'cover'} onChange={e => setC({ fit: e.target.value })}
|
||||
options={[{ value: 'cover', label: t('signage.fits.cover') }, { value: 'contain', label: t('signage.fits.contain') }]} />
|
||||
</Field>
|
||||
<div className="flex items-end pb-1"><Switch checked={c.muted !== false} onChange={on => setC({ muted: on })} label={t('signage.muted')} /></div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{slide.kind === 'text' && (
|
||||
<div className="grid gap-3">
|
||||
<Field label={t('signage.title')}><Input value={c.title || ''} maxLength={120} onChange={e => setC({ title: e.target.value })} data-testid="signage-text-title" /></Field>
|
||||
<Field label={t('signage.body')}><Textarea rows={3} value={c.body || ''} maxLength={1000} onChange={e => setC({ body: e.target.value })} data-testid="signage-text-body" /></Field>
|
||||
<TextLook c={c} setC={setC} />
|
||||
<BackgroundField value={c.background} onChange={background => setC({ background })} media={media} onMedia={onMedia}
|
||||
misfit={bad(c.background?.media_id)} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{slide.kind === 'menu' && <MenuEditor slide={slide} onChange={onChange} media={media} onMedia={onMedia} misfit={misfit} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Alignment, font, colour and size of a text slide. */
|
||||
export function TextLook({ c, setC, align = true }) {
|
||||
const { t } = useTranslation('manager')
|
||||
return (
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
{align && <>
|
||||
<Field label={t('signage.align')}>
|
||||
<Select value={c.align || 'center'} onChange={e => setC({ align: e.target.value })}
|
||||
options={['left', 'center', 'right'].map(x => ({ value: x, label: t(`signage.aligns.${x}`) }))} />
|
||||
</Field>
|
||||
<Field label={t('signage.vertical')}>
|
||||
<Select value={c.vertical || 'middle'} onChange={e => setC({ vertical: e.target.value })}
|
||||
options={['top', 'middle', 'bottom'].map(x => ({ value: x, label: t(`signage.verticals.${x}`) }))} />
|
||||
</Field>
|
||||
</>}
|
||||
<Field label={t('signage.font')}>
|
||||
<Select value={c.font || 'sans'} onChange={e => setC({ font: e.target.value })} data-testid="signage-font"
|
||||
options={FONT_KEYS.map(x => ({ value: x, label: t(`signage.fonts.${x}`) }))} />
|
||||
</Field>
|
||||
<ColourField label={t('signage.textColour')} value={c.text_colour || '#ffffff'} onChange={v => setC({ text_colour: v })} testid="signage-text-colour" />
|
||||
<label className="grid gap-1 text-label font-medium text-ink-2 sm:col-span-2">
|
||||
{t('signage.textSize', { value: c.text_size || 100 })}
|
||||
<input type="range" min={50} max={250} step={10} value={c.text_size || 100} onChange={e => setC({ text_size: Number(e.target.value) })} data-testid="signage-text-size" />
|
||||
</label>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// A slide drawn exactly as the TV draws it (@xenia/signage), in a box of the playlist's shape
|
||||
// (plan step 5.6a). The slide is laid out on a full-size 1920 × 1080 (or 1080 × 1920) frame and
|
||||
// scaled down to the box, so text, rows and menu pages match a real TV, not a small window.
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { boardPages, SlideView } from '@xenia/signage'
|
||||
|
||||
const LONG = 1920
|
||||
const SHORT = 1080
|
||||
|
||||
export default function SlidePreview({ slide, media, venue, orientation = 'landscape', page = 0, playing = false, className = '', testid = 'signage-preview' }) {
|
||||
const [now, setNow] = useState(() => new Date())
|
||||
const box = useRef(null)
|
||||
const [scale, setScale] = useState(0)
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setNow(new Date()), 1000)
|
||||
return () => clearInterval(id)
|
||||
}, [])
|
||||
const tall = orientation === 'portrait'
|
||||
const w = tall ? SHORT : LONG
|
||||
const h = tall ? LONG : SHORT
|
||||
useEffect(() => {
|
||||
const el = box.current
|
||||
if (!el) return undefined
|
||||
const measure = () => setScale(el.clientWidth / w)
|
||||
measure()
|
||||
const ro = new ResizeObserver(measure)
|
||||
ro.observe(el)
|
||||
return () => ro.disconnect()
|
||||
}, [w])
|
||||
const pages = slide?.kind === 'menu' ? boardPages(slide, 0, w, h) : null
|
||||
return (
|
||||
<div ref={box} className={`relative overflow-hidden rounded-control bg-black ${className}`} data-testid={testid} data-orientation={orientation}
|
||||
style={{ aspectRatio: tall ? '9 / 16' : '16 / 9' }}>
|
||||
{slide && scale > 0 && (
|
||||
<div style={{ position: 'absolute', top: 0, left: 0, width: w, height: h, transform: `scale(${scale})`, transformOrigin: 'top left', containerType: 'size' }}>
|
||||
<SlideView slide={slide} media={media} venue={venue} now={now} pages={pages} page={Math.min(page, (pages?.length || 1) - 1)} playing={playing} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// The signage editor's API (backend: local_backend/routers/signage.py, plan steps 5.4a-5.6c).
|
||||
import client from '../../api/client'
|
||||
|
||||
const data = r => r.data
|
||||
|
||||
export const listPlaylists = () => client.get('/api/signage/playlists').then(data)
|
||||
export const getPlaylist = id => client.get(`/api/signage/playlists/${id}`).then(data)
|
||||
export const createPlaylist = body => client.post('/api/signage/playlists', body).then(data)
|
||||
export const updatePlaylist = (id, body) => client.put(`/api/signage/playlists/${id}`, body).then(data)
|
||||
export const deletePlaylist = id => client.delete(`/api/signage/playlists/${id}`)
|
||||
export const duplicatePlaylist = id => client.post(`/api/signage/playlists/${id}/duplicate`).then(data)
|
||||
export const orderSlides = (id, slideIds) => client.put(`/api/signage/playlists/${id}/order`, { slide_ids: slideIds }).then(data)
|
||||
|
||||
export const addSlide = (playlistId, body) => client.post(`/api/signage/playlists/${playlistId}/slides`, body).then(data)
|
||||
export const updateSlide = (id, body) => client.put(`/api/signage/slides/${id}`, body).then(data)
|
||||
export const deleteSlide = id => client.delete(`/api/signage/slides/${id}`)
|
||||
export const duplicateSlide = id => client.post(`/api/signage/slides/${id}/duplicate`).then(data)
|
||||
|
||||
export const previewVenue = () => client.get('/api/signage/venue').then(data)
|
||||
export const previewMenu = content => client.post('/api/signage/preview/menu', { content }).then(data)
|
||||
@@ -0,0 +1,117 @@
|
||||
// The signage editor's pure helpers (plan step 5.6a): unit-tested in tests/signage.test.mjs.
|
||||
|
||||
export const KINDS = ['image', 'video', 'text', 'menu']
|
||||
export const TRANSITIONS = ['fade', 'slide', 'zoom', 'none']
|
||||
export const FONT_KEYS = ['sans', 'serif', 'rounded', 'condensed', 'display']
|
||||
|
||||
/** Ready-made slides to start from: { key, kind, slide fields, content }. '@x' texts are filled from
|
||||
* `signage.templates.<key>.<x>` in the manager's language when the slide is made. */
|
||||
export const TEMPLATES = [
|
||||
{ key: 'promo', kind: 'image', duration_s: 8, content: { fit: 'cover' } },
|
||||
{ key: 'announcement', kind: 'text', duration_s: 10, content: {
|
||||
title: '', body: '', align: 'center', vertical: 'middle', font: 'sans', text_colour: '#ffffff', text_size: 100,
|
||||
background: { kind: 'colour', colour: '#1e293b', media_id: null, dim: 0, fit: 'cover' },
|
||||
widgets: [{ kind: 'name', position: 'top-left' }, { kind: 'clock', position: 'top-right' }],
|
||||
} },
|
||||
{ key: 'happyHour', kind: 'text', duration_s: 10, time_from: '17:00', time_to: '19:00', content: {
|
||||
title: '@title', body: '@body', align: 'center', vertical: 'middle', font: 'display', text_colour: '#fde68a', text_size: 120,
|
||||
background: { kind: 'colour', colour: '#7c2d12', media_id: null, dim: 0, fit: 'cover' },
|
||||
} },
|
||||
{ key: 'welcome', kind: 'text', duration_s: 10, content: {
|
||||
title: '@title', body: '', align: 'center', vertical: 'middle', font: 'serif', text_colour: '#ffffff', text_size: 110,
|
||||
background: { kind: 'colour', colour: '#14532d', media_id: null, dim: 0, fit: 'cover' },
|
||||
widgets: [{ kind: 'logo', position: 'top-center', size: 'large' }, { kind: 'message', position: 'bottom-bar' }, { kind: 'date', position: 'bottom-bar' }],
|
||||
} },
|
||||
{ key: 'menuBoard', kind: 'menu', duration_s: 20, content: {
|
||||
title: '@title', select: 'all', group_by_category: true, columns: 2, sales_point: 'in_store', sold_out: 'strike',
|
||||
background: { kind: 'colour', colour: '#111827', media_id: null, dim: 0, fit: 'cover' }, accent_colour: '#f59e0b',
|
||||
widgets: [{ kind: 'clock', position: 'top-right' }, { kind: 'message', position: 'bottom-bar' }],
|
||||
} },
|
||||
{ key: 'video', kind: 'video', video_to_end: true, content: { fit: 'cover', muted: true } },
|
||||
]
|
||||
|
||||
/** The body to create a slide from a template; `t` fills its '@' texts. */
|
||||
export function slideFromTemplate(tpl, t = k => k) {
|
||||
const { key, kind, content, ...fields } = tpl
|
||||
const filled = JSON.parse(JSON.stringify(content || {}), (_, v) =>
|
||||
(typeof v === 'string' && v.startsWith('@') ? t(`signage.templates.${key}.${v.slice(1)}`) : v))
|
||||
return { kind, ...fields, content: filled }
|
||||
}
|
||||
|
||||
/** Does a picture / video fit a playlist's orientation? null when its size isn't known. */
|
||||
export function fitsOrientation(media, orientation) {
|
||||
if (!media?.width || !media?.height) return null
|
||||
const wide = media.width >= media.height
|
||||
return orientation === 'portrait' ? !wide || media.width === media.height : wide
|
||||
}
|
||||
|
||||
/** The media ids a slide shows big (its picture / video and its background): what must fit the shape. */
|
||||
export function bigMedia(slide) {
|
||||
const c = slide?.content || {}
|
||||
return [c.media_id, c.background?.kind === 'media' ? c.background.media_id : null].filter(Boolean)
|
||||
}
|
||||
|
||||
/** The slides whose big media doesn't fit the playlist's orientation: { slideId: [mediaId] }. */
|
||||
export function misfits(slides, media, orientation) {
|
||||
const out = {}
|
||||
for (const s of slides || []) {
|
||||
const bad = bigMedia(s).filter(id => fitsOrientation(media?.[String(id)], orientation) === false)
|
||||
if (bad.length) out[s.id] = bad
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** A short line about when a slide shows: [{ key, params }] for the timeline card ([] = always). */
|
||||
export function windowParts(slide) {
|
||||
const parts = []
|
||||
if (slide.days?.length && slide.days.length < 7) parts.push({ key: 'days', params: { days: slide.days } })
|
||||
if (slide.time_from || slide.time_to) parts.push({ key: 'hours', params: { from: slide.time_from || '00:00', to: slide.time_to || '24:00' } })
|
||||
if (slide.date_from || slide.date_to) parts.push({ key: 'dates', params: { from: slide.date_from || '…', to: slide.date_to || '…' } })
|
||||
return parts
|
||||
}
|
||||
|
||||
/** The playlist's total time for one round (videos to their end count by their length if known). */
|
||||
export function totalSeconds(slides, media) {
|
||||
let total = 0
|
||||
for (const s of slides || []) {
|
||||
if (!s.enabled) continue
|
||||
if (s.kind === 'video' && s.video_to_end) {
|
||||
const ms = media?.[String(s.content?.media_id)]?.duration_ms
|
||||
total += ms ? Math.round(ms / 1000) : s.duration_s || 10
|
||||
} else total += s.duration_s || 10
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
/** Move the item at `from` to `to` in a copy of `list`. */
|
||||
export function moved(list, from, to) {
|
||||
const out = [...list]
|
||||
if (from === to || from < 0 || to < 0 || from >= out.length || to >= out.length) return out
|
||||
const [x] = out.splice(from, 1)
|
||||
out.splice(to, 0, x)
|
||||
return out
|
||||
}
|
||||
|
||||
/** The fields of a slide that the editor sends back (PUT /api/signage/slides/{id}). */
|
||||
export function slideBody(s) {
|
||||
return {
|
||||
name: s.name || null, duration_s: s.duration_s, transition: s.transition || null, video_to_end: !!s.video_to_end, enabled: !!s.enabled,
|
||||
days: s.days || [], time_from: s.time_from || null, time_to: s.time_to || null, date_from: s.date_from || null, date_to: s.date_to || null,
|
||||
content: s.content || {},
|
||||
}
|
||||
}
|
||||
|
||||
/** A library item as the slide views need it (the same shape as the playlist's media map). */
|
||||
export function mediaEntry(item) {
|
||||
const u = item.urls || {}
|
||||
return { id: item.id, kind: item.kind, name: item.name, width: item.width, height: item.height, duration_ms: item.duration_ms,
|
||||
url: u.full || u.original, thumb: u.thumb, builtin: !!item.builtin }
|
||||
}
|
||||
|
||||
/** media(id) for the slide views: the playlist's media map (+ what the editor just picked). */
|
||||
export function mediaLookup(map) {
|
||||
return id => {
|
||||
const m = map?.[String(id)]
|
||||
return m ? { ...m, src: m.url } : null
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
BookUser, Users, Receipt, CreditCard,
|
||||
Package, TableProperties, UserCog, CalendarDays, Trash2, Boxes,
|
||||
BarChart2, TrendingUp, Users2, ShoppingCart, Tag, Activity, Printer, ConciergeBell, FileText,
|
||||
AppWindow, Settings, CookingPot, Truck, StickyNote, Percent, Plug, BadgeCheck, MonitorSmartphone, LogIn, ShieldCheck, QrCode, Images,
|
||||
AppWindow, Settings, CookingPot, Truck, StickyNote, Percent, Plug, BadgeCheck, MonitorSmartphone, LogIn, ShieldCheck, QrCode, Images, Tv,
|
||||
} from 'lucide-react'
|
||||
|
||||
const DASH = 'core.dashboard.access'
|
||||
@@ -62,6 +62,7 @@ export const NAV = [
|
||||
children: [
|
||||
{ to: '/management/products', icon: Package, label: 'nav.products', module: 'catalog', perm: 'catalog.menu.manage' },
|
||||
{ to: '/management/media', icon: Images, label: 'nav.media', module: 'core', anyPerm: MEDIA },
|
||||
{ to: '/management/signage', icon: Tv, label: 'nav.signage', module: 'signage', perm: 'signage.manage' },
|
||||
{ to: '/management/tables', icon: TableProperties, label: 'nav.tablesConfig', module: 'catalog', perm: 'catalog.tables.manage' },
|
||||
{ to: '/management/staff', icon: UserCog, label: 'nav.staff', module: 'core', perm: 'core.staff.manage' },
|
||||
{ to: '/management/sessions', icon: LogIn, label: 'nav.sessions', module: 'core', perm: 'core.staff.manage' },
|
||||
|
||||
Reference in New Issue
Block a user