diff --git a/docs/README.md b/docs/README.md index 263160c..7619024 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. **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`. **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/MenuEditor.jsx b/manager_dashboard/src/pages/signage/MenuEditor.jsx index 6b96830..80bb897 100644 --- a/manager_dashboard/src/pages/signage/MenuEditor.jsx +++ b/manager_dashboard/src/pages/signage/MenuEditor.jsx @@ -1,27 +1,184 @@ -// 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' +// A menu board's settings (plan step 5.6b): which products (everything, whole categories that stay +// up to date, single products, minus hidden ones), the board's own order of categories and products +// (arrows on what the board shows), badges, prices of a sales point, photos / descriptions, sold-out +// style, columns and pages, the look, and the widgets. `slide.menu` is the server's resolution of +// the draft (PlaylistEditor asks for it as you change things). +import { useEffect, useMemo, useState } from 'react' +import { ArrowDown, ArrowUp, EyeOff, X } from 'lucide-react' +import { SALES_POINTS } from '@xenia/access' +import { useFormat, useTranslation } from '@xenia/i18n' +import { Field, IconButton, Input, Select, Switch } from '@xenia/ui' +import client from '../../api/client' +import { BADGES, boardOrder, moveGroup, moveItem, toggled } from './signageLogic' import { BackgroundField, ColourField } from './SignageFields' import { TextLook } from './SlideEditor' +import WidgetsEditor from './WidgetsEditor' export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [] }) { const { t } = useTranslation('manager') + const { formatMoney } = useFormat() const c = slide.content || {} const setC = patch => onChange({ ...slide, content: { ...c, ...patch } }) + const [cats, setCats] = useState([]) + const [products, setProducts] = useState([]) + const [q, setQ] = useState('') + useEffect(() => { + client.get('/api/products/categories').then(r => setCats(r.data)).catch(() => {}) + client.get('/api/products/').then(r => setProducts(r.data.filter(p => p.lifecycle_status === 'active' && !p.is_service_item))).catch(() => {}) + }, []) + const byId = useMemo(() => Object.fromEntries(products.map(p => [p.id, p])), [products]) + const top = cats.filter(x => !x.parent_id) + const subsOf = id => cats.filter(x => x.parent_id === id) + const groups = slide.menu?.groups || [] + const shown = new Set(groups.flatMap(g => g.items.map(i => i.id))) + const found = q.trim().length < 1 ? [] : products.filter(p => p.name.toLowerCase().includes(q.trim().toLowerCase()) && !shown.has(p.id)).slice(0, 8) + const reorder = next => setC(boardOrder(next)) + const badges = c.badges || {} + return ( -
+
setC({ title: e.target.value })} data-testid="signage-menu-title" /> -
- - setC({ select: e.target.value })} aria-label={t('signage.menu.what')} data-testid="signage-menu-select" + options={[{ value: 'all', label: t('signage.menu.all') }, { value: 'custom', label: t('signage.menu.custom') }]} /> + {c.select !== 'all' && <> +
+ {t('signage.menu.categories')} +

{t('signage.menu.categoriesHint')}

+
+ {top.flatMap(cat => [cat, ...subsOf(cat.id)]).map(cat => { + const on = (c.category_ids || []).includes(cat.id) + return ( + + ) + })} +
+
+
+ {t('signage.menu.products')} + {(c.product_ids || []).length > 0 && ( +
+ {(c.product_ids || []).map(id => ( + + {byId[id]?.name ?? `#${id}`} + setC({ product_ids: (c.product_ids || []).filter(x => x !== id) })}> + + ))} +
+ )} + setQ(e.target.value)} placeholder={t('signage.menu.searchProduct')} aria-label={t('signage.menu.searchProduct')} data-testid="signage-menu-search" /> + {found.length > 0 && ( +
    + {found.map(p => ( +
  • + +
  • + ))} +
+ )} +
+ } + {(c.exclude_ids || []).length > 0 && ( +
+ {t('signage.menu.hidden')} +
+ {(c.exclude_ids || []).map(id => ( + + ))} +
+
+ )} + + + {/* the board's own order, badges, hiding */} +
+ {t('signage.menu.onTheBoard', { count: slide.menu?.count ?? 0 })} +

{t('signage.menu.orderHint')}

