feat(signage): menu look part by part, board-only names, stack bar, Delete key (owner review 3)
- Menus (slides and widgets): headings / names / prices each with size, colour, font, bold / italic / underline and alignment; dots size, colour and style; line and letter spacing; photo size and shape (menuLook) - Names aligned right end together, prices in a page-wide column - Names for one board only (names, category_names) with a pencil on the board's list; the catalogue name stays for the waiters - Fixed: menu lists inherited the page's fixed line height (big text overlapped); a menu slide's list grew past the screen (no 2nd column) - Stacks: parts sized by dragging the lines on the bar; "Add a widget" - Delete / Backspace removes the picked widget Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -76,6 +76,34 @@ Position = Literal["top-left", "top-center", "top-right", "bottom-left", "bottom
|
||||
|
||||
|
||||
Badge = Literal["new", "chef", "offer", "popular", "spicy", "vegetarian", "vegan"]
|
||||
Align = Literal["left", "center", "right"]
|
||||
|
||||
|
||||
class TextStyle(_Strict):
|
||||
"""How a menu's headings, product names or prices look (owner review 3, 2026-11-21). Empty
|
||||
values follow the board: its text size and font, the text colour (names) or the accent colour
|
||||
(headings, prices)."""
|
||||
size: Optional[int] = Field(default=None, ge=50, le=300) # % like the board's text size
|
||||
colour: Optional[str] = Field(default=None, pattern=HEX)
|
||||
font: Optional[Font] = None
|
||||
bold: bool = True
|
||||
italic: bool = False
|
||||
underline: bool = False
|
||||
align: Optional[Align] = None # None: names left, prices right, headings as the list
|
||||
|
||||
|
||||
class DotStyle(_Strict):
|
||||
"""The line between a product's name and its price."""
|
||||
size: int = Field(default=100, ge=50, le=300)
|
||||
colour: Optional[str] = Field(default=None, pattern=HEX) # None: the text colour, faint
|
||||
style: Literal["dotted", "dashed", "solid", "none"] = "dotted"
|
||||
|
||||
|
||||
def _names(v: dict) -> dict:
|
||||
if any(not k.isdigit() for k in v):
|
||||
raise ValueError("names are keyed by id")
|
||||
out = {k: " ".join(str(x).split())[:80] for k, x in v.items()}
|
||||
return {k: x for k, x in out.items() if x}
|
||||
|
||||
|
||||
class MenuList(_Strict):
|
||||
@@ -107,6 +135,23 @@ class MenuList(_Strict):
|
||||
text_colour: str = Field(default="#ffffff", pattern=HEX)
|
||||
accent_colour: str = Field(default="#f59e0b", pattern=HEX) # prices, headings, badges
|
||||
text_size: int = Field(default=100, ge=50, le=250)
|
||||
# the look of each part (owner review 3, 2026-11-21)
|
||||
heading_style: TextStyle = Field(default_factory=TextStyle)
|
||||
item_style: TextStyle = Field(default_factory=TextStyle)
|
||||
price_style: TextStyle = Field(default_factory=TextStyle)
|
||||
dot_style: DotStyle = Field(default_factory=DotStyle)
|
||||
line_height: Optional[float] = Field(default=None, ge=0.8, le=3) # × the text; None = auto
|
||||
letter_spacing: Optional[float] = Field(default=None, ge=-0.1, le=0.5) # em; None = auto
|
||||
photo_size: int = Field(default=100, ge=50, le=250)
|
||||
photo_shape: Literal["square", "rounded", "round"] = "rounded"
|
||||
# this board's own names (the menu's "official" names; the catalogue keeps its own)
|
||||
names: Dict[str, str] = Field(default_factory=dict) # product id → name
|
||||
category_names: Dict[str, str] = Field(default_factory=dict) # category id → name
|
||||
|
||||
@field_validator("names", "category_names")
|
||||
@classmethod
|
||||
def _own_names(cls, v):
|
||||
return _names(v)
|
||||
|
||||
@field_validator("sales_point")
|
||||
@classmethod
|
||||
|
||||
@@ -87,9 +87,18 @@ def resolve(db, content: dict, now=None, keep_hidden: bool = False) -> dict:
|
||||
def text(row, base, field):
|
||||
return menu_languages.texts(base, menu_languages.of(row), field).get(lang, base) if lang else base
|
||||
|
||||
own = content.get("names") or {} # this board's own names (2026-11-21)
|
||||
own_cats = content.get("category_names") or {}
|
||||
|
||||
def named(row, base, mine):
|
||||
"""(the name shown, the catalogue's name when the board has its own)"""
|
||||
shown = text(row, base, "name")
|
||||
return (mine, shown) if mine else (shown, None)
|
||||
|
||||
def item(p):
|
||||
image = media_store.image_of(p.media) if content.get("show_photos") else None
|
||||
return {"id": p.id, "name": text(p, p.digital_name or p.name, "name"),
|
||||
name, original = named(p, p.digital_name or p.name, own.get(str(p.id)))
|
||||
return {"id": p.id, "name": name, **({"original": original} if original and keep_hidden else {}),
|
||||
"description": text(p, p.digital_description or p.description or None, "description") if content.get("show_descriptions") else None,
|
||||
"price": round(prices[p.id], 2) if p.id in prices else None,
|
||||
"available": bool(p.is_available), "image": image["card"] if image else None,
|
||||
@@ -99,7 +108,10 @@ def resolve(db, content: dict, now=None, keep_hidden: bool = False) -> dict:
|
||||
groups: dict = {}
|
||||
for p in products:
|
||||
groups.setdefault(p.primary_category_id, []).append(p)
|
||||
out = [{"category": {"id": cid, "name": text(by_id[cid], by_id[cid].name, "name")} if cid in by_id else None,
|
||||
def cat(cid):
|
||||
name, original = named(by_id[cid], by_id[cid].name, own_cats.get(str(cid)))
|
||||
return {"id": cid, "name": name, **({"original": original} if original and keep_hidden else {})}
|
||||
out = [{"category": cat(cid) if cid in by_id else None,
|
||||
"items": [item(p) for p in sorted(ps, key=prod_key)]}
|
||||
for cid, ps in sorted(groups.items(), key=lambda kv: cat_key(kv[0]))]
|
||||
else:
|
||||
|
||||
@@ -95,3 +95,25 @@ def test_the_editor_previews_any_slide(client, owner_h, menu):
|
||||
m = r.json()["menu"]
|
||||
assert "Beer" in [i["name"] for g in m["groups"] for i in g["items"] if i.get("hidden")] and m["count"] == 3
|
||||
assert err(client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "text", "content": {"widgets": [stack()]}})) == "signage.content_invalid"
|
||||
|
||||
|
||||
def test_a_board_has_its_own_names_and_the_look_of_each_part(client, owner_h, menu):
|
||||
"""Owner review 3 (2026-11-21): names only for this board (the catalogue keeps its own), the look
|
||||
of headings, names, prices and the dots, spacing, photos."""
|
||||
content = {"category_ids": [menu["cats"]["drinks"]], "names": {str(menu["beer"].id): " Craft beer "}, "category_names": {str(menu["cats"]["drinks"]): "Bar"},
|
||||
"heading_style": {"size": 180, "colour": "#ff0000", "font": "serif", "align": "center", "italic": True},
|
||||
"price_style": {"align": "right", "bold": False}, "dot_style": {"style": "dashed", "size": 150},
|
||||
"line_height": 1.4, "letter_spacing": 0.05, "photo_size": 150, "photo_shape": "round"}
|
||||
r = client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "menu", "content": content})
|
||||
assert r.status_code == 200, r.text
|
||||
g = r.json()["menu"]["groups"][0]
|
||||
assert g["category"] == {"id": menu["cats"]["drinks"], "name": "Bar", "original": "Drinks"}
|
||||
assert g["items"][0]["name"] == "Craft beer" and g["items"][0]["original"] == "Beer"
|
||||
p = playlist(client, owner_h)
|
||||
s = slide(client, owner_h, p["id"], "menu", content=content)
|
||||
c = s["content"]
|
||||
assert c["names"] == {str(menu["beer"].id): "Craft beer"} and c["heading_style"]["italic"] and c["item_style"]["bold"]
|
||||
assert c["price_style"] == {"size": None, "colour": None, "font": None, "bold": False, "italic": False, "underline": False, "align": "right"}
|
||||
url = f"/api/signage/playlists/{p['id']}/slides"
|
||||
for bad in ({"names": {"x": "a"}}, {"heading_style": {"size": 20}}, {"dot_style": {"style": "wavy"}}, {"line_height": 9}, {"photo_shape": "star"}):
|
||||
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": bad})) == "signage.content_invalid", bad
|
||||
|
||||
Reference in New Issue
Block a user