diff --git a/docs/README.md b/docs/README.md index b5f5d8f..ea5e1b5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -46,7 +46,7 @@ The manager calls the API **same-origin, with relative paths**. The waiter app r | `local_backend/services/online_reservations.py` | Table bookings from the online ordering app (phase 3S): stored as `Reservation` rows (`requested` → `pending` confirmed / `declined`; `arrived`, `cancelled`, `no_show`), food ordered ahead kept on the booking (`items_json`) and turned into an order **only at the fire time** (`fire_worker`, a connect_orders module worker; needs an open business day) or on early arrival. Every step mirrors the cloud status. The counter's Online → Bookings and `/api/connect/bookings/*` use it; the reservations router delegates online bookings to it | | `local_backend/services/table_qr.py`, `services/qr_orders.py` | The QR menu at the table (phase 3S): every active table has a random `qr_token`; the menu snapshot carries only its sha256 (`qr`), so the cloud can check a code but never make one. A new code (rotate) kills the printed one at the next push (`/api/tables` and `/api/connect/qr` are in `MENU_PATHS`). A QR order with a valid table goes straight onto the table's open order (or a new one), to the kitchen, with a `qr_order` message to the table's waiters; the audit row `QR_ORDER` (note = the cloud ref) keeps repeats out. Manager page `/online/qr` | | `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`, `terminal/src/apps/customer-display/` | The customer display (3.4): 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 the venue's design (`customer_display.idle`: name, logo, both, blank, image, slideshow, QR, a line of text, dark/light), images in `/app/data/display_media`, served by name at `/api/display/media/{name}` (public, LAN, random names). 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///` (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/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) | @@ -200,7 +200,7 @@ An app makes one client with `createApiClient({ axios, baseURL, getToken, getDev - A screen with sign-in `none` (customer display) receives **every** broadcast event; send what is meant for one screen with `device_ids=[…]` (the customer display's `display.state` goes only to the displays linked to that POS) and what is meant for a role with `user_ids=[…]` plus the screens that need it (`call_incoming`: users with `caller_id.use` + the counter screens). - A device app may only reach routes of modules in its `DeviceApp.scope`. When an app must call another module's route, add one pattern for it (the POS has `customer_display.state`), never a wildcard. - Events are stored and **replayed on reconnect** (24 h). A screen that reacts with something visible must ignore stale ones: check the event's time (`call_incoming`: older than a minute → no popup) or let it expire (`display.state` "paid" → idle after 12 s); state a screen needs after a restart comes from a GET (`/api/display/state`, the KDS list), not from replay. -- What the device itself shows comes from its device config (`ConfigField`s) or a venue setting; the venue-wide look of a screen (the customer display's idle screen) is a setting with its own manager page, not free JSON in the device. +- What the device itself shows comes from its device config (`ConfigField`s) or a venue setting. Designs a venue makes for its screens (the customer display's looks, 5.3; later signage playlists) are their own records with a manager page, and a device picks one with a `ref` config field (none = the venue's default), never free JSON in the device. **CS-15. Support access is a challenge code, never a password** (branch `platform-v2`, D-16). There is no master account. A site's `SUPPORT_SECRET` (env only) comes from `tools/support_code.py --site-secret `, derived from the builder's master key in `%USERPROFILE%\.xenia\support_master_key.txt` (outside the repo, back it up). The derivation lives in `local_backend/core/support_codes.py` (stdlib only, the tool loads it by path) and is re-implemented for the e2e suites in `tests/e2e/lib/support.mjs`; `tests/test_support.py` pins a vector both must match. The e2e backends log in through support access (`login()` in `lib/proc.mjs`). diff --git a/tests/e2e/manager.mjs b/tests/e2e/manager.mjs index f80dc51..cd9e54d 100644 --- a/tests/e2e/manager.mjs +++ b/tests/e2e/manager.mjs @@ -614,10 +614,10 @@ try { await page.getByTestId('display-save').click() let idleCfg = null for (let i = 0; i < 30 && idleCfg?.style !== 'qr'; i++) { - idleCfg = (await api('GET', '/api/display/settings', { token: boss })).idle + idleCfg = (await api('GET', '/api/display/looks', { token: boss })).find(l => l.is_default)?.config if (idleCfg?.style !== 'qr') await sleep(100) } - r.check('settings: customer display → a QR code to the online ordering, with a caption', idleCfg?.style === 'qr' + r.check('settings: customer display → the default look: a QR code to the online ordering, with a caption', idleCfg?.style === 'qr' && idleCfg.qr_target === 'ordering' && idleCfg.qr_caption === 'Order online', JSON.stringify(idleCfg)) await page.screenshot({ path: path.join(OUT, 'manager-display-settings.png'), fullPage: true }) diff --git a/tests/e2e/media.mjs b/tests/e2e/media.mjs index 4e778f5..85f217d 100644 --- a/tests/e2e/media.mjs +++ b/tests/e2e/media.mjs @@ -156,6 +156,32 @@ try { (await page.getByTestId('media-used-by').innerText().catch(() => '')).includes(p1.name) && await page.getByTestId('media-delete').isDisabled()) await page.keyboard.press('Escape') + // ── 5.3: the customer display's looks pick their pictures from the library ── + await api('PUT', '/api/platform/modules/customer_display', { token: boss, body: { enabled: true } }).catch(() => {}) + await page.goto(`${MANAGER}/settings`) + await page.getByText('Customer display', { exact: true }).click() + await page.getByTestId('display-look-new').click({ timeout: 15_000 }) + await page.getByTestId('display-look-new-name').fill('Promo') + await page.getByTestId('display-look-create').click() + await page.locator('[data-testid="display-look"][data-name="Promo"][aria-selected="true"]').waitFor({ timeout: 10_000 }) + await page.getByTestId('display-style-slideshow').click() + await page.getByTestId('display-slides-add').click() + const picker = page.getByTestId('media-picker') + for (const i of [0, 1, 2]) await picker.getByTestId('media-item').nth(i).click() + await page.getByTestId('media-picker-add').click() + r.check('5.3: a new look "Promo": three pictures picked at once from the library, in order', + await page.getByTestId('display-slide-item').count() === 3) + await page.getByTestId('display-save').click() + await sleep(1000) + const looks = await api('GET', '/api/display/looks', { token: boss }) + const promo = looks.find(l => l.name === 'Promo') + r.check('5.3: saved: the look is a slideshow of three library pictures; the default look is unchanged', + promo?.config.style === 'slideshow' && promo.config.slides.length === 3 && promo.preview.slide_urls.length === 3 + && looks.find(l => l.is_default)?.name === 'Main', JSON.stringify(looks.map(l => [l.name, l.config.style, l.config.slides]))) + await page.screenshot({ path: path.join(OUT, 'media-display-looks.png'), fullPage: true }) + const usedSlide = await api('DELETE', `/api/media/${promo.config.slides[0]}`, { token: boss }).then(() => 'deleted', e => e.message) + r.check('5.3: a picture in a look cannot be deleted from the library', usedSlide.includes('409'), usedSlide) + // ── The waiter's phone: photos fetched ahead, shown offline ───────────────── const phone = await browser.newContext({ viewport: { width: 393, height: 852 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true }) const w = await phone.newPage() diff --git a/tests/e2e/terminal.mjs b/tests/e2e/terminal.mjs index 8a7bc4a..eae813a 100644 --- a/tests/e2e/terminal.mjs +++ b/tests/e2e/terminal.mjs @@ -15,8 +15,9 @@ import http from 'node:http' import net from 'node:net' import path from 'node:path' +import { execFileSync } from 'node:child_process' import { chromium } from 'playwright' -import { BROWSER_CHANNEL, OUT, reporter, sleep } from './lib/env.mjs' +import { BROWSER_CHANNEL, OUT, PYTHON, reporter, sleep, waitFor } from './lib/env.mjs' import { startBackend, startTerminalVite } from './lib/proc.mjs' import { supportLogin } from './lib/support.mjs' @@ -715,24 +716,36 @@ try { r.check('3.4: paid → "Thank you" with the change', await shown(myDisplay, 'display-paid', 5000) && (await myDisplay.getByTestId('display-paid').textContent()).includes('Thank you')) await myDisplay.screenshot({ path: path.join(OUT, 'terminal-display-paid.png') }) - // the venue's choice: a QR code to its online ordering, then a slideshow of its photos - await api('PUT', '/api/display/settings', { token: boss, body: { style: 'qr', qr_target: 'ordering', qr_caption: 'Order online', theme: 'light' } }) - r.check('3.4: the idle screen follows the venue\'s settings at once (a QR code to its ordering, light)', + // the venue's choice: a QR code to its online ordering, then a slideshow of its photos (a look; 5.3) + const main = (await api('GET', '/api/display/looks', { token: boss })).find(l => l.is_default) + await api('PUT', `/api/display/looks/${main.id}`, { token: boss, body: { config: { style: 'qr', qr_target: 'ordering', qr_caption: 'Order online', theme: 'light' } } }) + r.check('3.4: the idle screen follows the look at once (a QR code to the venue ordering, light)', await myDisplay.waitForFunction(() => document.querySelector('[data-testid="display-qr"]'), null, { timeout: 20_000 }).then(() => true).catch(() => false) && (await myDisplay.getByTestId('display-qr').getAttribute('data-link')).includes('/order/') && await myDisplay.evaluate(() => document.documentElement.dataset.theme) === 'light') await myDisplay.screenshot({ path: path.join(OUT, 'terminal-display-qr.png') }) - const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==', 'base64') - const uploadImg = async () => { + const uploadImg = async (rgb) => { + const jpg = execFileSync(PYTHON, ['-c', `import io,sys;from PIL import Image;b=io.BytesIO();Image.new('RGB',(1280,720),(${rgb})).save(b,'JPEG');sys.stdout.buffer.write(b.getvalue())`]) const form = new FormData() - form.append('file', new Blob([png], { type: 'image/png' }), 'promo.png') - const res = await fetch(`${backend.url}/api/display/media`, { method: 'POST', headers: { authorization: `Bearer ${boss}` }, body: form }) + form.append('file', new Blob([jpg], { type: 'image/jpeg' }), 'promo.jpg') + const res = await fetch(`${backend.url}/api/media`, { method: 'POST', headers: { authorization: `Bearer ${boss}` }, body: form }) return res.json() } - const [a, b] = [await uploadImg(), await uploadImg()] - await api('PUT', '/api/display/settings', { token: boss, body: { style: 'slideshow', slides: [a.name, b.name], slide_seconds: 3, message: 'Today: 2 for 1' } }) - r.check('3.4: …or a slideshow of its photos, with its line of text', + const [a, b, c] = [await uploadImg('200,40,40'), await uploadImg('40,200,40'), await uploadImg('40,40,200')] + await api('PUT', `/api/display/looks/${main.id}`, { token: boss, body: { config: { style: 'slideshow', slides: [a.id, b.id], slide_seconds: 3, message: 'Today: 2 for 1' } } }) + r.check('3.4: …or a slideshow of its photos (from the media library), with its line of text', await myDisplay.waitForFunction(() => document.querySelectorAll('[data-testid="display-slide"]').length === 2, null, { timeout: 20_000 }).then(() => true).catch(() => false) && (await myDisplay.getByTestId('display-message').textContent()) === 'Today: 2 for 1') + // 5.3: the other display gets its own look, another slideshow + const promo = await api('POST', '/api/display/looks', { token: boss, body: { name: 'Promo', config: { style: 'slideshow', slides: [c.id], slide_seconds: 5 } } }) + const otherId = (await api('GET', '/api/display/displays', { token: boss })).find(d => d.name === 'Display elsewhere').id + await api('PUT', `/api/display/displays/${otherId}/look`, { token: boss, body: { look_id: promo.id } }) + const slidesOf = page => page.evaluate(() => [...document.querySelectorAll('[data-testid="display-slide"]')].map(e => e.getAttribute('src') || e.style.backgroundImage || '')) + const otherSlides = await waitFor(async () => { const s = await slidesOf(otherDisplay); return s.length === 1 ? s : null }, 20_000, 300) + const mySlides = await slidesOf(myDisplay) + r.check('5.3: two displays, two slideshows from the library (each display its own look)', + !!otherSlides && otherSlides[0].includes(c.sha256) && mySlides.length === 2 && mySlides.every(u => !u.includes(c.sha256)), + JSON.stringify({ mine: mySlides.map(u => u.slice(-40)), other: otherSlides?.map(u => u.slice(-40)) })) + await otherDisplay.screenshot({ path: path.join(OUT, 'terminal-display-promo.png') }) // ── 3.5: caller ID at the counter ──────────────────────────────────────── await api('PUT', '/api/platform/modules/caller_id', { token: boss, body: { enabled: true } }).catch(() => {}) await api('POST', '/api/customers/', { token: boss, body: { name: 'Kostas Regular', phone: '+30 697 555 1234', notes: 'Always extra tzatziki' } })