diff --git a/docs/README.md b/docs/README.md index 7619024..2d46952 100644 --- a/docs/README.md +++ b/docs/README.md @@ -48,7 +48,7 @@ The manager calls the API **same-origin, with relative paths**. The waiter app r | `local_backend/routers/fees.py` | The venue's online ordering settings (`connect_orders.ordering`: services, hours, slots, ASAP; `reservations`: bookings, food ahead, fire minutes), delivery areas and fee rules, the fee line's name/VAT, and the venue's links (`links.order`, `links.menu` from the cloud's `apps_url`). Everything here travels to the cloud in the menu snapshot (contract C-2) | | `local_backend/routers/customer_display.py`, `models/display_look.py`, `terminal/src/apps/customer-display/` | The customer display (3.4, 5.3): the counter POS pushes `POST /api/display/state` (`useDisplay()` in `apps/pos/usePos.js`: the sale cart, the payment dialog's bill, then "paid"); only displays whose `linked_device_id` is that POS get `display.state`. The idle screen is a **look** (`display_looks`: name, `is_default`, config = style, message, theme, QR, pictures as media library ids; looks register their media usage). One look is the venue's default; a display shows the look in its device config `look` (a `ref` to `display_looks`, also set from Settings → Customer display through `PUT /api/display/displays/{id}/look`) or the default. A look's change sends `display.settings` only to the displays showing it. Pictures are served from the library (`full` for image / slides, `card` for the logo). The POS's last state lives in memory | | `local_backend/routers/media.py`, `services/media.py`, `models/media.py`; manager `src/pages/media/` | The media library (5.1, 5.2): every picture and video once, by sha256, under `/app/data/media///` (the untouched original + `thumb` 200 / `card` 600 / `full` 1920 WebP for pictures, AVIF accepted; videos kept as uploaded). Served public by hash at `/api/media/file//` with year-long `immutable` caching (a different file is a different URL; byte ranges for video). The display name is only for people; files on disk are named by the backend. Whoever manages the menu, customer display, signage or menu tablets manages it. **What points at media has a `media_id` column and registers `register_usage(kind, fn)`** (products and categories in `routers/products.py`) so delete is refused (`media.in_use`) while it's used. APIs give `image` = `{id, name, thumb, card, full}` (`services.media.image_of`); a product's `image_url` is its card size. Manager: the Media page (batch upload, details) and `MediaField` (upload on the spot / pick from the library / "Name it after" with `latin()` from `@xenia/i18n`) for any form that takes a picture. The waiter fetches the menu's photos ahead (`services/photoCache.js`; PWA: workbox `xenia-media` cache-first) so they show offline. Upload limits: 20 MB pictures, 200 MB videos; every nginx config sets `client_max_body_size 250m` | -| `local_backend/routers/signage.py`, `models/signage.py`, `assets/builtin_media/` | Digital signage (5.4a): **playlists** (name, orientation, default transition) of **slides** (kind menu / image / video / text, position, duration, transition, video to its end, on / off, days / hours / dates window, `content` typed per kind in the router: extra fields refused, pictures and videos as media ids, walked by `media_ids()` for the library's usage check). A screen's device config: `playlist` (ref `signage_playlists`), `orientation`, `rotation`; `GET /api/signage/screen` gives it the playlist resolved (enabled slides, media addresses, a `version` hash); changes send `signage.changed` only to the screens playing that playlist. **Built-in pictures:** files in `assets/builtin_media/` are imported at start (`services.media.import_builtin`, `media.builtin`), listed as their own collection, never deleted or renamed. **Menu boards (5.4b):** `services/signage_menu.py` resolves a menu slide (all / whole categories incl. sub-categories, live / single products, minus exclusions; the board's own `category_order` / `product_order`; prices from `pos_cart.unit_prices` of its sales point; customer-facing names); every request that changes the menu (`cloud_sync.menu_changed` paths) also sends `signage.changed` to the screens with a menu board (`main._signage_menu_changed`). **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. The menu board editor (5.6b, `MenuEditor.jsx`) orders what the server resolved: `boardOrder()` writes the whole shown order into `category_order` / `product_order`; widgets: `WidgetsEditor.jsx`. **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/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. The menu board editor (5.6b, `MenuEditor.jsx`) orders what the server resolved: `boardOrder()` writes the whole shown order into `category_order` / `product_order`; widgets: `WidgetsEditor.jsx`. Tabs (5.6c): Screens (`ScreensTab`: playlist, schedule, shape, rotation through `PUT /api/signage/screens/{id}`), Schedules (`SchedulesTab`), Message and weather (`SignageSettingsTab`: `PUT /api/signage/message`, the town search and `PUT /api/signage/weather/place`). **Widgets (5.4c):** `Widget` on text and menu slides (logo, name, date, clock, message, QR, weather; position, size); the screen also gets `venue` = name, the message of the day (`signage.message`, `PUT /api/signage/message` tells every screen) and the weather (`services/weather.py`: Open-Meteo, no key, every 30 min by the signage worker, kept in memory; `null` when there is no place, no internet or it is older than 3 h, so the player hides the widget). **Schedules (5.4d):** `signage_schedules` (entries {playlist, days, hours that may pass midnight, dates, priority} + a fallback); a screen's `schedule` (ref) wins over its `playlist`; `services/signage_schedule.pick` chooses in venue time (highest priority, then dates > days > hours, then the later entry); `/screen` then carries the schedule (with the venue's time zone) and every playlist in it so the player switches offline; `schedule_worker` (30 s) tells a screen when its pick changes. **The player (5.5a):** `terminal/src/apps/signage/` (the logic and slides moved to `packages/signage` in 5.6a; the schedule pick ported from Python with the same test cases, slide windows, next slide, frame rotation; `SignageApp.jsx`: the last `/screen` answer in localStorage, every picture / video (≤ 120 MB) as an in-memory blob copy, so it plays with the server down; reads again on `signage.changed`, `device.updated`, a reconnect and every 5 min). Signage is in `QUIET_OFFLINE` (`apps/registry.js`): no offline banner, a small mark. The terminal is plain HTTP (no service worker), so a TV that restarts while the server is down waits for it. Menu boards page by themselves (`boardPages`: rows that fit from the frame's shape, text size, photos / descriptions, title and widget bars; `page_size` overrides) and go round while the slide lasts (at least its pages × `page_seconds`); widgets in `Slides.jsx` (`Widgets`), a widget with nothing to show (no weather, no message) is left out | | `local_backend/routers/phone.py`, `services/caller_id.py` | Caller ID (3.5): the UCM's `GET /api/phone/call-event` is public but **LAN-only in the proxy** (the same `location ~ ^/api/(devices/pair-request|phone/call-event)` block in `nginx-proxy/nginx.conf` and `install.sh`) with an optional `caller_id.secret`; calls are logged (`phone_calls`), matched on the server (Greek number rules) and published as `call_incoming` to users with `caller_id.use` and to the counter screens. There is no public call socket any more | | `local_backend/routers/ws.py` | Real-time event stream (seq + cursor replay) | | `waiter_pwa/src/config/server.js` | **Where the backend is**: active venue, `apiBase()`, `wsUrl()`, `assetUrl()`, `storageKey()`, `dbName()`, `deliveryMode()` | diff --git a/manager_dashboard/src/pages/signage/SchedulesTab.jsx b/manager_dashboard/src/pages/signage/SchedulesTab.jsx new file mode 100644 index 0000000..16ca8b6 --- /dev/null +++ b/manager_dashboard/src/pages/signage/SchedulesTab.jsx @@ -0,0 +1,136 @@ +// Signage → Schedules (plan step 5.6c): which playlist plays when. A schedule is lines (a playlist +// on some days, between some hours, between some dates, with a priority) and a playlist for the rest +// of the time. When two lines match, the higher priority wins, then the more specific (dates, then +// days, then hours). A TV with a schedule switches by itself, also while the server is down. +import { useCallback, useEffect, useMemo, useState } from 'react' +import toast from 'react-hot-toast' +import { Plus, Trash2 } from 'lucide-react' +import { errorMessage } from '@xenia/api' +import { useTranslation } from '@xenia/i18n' +import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, Spinner } from '@xenia/ui' +import * as api from './signageApi' + +const emptyEntry = playlistId => ({ playlist_id: playlistId, days: [], time_from: null, time_to: null, date_from: null, date_to: null, priority: 0 }) + +export default function SchedulesTab() { + const { t } = useTranslation('manager') + const [list, setList] = useState(null) + const [playlists, setPlaylists] = useState([]) + const [current, setCurrent] = useState(null) + const [draft, setDraft] = useState(null) + const [busy, setBusy] = useState(false) + const [confirm, setConfirm] = useState(false) + + const load = useCallback(async (pick) => { + try { + const [l, p] = await Promise.all([api.listSchedules(), api.listPlaylists()]) + setList(l); setPlaylists(p) + const s = l.find(x => x.id === pick) || (pick === undefined ? l[0] : null) + setCurrent(s?.id ?? null) + setDraft(s ? { name: s.name, fallback_playlist_id: s.fallback_playlist_id, entries: s.entries } : null) + } catch (err) { toast.error(errorMessage(err, t)) } + }, [t]) + useEffect(() => { load() }, [load]) + const saved = list?.find(x => x.id === current) + const dirty = useMemo(() => !!(saved && draft && JSON.stringify({ name: saved.name, fallback_playlist_id: saved.fallback_playlist_id, entries: saved.entries }) !== JSON.stringify(draft)), [saved, draft]) + if (!list) return
+ + const act = async (fn, done, pick = current) => { + setBusy(true) + try { const r = await fn(); toast.success(done); await load(r?.id ?? pick) } catch (err) { toast.error(errorMessage(err, t)) } + setBusy(false) + } + const plOptions = playlists.map(p => ({ value: String(p.id), label: p.name })) + const setEntry = (i, patch) => setDraft(d => ({ ...d, entries: d.entries.map((e, j) => (j === i ? { ...e, ...patch } : e)) })) + const toggleDay = (i, day) => setEntry(i, { days: draft.entries[i].days.includes(day) ? draft.entries[i].days.filter(x => x !== day) : [...draft.entries[i].days, day].sort() }) + + return ( +
+ + + {!draft ? : ( +
+
+ + setDraft(d => ({ ...d, name: e.target.value }))} data-testid="signage-schedule-name" /> + + setConfirm(true)} data-testid="signage-schedule-delete"> +
+

{t('signage.schedules.how')}

+
    + {draft.entries.map((e, i) => ( +
  1. +
    + + setEntry(i, { priority: Math.min(100, Number(ev.target.value.replace(/\D/g, '')) || 0) })} data-testid="signage-entry-priority" /> + + setDraft(d => ({ ...d, entries: d.entries.filter((_, j) => j !== i) }))}> +
    +
    + {[0, 1, 2, 3, 4, 5, 6].map(d => ( + + ))} +
    +
    + setEntry(i, { time_from: ev.target.value || null })} data-testid="signage-entry-from" /> + setEntry(i, { time_to: ev.target.value || null })} data-testid="signage-entry-to" /> + setEntry(i, { date_from: ev.target.value || null })} /> + setEntry(i, { date_to: ev.target.value || null })} /> +
    +
  2. + ))} +
