diff --git a/docs/README.md b/docs/README.md index f58e3c7..263160c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -48,7 +48,7 @@ The manager calls the API **same-origin, with relative paths**. The waiter app r | `local_backend/routers/fees.py` | The venue's online ordering settings (`connect_orders.ordering`: services, hours, slots, ASAP; `reservations`: bookings, food ahead, fire minutes), delivery areas and fee rules, the fee line's name/VAT, and the venue's links (`links.order`, `links.menu` from the cloud's `apps_url`). Everything here travels to the cloud in the menu snapshot (contract C-2) | | `local_backend/routers/customer_display.py`, `models/display_look.py`, `terminal/src/apps/customer-display/` | The customer display (3.4, 5.3): the counter POS pushes `POST /api/display/state` (`useDisplay()` in `apps/pos/usePos.js`: the sale cart, the payment dialog's bill, then "paid"); only displays whose `linked_device_id` is that POS get `display.state`. The idle screen is a **look** (`display_looks`: name, `is_default`, config = style, message, theme, QR, pictures as media library ids; looks register their media usage). One look is the venue's default; a display shows the look in its device config `look` (a `ref` to `display_looks`, also set from Settings → Customer display through `PUT /api/display/displays/{id}/look`) or the default. A look's change sends `display.settings` only to the displays showing it. Pictures are served from the library (`full` for image / slides, `card` for the logo). The POS's last state lives in memory | | `local_backend/routers/media.py`, `services/media.py`, `models/media.py`; manager `src/pages/media/` | The media library (5.1, 5.2): every picture and video once, by sha256, under `/app/data/media///` (the untouched original + `thumb` 200 / `card` 600 / `full` 1920 WebP for pictures, AVIF accepted; videos kept as uploaded). Served public by hash at `/api/media/file//` with year-long `immutable` caching (a different file is a different URL; byte ranges for video). The display name is only for people; files on disk are named by the backend. Whoever manages the menu, customer display, signage or menu tablets manages it. **What points at media has a `media_id` column and registers `register_usage(kind, fn)`** (products and categories in `routers/products.py`) so delete is refused (`media.in_use`) while it's used. APIs give `image` = `{id, name, thumb, card, full}` (`services.media.image_of`); a product's `image_url` is its card size. Manager: the Media page (batch upload, details) and `MediaField` (upload on the spot / pick from the library / "Name it after" with `latin()` from `@xenia/i18n`) for any form that takes a picture. The waiter fetches the menu's photos ahead (`services/photoCache.js`; PWA: workbox `xenia-media` cache-first) so they show offline. Upload limits: 20 MB pictures, 200 MB videos; every nginx config sets `client_max_body_size 250m` | -| `local_backend/routers/signage.py`, `models/signage.py`, `assets/builtin_media/` | Digital signage (5.4a): **playlists** (name, orientation, default transition) of **slides** (kind menu / image / video / text, position, duration, transition, video to its end, on / off, days / hours / dates window, `content` typed per kind in the router: extra fields refused, pictures and videos as media ids, walked by `media_ids()` for the library's usage check). A screen's device config: `playlist` (ref `signage_playlists`), `orientation`, `rotation`; `GET /api/signage/screen` gives it the playlist resolved (enabled slides, media addresses, a `version` hash); changes send `signage.changed` only to the screens playing that playlist. **Built-in pictures:** files in `assets/builtin_media/` are imported at start (`services.media.import_builtin`, `media.builtin`), listed as their own collection, never deleted or renamed. **Menu boards (5.4b):** `services/signage_menu.py` resolves a menu slide (all / whole categories incl. sub-categories, live / single products, minus exclusions; the board's own `category_order` / `product_order`; prices from `pos_cart.unit_prices` of its sales point; customer-facing names); every request that changes the menu (`cloud_sync.menu_changed` paths) also sends `signage.changed` to the screens with a menu board (`main._signage_menu_changed`). **Widgets (5.4c):** `Widget` on text and menu slides (logo, name, date, clock, message, QR, weather; position, size); the screen also gets `venue` = name, the message of the day (`signage.message`, `PUT /api/signage/message` tells every screen) and the weather (`services/weather.py`: Open-Meteo, no key, every 30 min by the signage worker, kept in memory; `null` when there is no place, no internet or it is older than 3 h, so the player hides the widget). **Schedules (5.4d):** `signage_schedules` (entries {playlist, days, hours that may pass midnight, dates, priority} + a fallback); a screen's `schedule` (ref) wins over its `playlist`; `services/signage_schedule.pick` chooses in venue time (highest priority, then dates > days > hours, then the later entry); `/screen` then carries the schedule (with the venue's time zone) and every playlist in it so the player switches offline; `schedule_worker` (30 s) tells a screen when its pick changes. **The player (5.5a):** `terminal/src/apps/signage/` (`logic.js`: the schedule pick ported from Python with the same test cases, slide windows, next slide, frame rotation; `SignageApp.jsx`: the last `/screen` answer in localStorage, every picture / video (≤ 120 MB) as an in-memory blob copy, so it plays with the server down; reads again on `signage.changed`, `device.updated`, a reconnect and every 5 min). Signage is in `QUIET_OFFLINE` (`apps/registry.js`): no offline banner, a small mark. The terminal is plain HTTP (no service worker), so a TV that restarts while the server is down waits for it. Menu boards page by themselves (`boardPages`: rows that fit from the frame's shape, text size, photos / descriptions, title and widget bars; `page_size` overrides) and go round while the slide lasts (at least its pages × `page_seconds`); widgets in `Slides.jsx` (`Widgets`), a widget with nothing to show (no weather, no message) is left out | +| `local_backend/routers/signage.py`, `models/signage.py`, `assets/builtin_media/` | Digital signage (5.4a): **playlists** (name, orientation, default transition) of **slides** (kind menu / image / video / text, position, duration, transition, video to its end, on / off, days / hours / dates window, `content` typed per kind in the router: extra fields refused, pictures and videos as media ids, walked by `media_ids()` for the library's usage check). A screen's device config: `playlist` (ref `signage_playlists`), `orientation`, `rotation`; `GET /api/signage/screen` gives it the playlist resolved (enabled slides, media addresses, a `version` hash); changes send `signage.changed` only to the screens playing that playlist. **Built-in pictures:** files in `assets/builtin_media/` are imported at start (`services.media.import_builtin`, `media.builtin`), listed as their own collection, never deleted or renamed. **Menu boards (5.4b):** `services/signage_menu.py` resolves a menu slide (all / whole categories incl. sub-categories, live / single products, minus exclusions; the board's own `category_order` / `product_order`; prices from `pos_cart.unit_prices` of its sales point; customer-facing names); every request that changes the menu (`cloud_sync.menu_changed` paths) also sends `signage.changed` to the screens with a menu board (`main._signage_menu_changed`). **The editor (5.6a):** manager `src/pages/signage/` (Management → Signage): playlists, the timeline (drag / arrows, duplicate, remove), a slide's settings with a live preview (`SlidePreview`), templates (`signageLogic.TEMPLATES`), the orientation warning; `GET /api/signage/venue` and `POST /api/signage/preview/menu` feed the previews. **Widgets (5.4c):** `Widget` on text and menu slides (logo, name, date, clock, message, QR, weather; position, size); the screen also gets `venue` = name, the message of the day (`signage.message`, `PUT /api/signage/message` tells every screen) and the weather (`services/weather.py`: Open-Meteo, no key, every 30 min by the signage worker, kept in memory; `null` when there is no place, no internet or it is older than 3 h, so the player hides the widget). **Schedules (5.4d):** `signage_schedules` (entries {playlist, days, hours that may pass midnight, dates, priority} + a fallback); a screen's `schedule` (ref) wins over its `playlist`; `services/signage_schedule.pick` chooses in venue time (highest priority, then dates > days > hours, then the later entry); `/screen` then carries the schedule (with the venue's time zone) and every playlist in it so the player switches offline; `schedule_worker` (30 s) tells a screen when its pick changes. **The player (5.5a):** `terminal/src/apps/signage/` (the logic and slides moved to `packages/signage` in 5.6a; the schedule pick ported from Python with the same test cases, slide windows, next slide, frame rotation; `SignageApp.jsx`: the last `/screen` answer in localStorage, every picture / video (≤ 120 MB) as an in-memory blob copy, so it plays with the server down; reads again on `signage.changed`, `device.updated`, a reconnect and every 5 min). Signage is in `QUIET_OFFLINE` (`apps/registry.js`): no offline banner, a small mark. The terminal is plain HTTP (no service worker), so a TV that restarts while the server is down waits for it. Menu boards page by themselves (`boardPages`: rows that fit from the frame's shape, text size, photos / descriptions, title and widget bars; `page_size` overrides) and go round while the slide lasts (at least its pages × `page_seconds`); widgets in `Slides.jsx` (`Widgets`), a widget with nothing to show (no weather, no message) is left out | | `local_backend/routers/phone.py`, `services/caller_id.py` | Caller ID (3.5): the UCM's `GET /api/phone/call-event` is public but **LAN-only in the proxy** (the same `location ~ ^/api/(devices/pair-request|phone/call-event)` block in `nginx-proxy/nginx.conf` and `install.sh`) with an optional `caller_id.secret`; calls are logged (`phone_calls`), matched on the server (Greek number rules) and published as `call_incoming` to users with `caller_id.use` and to the counter screens. There is no public call socket any more | | `local_backend/routers/ws.py` | Real-time event stream (seq + cursor replay) | | `waiter_pwa/src/config/server.js` | **Where the backend is**: active venue, `apiBase()`, `wsUrl()`, `assetUrl()`, `storageKey()`, `dbName()`, `deliveryMode()` | @@ -66,6 +66,7 @@ The manager calls the API **same-origin, with relative paths**. The waiter app r | `terminal/` | The terminal app (phase 3): `src/device/DeviceProvider.jsx` (the device's `/me`, who is signed in, the live connection with credentials in the first frame, offline; apps listen with `useLiveEvent`), `src/device/flow.js` (which screen shows when: pairing → sign-in → app / blocked; pure, unit-tested), `src/screens/` (pairing, sign-in per mode, blocked, app + bar), `src/apps/registry.js` (which apps a screen runs, lazy chunks), `src/device/storage.js` (device + session tokens), `src/api/client.js` (`X-Xenia-Device` on every request; 401 / unreachable listeners). The screen follows the device, not the URL. Lint covers all of `src` | | `packages/ui/` | Shared design tokens, Tailwind preset and base components (CS-16). Visual check: `npm run dev:manager` → `/ui-gallery` | | `packages/api/` | Shared HTTP client (`createApiClient`: session/device headers, `err.xenia` codes, the manager-approval retry) and the live WebSocket client with cursor replay (`createLiveClient`, used by the waiter's `useWebSocket`) (CS-18) | +| `packages/signage/` | `@xenia/signage` (5.6a): signage slides as the TVs draw them (`SlideView`, `TextSlide`, `MenuSlide`, `Widgets`) and the player's pure logic (schedule pick, slide windows, menu pages; tests in `tests/`), shared by the terminal's player and the manager's previews. Sizes are container units (`cqmin`): a slide needs a parent with `container-type: size` (`frameStyle()`; the manager's `SlidePreview` lays it out at 1920 × 1080 and scales it down, so previews match a TV). Both apps' Tailwind `content` include it | | `packages/access/` | `` (bootstrap → modules, permission keys, venue, language; mounts the approval dialog), `useCan`, `useModule`, ``, `` (CS-18) | | `packages/i18n/` | Translations (`locales//.json`), language resolution, venue-time / money / number formatting, the comma-or-dot number parser, and the guard `scripts/check-i18n.mjs` (CS-17). Sample: `/i18n-sample` (dev) | | `.dockerignore` | The frontend images build with **`client-services/` as context** (`-f waiter_pwa/Dockerfile .`), so this file decides what Docker sees. The backend still builds from `local_backend/`. | diff --git a/manager_dashboard/src/App.jsx b/manager_dashboard/src/App.jsx index 61e1302..ca03e83 100644 --- a/manager_dashboard/src/App.jsx +++ b/manager_dashboard/src/App.jsx @@ -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) ── */} } /> } /> + } /> } /> } /> } /> diff --git a/manager_dashboard/src/pages/signage/MenuEditor.jsx b/manager_dashboard/src/pages/signage/MenuEditor.jsx new file mode 100644 index 0000000..6b96830 --- /dev/null +++ b/manager_dashboard/src/pages/signage/MenuEditor.jsx @@ -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 ( +
+ setC({ title: e.target.value })} data-testid="signage-menu-title" /> +
+ + 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() }} /> + + + savePlaylist({ transition: e.target.value })} + options={TRANSITIONS.map(x => ({ value: x, label: t(`signage.transitions.${x}`) }))} /> + + run(() => api.duplicatePlaylist(pl.id), t('signage.duplicated')).then(() => onChanged?.())}> + setConfirmDelete(true)} data-testid="signage-playlist-delete"> + +