+
+ {groups.map((g, gi) => ( +
+ {g.category && ( +
+ {g.category.name} + reorder(moveGroup(groups, gi, -1))} data-testid="signage-group-up"> + reorder(moveGroup(groups, gi, 1))}> +
+ )} +
    + {g.items.map((it, ii) => ( +
  • + {it.name} + {it.price != null && {formatMoney(it.price)}} + setC({ sales_point: e.target.value || null })} data-testid="signage-menu-prices" + options={[{ value: '', label: t('signage.menu.noPrices') }, ...SALES_POINTS.map(sp => ({ value: sp, label: t(`common:salesPoints.${sp}.name`) }))]} /> + + setC({ columns: Number(e.target.value) })} data-testid="signage-columns" + options={[1, 2, 3].map(n => ({ value: String(n), label: String(n) }))} /> + + + { const n = Number(e.target.value.replace(/\D/g, '')); setC({ page_size: n ? Math.min(60, Math.max(3, n)) : null }) }} /> + + + setC({ page_seconds: Math.min(120, Math.max(3, Number(e.target.value.replace(/\D/g, '')) || 3)) })} /> + +
+ +
setC({ accent_colour: v })} testid="signage-accent" />
setC({ background })} media={media} onMedia={onMedia} misfit={misfit.includes(c.background?.media_id)} /> + setC({ widgets })} media={media} onMedia={onMedia} />
) } diff --git a/manager_dashboard/src/pages/signage/PlaylistEditor.jsx b/manager_dashboard/src/pages/signage/PlaylistEditor.jsx index dc7aab1..305d250 100644 --- a/manager_dashboard/src/pages/signage/PlaylistEditor.jsx +++ b/manager_dashboard/src/pages/signage/PlaylistEditor.jsx @@ -158,8 +158,11 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) { {/* the slide being edited */}
{draft ? <> - + {/* the preview stays in view while the settings below scroll */} +
+ +
setMedia(m => ({ ...m, [String(item.id)]: mediaEntry(item) }))} misfit={draftBad} />
diff --git a/manager_dashboard/src/pages/signage/SlideEditor.jsx b/manager_dashboard/src/pages/signage/SlideEditor.jsx index ade1664..86fc880 100644 --- a/manager_dashboard/src/pages/signage/SlideEditor.jsx +++ b/manager_dashboard/src/pages/signage/SlideEditor.jsx @@ -6,6 +6,7 @@ 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' +import WidgetsEditor from './WidgetsEditor' export default function SlideEditor({ slide, onChange, media, onMedia, misfit = [] }) { const { t } = useTranslation('manager') @@ -98,6 +99,7 @@ export default function SlideEditor({ slide, onChange, media, onMedia, misfit = setC({ background })} media={media} onMedia={onMedia} misfit={bad(c.background?.media_id)} /> + setC({ widgets })} media={media} onMedia={onMedia} />
)} diff --git a/manager_dashboard/src/pages/signage/WidgetsEditor.jsx b/manager_dashboard/src/pages/signage/WidgetsEditor.jsx new file mode 100644 index 0000000..f25385a --- /dev/null +++ b/manager_dashboard/src/pages/signage/WidgetsEditor.jsx @@ -0,0 +1,77 @@ +// The widgets of a text or menu slide (plan step 5.6b): logo, name, date, clock, message of the +// day, QR code, weather; each in a corner or a bar, small / medium / large, with its own options. +// Up to 10 (the server's limit). +import { Plus, Trash2 } from 'lucide-react' +import { useTranslation } from '@xenia/i18n' +import { Button, Field, IconButton, Input, Select, Switch } from '@xenia/ui' +import { MediaPick } from './SignageFields' +import { WIDGET_KINDS, WIDGET_POSITIONS } from './signageLogic' + +export default function WidgetsEditor({ widgets = [], onChange, media, onMedia }) { + const { t } = useTranslation('manager') + const set = (i, patch) => onChange(widgets.map((w, j) => (j === i ? { ...w, ...patch } : w))) + const add = kind => onChange([...widgets, { kind, position: kind === 'message' ? 'bottom-bar' : 'top-right', size: 'medium' }]) + return ( +
+ {t('signage.widgets.title')} + {widgets.length === 0 &&

{t('signage.widgets.none')}

} + {widgets.map((w, i) => ( +
+
+ {t(`signage.widgets.kinds.${w.kind}`)} + + set(i, { size: e.target.value })} + options={['small', 'medium', 'large'].map(s => ({ value: s, label: t(`signage.widgets.sizes.${s}`) }))} /> + + onChange(widgets.filter((_, j) => j !== i))} data-testid="signage-widget-remove"> +
+ {w.kind === 'logo' && ( + { onMedia(item); set(i, { media_id: item.id }) }} /> + )} + {w.kind === 'message' && ( + + set(i, { text: e.target.value || null })} data-testid="signage-widget-text" /> + + )} + {w.kind === 'date' && ( + set(i, { qr_target: e.target.value })} + options={['ordering', 'menu', 'custom'].map(q => ({ value: q, label: t(`display.qrTargets.${q}`) }))} /> + + {w.qr_target === 'custom' && ( + set(i, { qr_url: e.target.value || null })} /> + )} + set(i, { qr_caption: e.target.value || null })} /> +
+ )} + {w.kind === 'weather' && ( +
+