feat: the table map (platform-v2 step 6.8, D-31)
- floor_plans / floor_items (0035), tables' plan_id + width/height/rotation/shape; /api/floor-plans (set-up, catalog.tables.manage, floor_plans.changed) and /api/floor-plans/live (each table's state, guests, waiters, time; zone rule) - @xenia/floorplan: the drawing (Floor, Item, TableShape, FloorView) and its geometry (grid snap in whole cells, outlines, chairs), tested - manager: Management -> Tables -> Floor plans (editor: drag, grid, irregular floor, walls/bar/labels/areas, background picture), Tables page List / Map - counter POS: Tables List / Map; waiter: Map mode, the list stays the default - tests: test_floor_plans.py, floor + geometry unit tests, manager/waiter/terminal e2e Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@xenia/floorplan",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "The table map (plan step 6.8, D-31): floor plans drawn the same in the waiter app, the counter POS and the manager (live map and editor), and their pure geometry (grid snap, outlines, chairs).",
|
||||
"main": "src/index.js",
|
||||
"exports": {
|
||||
".": "./src/index.js",
|
||||
"./geometry": "./src/geometry.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@xenia/i18n": "^0.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --test \"tests/*.test.mjs\""
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^19.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// The live table map (plan step 6.8, D-31), the same in the waiter app, the counter POS and the
|
||||
// manager's Tables page. `data` is GET /api/floor-plans/live ({plans, tables}); the app reloads it
|
||||
// on its live events. A tab per floor plan (of the zone, when one is chosen), zoom buttons, and
|
||||
// the tables not on any plan as buttons under it. A tap on a table calls onPick(table).
|
||||
// Styles are inline with @xenia/ui tokens, so it fits the apps with and without Tailwind.
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { plansFor, splitTables, toneOf, TONES } from './geometry.js'
|
||||
import { Floor, Item, TableShape } from './Shapes.jsx'
|
||||
|
||||
const ZOOMS = [0.5, 0.75, 1, 1.25, 1.5, 2, 3]
|
||||
|
||||
function useMinuteClock() {
|
||||
const [now, setNow] = useState(() => Date.now())
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setNow(Date.now()), 30_000)
|
||||
return () => clearInterval(id)
|
||||
}, [])
|
||||
return now
|
||||
}
|
||||
|
||||
const btn = active => ({
|
||||
padding: '6px 12px', borderRadius: 999, border: `1px solid ${active ? 'var(--x-accent)' : 'var(--x-line)'}`,
|
||||
background: active ? 'var(--x-accent-soft)' : 'var(--x-surface)', color: active ? 'var(--x-accent-ink)' : 'var(--x-ink-2)',
|
||||
fontWeight: 600, fontSize: 13, cursor: 'pointer', whiteSpace: 'nowrap',
|
||||
})
|
||||
const round = { width: 36, height: 36, borderRadius: 999, border: '1px solid var(--x-line)', background: 'var(--x-surface)', color: 'var(--x-ink)', fontSize: 18, fontWeight: 700, cursor: 'pointer' }
|
||||
|
||||
export function FloorView({ data, zone = null, onPick, mediaBase = '', height = '100%' }) {
|
||||
const { t } = useTranslation('common')
|
||||
const now = useMinuteClock()
|
||||
const plans = useMemo(() => plansFor(data?.plans ?? [], zone), [data, zone])
|
||||
const [chosen, setChosen] = useState(null)
|
||||
const [zoom, setZoom] = useState(null) // null = fit the width
|
||||
const plan = plans.find(p => p.id === chosen) ?? plans[0] ?? null
|
||||
const { placed, unplaced } = useMemo(() => splitTables(data?.tables ?? [], plan?.id ?? -1, zone), [data, plan, zone])
|
||||
|
||||
if (!data) return null
|
||||
if (!plan) {
|
||||
return (
|
||||
<div style={{ padding: 24, textAlign: 'center', color: 'var(--x-ink-2)' }} data-testid="floor-none">
|
||||
<p style={{ fontWeight: 700, color: 'var(--x-ink)', marginBottom: 6 }}>{t('floorMap.none')}</p>
|
||||
<p style={{ fontSize: 13 }}>{t('floorMap.noneHint')}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const step = d => setZoom(z => {
|
||||
const cur = z ?? 1
|
||||
const i = ZOOMS.findIndex(v => v >= cur - 0.001)
|
||||
return ZOOMS[Math.min(ZOOMS.length - 1, Math.max(0, (i < 0 ? ZOOMS.length - 1 : i) + d))]
|
||||
})
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, height, minHeight: 0 }} data-testid="floor-view" data-plan={plan.id}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||||
{plans.length > 1 && plans.map(p => (
|
||||
<button key={p.id} type="button" style={btn(p.id === plan.id)} onClick={() => setChosen(p.id)} aria-pressed={p.id === plan.id} data-testid="floor-plan-tab">{p.name}</button>
|
||||
))}
|
||||
<span style={{ flex: 1 }} />
|
||||
<button type="button" style={round} onClick={() => step(-1)} aria-label={t('floorMap.zoomOut')}>−</button>
|
||||
<button type="button" style={{ ...round, width: 'auto', padding: '0 12px', fontSize: 13 }} onClick={() => setZoom(null)}>{t('floorMap.fit')}</button>
|
||||
<button type="button" style={round} onClick={() => step(1)} aria-label={t('floorMap.zoomIn')}>+</button>
|
||||
</div>
|
||||
<div style={{ flex: 1, minHeight: 0, overflow: 'auto', borderRadius: 12, background: 'var(--x-canvas)', border: '1px solid var(--x-line)' }}>
|
||||
<svg viewBox={`0 0 ${plan.width} ${plan.height}`} role="img" aria-label={plan.name}
|
||||
style={{ display: 'block', width: zoom ? `${plan.width * zoom}px` : '100%', height: 'auto', touchAction: 'pan-x pan-y pinch-zoom' }}>
|
||||
<Floor plan={plan} mediaBase={mediaBase} />
|
||||
{plan.items.map(i => <Item key={i.id} item={i} label={t('floorMap.bar')} />)}
|
||||
{placed.map(table => (
|
||||
<TableShape key={table.id} table={table} now={now} role="button" tabIndex={0} style={{ cursor: 'pointer' }}
|
||||
aria-label={`${table.name}: ${t(`floorMap.state.${toneOf(table)}`)}`} data-testid="floor-table"
|
||||
onClick={() => onPick?.(table)} onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onPick?.(table) } }} />
|
||||
))}
|
||||
</svg>
|
||||
</div>
|
||||
<Legend t={t} />
|
||||
{unplaced.length > 0 && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap', fontSize: 12, color: 'var(--x-ink-2)' }} data-testid="floor-unplaced">
|
||||
<span>{t('floorMap.notOnMap')}</span>
|
||||
{unplaced.map(table => {
|
||||
const tone = TONES[toneOf(table)]
|
||||
return (
|
||||
<button key={table.id} type="button" onClick={() => onPick?.(table)} data-table={table.id}
|
||||
style={{ padding: '4px 10px', borderRadius: 8, border: `1.5px solid ${tone.stroke}`, background: tone.fill, color: tone.ink, fontWeight: 600, cursor: 'pointer' }}>
|
||||
{table.name}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Legend({ t }) {
|
||||
return (
|
||||
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', fontSize: 12, color: 'var(--x-ink-2)' }}>
|
||||
{['free', 'mine', 'open', 'paid', 'reserved'].map(k => (
|
||||
<span key={k} style={{ display: 'inline-flex', alignItems: 'center', gap: 5 }}>
|
||||
<span style={{ width: 12, height: 12, borderRadius: 4, background: TONES[k].fill, border: `2px solid ${TONES[k].stroke}` }} />
|
||||
{t(`floorMap.state.${k}`)}
|
||||
</span>
|
||||
))}
|
||||
<span>{t('floorMap.legendGuests')}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// The pieces of a floor plan as SVG (plan step 6.8): the floor (outline, grid, background
|
||||
// picture), the walls / bar / labels / areas, and a table with its chairs and what it shows.
|
||||
// Colours are @xenia/ui tokens (CSS variables), so the same drawing works in every app.
|
||||
import { chairs, durationText, outlineOf, peopleText, pointsAttr, TONES, toneOf } from './geometry.js'
|
||||
|
||||
/** The floor: background picture, the floor's shape, and the grid (when asked). */
|
||||
export function Floor({ plan, showGrid = false, mediaBase = '' }) {
|
||||
const pts = pointsAttr(outlineOf(plan))
|
||||
const g = plan.grid_size
|
||||
const clip = `floor-clip-${plan.id ?? 'new'}`
|
||||
return (
|
||||
<g>
|
||||
<defs>
|
||||
<clipPath id={clip}><polygon points={pts} /></clipPath>
|
||||
{showGrid && g > 0 && (
|
||||
<pattern id={`${clip}-grid`} width={g} height={g} patternUnits="userSpaceOnUse">
|
||||
<path d={`M ${g} 0 L 0 0 0 ${g}`} fill="none" stroke="var(--x-line)" strokeWidth="1" />
|
||||
</pattern>
|
||||
)}
|
||||
</defs>
|
||||
<polygon points={pts} fill="var(--x-surface)" stroke="var(--x-line-strong)" strokeWidth="3" />
|
||||
{plan.background?.full && (
|
||||
<image href={`${mediaBase}${plan.background.full}`} x="0" y="0" width={plan.width} height={plan.height}
|
||||
preserveAspectRatio="xMidYMid slice" opacity={plan.background_opacity ?? 0.6} clipPath={`url(#${clip})`} />
|
||||
)}
|
||||
{showGrid && g > 0 && <rect x="0" y="0" width={plan.width} height={plan.height} fill={`url(#${clip}-grid)`} clipPath={`url(#${clip})`} pointerEvents="none" />}
|
||||
</g>
|
||||
)
|
||||
}
|
||||
|
||||
const ITEM_LOOK = {
|
||||
wall: { fill: 'var(--x-ink-2)', stroke: 'none' },
|
||||
bar: { fill: 'var(--x-surface-3)', stroke: 'var(--x-ink-3)' },
|
||||
label: { fill: 'none', stroke: 'none' },
|
||||
area: { fill: 'var(--x-surface-2)', stroke: 'var(--x-line-strong)', dash: '8 6' },
|
||||
}
|
||||
|
||||
/** A wall, the bar, a label or an area. */
|
||||
export function Item({ item, selected = false, label, ...rest }) {
|
||||
const look = ITEM_LOOK[item.kind] ?? ITEM_LOOK.area
|
||||
const w = item.width
|
||||
const h = item.height
|
||||
const text = item.text || (item.kind === 'bar' ? label : '')
|
||||
return (
|
||||
<g transform={`translate(${item.x} ${item.y}) rotate(${item.rotation || 0})`} {...rest}>
|
||||
<rect x={-w / 2} y={-h / 2} width={w} height={h} rx={item.kind === 'wall' ? 2 : 8}
|
||||
fill={look.fill} stroke={selected ? 'var(--x-accent)' : look.stroke} strokeWidth={selected ? 4 : 2} strokeDasharray={selected ? undefined : look.dash} />
|
||||
{item.kind === 'label' && selected && <rect x={-w / 2} y={-h / 2} width={w} height={h} fill="none" stroke="var(--x-accent)" strokeWidth="2" strokeDasharray="6 4" />}
|
||||
{text && (
|
||||
<text x="0" y="0" textAnchor="middle" dominantBaseline="central" fill="var(--x-ink-2)" pointerEvents="none"
|
||||
fontSize={Math.max(12, Math.min(28, h * 0.5, (w / Math.max(text.length, 1)) * 1.6))} fontWeight="600"
|
||||
transform={`rotate(${-(item.rotation || 0)})`}>{text}</text>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
}
|
||||
|
||||
/** A small person (for seats / guests): drawn, so it looks the same everywhere. */
|
||||
function Person({ x, y, size, color }) {
|
||||
const r = size / 2
|
||||
return (
|
||||
<g transform={`translate(${x} ${y})`} fill={color}>
|
||||
<circle cx={0} cy={-r * 0.35} r={r * 0.32} />
|
||||
<path d={`M ${-r * 0.6} ${r * 0.55} Q 0 ${-r * 0.25} ${r * 0.6} ${r * 0.55} Z`} />
|
||||
</g>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A table: its shape, chairs for its seats, and (live) its name, guests / seats, time open,
|
||||
* waiters and a "ready" count. `now` (ms) moves the clock.
|
||||
*/
|
||||
export function TableShape({ table, live = true, selected = false, now = Date.now(), ...rest }) {
|
||||
const tone = TONES[live ? toneOf(table) : 'free']
|
||||
const w = table.width || 80
|
||||
const h = table.height || 80
|
||||
const rot = table.rotation || 0
|
||||
const o = live ? table.order : null
|
||||
const fs = Math.max(11, Math.min(22, Math.min(w, h) * 0.24))
|
||||
const lines = [table.name]
|
||||
const second = o ? `${o.guests ?? '–'}/${table.seats ?? '–'}` : table.seats ? `${table.seats}` : ''
|
||||
const third = o ? [durationText(o.opened_at ? Math.max(0, Math.floor((now - new Date(o.opened_at).getTime()) / 60000)) : null), peopleText(o.people)].filter(Boolean).join(' · ') : ''
|
||||
return (
|
||||
<g transform={`translate(${table.x} ${table.y})`} data-table={table.id} data-state={live ? toneOf(table) : undefined} {...rest}>
|
||||
<g transform={`rotate(${rot})`}>
|
||||
{chairs(table.shape, w, h, table.seats).map(([cx, cy], i) => (
|
||||
<circle key={i} cx={cx} cy={cy} r={Math.max(6, Math.min(10, fs * 0.45))} fill="var(--x-surface-2)" stroke={tone.stroke} strokeWidth="1.5" />
|
||||
))}
|
||||
{table.shape === 'round'
|
||||
? <ellipse cx="0" cy="0" rx={w / 2} ry={h / 2} fill={tone.fill} stroke={selected ? 'var(--x-accent)' : tone.stroke} strokeWidth={selected ? 5 : 3} />
|
||||
: <rect x={-w / 2} y={-h / 2} width={w} height={h} rx="10" fill={tone.fill} stroke={selected ? 'var(--x-accent)' : tone.stroke} strokeWidth={selected ? 5 : 3} />}
|
||||
</g>
|
||||
<g fill={tone.ink} pointerEvents="none">
|
||||
<text x="0" y={second || third ? -fs * (third ? 0.9 : 0.45) : 0} textAnchor="middle" dominantBaseline="central" fontSize={fs} fontWeight="700">{lines[0]}</text>
|
||||
{second && (
|
||||
<g>
|
||||
<Person x={-fs * 0.95} y={third ? fs * 0.15 : fs * 0.6} size={fs * 0.85} color={tone.ink} />
|
||||
<text x={fs * 0.1} y={third ? fs * 0.15 : fs * 0.6} textAnchor="middle" dominantBaseline="central" fontSize={fs * 0.75} fontWeight="600">{second}</text>
|
||||
</g>
|
||||
)}
|
||||
{third && <text x="0" y={fs * 1.1} textAnchor="middle" dominantBaseline="central" fontSize={fs * 0.62}>{third}</text>}
|
||||
</g>
|
||||
{o?.ready > 0 && (
|
||||
<g transform={`translate(${w / 2 - 4} ${-h / 2 + 4})`} pointerEvents="none">
|
||||
<circle r={fs * 0.55} fill="var(--x-success)" />
|
||||
<text textAnchor="middle" dominantBaseline="central" fontSize={fs * 0.6} fontWeight="700" fill="var(--x-success-fg)">{o.ready}</text>
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
// The table map's geometry (plan step 6.8, D-31), pure and tested (tests/geometry.test.mjs).
|
||||
// Plan units: 1 unit = 1 px at 100 %. A table's or an item's (x, y) is its centre; rotation in
|
||||
// degrees, clockwise. The grid is a "snap to fixed positions" grid: positions (centres) and sizes
|
||||
// become multiples of the grid size (half a cell for odd sizes, so a 1-cell table sits in a cell).
|
||||
|
||||
export const SHAPES = ['square', 'round', 'long']
|
||||
export const ITEM_KINDS = ['wall', 'bar', 'label', 'area']
|
||||
export const GRID_SIZES = [20, 25, 40, 50, 80, 100]
|
||||
|
||||
/** A value on the grid (off: as it is, to 1 decimal). */
|
||||
export function snap(v, grid) {
|
||||
if (!grid) return Math.round(v * 10) / 10
|
||||
return Math.round(v / grid) * grid
|
||||
}
|
||||
|
||||
/** A size on the grid: whole cells, at least one. */
|
||||
export const snapSize = (v, grid) => (grid ? Math.max(grid, Math.round(v / grid) * grid) : Math.max(10, Math.round(v * 10) / 10))
|
||||
|
||||
/** A centre on the grid: an odd number of cells puts the centre in the middle of a cell. */
|
||||
export function snapCentre(c, size, grid) {
|
||||
if (!grid) return Math.round(c * 10) / 10
|
||||
const cells = Math.round(size / grid)
|
||||
const off = cells % 2 ? grid / 2 : 0
|
||||
return Math.round((c - off) / grid) * grid + off
|
||||
}
|
||||
|
||||
export const clamp = (v, lo, hi) => Math.min(Math.max(v, lo), hi)
|
||||
|
||||
/** Where a thing goes after a drag, kept on the plan and (grid on) on the grid. */
|
||||
export function moveTo(thing, x, y, plan) {
|
||||
const grid = plan.grid_on ? plan.grid_size : 0
|
||||
return { ...thing, x: clamp(snapCentre(x, thing.width, grid), 0, plan.width), y: clamp(snapCentre(y, thing.height, grid), 0, plan.height) }
|
||||
}
|
||||
|
||||
/** A new table's size from its shape and seats (2 seats: small; long tables grow with seats). */
|
||||
export function defaultSize(shape, seats, grid = 0) {
|
||||
const n = Math.max(1, seats || 4)
|
||||
let w = 80
|
||||
let h = 80
|
||||
if (shape === 'round') { w = h = n <= 2 ? 70 : n <= 4 ? 90 : 120 }
|
||||
else if (shape === 'square') { w = h = n <= 2 ? 70 : 90 }
|
||||
else { h = 80; w = Math.max(140, Math.ceil(n / 2) * 60) }
|
||||
return { width: snapSize(w, grid), height: snapSize(h, grid) }
|
||||
}
|
||||
|
||||
export const ITEM_SIZES = { wall: [300, 12], bar: [320, 60], label: [140, 36], area: [300, 200] }
|
||||
|
||||
/** The floor's corners: its outline, or the whole rectangle. */
|
||||
export const outlineOf = plan => (plan.outline?.length >= 3 ? plan.outline : [[0, 0], [plan.width, 0], [plan.width, plan.height], [0, plan.height]])
|
||||
|
||||
export const pointsAttr = points => points.map(([x, y]) => `${x},${y}`).join(' ')
|
||||
|
||||
/** A corner more: the middle of the edge after corner `i`. */
|
||||
export function addCorner(points, i) {
|
||||
const a = points[i]
|
||||
const b = points[(i + 1) % points.length]
|
||||
const out = [...points]
|
||||
out.splice(i + 1, 0, [Math.round((a[0] + b[0]) / 2), Math.round((a[1] + b[1]) / 2)])
|
||||
return out
|
||||
}
|
||||
|
||||
/** A corner less (a floor keeps at least 3). */
|
||||
export const removeCorner = (points, i) => (points.length <= 3 ? points : points.filter((_, j) => j !== i))
|
||||
|
||||
/** Move corner `i` (kept on the plan, on the grid). */
|
||||
export function moveCorner(points, i, x, y, plan) {
|
||||
const grid = plan.grid_on ? plan.grid_size : 0
|
||||
return points.map((p, j) => (j === i ? [clamp(snap(x, grid), 0, plan.width), clamp(snap(y, grid), 0, plan.height)] : p))
|
||||
}
|
||||
|
||||
/** Where the chairs go around a table (centres, relative to the table's centre). */
|
||||
export function chairs(shape, width, height, seats) {
|
||||
const n = Math.max(0, Math.min(seats || 0, 24))
|
||||
if (!n) return []
|
||||
const gap = 10
|
||||
if (shape === 'round') {
|
||||
const rx = width / 2 + gap
|
||||
const ry = height / 2 + gap
|
||||
return Array.from({ length: n }, (_, i) => {
|
||||
const a = (2 * Math.PI * i) / n - Math.PI / 2
|
||||
return [Math.round(rx * Math.cos(a) * 10) / 10, Math.round(ry * Math.sin(a) * 10) / 10]
|
||||
})
|
||||
}
|
||||
// rectangles: along the two long sides (one at each end when there are few)
|
||||
const along = width >= height
|
||||
const len = along ? width : height
|
||||
const top = Math.ceil(n / 2)
|
||||
const bottom = n - top
|
||||
const row = (count, side) => Array.from({ length: count }, (_, i) => {
|
||||
const t = -len / 2 + (len * (i + 0.5)) / count
|
||||
const off = side * ((along ? height : width) / 2 + gap)
|
||||
return along ? [Math.round(t * 10) / 10, off] : [off, Math.round(t * 10) / 10]
|
||||
})
|
||||
if (n === 1) return [along ? [0, -(height / 2 + gap)] : [-(width / 2 + gap), 0]]
|
||||
return [...row(top, -1), ...row(bottom, 1)]
|
||||
}
|
||||
|
||||
/** How a table looks from its state: free | open | mine | paid | reserved. */
|
||||
export function toneOf(table) {
|
||||
if (table.state === 'open' && table.mine) return 'mine'
|
||||
return table.state ?? 'free'
|
||||
}
|
||||
|
||||
export const TONES = {
|
||||
free: { fill: 'var(--x-surface)', stroke: 'var(--x-line-strong)', ink: 'var(--x-ink)' },
|
||||
open: { fill: 'var(--x-info-soft)', stroke: 'var(--x-info)', ink: 'var(--x-info-ink)' },
|
||||
mine: { fill: 'var(--x-accent-soft)', stroke: 'var(--x-accent)', ink: 'var(--x-accent-ink)' },
|
||||
paid: { fill: 'var(--x-success-soft)', stroke: 'var(--x-success)', ink: 'var(--x-success-ink)' },
|
||||
reserved: { fill: 'var(--x-special-soft)', stroke: 'var(--x-special)', ink: 'var(--x-special-ink)' }, // not the accent: some venues' accent is amber
|
||||
}
|
||||
|
||||
/** Minutes since an order opened. */
|
||||
export const minutesSince = (iso, now = Date.now()) => (iso ? Math.max(0, Math.floor((now - new Date(iso).getTime()) / 60000)) : null)
|
||||
|
||||
/** "42′" under an hour, "1:05" after. */
|
||||
export function durationText(min) {
|
||||
if (min == null) return ''
|
||||
if (min < 60) return `${min}′`
|
||||
return `${Math.floor(min / 60)}:${String(min % 60).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
/** "Maria", "Maria +1". */
|
||||
export const peopleText = people => (!people?.length ? '' : people.length === 1 ? people[0] : `${people[0]} +${people.length - 1}`)
|
||||
|
||||
/** The tables of one plan, and the ones not on any plan (of a zone, when given). */
|
||||
export function splitTables(tables, planId, zone = null) {
|
||||
const inZone = zone == null ? tables : tables.filter(t => t.group_id === zone)
|
||||
return { placed: tables.filter(t => t.plan_id === planId && t.x != null), unplaced: inZone.filter(t => t.plan_id == null || t.x == null) }
|
||||
}
|
||||
|
||||
/** The plans to offer for a zone (null = all): the zone's plans and the plans without a zone. */
|
||||
export const plansFor = (plans, zone = null) => (zone == null ? plans : plans.filter(p => p.group_id === zone || p.group_id == null))
|
||||
|
||||
/** Turn a point on screen (client coordinates) into plan units, for an <svg> drawn with a viewBox. */
|
||||
export function toPlan(svg, clientX, clientY) {
|
||||
const r = svg.getBoundingClientRect()
|
||||
const vb = svg.viewBox.baseVal
|
||||
return [vb.x + ((clientX - r.left) / r.width) * vb.width, vb.y + ((clientY - r.top) / r.height) * vb.height]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// @xenia/floorplan (plan step 6.8, D-31): the table map, drawn the same in the waiter app, the
|
||||
// counter POS and the manager (the live map and the editor), with its pure geometry.
|
||||
export * from './geometry.js'
|
||||
export { Floor, Item, TableShape } from './Shapes.jsx'
|
||||
export { FloorView } from './FloorView.jsx'
|
||||
@@ -0,0 +1,65 @@
|
||||
// The table map's geometry (plan step 6.8): the grid, outlines, chairs, what a table shows.
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
addCorner, chairs, defaultSize, durationText, minutesSince, moveCorner, moveTo, outlineOf, peopleText, plansFor, removeCorner,
|
||||
snap, snapCentre, snapSize, splitTables, toneOf,
|
||||
} from '../src/geometry.js'
|
||||
|
||||
const plan = { width: 1000, height: 600, grid_on: true, grid_size: 50 }
|
||||
|
||||
test('the grid snaps positions and sizes; off, they stay as they are', () => {
|
||||
assert.equal(snap(73, 50), 50)
|
||||
assert.equal(snap(73.27, 0), 73.3)
|
||||
assert.equal(snapSize(20, 50), 50) // at least one cell
|
||||
assert.equal(snapSize(130, 50), 150)
|
||||
assert.equal(snapCentre(130, 50, 50), 125) // one cell: the centre of a cell
|
||||
assert.equal(snapCentre(130, 100, 50), 150) // two cells: on a line
|
||||
assert.deepEqual(moveTo({ width: 50, height: 50 }, 1210, -20, plan), { width: 50, height: 50, x: 1000, y: 0 })
|
||||
assert.deepEqual(moveTo({ width: 50, height: 50 }, 312.4, 99, { ...plan, grid_on: false }), { width: 50, height: 50, x: 312.4, y: 99 })
|
||||
})
|
||||
|
||||
test('new tables get a size from their shape and seats', () => {
|
||||
assert.deepEqual(defaultSize('round', 2), { width: 70, height: 70 })
|
||||
assert.deepEqual(defaultSize('long', 8), { width: 240, height: 80 })
|
||||
assert.deepEqual(defaultSize('square', 4, 50), { width: 100, height: 100 })
|
||||
})
|
||||
|
||||
test('irregular floors: corners added, moved, removed (never fewer than 3)', () => {
|
||||
const rect = outlineOf(plan)
|
||||
assert.equal(rect.length, 4)
|
||||
const five = addCorner(rect, 1) // the middle of the right side
|
||||
assert.deepEqual(five[2], [1000, 300])
|
||||
const moved = moveCorner(five, 2, 640, 333, plan)
|
||||
assert.deepEqual(moved[2], [650, 350])
|
||||
assert.equal(removeCorner(removeCorner(moved, 0), 0).length, 3)
|
||||
assert.equal(removeCorner([[0, 0], [1, 0], [0, 1]], 0).length, 3)
|
||||
assert.deepEqual(outlineOf({ ...plan, outline: moved }), moved)
|
||||
})
|
||||
|
||||
test('chairs go around round tables and along the long sides', () => {
|
||||
const r = chairs('round', 80, 80, 4)
|
||||
assert.deepEqual(r[0], [0, -50])
|
||||
assert.equal(r.length, 4)
|
||||
const l = chairs('long', 200, 80, 6)
|
||||
assert.equal(l.filter(([, y]) => y < 0).length, 3)
|
||||
assert.equal(l.filter(([, y]) => y > 0).length, 3)
|
||||
assert.deepEqual(chairs('square', 80, 80, 0), [])
|
||||
})
|
||||
|
||||
test('what a table shows', () => {
|
||||
assert.equal(toneOf({ state: 'open', mine: true }), 'mine')
|
||||
assert.equal(toneOf({ state: 'paid', mine: true }), 'paid')
|
||||
assert.equal(durationText(42), '42′')
|
||||
assert.equal(durationText(65), '1:05')
|
||||
assert.equal(peopleText(['Maria', 'Nikos']), 'Maria +1')
|
||||
assert.equal(minutesSince('2026-11-18T10:00:00Z', Date.parse('2026-11-18T10:42:30Z')), 42)
|
||||
})
|
||||
|
||||
test('plans of a zone, and the tables not on a plan', () => {
|
||||
const plans = [{ id: 1, group_id: 1 }, { id: 2, group_id: 2 }, { id: 3, group_id: null }]
|
||||
assert.deepEqual(plansFor(plans, 2).map(p => p.id), [2, 3])
|
||||
const tables = [{ id: 1, plan_id: 1, x: 5, group_id: 1 }, { id: 2, plan_id: null, group_id: 1 }, { id: 3, plan_id: null, group_id: 2 }]
|
||||
const s = splitTables(tables, 1, 1)
|
||||
assert.deepEqual([s.placed.map(t => t.id), s.unplaced.map(t => t.id)], [[1], [2]])
|
||||
})
|
||||
@@ -98,5 +98,24 @@
|
||||
"sulphites": "Θειώδη",
|
||||
"lupin": "Λούπινο",
|
||||
"molluscs": "Μαλάκια"
|
||||
},
|
||||
"floorMap": {
|
||||
"none": "Δεν υπάρχει ακόμα κάτοψη",
|
||||
"noneHint": "Ένας διευθυντής σχεδιάζει τις κατόψεις στη Διαχείριση → Τραπέζια → Κατόψεις.",
|
||||
"zoomIn": "Μεγέθυνση",
|
||||
"zoomOut": "Σμίκρυνση",
|
||||
"fit": "Προσαρμογή",
|
||||
"bar": "Μπαρ",
|
||||
"notOnMap": "Εκτός κάτοψης:",
|
||||
"legendGuests": "👤 άτομα / θέσεις",
|
||||
"map": "Κάτοψη",
|
||||
"list": "Λίστα",
|
||||
"state": {
|
||||
"free": "Ελεύθερο",
|
||||
"mine": "Δικό σας",
|
||||
"open": "Ανοιχτό",
|
||||
"paid": "Πληρωμένο",
|
||||
"reserved": "Κράτηση σύντομα"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,5 +329,12 @@
|
||||
"pricing": {
|
||||
"bad_limit": "Ένα όριο έκπτωσης πρέπει να είναι αριθμός 0 ή μεγαλύτερος, ή κενό για χωρίς όριο.",
|
||||
"bad_condition": "Μια συνθήκη είναι ελλιπής: συμπληρώστε όλες τις τιμές της."
|
||||
},
|
||||
"floor_plan": {
|
||||
"not_found": "Η κάτοψη δεν βρέθηκε.",
|
||||
"bad_outline": "Το σχήμα του χώρου χρειάζεται 3 έως 100 γωνίες, όλες μέσα στην κάτοψη.",
|
||||
"bad_zone": "Αυτή η ζώνη δεν υπάρχει πια.",
|
||||
"bad_background": "Το φόντο πρέπει να είναι εικόνα από τη βιβλιοθήκη πολυμέσων.",
|
||||
"bad_layout": "Η διάταξη έχει ένα τραπέζι δύο φορές ή μια θέση που δεν είναι αριθμός."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2097,5 +2097,90 @@
|
||||
"max_items_per_orderHint": "Τεμάχια με έκπτωση σε μία παραγγελία."
|
||||
}
|
||||
}
|
||||
},
|
||||
"floor": {
|
||||
"pageTabs": "Τραπέζια",
|
||||
"tabs": {
|
||||
"list": "Τραπέζια και ζώνες",
|
||||
"floor": "Κατόψεις"
|
||||
},
|
||||
"title": "Κατόψεις",
|
||||
"intro": "Σχεδιάστε πού βρίσκονται τα τραπέζια. Μια ζώνη μπορεί να έχει πολλές κατόψεις (π.χ. ισόγειο και όροφο). Τα κινητά, το ταμείο και η σελίδα Τραπέζια τις δείχνουν ζωντανά.",
|
||||
"none": "Δεν υπάρχει ακόμα κάτοψη",
|
||||
"noneHint": "Φτιάξτε μία και βάλτε πάνω της τα τραπέζια.",
|
||||
"new": "Νέα κάτοψη",
|
||||
"create": "Δημιουργία",
|
||||
"cancel": "Ακύρωση",
|
||||
"save": "Αποθήκευση",
|
||||
"saved": "Η κάτοψη αποθηκεύτηκε.",
|
||||
"delete": "Διαγραφή της κάτοψης",
|
||||
"deleted": "Η κάτοψη διαγράφηκε.",
|
||||
"deleteTitle": "Διαγραφή της κάτοψης;",
|
||||
"deleteBody": "Η «{{name}}» θα χαθεί. Τα τραπέζια της μένουν (εκτός κάτοψης), όπως και οι παραγγελίες τους.",
|
||||
"unsaved": "Δεν αποθηκεύτηκε",
|
||||
"undoAll": "Αναίρεση αλλαγών",
|
||||
"name": "Όνομα",
|
||||
"namePlaceholder": "π.χ. Ισόγειο",
|
||||
"zone": "Ζώνη",
|
||||
"zoneHint": "Τα τραπέζια της προτείνονται πρώτα· οι σερβιτόροι άλλων ζωνών δεν τη βλέπουν.",
|
||||
"noZone": "Χωρίς ζώνη",
|
||||
"size": "Μέγεθος",
|
||||
"sizeHint": "Μπορείτε να το αλλάξετε αργότερα.",
|
||||
"sizes": {
|
||||
"small": "Μικρό ({{w}} × {{h}})",
|
||||
"medium": "Μεσαίο ({{w}} × {{h}})",
|
||||
"large": "Μεγάλο ({{w}} × {{h}})"
|
||||
},
|
||||
"tableCount_one": "{{count}} τραπέζι",
|
||||
"tableCount_other": "{{count}} τραπέζια",
|
||||
"grid": "Πλέγμα",
|
||||
"gridSize": "Μέγεθος πλέγματος",
|
||||
"gridCell": "Κελιά των {{size}}",
|
||||
"editShape": "Αλλαγή σχήματος χώρου",
|
||||
"shapeHint": "Σύρετε τις γωνίες για να πάρει ο χώρος το πραγματικό του σχήμα (Γ, βεράντα…). Επιλέξτε μια γωνία για να προσθέσετε μία μετά από αυτή ή να την αφαιρέσετε.",
|
||||
"shapeTitle": "Το σχήμα του χώρου",
|
||||
"cornerCount_one": "{{count}} γωνία",
|
||||
"cornerCount_other": "{{count}} γωνίες",
|
||||
"addCorner": "Προσθήκη γωνίας μετά",
|
||||
"removeCorner": "Αφαίρεση γωνίας",
|
||||
"rectangle": "Πίσω σε ορθογώνιο",
|
||||
"canvas": "Η κάτοψη: σύρετε τραπέζια και αντικείμενα· τα βέλη μετακινούν το επιλεγμένο",
|
||||
"keysHint": "Τα βέλη μετακινούν το επιλεγμένο (ένα κελί, ή 5· με Shift 1), το Delete το αφαιρεί, το Escape το αφήνει.",
|
||||
"add": "Προσθήκη",
|
||||
"newTableShape": "Τα νέα τραπέζια είναι",
|
||||
"allPlaced": "Όλα τα τραπέζια είναι σε αυτή την κάτοψη.",
|
||||
"zoneTables": "Τραπέζια της ζώνης {{zone}}",
|
||||
"offPlan": "Τραπέζια εκτός της κάτοψης",
|
||||
"otherTables": "Τραπέζια άλλων ζωνών",
|
||||
"things": "Αντικείμενα",
|
||||
"kinds": {
|
||||
"wall": "Τοίχος",
|
||||
"bar": "Μπαρ",
|
||||
"label": "Ετικέτα",
|
||||
"area": "Περιοχή"
|
||||
},
|
||||
"labelText": "Ετικέτα",
|
||||
"settings": "Η κάτοψη",
|
||||
"width": "Πλάτος",
|
||||
"height": "Ύψος",
|
||||
"background": "Εικόνα φόντου",
|
||||
"backgroundOpacity": "Ένταση: {{value}}%",
|
||||
"table": "Τραπέζι {{name}}",
|
||||
"shape": "Σχήμα",
|
||||
"shapes": {
|
||||
"square": "Τετράγωνο",
|
||||
"round": "Στρογγυλό",
|
||||
"long": "Μακρύ"
|
||||
},
|
||||
"seats": "Θέσεις",
|
||||
"seatsHint": "Φαίνονται ως καρέκλες και προτείνονται ως αριθμός ατόμων.",
|
||||
"text": "Κείμενο",
|
||||
"itemWidth": "Πλάτος",
|
||||
"itemHeight": "Βάθος",
|
||||
"rotation": "Γυρισμένο {{deg}}°",
|
||||
"rotateLeft": "Στροφή αριστερά 15°",
|
||||
"rotateRight": "Στροφή δεξιά 15°",
|
||||
"takeOff": "Βγάλτε το από την κάτοψη",
|
||||
"removeThing": "Αφαίρεση"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,5 +98,24 @@
|
||||
"sulphites": "Sulphites",
|
||||
"lupin": "Lupin",
|
||||
"molluscs": "Molluscs"
|
||||
},
|
||||
"floorMap": {
|
||||
"none": "No floor plan yet",
|
||||
"noneHint": "A manager draws the floor plans in Management → Tables → Floor plans.",
|
||||
"zoomIn": "Zoom in",
|
||||
"zoomOut": "Zoom out",
|
||||
"fit": "Fit",
|
||||
"bar": "Bar",
|
||||
"notOnMap": "Not on the map:",
|
||||
"legendGuests": "👤 guests / seats",
|
||||
"map": "Map",
|
||||
"list": "List",
|
||||
"state": {
|
||||
"free": "Free",
|
||||
"mine": "Yours",
|
||||
"open": "Open",
|
||||
"paid": "Paid",
|
||||
"reserved": "Booked soon"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,5 +329,12 @@
|
||||
"pricing": {
|
||||
"bad_limit": "A discount limit must be a number of 0 or more, or empty for no limit.",
|
||||
"bad_condition": "A condition is incomplete: fill in all its values."
|
||||
},
|
||||
"floor_plan": {
|
||||
"not_found": "Floor plan not found.",
|
||||
"bad_outline": "The floor's shape needs 3 to 100 corners, all inside the plan.",
|
||||
"bad_zone": "That zone no longer exists.",
|
||||
"bad_background": "The background must be a picture from the media library.",
|
||||
"bad_layout": "The layout has a table twice or a place that is not a number."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2097,5 +2097,90 @@
|
||||
"max_items_per_orderHint": "Discounted items on one order."
|
||||
}
|
||||
}
|
||||
},
|
||||
"floor": {
|
||||
"pageTabs": "Tables",
|
||||
"tabs": {
|
||||
"list": "Tables and zones",
|
||||
"floor": "Floor plans"
|
||||
},
|
||||
"title": "Floor plans",
|
||||
"intro": "Draw where the tables stand. A zone can have several floor plans (e.g. ground floor and upstairs). The phones, the counter and the Tables page show them live.",
|
||||
"none": "No floor plan yet",
|
||||
"noneHint": "Make one, then put the tables on it.",
|
||||
"new": "New floor plan",
|
||||
"create": "Create",
|
||||
"cancel": "Cancel",
|
||||
"save": "Save",
|
||||
"saved": "Floor plan saved.",
|
||||
"delete": "Delete the floor plan",
|
||||
"deleted": "Floor plan deleted.",
|
||||
"deleteTitle": "Delete the floor plan?",
|
||||
"deleteBody": "\"{{name}}\" will be gone. Its tables stay (off any plan) and so do their orders.",
|
||||
"unsaved": "Not saved",
|
||||
"undoAll": "Undo the changes",
|
||||
"name": "Name",
|
||||
"namePlaceholder": "e.g. Ground floor",
|
||||
"zone": "Zone",
|
||||
"zoneHint": "Its tables are the ones offered first; the waiters of other zones don't see it.",
|
||||
"noZone": "No zone",
|
||||
"size": "Size",
|
||||
"sizeHint": "You can change it later.",
|
||||
"sizes": {
|
||||
"small": "Small ({{w}} × {{h}})",
|
||||
"medium": "Medium ({{w}} × {{h}})",
|
||||
"large": "Large ({{w}} × {{h}})"
|
||||
},
|
||||
"tableCount_one": "{{count}} table",
|
||||
"tableCount_other": "{{count}} tables",
|
||||
"grid": "Grid",
|
||||
"gridSize": "Grid size",
|
||||
"gridCell": "Cells of {{size}}",
|
||||
"editShape": "Edit the floor's shape",
|
||||
"shapeHint": "Drag the corners to give the floor its real shape (an L, a terrace…). Pick a corner to add one after it or remove it.",
|
||||
"shapeTitle": "The floor's shape",
|
||||
"cornerCount_one": "{{count}} corner",
|
||||
"cornerCount_other": "{{count}} corners",
|
||||
"addCorner": "Add a corner after it",
|
||||
"removeCorner": "Remove the corner",
|
||||
"rectangle": "Back to a rectangle",
|
||||
"canvas": "The floor plan: drag the tables and things; arrow keys move the selected one",
|
||||
"keysHint": "Arrow keys move what's selected (one grid cell, or 5; with Shift 1), Delete takes it off, Escape lets go.",
|
||||
"add": "Add",
|
||||
"newTableShape": "New tables are",
|
||||
"allPlaced": "Every table is on this plan.",
|
||||
"zoneTables": "Tables of {{zone}}",
|
||||
"offPlan": "Tables not on this plan",
|
||||
"otherTables": "Other zones' tables",
|
||||
"things": "Things",
|
||||
"kinds": {
|
||||
"wall": "Wall",
|
||||
"bar": "Bar",
|
||||
"label": "Label",
|
||||
"area": "Area"
|
||||
},
|
||||
"labelText": "Label",
|
||||
"settings": "The plan",
|
||||
"width": "Width",
|
||||
"height": "Height",
|
||||
"background": "Background picture",
|
||||
"backgroundOpacity": "How strong: {{value}}%",
|
||||
"table": "Table {{name}}",
|
||||
"shape": "Shape",
|
||||
"shapes": {
|
||||
"square": "Square",
|
||||
"round": "Round",
|
||||
"long": "Long"
|
||||
},
|
||||
"seats": "Seats",
|
||||
"seatsHint": "Shown as chairs, and offered as the number of guests.",
|
||||
"text": "Text",
|
||||
"itemWidth": "Width",
|
||||
"itemHeight": "Depth",
|
||||
"rotation": "Turned {{deg}}°",
|
||||
"rotateLeft": "Turn left 15°",
|
||||
"rotateRight": "Turn right 15°",
|
||||
"takeOff": "Take it off the plan",
|
||||
"removeThing": "Remove"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user