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:
+2
-1
@@ -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/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/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/<sha[:2]>/<sha>/` (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/<sha>/<variant>` 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/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/<sha[:2]>/<sha>/` (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/<sha>/<variant>` 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/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) |
|
| `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()` |
|
| `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` |
|
| `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/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/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/` | `<AccessProvider>` (bootstrap → modules, permission keys, venue, language; mounts the approval dialog), `useCan`, `useModule`, `<Can>`, `<RequireModule>` (CS-18) |
|
| `packages/access/` | `<AccessProvider>` (bootstrap → modules, permission keys, venue, language; mounts the approval dialog), `useCan`, `useModule`, `<Can>`, `<RequireModule>` (CS-18) |
|
||||||
| `packages/i18n/` | Translations (`locales/<lang>/<ns>.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) |
|
| `packages/i18n/` | Translations (`locales/<lang>/<ns>.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/`. |
|
| `.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/`. |
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import TabsPage from './pages/financials/TabsPage'
|
|||||||
// Management
|
// Management
|
||||||
import ProductsPage from './pages/Management/ProductsPage'
|
import ProductsPage from './pages/Management/ProductsPage'
|
||||||
import MediaPage from './pages/media/MediaPage'
|
import MediaPage from './pages/media/MediaPage'
|
||||||
|
import SignagePage from './pages/signage/SignagePage'
|
||||||
import TablesConfigPage from './pages/Management/TablesConfigPage'
|
import TablesConfigPage from './pages/Management/TablesConfigPage'
|
||||||
import StaffPage from './pages/Management/StaffPage'
|
import StaffPage from './pages/Management/StaffPage'
|
||||||
import SessionsPage from './pages/staff/SessionsPage'
|
import SessionsPage from './pages/staff/SessionsPage'
|
||||||
@@ -163,6 +164,7 @@ export default function App() {
|
|||||||
{/* ── Management (Headquarters) ── */}
|
{/* ── Management (Headquarters) ── */}
|
||||||
<Route path="management/products" element={<ProductsPage />} />
|
<Route path="management/products" element={<ProductsPage />} />
|
||||||
<Route path="management/media" element={<MediaPage />} />
|
<Route path="management/media" element={<MediaPage />} />
|
||||||
|
<Route path="management/signage" element={<SignagePage />} />
|
||||||
<Route path="management/tables" element={<TablesConfigPage />} />
|
<Route path="management/tables" element={<TablesConfigPage />} />
|
||||||
<Route path="management/staff" element={<StaffPage />} />
|
<Route path="management/staff" element={<StaffPage />} />
|
||||||
<Route path="management/sessions" element={<SessionsPage />} />
|
<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,
|
BookUser, Users, Receipt, CreditCard,
|
||||||
Package, TableProperties, UserCog, CalendarDays, Trash2, Boxes,
|
Package, TableProperties, UserCog, CalendarDays, Trash2, Boxes,
|
||||||
BarChart2, TrendingUp, Users2, ShoppingCart, Tag, Activity, Printer, ConciergeBell, FileText,
|
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'
|
} from 'lucide-react'
|
||||||
|
|
||||||
const DASH = 'core.dashboard.access'
|
const DASH = 'core.dashboard.access'
|
||||||
@@ -62,6 +62,7 @@ export const NAV = [
|
|||||||
children: [
|
children: [
|
||||||
{ to: '/management/products', icon: Package, label: 'nav.products', module: 'catalog', perm: 'catalog.menu.manage' },
|
{ 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/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/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/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' },
|
{ to: '/management/sessions', icon: LogIn, label: 'nav.sessions', module: 'core', perm: 'core.staff.manage' },
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// The signage editor's helpers (plan step 5.6a).
|
||||||
|
import { test } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { fitsOrientation, mediaEntry, misfits, moved, slideBody, slideFromTemplate, TEMPLATES, totalSeconds, windowParts } from '../src/pages/signage/signageLogic.js'
|
||||||
|
|
||||||
|
test('templates fill their texts in the manager\'s language and copy their content', () => {
|
||||||
|
const tpl = TEMPLATES.find(x => x.key === 'happyHour')
|
||||||
|
const a = slideFromTemplate(tpl, k => `T(${k})`)
|
||||||
|
assert.equal(a.kind, 'text')
|
||||||
|
assert.equal(a.content.title, 'T(signage.templates.happyHour.title)')
|
||||||
|
assert.equal(a.time_from, '17:00')
|
||||||
|
a.content.background.colour = '#000000'
|
||||||
|
assert.notEqual(tpl.content.background.colour, '#000000') // a copy, never the template itself
|
||||||
|
assert.ok(TEMPLATES.every(x => ['image', 'video', 'text', 'menu'].includes(x.kind)))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('does a picture fit the playlist\'s shape', () => {
|
||||||
|
assert.equal(fitsOrientation({ width: 1920, height: 1080 }, 'landscape'), true)
|
||||||
|
assert.equal(fitsOrientation({ width: 1080, height: 1920 }, 'landscape'), false)
|
||||||
|
assert.equal(fitsOrientation({ width: 1080, height: 1920 }, 'portrait'), true)
|
||||||
|
assert.equal(fitsOrientation({ width: 800, height: 800 }, 'portrait'), true)
|
||||||
|
assert.equal(fitsOrientation({}, 'portrait'), null)
|
||||||
|
const media = { 1: { width: 1080, height: 1920 }, 2: { width: 1920, height: 1080 } }
|
||||||
|
const slides = [{ id: 10, content: { media_id: 1 } }, { id: 11, content: { media_id: 2 } },
|
||||||
|
{ id: 12, content: { background: { kind: 'media', media_id: 1 } } }, { id: 13, content: { background: { kind: 'colour', media_id: 1 } } }]
|
||||||
|
assert.deepEqual(misfits(slides, media, 'landscape'), { 10: [1], 12: [1] })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('the timeline: when a slide shows, the round\'s time, moving', () => {
|
||||||
|
assert.deepEqual(windowParts({}), [])
|
||||||
|
assert.deepEqual(windowParts({ days: [0, 1, 2, 3, 4, 5, 6] }), [])
|
||||||
|
assert.deepEqual(windowParts({ days: [5, 6], time_from: '12:00' }).map(p => p.key), ['days', 'hours'])
|
||||||
|
assert.equal(windowParts({ date_to: '2026-12-31' })[0].params.from, '…')
|
||||||
|
const media = { 7: { duration_ms: 12_400 } }
|
||||||
|
assert.equal(totalSeconds([{ enabled: true, duration_s: 8 }, { enabled: false, duration_s: 50 },
|
||||||
|
{ enabled: true, kind: 'video', video_to_end: true, content: { media_id: 7 } }], media), 20)
|
||||||
|
assert.deepEqual(moved([1, 2, 3, 4], 3, 0), [4, 1, 2, 3])
|
||||||
|
assert.deepEqual(moved([1, 2, 3], 0, 9), [1, 2, 3])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('what is sent back, and library items as the slides need them', () => {
|
||||||
|
const b = slideBody({ id: 1, kind: 'text', name: '', duration_s: 9, enabled: 1, days: undefined, content: { title: 'x' }, menu: {} })
|
||||||
|
assert.deepEqual(b, { name: null, duration_s: 9, transition: null, video_to_end: false, enabled: true, days: [], time_from: null, time_to: null,
|
||||||
|
date_from: null, date_to: null, content: { title: 'x' } })
|
||||||
|
assert.deepEqual(mediaEntry({ id: 3, kind: 'video', name: 'v', width: 1, height: 2, duration_ms: 5, urls: { original: '/o' } }).url, '/o')
|
||||||
|
assert.equal(mediaEntry({ id: 3, kind: 'image', urls: { full: '/f', original: '/o', thumb: '/t' } }).url, '/f')
|
||||||
|
})
|
||||||
@@ -47,7 +47,8 @@
|
|||||||
"approvals": "Εγκρίσεις υπευθύνου",
|
"approvals": "Εγκρίσεις υπευθύνου",
|
||||||
"deliveryFees": "Online παραγγελίες (ρύθμιση)",
|
"deliveryFees": "Online παραγγελίες (ρύθμιση)",
|
||||||
"qrCodes": "QR τραπεζιών",
|
"qrCodes": "QR τραπεζιών",
|
||||||
"media": "Πολυμέσα"
|
"media": "Πολυμέσα",
|
||||||
|
"signage": "Προβολή"
|
||||||
},
|
},
|
||||||
"profile": {
|
"profile": {
|
||||||
"edit": "Επεξεργασία προφίλ",
|
"edit": "Επεξεργασία προφίλ",
|
||||||
@@ -805,5 +806,164 @@
|
|||||||
},
|
},
|
||||||
"builtin": "Ενσωματωμένο",
|
"builtin": "Ενσωματωμένο",
|
||||||
"builtinHint": "Οι ενσωματωμένες εικόνες έρχονται με το Xenia: χρησιμοποιούνται παντού, αλλά δεν μετονομάζονται ούτε διαγράφονται."
|
"builtinHint": "Οι ενσωματωμένες εικόνες έρχονται με το Xenia: χρησιμοποιούνται παντού, αλλά δεν μετονομάζονται ούτε διαγράφονται."
|
||||||
|
},
|
||||||
|
"signage": {
|
||||||
|
"pageTitle": "Προβολή",
|
||||||
|
"intro": "Τι δείχνουν οι τηλεοράσεις σας: λίστες με μενού, εικόνες, βίντεο και κείμενα. Φτιάξτε κάθε λίστα για το σχήμα της τηλεόρασής της (οριζόντια ή κάθετη)· η προεπισκόπηση δείχνει τη διαφάνεια ακριβώς όπως η τηλεόραση.",
|
||||||
|
"playlists": "Λίστες",
|
||||||
|
"newPlaylist": "Νέα λίστα",
|
||||||
|
"noPlaylists": "Δεν υπάρχουν λίστες ακόμα.",
|
||||||
|
"noPlaylistsHint": "Φτιάξτε μία για οριζόντια ή κάθετη τηλεόραση και προσθέστε διαφάνειες.",
|
||||||
|
"playlistName": "Όνομα",
|
||||||
|
"playlistPlaceholder": "π.χ. Τηλεόραση βιτρίνας",
|
||||||
|
"orientation": "Σχήμα τηλεόρασης",
|
||||||
|
"orientationHint": "Φαρδιά (οριζόντια) ή ψηλή (κάθετη): διαλέξτε εικόνες και βίντεο για αυτό το σχήμα.",
|
||||||
|
"orientations": {
|
||||||
|
"landscape": "Οριζόντια (φαρδιά)",
|
||||||
|
"portrait": "Κάθετη (ψηλή)"
|
||||||
|
},
|
||||||
|
"defaultTransition": "Μετάβαση",
|
||||||
|
"transitions": {
|
||||||
|
"fade": "Σβήσιμο",
|
||||||
|
"slide": "Ολίσθηση",
|
||||||
|
"zoom": "Ζουμ",
|
||||||
|
"none": "Καμία"
|
||||||
|
},
|
||||||
|
"duplicatePlaylist": "Αντίγραφο της λίστας",
|
||||||
|
"duplicated": "Αντιγράφηκε.",
|
||||||
|
"summary_one": "{{count}} διαφάνεια · {{minutes}}:{{seconds}} ο γύρος",
|
||||||
|
"summary_other": "{{count}} διαφάνειες · {{minutes}}:{{seconds}} ο γύρος",
|
||||||
|
"playingOn": "παίζει σε: {{names}}",
|
||||||
|
"timeline": "Χρονολόγιο",
|
||||||
|
"kinds": {
|
||||||
|
"image": "Εικόνα",
|
||||||
|
"video": "Βίντεο",
|
||||||
|
"text": "Κείμενο",
|
||||||
|
"menu": "Μενού"
|
||||||
|
},
|
||||||
|
"misfit": "Αυτή η εικόνα ή το βίντεο δεν ταιριάζει στο σχήμα της λίστας: θα κοπεί ή θα έχει μπάρες.",
|
||||||
|
"toTheEnd": "ως το τέλος",
|
||||||
|
"seconds_one": "{{count}} δευτερόλεπτο",
|
||||||
|
"seconds_other": "{{count}} δευτερόλεπτα",
|
||||||
|
"off": "κλειστή",
|
||||||
|
"window": {
|
||||||
|
"hours": "{{from}}–{{to}}",
|
||||||
|
"dates": "{{from}} → {{to}}"
|
||||||
|
},
|
||||||
|
"weekdays": {
|
||||||
|
"0": "Δευ",
|
||||||
|
"1": "Τρι",
|
||||||
|
"2": "Τετ",
|
||||||
|
"3": "Πεμ",
|
||||||
|
"4": "Παρ",
|
||||||
|
"5": "Σαβ",
|
||||||
|
"6": "Κυρ"
|
||||||
|
},
|
||||||
|
"duplicateSlide": "Αντίγραφο της διαφάνειας",
|
||||||
|
"deleteSlide": "Αφαίρεση αυτής της διαφάνειας;",
|
||||||
|
"removed": "Η διαφάνεια αφαιρέθηκε.",
|
||||||
|
"addSlide": "Προσθήκη διαφάνειας",
|
||||||
|
"added": "Η διαφάνεια προστέθηκε.",
|
||||||
|
"undo": "Αναίρεση αλλαγών",
|
||||||
|
"pickSlide": "Διαλέξτε μια διαφάνεια στο χρονολόγιο για να την αλλάξετε.",
|
||||||
|
"noSlides": "Δεν υπάρχουν διαφάνειες: προσθέστε την πρώτη.",
|
||||||
|
"blank": "Κενή",
|
||||||
|
"templatesTitle": "Ή ξεκινήστε από έτοιμη διαφάνεια",
|
||||||
|
"templates": {
|
||||||
|
"promo": {
|
||||||
|
"name": "Εικόνα προσφοράς"
|
||||||
|
},
|
||||||
|
"announcement": {
|
||||||
|
"name": "Ανακοίνωση"
|
||||||
|
},
|
||||||
|
"happyHour": {
|
||||||
|
"name": "Happy hour (μόνο 17:00–19:00)",
|
||||||
|
"title": "Happy hour",
|
||||||
|
"body": "17:00 – 19:00"
|
||||||
|
},
|
||||||
|
"welcome": {
|
||||||
|
"name": "Καλώς ήρθατε",
|
||||||
|
"title": "Καλώς ήρθατε"
|
||||||
|
},
|
||||||
|
"menuBoard": {
|
||||||
|
"name": "Μενού",
|
||||||
|
"title": "Μενού"
|
||||||
|
},
|
||||||
|
"video": {
|
||||||
|
"name": "Βίντεο ως το τέλος"
|
||||||
|
},
|
||||||
|
"image": {
|
||||||
|
"name": "Εικόνα"
|
||||||
|
},
|
||||||
|
"text": {
|
||||||
|
"name": "Κείμενο"
|
||||||
|
},
|
||||||
|
"menu": {
|
||||||
|
"name": "Μενού"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deletePlaylistTitle": "Διαγραφή «{{name}}»;",
|
||||||
|
"deletePlaylistBody": "Οι διαφάνειές της φεύγουν μαζί της. Οι εικόνες και τα βίντεο μένουν στη βιβλιοθήκη.",
|
||||||
|
"deletePlaylistUsed": "Παίζει σε: {{names}}. Αυτές οι οθόνες δεν θα δείχνουν τίποτα μέχρι να τους δώσετε άλλη λίστα. Οι διαφάνειές της φεύγουν· οι εικόνες και τα βίντεο μένουν στη βιβλιοθήκη.",
|
||||||
|
"discard": "Η διαφάνεια έχει αλλαγές που δεν αποθηκεύτηκαν. Να φύγετε;",
|
||||||
|
"slideName": "Όνομα στο χρονολόγιο",
|
||||||
|
"slideNameHint": "Μόνο για εσάς (προαιρετικό).",
|
||||||
|
"enabled": "Να εμφανίζεται",
|
||||||
|
"videoToEnd": "Το βίντεο παίζει ως το τέλος",
|
||||||
|
"videoToEndHint": "Όχι: δείχνεται για τα δευτερόλεπτα παρακάτω (και επαναλαμβάνεται αν είναι μικρότερο).",
|
||||||
|
"duration": "Δευτερόλεπτα στην οθόνη",
|
||||||
|
"durationMenuHint": "Ένα μεγάλο μενού γυρίζει σελίδες και μένει όσο χρειάζεται.",
|
||||||
|
"transition": "Μπαίνει με",
|
||||||
|
"transitionDefault": "Τη μετάβαση της λίστας",
|
||||||
|
"when": "Πότε εμφανίζεται",
|
||||||
|
"whenHint": "Κενό για πάντα. Διαλέξτε μέρες, ώρες (μπορεί να περνούν τα μεσάνυχτα) ή ημερομηνίες για να εμφανίζεται μόνο τότε.",
|
||||||
|
"days": "Μέρες",
|
||||||
|
"timeFrom": "Από (ώρα)",
|
||||||
|
"timeTo": "Έως (ώρα)",
|
||||||
|
"dateFrom": "Από (ημερομηνία)",
|
||||||
|
"dateTo": "Έως (ημερομηνία)",
|
||||||
|
"picture": "Η εικόνα",
|
||||||
|
"video": "Το βίντεο",
|
||||||
|
"fit": "Προσαρμογή",
|
||||||
|
"fits": {
|
||||||
|
"cover": "Γεμίζει την οθόνη (μπορεί να κοπεί)",
|
||||||
|
"contain": "Ολόκληρη (μπορεί να αφήσει μπάρες)"
|
||||||
|
},
|
||||||
|
"around": "Χρώμα στις μπάρες",
|
||||||
|
"muted": "Χωρίς ήχο",
|
||||||
|
"title": "Τίτλος",
|
||||||
|
"body": "Κείμενο",
|
||||||
|
"align": "Στοίχιση",
|
||||||
|
"aligns": {
|
||||||
|
"left": "Αριστερά",
|
||||||
|
"center": "Κέντρο",
|
||||||
|
"right": "Δεξιά"
|
||||||
|
},
|
||||||
|
"vertical": "Ύψος",
|
||||||
|
"verticals": {
|
||||||
|
"top": "Πάνω",
|
||||||
|
"middle": "Μέση",
|
||||||
|
"bottom": "Κάτω"
|
||||||
|
},
|
||||||
|
"font": "Γραμματοσειρά",
|
||||||
|
"fonts": {
|
||||||
|
"sans": "Καθαρή",
|
||||||
|
"serif": "Κλασική",
|
||||||
|
"rounded": "Στρογγυλή",
|
||||||
|
"condensed": "Στενή",
|
||||||
|
"display": "Έντονη αφίσα"
|
||||||
|
},
|
||||||
|
"textColour": "Χρώμα κειμένου",
|
||||||
|
"textSize": "Μέγεθος κειμένου: {{value}}%",
|
||||||
|
"change": "Αλλαγή",
|
||||||
|
"pickVideo": "Επιλογή βίντεο",
|
||||||
|
"pickPicture": "Επιλογή εικόνας",
|
||||||
|
"background": "Φόντο",
|
||||||
|
"bgColour": "Ένα χρώμα",
|
||||||
|
"bgPhoto": "Μια φωτογραφία",
|
||||||
|
"colour": "Χρώμα",
|
||||||
|
"dim": "Σκούρεμα φωτογραφίας: {{value}}%",
|
||||||
|
"columns": "Στήλες",
|
||||||
|
"accent": "Χρώμα τιμών και επικεφαλίδων"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,8 @@
|
|||||||
"approvals": "Manager approvals",
|
"approvals": "Manager approvals",
|
||||||
"deliveryFees": "Online ordering",
|
"deliveryFees": "Online ordering",
|
||||||
"qrCodes": "Table QR codes",
|
"qrCodes": "Table QR codes",
|
||||||
"media": "Media"
|
"media": "Media",
|
||||||
|
"signage": "Signage"
|
||||||
},
|
},
|
||||||
"profile": {
|
"profile": {
|
||||||
"edit": "Edit profile",
|
"edit": "Edit profile",
|
||||||
@@ -805,5 +806,164 @@
|
|||||||
},
|
},
|
||||||
"builtin": "Built-in",
|
"builtin": "Built-in",
|
||||||
"builtinHint": "Built-in pictures come with Xenia: they can be used anywhere, but not renamed or deleted."
|
"builtinHint": "Built-in pictures come with Xenia: they can be used anywhere, but not renamed or deleted."
|
||||||
|
},
|
||||||
|
"signage": {
|
||||||
|
"pageTitle": "Signage",
|
||||||
|
"intro": "What your TVs show: playlists of menu boards, pictures, videos and texts. Build each playlist for the shape of its TV (landscape or portrait); the preview shows a slide exactly as the TV will.",
|
||||||
|
"playlists": "Playlists",
|
||||||
|
"newPlaylist": "New playlist",
|
||||||
|
"noPlaylists": "No playlists yet.",
|
||||||
|
"noPlaylistsHint": "Make one for a landscape or a portrait TV, then add slides.",
|
||||||
|
"playlistName": "Name",
|
||||||
|
"playlistPlaceholder": "e.g. Window TV",
|
||||||
|
"orientation": "TV shape",
|
||||||
|
"orientationHint": "Wide (landscape) or tall (portrait): pick the pictures and videos for this shape.",
|
||||||
|
"orientations": {
|
||||||
|
"landscape": "Landscape (wide)",
|
||||||
|
"portrait": "Portrait (tall)"
|
||||||
|
},
|
||||||
|
"defaultTransition": "Transition",
|
||||||
|
"transitions": {
|
||||||
|
"fade": "Fade",
|
||||||
|
"slide": "Slide in",
|
||||||
|
"zoom": "Zoom",
|
||||||
|
"none": "None"
|
||||||
|
},
|
||||||
|
"duplicatePlaylist": "Duplicate the playlist",
|
||||||
|
"duplicated": "Copied.",
|
||||||
|
"summary_one": "{{count}} slide · {{minutes}}:{{seconds}} a round",
|
||||||
|
"summary_other": "{{count}} slides · {{minutes}}:{{seconds}} a round",
|
||||||
|
"playingOn": "playing on {{names}}",
|
||||||
|
"timeline": "Timeline",
|
||||||
|
"kinds": {
|
||||||
|
"image": "Picture",
|
||||||
|
"video": "Video",
|
||||||
|
"text": "Text",
|
||||||
|
"menu": "Menu board"
|
||||||
|
},
|
||||||
|
"misfit": "This picture or video doesn't fit the playlist's shape: it will be cropped or have bars.",
|
||||||
|
"toTheEnd": "to the end",
|
||||||
|
"seconds_one": "{{count}} second",
|
||||||
|
"seconds_other": "{{count}} seconds",
|
||||||
|
"off": "off",
|
||||||
|
"window": {
|
||||||
|
"hours": "{{from}}–{{to}}",
|
||||||
|
"dates": "{{from}} → {{to}}"
|
||||||
|
},
|
||||||
|
"weekdays": {
|
||||||
|
"0": "Mon",
|
||||||
|
"1": "Tue",
|
||||||
|
"2": "Wed",
|
||||||
|
"3": "Thu",
|
||||||
|
"4": "Fri",
|
||||||
|
"5": "Sat",
|
||||||
|
"6": "Sun"
|
||||||
|
},
|
||||||
|
"duplicateSlide": "Duplicate the slide",
|
||||||
|
"deleteSlide": "Remove this slide?",
|
||||||
|
"removed": "Slide removed.",
|
||||||
|
"addSlide": "Add a slide",
|
||||||
|
"added": "Slide added.",
|
||||||
|
"undo": "Undo changes",
|
||||||
|
"pickSlide": "Pick a slide on the timeline to change it.",
|
||||||
|
"noSlides": "No slides yet: add the first one.",
|
||||||
|
"blank": "Start empty",
|
||||||
|
"templatesTitle": "Or start from a ready-made slide",
|
||||||
|
"templates": {
|
||||||
|
"promo": {
|
||||||
|
"name": "Promotion picture"
|
||||||
|
},
|
||||||
|
"announcement": {
|
||||||
|
"name": "Announcement"
|
||||||
|
},
|
||||||
|
"happyHour": {
|
||||||
|
"name": "Happy hour (17:00–19:00 only)",
|
||||||
|
"title": "Happy hour",
|
||||||
|
"body": "17:00 – 19:00"
|
||||||
|
},
|
||||||
|
"welcome": {
|
||||||
|
"name": "Welcome",
|
||||||
|
"title": "Welcome"
|
||||||
|
},
|
||||||
|
"menuBoard": {
|
||||||
|
"name": "Menu board",
|
||||||
|
"title": "Menu"
|
||||||
|
},
|
||||||
|
"video": {
|
||||||
|
"name": "Video to its end"
|
||||||
|
},
|
||||||
|
"image": {
|
||||||
|
"name": "Picture"
|
||||||
|
},
|
||||||
|
"text": {
|
||||||
|
"name": "Text"
|
||||||
|
},
|
||||||
|
"menu": {
|
||||||
|
"name": "Menu board"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deletePlaylistTitle": "Delete \"{{name}}\"?",
|
||||||
|
"deletePlaylistBody": "Its slides go with it. The pictures and videos stay in the media library.",
|
||||||
|
"deletePlaylistUsed": "It is playing on {{names}}: those screens will show nothing until you give them another playlist. Its slides go with it; the pictures and videos stay in the media library.",
|
||||||
|
"discard": "This slide has changes that aren't saved. Leave it anyway?",
|
||||||
|
"slideName": "Name on the timeline",
|
||||||
|
"slideNameHint": "Only for you (optional).",
|
||||||
|
"enabled": "Show this slide",
|
||||||
|
"videoToEnd": "Play the video to its end",
|
||||||
|
"videoToEndHint": "Off: it shows for the seconds below (and repeats if it is shorter).",
|
||||||
|
"duration": "Seconds on screen",
|
||||||
|
"durationMenuHint": "A long menu turns its pages and stays as long as it needs.",
|
||||||
|
"transition": "Comes in with",
|
||||||
|
"transitionDefault": "The playlist's transition",
|
||||||
|
"when": "When it shows",
|
||||||
|
"whenHint": "Leave empty for always. Pick days, hours (they may pass midnight) or dates to show it only then.",
|
||||||
|
"days": "Days",
|
||||||
|
"timeFrom": "From (time)",
|
||||||
|
"timeTo": "To (time)",
|
||||||
|
"dateFrom": "From (date)",
|
||||||
|
"dateTo": "To (date)",
|
||||||
|
"picture": "The picture",
|
||||||
|
"video": "The video",
|
||||||
|
"fit": "Fit",
|
||||||
|
"fits": {
|
||||||
|
"cover": "Fill the screen (may crop)",
|
||||||
|
"contain": "Show it whole (may leave bars)"
|
||||||
|
},
|
||||||
|
"around": "Colour of the bars",
|
||||||
|
"muted": "Without sound",
|
||||||
|
"title": "Title",
|
||||||
|
"body": "Text",
|
||||||
|
"align": "Alignment",
|
||||||
|
"aligns": {
|
||||||
|
"left": "Left",
|
||||||
|
"center": "Centre",
|
||||||
|
"right": "Right"
|
||||||
|
},
|
||||||
|
"vertical": "Height",
|
||||||
|
"verticals": {
|
||||||
|
"top": "Top",
|
||||||
|
"middle": "Middle",
|
||||||
|
"bottom": "Bottom"
|
||||||
|
},
|
||||||
|
"font": "Font",
|
||||||
|
"fonts": {
|
||||||
|
"sans": "Clean",
|
||||||
|
"serif": "Classic",
|
||||||
|
"rounded": "Rounded",
|
||||||
|
"condensed": "Narrow",
|
||||||
|
"display": "Bold poster"
|
||||||
|
},
|
||||||
|
"textColour": "Text colour",
|
||||||
|
"textSize": "Text size: {{value}}%",
|
||||||
|
"change": "Change",
|
||||||
|
"pickVideo": "Pick a video",
|
||||||
|
"pickPicture": "Pick a picture",
|
||||||
|
"background": "Background",
|
||||||
|
"bgColour": "A colour",
|
||||||
|
"bgPhoto": "A photo",
|
||||||
|
"colour": "Colour",
|
||||||
|
"dim": "Darken the photo: {{value}}%",
|
||||||
|
"columns": "Columns",
|
||||||
|
"accent": "Prices and headings colour"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+67
-5
@@ -1,20 +1,28 @@
|
|||||||
// Signage suite (plan steps 5.5a, 5.5b): a TV paired as a signage screen plays its playlist (picture,
|
// Signage suite (plan steps 5.5a, 5.5b, 5.6a): a TV paired as a signage screen plays its playlist (picture,
|
||||||
// text, video to its end, menu board) in order with transitions, turns for a TV mounted sideways,
|
// text, video to its end, menu board) in order with transitions, turns for a TV mounted sideways,
|
||||||
// keeps playing with the server stopped (a quiet mark, no banner), and catches up when it is back.
|
// keeps playing with the server stopped (a quiet mark, no banner), and catches up when it is back.
|
||||||
// Starts its own backend (:8065) and the terminal (:5193).
|
// Starts its own backend (:8065) and the terminal (:5193).
|
||||||
// node signage.mjs
|
// node signage.mjs
|
||||||
import { execFileSync } from 'node:child_process'
|
import { execFileSync, spawn } from 'node:child_process'
|
||||||
|
import { openSync } from 'node:fs'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import { chromium } from 'playwright'
|
import { chromium } from 'playwright'
|
||||||
import { BROWSER_CHANNEL, OUT, PYTHON, reporter, sleep, waitFor } from './lib/env.mjs'
|
import { BROWSER_CHANNEL, CS, OUT, PYTHON, reporter, sleep, waitFor } from './lib/env.mjs'
|
||||||
import { startBackend, startTerminalVite } from './lib/proc.mjs'
|
import { killTree, startBackend, startTerminalVite, waitHttp } from './lib/proc.mjs'
|
||||||
import { supportLogin } from './lib/support.mjs'
|
import { supportLogin } from './lib/support.mjs'
|
||||||
|
|
||||||
let backend = await startBackend({ port: 8065, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } })
|
let backend = await startBackend({ port: 8065, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } })
|
||||||
const dataDir = backend.dataDir
|
const dataDir = backend.dataDir
|
||||||
const term = await startTerminalVite({ port: 5193, backendUrl: backend.url })
|
const term = await startTerminalVite({ port: 5193, backendUrl: backend.url })
|
||||||
|
const MPORT = 5194
|
||||||
|
const MANAGER = `http://localhost:${MPORT}`
|
||||||
|
const mlog = openSync(path.join(OUT, `vite-${MPORT}.log`), 'w')
|
||||||
|
const managerVite = spawn('npx', ['vite', '--port', String(MPORT), '--strictPort'], {
|
||||||
|
cwd: path.join(CS, 'manager_dashboard'), shell: process.platform === 'win32', detached: process.platform !== 'win32',
|
||||||
|
stdio: ['ignore', mlog, mlog], env: { ...process.env, XENIA_BACKEND: backend.url },
|
||||||
|
})
|
||||||
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
|
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
|
||||||
const r = reporter('signage: the player on a TV (5.5a), menu boards and widgets (5.5b)')
|
const r = reporter('signage: the player on a TV (5.5a), menu boards and widgets (5.5b), the editor (5.6a)')
|
||||||
const errors = []
|
const errors = []
|
||||||
let failures = 0
|
let failures = 0
|
||||||
|
|
||||||
@@ -177,6 +185,59 @@ try {
|
|||||||
await api('PUT', `/api/signage/screens/${dev.id}`, { token: boss, body: { playlist_id: pl.id } })
|
await api('PUT', `/api/signage/screens/${dev.id}`, { token: boss, body: { playlist_id: pl.id } })
|
||||||
await waitFor(async () => (await tv.getByTestId('app-signage').getAttribute('data-playlist')) === String(pl.id), 15_000, 300)
|
await waitFor(async () => (await tv.getByTestId('app-signage').getAttribute('data-playlist')) === String(pl.id), 15_000, 300)
|
||||||
|
|
||||||
|
// ── 5.6a: the editor in the manager ──────────────────────────────────────
|
||||||
|
await waitHttp(`${MANAGER}/`)
|
||||||
|
const tallJpg = execFileSync(PYTHON, ['-c', "import io,sys;from PIL import Image;b=io.BytesIO();Image.new('RGB',(1080,1920),(30,140,90)).save(b,'JPEG');sys.stdout.buffer.write(b.getvalue())"])
|
||||||
|
const tallPhoto = await upload(boss, tallJpg, 'tall poster.jpg', 'image/jpeg')
|
||||||
|
const mgr = await (await browser.newContext({ viewport: { width: 1440, height: 900 } })).newPage()
|
||||||
|
mgr.on('pageerror', e => errors.push(e.message))
|
||||||
|
await mgr.goto(`${MANAGER}/login`)
|
||||||
|
await mgr.getByTestId('login-form').waitFor({ timeout: 60_000 })
|
||||||
|
if (!(await mgr.getByTestId('login-account').count())) await mgr.getByLabel('Username').fill('manager')
|
||||||
|
await mgr.getByLabel('Password').fill('password')
|
||||||
|
await mgr.getByRole('button', { name: 'Sign in', exact: true }).click()
|
||||||
|
await mgr.waitForURL(u => u.pathname !== '/login', { timeout: 20_000 })
|
||||||
|
await mgr.goto(`${MANAGER}/management/signage`)
|
||||||
|
r.check('5.6a: Management → Signage lists the playlists', await shown(mgr, 'signage-playlist-item', 20_000)
|
||||||
|
&& await mgr.getByTestId('signage-playlist-item').count() >= 2)
|
||||||
|
await mgr.getByTestId('signage-new-playlist').click()
|
||||||
|
await mgr.getByTestId('signage-new-name').fill('Opening')
|
||||||
|
await mgr.getByTestId('signage-create-playlist').click()
|
||||||
|
await waitFor(async () => (await mgr.getByTestId('signage-playlist-name').inputValue().catch(() => '')) === 'Opening', 15_000, 200)
|
||||||
|
await mgr.getByRole('dialog').waitFor({ state: 'detached', timeout: 5000 }).catch(() => {})
|
||||||
|
await mgr.getByTestId('signage-add-slide').click()
|
||||||
|
r.check('5.6a: "Add a slide" offers empty slides and ready-made ones with a preview',
|
||||||
|
await mgr.getByTestId('signage-template-preview').count() >= 5)
|
||||||
|
await mgr.getByTestId('signage-template-announcement').click()
|
||||||
|
await mgr.getByTestId('signage-slide-editor').waitFor({ timeout: 10_000 })
|
||||||
|
await mgr.getByTestId('signage-text-title').fill('Opening soon')
|
||||||
|
r.check('5.6a: the preview follows the editor as you type (as the TV draws it)',
|
||||||
|
await waitFor(async () => (await mgr.getByTestId('signage-preview').getByTestId('signage-title').textContent().catch(() => '')) === 'Opening soon', 5000, 200))
|
||||||
|
await mgr.getByTestId('signage-slide-save').click()
|
||||||
|
await sleep(800)
|
||||||
|
await mgr.getByTestId('signage-add-slide').click()
|
||||||
|
await mgr.getByTestId('signage-template-promo').click()
|
||||||
|
await mgr.getByTestId('signage-picture-pick').click({ timeout: 10_000 })
|
||||||
|
await mgr.getByTestId('media-picker').locator(`[data-testid="media-item"][data-id="${tallPhoto.id}"]`).click()
|
||||||
|
r.check('5.6a: a tall picture on a landscape playlist is flagged', await shown(mgr, 'signage-picture-misfit', 5000))
|
||||||
|
await mgr.getByTestId('signage-slide-save').click()
|
||||||
|
await sleep(800)
|
||||||
|
r.check('5.6a: …and the timeline card shows the warning', await mgr.getByTestId('signage-card-misfit').count() === 1)
|
||||||
|
await mgr.screenshot({ path: path.join(OUT, 'signage-editor.png'), fullPage: true })
|
||||||
|
// the picture first: the arrow on its card
|
||||||
|
await mgr.getByTestId('signage-slide-card').nth(1).getByTestId('signage-up').click()
|
||||||
|
await sleep(800)
|
||||||
|
const opening = (await api('GET', '/api/signage/playlists', { token: boss })).find(p => p.name === 'Opening')
|
||||||
|
const full = await api('GET', `/api/signage/playlists/${opening.id}`, { token: boss })
|
||||||
|
r.check('5.6a: built in the manager: the picture, then the text "Opening soon"', full.slides.map(x => x.kind).join(',') === 'image,text'
|
||||||
|
&& full.slides[1].content.title === 'Opening soon' && full.slides[0].content.media_id === tallPhoto.id, JSON.stringify(full.slides.map(x => [x.kind, x.content.title])))
|
||||||
|
await api('PUT', `/api/signage/screens/${dev.id}`, { token: boss, body: { playlist_id: opening.id } })
|
||||||
|
const onTv = await waitFor(async () => ((await tv.getByTestId('signage-title').allTextContents().catch(() => [])).includes('Opening soon') ? true : null), 30_000, 300)
|
||||||
|
r.check('5.6a: …and the TV plays it', !!onTv)
|
||||||
|
await mgr.context().close()
|
||||||
|
await api('PUT', `/api/signage/screens/${dev.id}`, { token: boss, body: { playlist_id: pl.id } })
|
||||||
|
await waitFor(async () => (await tv.getByTestId('app-signage').getAttribute('data-playlist')) === String(pl.id), 15_000, 300)
|
||||||
|
|
||||||
// ── the server stops: the TV keeps playing ────────────────────────────────
|
// ── the server stops: the TV keeps playing ────────────────────────────────
|
||||||
await backend.stop()
|
await backend.stop()
|
||||||
const offlineOrder = await watch(tv, 14_000)
|
const offlineOrder = await watch(tv, 14_000)
|
||||||
@@ -204,6 +265,7 @@ try {
|
|||||||
} finally {
|
} finally {
|
||||||
await browser.close()
|
await browser.close()
|
||||||
term.stop()
|
term.stop()
|
||||||
|
killTree(managerVite)
|
||||||
await backend.stop()
|
await backend.stop()
|
||||||
}
|
}
|
||||||
process.exit(failures ? 1 : 0)
|
process.exit(failures ? 1 : 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user