+ {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(', ') })}} +

+ +
+ {/* the timeline */} +
+
    + {pl.slides.map((s, i) => { + const Icon = KIND_ICON[s.kind] || ImageIcon + const parts = windowParts(s) + return ( +
  1. 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)}> +
  2. + ) + })} +
+ +
+ + {/* the slide being edited */} +
+ {draft ? <> + + setMedia(m => ({ ...m, [String(item.id)]: mediaEntry(item) }))} + misfit={draftBad} /> +
+ + + {dirty && {t('display.looks.unsaved')}} +
+ :

{t(pl.slides.length ? 'signage.pickSlide' : 'signage.noSlides')}

} +
+
+ + {adding && ( + setAdding(false)} + footer={}> +
+
+ {t('signage.blank')} +
+ {['image', 'video', 'text', 'menu'].map(k => { + const Icon = KIND_ICON[k] + return ( + + ) + })} +
+
+
+ {t('signage.templatesTitle')} +
+ {TEMPLATES.map(tpl => { + const sample = { id: 0, ...slideFromTemplate(tpl, t), enabled: true, menu: { groups: [] } } + return ( + + ) + })} +
+
+
+
+ )} + + {confirmDelete && ( + setConfirmDelete(false)} + footer={<> + + + }> +

{t(pl.screens.length ? 'signage.deletePlaylistUsed' : 'signage.deletePlaylistBody', { names: pl.screens.map(s => s.name).join(', ') })}

+
+ )} +
+ ) +} diff --git a/manager_dashboard/src/pages/signage/SignageFields.jsx b/manager_dashboard/src/pages/signage/SignageFields.jsx new file mode 100644 index 0000000..f574efb --- /dev/null +++ b/manager_dashboard/src/pages/signage/SignageFields.jsx @@ -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 ( +
+ {label && {label}} +
+
+ {entry?.thumb ? + : kind === 'video' ?
+
+ {entry && {entry.name}} +
+ + {value && onRemove && } +
+
+
+ {misfit && ( +

+

+ )} + {open && setOpen(false)} + onPick={item => { onChange(item); setOpen(false) }} />} +
+ ) +} + +/** A colour the venue chooses for its TV (stored as #rrggbb: data, not a theme colour). */ +export function ColourField({ label, value, onChange, testid }) { + return ( + + ) +} + +/** 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 ( +
+ {t('signage.background')} + set({ dim: Number(e.target.value) })} data-testid={`${testid}-dim`} /> + + setName(e.target.value)} placeholder={t('signage.playlistPlaceholder')} data-testid="signage-new-name" /> + + + set({ name: e.target.value })} data-testid="signage-slide-name" /> + +
+ set({ enabled: on })} label={t('signage.enabled')} data-testid="signage-slide-enabled" /> +
+ {slide.kind === 'video' && ( +
+ set({ video_to_end: on })} label={t('signage.videoToEnd')} + description={t('signage.videoToEndHint')} data-testid="signage-video-to-end" /> +
+ )} + {!(slide.kind === 'video' && slide.video_to_end) && ( + + set({ duration_s: Math.min(3600, Number(e.target.value.replace(/\D/g, '')) || 0) })} /> + + )} + + set({ time_from: e.target.value || null })} data-testid="signage-time-from" /> + set({ time_to: e.target.value || null })} data-testid="signage-time-to" /> + set({ date_from: e.target.value || null })} data-testid="signage-date-from" /> + set({ date_to: e.target.value || null })} data-testid="signage-date-to" /> +
+ + + {slide.kind === 'image' && ( +
+ { onMedia(item); setC({ media_id: item.id }) }} testid="signage-picture" /> +
+ + setC({ fit: e.target.value })} + options={[{ value: 'cover', label: t('signage.fits.cover') }, { value: 'contain', label: t('signage.fits.contain') }]} /> + +
setC({ muted: on })} label={t('signage.muted')} />
+
+
+ )} + + {slide.kind === 'text' && ( +
+ setC({ title: e.target.value })} data-testid="signage-text-title" /> +