feat(signage): look rows that wrap, one colour field with opacity, badges' text, several widgets per stack part, pages up to 2200 px (owner review 4)
- Menu text look: each field names its part ("Headings size"), rows wrap in aligned columns on
alternating bands; names align left / right; line and letter spacing as lists (Auto default);
each field changes only itself (followers frozen before the other changes); badge colour +
badge text colour (auto: readableOn); "Reset the look" with a question.
- ColourField everywhere in signage: a Popover panel (new @xenia/ui Popover, portal, kept in the
window) with 12 presets, picker, opacity (#rrggbbaa) and typed code; HEX accepts 8 digits.
- Stacks: Cell.widgets (a stored `widget` still reads), several widgets per part laid across the
stack's direction; extras by path stack.part.place; Add a widget adds, each removable / ordered.
- Page rule: --x-page-max is 2200px (no longer follows the window height).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -49,7 +49,7 @@ from services.ws_bus import broadcast_sync
|
||||
router = APIRouter()
|
||||
KEY = "signage.manage"
|
||||
MESSAGE = "signage.message"
|
||||
HEX = r"^#[0-9a-fA-F]{6}$"
|
||||
HEX = r"^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$" # #rrggbb, or #rrggbbaa (see-through, 2026-11-21)
|
||||
TIME = r"^([01]\d|2[0-3]):[0-5]\d$"
|
||||
DATE = r"^\d{4}-\d{2}-\d{2}$"
|
||||
Orientation = Literal["landscape", "portrait"]
|
||||
@@ -133,7 +133,8 @@ class MenuList(_Strict):
|
||||
page_seconds: int = Field(default=10, ge=3, le=120)
|
||||
font: Font = "sans"
|
||||
text_colour: str = Field(default="#ffffff", pattern=HEX)
|
||||
accent_colour: str = Field(default="#f59e0b", pattern=HEX) # prices, headings, badges
|
||||
accent_colour: str = Field(default="#f59e0b", pattern=HEX) # badges, page dots (headings and prices unless their own)
|
||||
badge_text_colour: Optional[str] = Field(default=None, pattern=HEX) # None: white or black, to read on the badge
|
||||
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)
|
||||
@@ -188,16 +189,28 @@ class Box(_Strict):
|
||||
|
||||
class Cell(_Strict):
|
||||
"""A part of a stack (2026-11-21): its share of the stack (the parts' shares are weights; the
|
||||
editor keeps them adding up to 100) and what it shows: a widget (another stack too, one level
|
||||
deep) or a slide of the Slides library, drawn whole inside the part; or nothing."""
|
||||
editor keeps them adding up to 100) and what it shows: widgets (another stack too, one level
|
||||
deep; several share the part, one over the other in a side-by-side stack, side by side in the
|
||||
other), or a slide of the Slides library, drawn whole inside the part; or nothing."""
|
||||
share: float = Field(default=50, ge=1, le=100)
|
||||
widget: Optional["Widget"] = None
|
||||
widgets: List["Widget"] = Field(default_factory=list, max_length=6)
|
||||
slide_id: Optional[int] = None
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def _one_widget(cls, v):
|
||||
# a part held one widget (`widget`) until owner review 4 (2026-11-21)
|
||||
if isinstance(v, dict) and "widget" in v:
|
||||
v = dict(v)
|
||||
w = v.pop("widget")
|
||||
if w is not None:
|
||||
v["widgets"] = [w, *(v.get("widgets") or [])]
|
||||
return v
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _one(self):
|
||||
if self.widget is not None and self.slide_id is not None:
|
||||
raise ValueError("a part shows a widget or a slide, not both")
|
||||
if self.widgets and self.slide_id is not None:
|
||||
raise ValueError("a part shows widgets or a slide, not both")
|
||||
self.share = round(self.share, 2)
|
||||
return self
|
||||
|
||||
@@ -461,20 +474,26 @@ def media_ids(value) -> list[int]:
|
||||
|
||||
|
||||
def walk_widgets(widgets, prefix: str = ""):
|
||||
"""Every widget of a slide, inside stacks too, with its path ("2", "2.0", "2.1.1": the widget's
|
||||
index, then its part's): → (path, widget, None), and (path, None, slide id) for a part that
|
||||
shows a library slide. The editor and the player find a widget's extras by its path."""
|
||||
"""Every widget of a slide, inside stacks too, with its path ("2"; "2.1.0": the widget's index,
|
||||
then its part's, then its place in the part): → (path, widget, None), and ("2.1", None, slide
|
||||
id) for a part that shows a library slide. The editor and the player find a widget's extras by its path."""
|
||||
for i, w in enumerate(widgets or []):
|
||||
yield from _walk_one(w, f"{prefix}{i}")
|
||||
|
||||
|
||||
def cell_widgets(c: dict) -> list:
|
||||
"""A part's widgets (stored before owner review 4 as one `widget`)."""
|
||||
return c.get("widgets") or ([c["widget"]] if c.get("widget") else [])
|
||||
|
||||
|
||||
def _walk_one(w: dict, path: str):
|
||||
yield path, w, None
|
||||
for j, c in enumerate(w.get("cells") or []):
|
||||
cp = f"{path}.{j}"
|
||||
if c.get("widget"):
|
||||
yield from _walk_one(c["widget"], cp)
|
||||
elif c.get("slide_id"):
|
||||
ws = cell_widgets(c)
|
||||
for k, cw in enumerate(ws):
|
||||
yield from _walk_one(cw, f"{cp}.{k}")
|
||||
if not ws and c.get("slide_id"):
|
||||
yield cp, None, c["slide_id"]
|
||||
|
||||
|
||||
@@ -542,7 +561,7 @@ def _content(db, kind: str, raw: dict | None) -> dict:
|
||||
raise XeniaError("media.not_a_picture")
|
||||
for path, w, sid in found:
|
||||
# a stack inside a stack, not deeper (2026-11-21)
|
||||
if w and w.get("kind") == "stack" and path.count(".") > 1:
|
||||
if w and w.get("kind") == "stack" and path.count(".") > 2:
|
||||
raise XeniaError("signage.content_invalid", field=f"widgets.{path}", reason="a stack goes at most one stack deep")
|
||||
if sid and db.get(SignageSavedSlide, sid) is None:
|
||||
raise XeniaError("signage.slide_unknown", slide_id=sid)
|
||||
|
||||
@@ -29,7 +29,7 @@ def test_text_weather_and_stack_widgets_are_checked(client, owner_h):
|
||||
ws = s["content"]["widgets"]
|
||||
assert ws[0]["text"] == "Happy hour 18-20"
|
||||
assert ws[1]["weather_from"] == 1 and ws[1]["weather_days"] == 2 and ws[1]["weather_style"] == "icon" # the forecast has 3 days
|
||||
assert [c["share"] for c in ws[2]["cells"]] == [30, 70] and ws[2]["cells"][1]["widget"]["direction"] == "column"
|
||||
assert [c["share"] for c in ws[2]["cells"]] == [30, 70] and ws[2]["cells"][1]["widgets"][0]["direction"] == "column"
|
||||
assert ws[0]["cells"] == [] and ws[0]["board"] is None
|
||||
url = f"/api/signage/playlists/{p['id']}/slides"
|
||||
bad = [
|
||||
@@ -57,12 +57,12 @@ def test_a_stack_shows_a_library_slide_and_a_menu_widget(client, owner_h, screen
|
||||
got = client.get("/api/signage/screen", headers=tv["h"]).json()["playlist"]["slides"][0]
|
||||
ex = got["extras"]
|
||||
assert ex["0"]["link"] and got["content"]["widgets"][0]["link"] == ex["0"]["link"]
|
||||
assert names(ex["1.0"]["menu"]) == [] and ex["1.0"]["menu"]["count"] == 0 # Beer hidden; Wine: delivery only
|
||||
assert names(ex["1.0.0"]["menu"]) == [] and ex["1.0.0"]["menu"]["count"] == 0 # Beer hidden; Wine: delivery only
|
||||
inner = ex["1.1"]["slide"]
|
||||
assert inner["id"] == promo["id"] and inner["kind"] == "text" and inner["content"]["title"] == "Fresh fish"
|
||||
assert inner["extras"]["0"]["link"] # its own widgets' extras
|
||||
# the editor: the hidden product stays in the list, marked
|
||||
ed = client.get(f"/api/signage/playlists/{p['id']}", headers=owner_h).json()["slides"][0]["extras"]["1.0"]["menu"]
|
||||
ed = client.get(f"/api/signage/playlists/{p['id']}", headers=owner_h).json()["slides"][0]["extras"]["1.0.0"]["menu"]
|
||||
assert [(i["name"], i.get("hidden", False)) for g in ed["groups"] for i in g["items"]] == [("Beer", True)] and ed["count"] == 0
|
||||
# a change to the library slide reaches the screens that show it inside a stack
|
||||
sent.clear()
|
||||
@@ -89,7 +89,7 @@ def test_the_editor_previews_any_slide(client, owner_h, menu):
|
||||
{"share": 50, "slide_id": promo["id"]})]}})
|
||||
assert r.status_code == 200, r.text
|
||||
got = r.json()
|
||||
assert [i.get("hidden") for g in got["extras"]["0.0"]["menu"]["groups"] for i in g["items"]] == [True]
|
||||
assert [i.get("hidden") for g in got["extras"]["0.0.0"]["menu"]["groups"] for i in g["items"]] == [True]
|
||||
assert got["extras"]["0.1"]["slide"]["content"]["title"] == "Inside" and got["menu"] is None and got["media"] == {}
|
||||
r = client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "menu", "content": {"select": "all", "exclude_ids": [menu["beer"].id]}})
|
||||
m = r.json()["menu"]
|
||||
@@ -117,3 +117,27 @@ def test_a_board_has_its_own_names_and_the_look_of_each_part(client, owner_h, me
|
||||
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
|
||||
|
||||
|
||||
def test_a_part_holds_several_widgets_and_colours_can_be_see_through(client, owner_h, menu):
|
||||
"""Owner review 4 (2026-11-21): a stack's part holds several widgets (each with its own extras,
|
||||
by path "stack.part.place"); a part stored with one `widget` still reads; colours #rrggbbaa; a
|
||||
board's badges have their own text colour."""
|
||||
p = playlist(client, owner_h)
|
||||
s = slide(client, owner_h, p["id"], "blank", content={"background": {"colour": "#11182780"}, "widgets": [
|
||||
stack({"share": 40, "widgets": [{"kind": "clock"}, {"kind": "qr"}, {"kind": "menu", "board": {"product_ids": [menu["steak"].id]}}]},
|
||||
{"share": 60, "widget": {"kind": "date"}}),
|
||||
]})
|
||||
cells = s["content"]["widgets"][0]["cells"]
|
||||
assert [w["kind"] for w in cells[0]["widgets"]] == ["clock", "qr", "menu"] and [w["kind"] for w in cells[1]["widgets"]] == ["date"]
|
||||
assert "widget" not in cells[1] and s["content"]["background"]["colour"] == "#11182780"
|
||||
ex = client.get(f"/api/signage/playlists/{p['id']}", headers=owner_h).json()["slides"][0]["extras"]
|
||||
assert ex["0.0.1"]["link"] and names(ex["0.0.2"]["menu"]) == [["Grill", ["Steak"]]]
|
||||
url = f"/api/signage/playlists/{p['id']}/slides"
|
||||
for bad in (stack({"share": 50, "widgets": [{"kind": "clock"}], "slide_id": 1}),
|
||||
stack({"share": 50, "widgets": [{"kind": "clock"}] * 7})):
|
||||
assert err(client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": [bad]}})) == "signage.content_invalid", bad
|
||||
m = slide(client, owner_h, p["id"], "menu", content={"accent_colour": "#1e3a8a", "badge_text_colour": "#fde68aCC"})["content"]
|
||||
assert m["badge_text_colour"] == "#fde68aCC" and m["accent_colour"] == "#1e3a8a"
|
||||
for bad in ({"badge_text_colour": "#fff"}, {"text_colour": "#12345"}):
|
||||
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": bad})) == "signage.content_invalid", bad
|
||||
|
||||
Reference in New Issue
Block a user