+ + + save(s.id, { playlist_id: e.target.value ? Number(e.target.value) : null })} + options={[{ value: '', label: t('signage.screens.nothing') }, ...playlists.map(p => ({ value: String(p.id), label: p.name }))]} /> + + + save(s.id, { orientation: e.target.value })} data-testid="signage-screen-orientation" + options={['landscape', 'portrait'].map(o => ({ value: o, label: t(`signage.orientations.${o}`) }))} /> + + + setMessage(e.target.value)} className="flex-1" aria-label={t('signage.settings.message')} data-testid="signage-message" /> + +
+ + +
+

{t('signage.settings.weather')}

+

+ {status?.place ? ( +
+ {status.place.name} · {t(`signage.settings.units.${status.place.units}`)} + {w ? {t('signage.settings.now', { temp: Math.round(w.temperature), unit: status.place.units === 'fahrenheit' ? '°F' : '°C', at: status.fetched_at ? formatDateTime(new Date(status.fetched_at * 1000)) : '' })} + : {t(status.error ? 'signage.settings.noForecast' : 'signage.settings.waiting')}} +
+ + +
+
+ ) :

{t('signage.settings.noPlace')}

} +
+
+ + setQ(e.target.value)} placeholder={t('signage.settings.townPlaceholder')} data-testid="signage-weather-search" /> + + +