feat(signage): menus play whole rounds, seconds fields with − / +, widget limit setting, widgets as big as their content (owner review 6)

- A menu board with pages plays whole rounds (menuMs rounds its seconds up); the editor says how
  long it really plays under "Seconds on screen", the card and the playlist total use it.
- Seconds on screen / per page: shared NumberInput (− / +, may be emptied: an error under the
  field and Save blocked until filled; 1 s at least, server ge=1).
- Performance (Signage -> Message & settings): widgets per slide (signage.max_widgets, 10
  recommended, up to 50), checked by the server (signage.too_many_widgets) and the editor.
- Text, clock, date, QR, weather, logo placed by hand: the box is exactly the content (its height
  x text size sets the size, the width follows; handles scale keeping the shape; text size grows
  the box); a slide's widget may run off the slide while 5 % stays on it.
- Slider: the value as close to the slider as the frame's padding; floor and table-colour sliders
  use the shared Slider. Timeline cards' ring no longer clipped; larger playlist buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 15:11:48 +02:00
co-authored by Claude Opus 5.5
parent aa3fe85053
commit aa8ba5d1d4
33 changed files with 436 additions and 75 deletions
+1
View File
@@ -110,6 +110,7 @@ CODES: dict[str, tuple[int, str]] = {
"signage.not_a_screen": (404, "Device {device_id} isn't a signage screen."),
"signage.schedule_unknown": (404, "Schedule {schedule_id} not found."),
"signage.not_a_video": (422, "Pick a video for this slide."),
"signage.too_many_widgets": (422, "A slide holds at most {max} widgets (Signage → Message & settings → Performance)."),
"signage.content_invalid": (422, "This slide's setting isn't valid ({field}: {reason})."),
"signage.order_mismatch": (409, "The playlist changed in the meantime. Reload it and try again."),
"signage.weather_offline": (503, "The weather service can't be reached: the venue's server needs internet for it."),
+44 -13
View File
@@ -49,6 +49,8 @@ from services.ws_bus import broadcast_sync
router = APIRouter()
KEY = "signage.manage"
MESSAGE = "signage.message"
MAX_WIDGETS = "signage.max_widgets" # widgets a slide may hold (owner review 6: Performance; 10 recommended)
MAX_WIDGETS_CAP = 50 # never more, whatever the setting
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}$"
@@ -130,7 +132,7 @@ class MenuList(_Strict):
# pages (the player pages through what doesn't fit, 5.5b)
columns: int = Field(default=2, ge=1, le=3)
page_size: Optional[int] = Field(default=None, ge=3, le=60) # items per page; None = as many as fit
page_seconds: int = Field(default=10, ge=3, le=120)
page_seconds: int = Field(default=10, ge=1, le=120)
font: Font = "sans"
text_colour: str = Field(default="#ffffff", pattern=HEX)
accent_colour: str = Field(default="#f59e0b", pattern=HEX) # page dots; headings and prices until their own
@@ -183,19 +185,20 @@ class MenuList(_Strict):
class Box(_Strict):
"""Where a widget moved by hand sits (2026-11-21): % of the slide's width / height."""
x: float = Field(ge=0, le=100)
y: float = Field(ge=0, le=100)
w: float = Field(ge=2, le=100)
h: float = Field(ge=2, le=100)
"""Where a widget moved by hand sits (2026-11-21): % of the slide's (or its stack place's) width /
height. Owner review 6: it may run off the slide, as long as a strip of it (5 %) stays on it to
grab it back; a text, clock, QR… is as big as its content (its height sets the size)."""
x: float = Field(ge=-100, le=100)
y: float = Field(ge=-100, le=100)
w: float = Field(ge=1, le=100)
h: float = Field(ge=1, le=100)
@model_validator(mode="after")
def _inside(self):
# kept on the slide: a box never runs past its right or bottom edge
self.w = round(min(self.w, 100), 2)
self.h = round(min(self.h, 100), 2)
self.x = round(min(self.x, 100 - self.w), 2)
self.y = round(min(self.y, 100 - self.h), 2)
self.x = round(min(max(self.x, 5 - self.w), 95), 2)
self.y = round(min(max(self.y, 5 - self.h), 95), 2)
return self
@@ -324,13 +327,13 @@ class TextContent(_Strict):
text_colour: str = Field(default="#ffffff", pattern=HEX)
text_size: int = Field(default=100, ge=50, le=250) # %
background: Background = Field(default_factory=Background)
widgets: List[Widget] = Field(default_factory=list, max_length=10)
widgets: List[Widget] = Field(default_factory=list, max_length=MAX_WIDGETS_CAP) # the venue's limit: _content
class BlankContent(_Strict):
"""A blank slide (2026-11-21): only its background and its widgets."""
background: Background = Field(default_factory=Background)
widgets: List[Widget] = Field(default_factory=list, max_length=10)
widgets: List[Widget] = Field(default_factory=list, max_length=MAX_WIDGETS_CAP) # the venue's limit: _content
class MenuContent(MenuList):
@@ -341,7 +344,7 @@ class MenuContent(MenuList):
board_align: Literal["left", "center", "right"] = "left" # where a narrower list sits, and its title
board_valign: Literal["top", "middle", "bottom"] = "top" # where a shorter list sits (owner review 5)
background: Background = Field(default_factory=Background)
widgets: List[Widget] = Field(default_factory=list, max_length=10)
widgets: List[Widget] = Field(default_factory=list, max_length=MAX_WIDGETS_CAP) # the venue's limit: _content
CONTENT = {"image": ImageContent, "video": VideoContent, "text": TextContent, "menu": MenuContent, "blank": BlankContent}
@@ -364,7 +367,7 @@ class PlaylistUpdate(BaseModel):
class SlideFields(BaseModel):
name: Optional[str] = Field(default=None, max_length=80)
duration_s: Optional[int] = Field(default=None, ge=2, le=3600)
duration_s: Optional[int] = Field(default=None, ge=1, le=3600)
transition: Optional[Transition] = None # None: the playlist's
video_to_end: Optional[bool] = None
enabled: Optional[bool] = None
@@ -566,6 +569,9 @@ def _content(db, kind: str, raw: dict | None) -> dict:
first = e.errors()[0]
raise XeniaError("signage.content_invalid", field=".".join(str(x) for x in first["loc"]), reason=first["msg"])
data = model.model_dump()
most = max_widgets(db)
if len(data.get("widgets") or []) > most:
raise XeniaError("signage.too_many_widgets", max=most)
from models.media import Media
for mid in media_ids(data):
m = db.get(Media, mid)
@@ -1240,6 +1246,31 @@ def put_message(body: MessageBody, db: Session = Depends(get_db), user=Depends(r
return {"text": (body.text or "").strip() or None}
def max_widgets(db) -> int:
"""How many widgets a slide may hold: the venue's setting (Performance), 10 until it changes it."""
try:
return max(1, min(MAX_WIDGETS_CAP, int(_setting(db, MAX_WIDGETS, "10") or 10)))
except ValueError:
return 10
class PerformanceBody(BaseModel):
max_widgets: int = Field(ge=1, le=MAX_WIDGETS_CAP)
@router.get("/performance")
def get_performance(db: Session = Depends(get_db), user=Depends(require(KEY))):
"""Limits that keep the TVs smooth (owner review 6): widgets per slide (10 recommended)."""
return {"max_widgets": max_widgets(db), "recommended": 10, "cap": MAX_WIDGETS_CAP}
@router.put("/performance")
def put_performance(body: PerformanceBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
_save_setting(db, MAX_WIDGETS, str(body.max_widgets))
db.commit()
return {"max_widgets": body.max_widgets, "recommended": 10, "cap": MAX_WIDGETS_CAP}
class BadgesBody(BaseModel):
badges: list = Field(default_factory=list)
+6 -3
View File
@@ -77,9 +77,12 @@ def test_blank_slides_and_widgets_placed_by_hand(client, owner_h):
p = playlist(client, owner_h)
s = slide(client, owner_h, p["id"], "blank", content={"widgets": [
{"kind": "clock", "position": "custom", "box": {"x": 90, "y": 5, "w": 20, "h": 10}, "align": "right"},
{"kind": "date", "position": "top-left", "size": "custom", "box": {"x": 1, "y": 1, "w": 5, "h": 5}}]})
clock, date = s["content"]["widgets"]
assert clock["size"] == "custom" and clock["box"] == {"x": 80, "y": 5, "w": 20, "h": 10} and clock["align"] == "right" # kept on the slide
{"kind": "date", "position": "top-left", "size": "custom", "box": {"x": 1, "y": 1, "w": 5, "h": 5}},
{"kind": "text", "text": "Big", "position": "custom", "box": {"x": 99, "y": -50, "w": 30, "h": 20}}]})
clock, date, big = s["content"]["widgets"]
# owner review 6: a box may run off the slide (here past the right edge), a strip of it stays on it
assert clock["size"] == "custom" and clock["box"] == {"x": 90, "y": 5, "w": 20, "h": 10} and clock["align"] == "right"
assert big["box"] == {"x": 95, "y": -15, "w": 30, "h": 20}
assert date["size"] == "medium" and date["box"] is None # a corner: no box, a real size
r = client.put(f"/api/signage/slides/{s['id']}", headers=owner_h, json={"content": {"widgets": [{"kind": "clock", "position": "custom"}]}})
assert err(r) == "signage.content_invalid" # placed by hand needs its box
@@ -173,3 +173,19 @@ def test_the_venues_badges_and_a_widgets_own_look(client, owner_h, menu, screens
url = f"/api/signage/playlists/{p['id']}/slides"
for bad in ({"badges": {sid: ["a", "b", "c", "d", "e"]}}, {"board_valign": "centre"}, {"widgets": [{"kind": "clock", "text_size": 400}]}):
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": bad})) == "signage.content_invalid", bad
def test_how_many_widgets_a_slide_may_hold_is_the_venues(client, owner_h):
"""Owner review 6 (2026-11-21): 10 widgets a slide (recommended), more when the venue allows them
(Signage → Message & settings → Performance), never over 50; a menu with pages may now turn them
every second."""
assert client.get("/api/signage/performance", headers=owner_h).json() == {"max_widgets": 10, "recommended": 10, "cap": 50}
p = playlist(client, owner_h)
url = f"/api/signage/playlists/{p['id']}/slides"
eleven = [{"kind": "clock"}] * 11
assert err(client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": eleven}})) == "signage.too_many_widgets"
assert client.put("/api/signage/performance", headers=owner_h, json={"max_widgets": 12}).json()["max_widgets"] == 12
assert client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": eleven}}).status_code == 201
assert err(client.put("/api/signage/performance", headers=owner_h, json={"max_widgets": 51})) is not None
s = slide(client, owner_h, p["id"], "menu", content={"page_seconds": 1}, duration_s=1)
assert s["content"]["page_seconds"] == 1 and s["duration_s"] == 1