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:
2026-11-18 17:00:45 +02:00
co-authored by Claude Opus 5.5
parent fd3254aa31
commit f4aae6abbc
47 changed files with 2102 additions and 8 deletions
+111
View File
@@ -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>
)
}