feat(signage): venue badges, widgets' own look, widgets placed inside stacks, Save and leave, shared controls (owner review 5)
- Badges: the venue's list (setting signage.badges: names el/en, colours, an icon from a food and drink set) edited under Signage -> "Message & settings"; sent with the venue to screens and previews; several badges per product (MenuList.badges lists, a single one still read) in the shared multiple Dropdown; a board's badge colour / text colour override them (None = each own). - Widgets: colour, background plate, font, bold / italic / underline, text size, QR colours; widgets in a stack's part get every setting, vertical alignment, and a custom box inside their place, picked (stack, then widget) and dragged on the preview (selection by path "2.1.0"). - Menu slides: vertical alignment of the list (board_valign); "Where the list sits" is now "Horizontal alignment". - Message of the day: one component in the settings tab, on the Overview and from its widget. - Leaving a slide with changes: "Save and leave" (ConfirmDialog altLabel). - @xenia/ui: ColourField (with colour.js helpers), FieldRow (framed only while wrapped), Slider, IconPicker, Segmented multiple; native selects on the Overview and signage replaced by Dropdown, the device settings' colour input by ColourField. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -75,7 +75,7 @@ WidgetKind = Literal["logo", "name", "date", "clock", "message", "qr", "weather"
|
||||
Position = Literal["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right", "top-bar", "bottom-bar", "custom"]
|
||||
|
||||
|
||||
Badge = Literal["new", "chef", "offer", "popular", "spicy", "vegetarian", "vegan"]
|
||||
BADGE_KEY = r"^[a-z0-9][a-z0-9_-]{0,23}$" # a badge of the venue's list (services/signage_badges.py)
|
||||
Align = Literal["left", "center", "right"]
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ class MenuList(_Strict):
|
||||
sales_point: Optional[str] = "in_store" # whose prices; None = no prices
|
||||
show_photos: bool = False
|
||||
show_descriptions: bool = False
|
||||
badges: Dict[str, Badge] = Field(default_factory=dict) # product id → badge
|
||||
badges: Dict[str, List[str]] = Field(default_factory=dict) # product id → its badges (keys of the venue's list; up to 4)
|
||||
sold_out: Literal["strike", "hide"] = "strike"
|
||||
language: Optional[Literal["el", "en"]] = None # 6.4: the menu's language on this board; None = as typed
|
||||
# pages (the player pages through what doesn't fit, 5.5b)
|
||||
@@ -133,8 +133,9 @@ 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) # 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
|
||||
accent_colour: str = Field(default="#f59e0b", pattern=HEX) # page dots; headings and prices until their own
|
||||
badge_colour: Optional[str] = Field(default=None, pattern=HEX) # None: each badge its own (the venue's list)
|
||||
badge_text_colour: Optional[str] = Field(default=None, pattern=HEX) # None: each badge its own (else white / black)
|
||||
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)
|
||||
@@ -162,12 +163,23 @@ class MenuList(_Strict):
|
||||
raise ValueError(f"one of {', '.join(sales_points.ALL)}")
|
||||
return v
|
||||
|
||||
@field_validator("badges")
|
||||
@field_validator("badges", mode="before")
|
||||
@classmethod
|
||||
def _badge_keys(cls, v):
|
||||
if any(not k.isdigit() for k in v):
|
||||
raise ValueError("badges are keyed by product id")
|
||||
return v
|
||||
import re as _re
|
||||
if not isinstance(v, dict):
|
||||
return v
|
||||
out = {}
|
||||
for k, x in v.items():
|
||||
if not str(k).isdigit():
|
||||
raise ValueError("badges are keyed by product id")
|
||||
keys = [x] if isinstance(x, str) else list(x or []) # one badge (before owner review 5) or several
|
||||
keys = list(dict.fromkeys(str(b) for b in keys))
|
||||
if len(keys) > 4 or any(not _re.match(BADGE_KEY, b) for b in keys):
|
||||
raise ValueError("up to 4 badges of the venue's list")
|
||||
if keys:
|
||||
out[str(k)] = keys
|
||||
return out
|
||||
|
||||
|
||||
class Box(_Strict):
|
||||
@@ -237,6 +249,17 @@ class Widget(_Strict):
|
||||
weather_from: int = Field(default=0, ge=0, le=2) # 0 today (now), 1 tomorrow, 2 the day after
|
||||
weather_style: Literal["both", "icon", "text"] = "both" # picture and degrees, the picture, the degrees
|
||||
board: Optional[MenuList] = None # menu: what it lists and how
|
||||
# its look (owner review 5, 2026-11-21): None = the slide's
|
||||
vertical: Literal["auto", "top", "middle", "bottom"] = "auto" # inside its place (a stack's part, its box)
|
||||
colour: Optional[str] = Field(default=None, pattern=HEX) # its text and pictures (weather, clock…)
|
||||
background_colour: Optional[str] = Field(default=None, pattern=HEX) # a plate behind it
|
||||
font: Optional[Font] = None
|
||||
bold: Optional[bool] = None # None: as the widget usually is
|
||||
italic: bool = False
|
||||
underline: bool = False
|
||||
text_size: int = Field(default=100, ge=50, le=200) # % of its usual text
|
||||
qr_colour: Optional[str] = Field(default=None, pattern=HEX) # the code's dots (default black)
|
||||
qr_background: Optional[str] = Field(default=None, pattern=HEX) # around them (default white)
|
||||
direction: Literal["row", "column"] = "row" # stack: side by side / one over the other
|
||||
cells: List[Cell] = Field(default_factory=list, max_length=6)
|
||||
|
||||
@@ -316,6 +339,7 @@ class MenuContent(MenuList):
|
||||
with its widgets."""
|
||||
board_width: int = Field(default=100, ge=40, le=100) # % of the screen the list takes (2026-11-21)
|
||||
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)
|
||||
|
||||
@@ -1116,8 +1140,7 @@ def screen(db: Session = Depends(get_db), dev=Depends(require_device("signage"))
|
||||
out = {"screen": {"id": dev.id, "name": dev.name, "orientation": cfg["orientation"], "rotation": cfg["rotation"]},
|
||||
"playlist": playlist, "schedule": schedule, "playlists": playlists,
|
||||
# for the widgets (5.4c): weather None = hide it (no internet, no place, too old)
|
||||
"venue": {"name": _setting(db, "venue.name") or None, "message": _setting(db, MESSAGE) or None,
|
||||
"weather": weather.current(db)}}
|
||||
"venue": _venue(db)}
|
||||
out["version"] = hashlib.sha256(json.dumps(out, sort_keys=True, default=str).encode()).hexdigest()[:16]
|
||||
return out
|
||||
|
||||
@@ -1217,6 +1240,33 @@ def put_message(body: MessageBody, db: Session = Depends(get_db), user=Depends(r
|
||||
return {"text": (body.text or "").strip() or None}
|
||||
|
||||
|
||||
class BadgesBody(BaseModel):
|
||||
badges: list = Field(default_factory=list)
|
||||
|
||||
|
||||
@router.get("/badges")
|
||||
def get_badges(db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
"""The badges boards can put on products (owner review 5), with the icons they may have."""
|
||||
from services import signage_badges
|
||||
return {"badges": signage_badges.load(db), "icons": list(signage_badges.ICONS)}
|
||||
|
||||
|
||||
@router.put("/badges")
|
||||
def put_badges(body: BadgesBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
"""The venue's badges, all at once: their names, colours (the boards' defaults) and icons."""
|
||||
from pydantic import ValidationError
|
||||
from services import signage_badges
|
||||
try:
|
||||
parsed = signage_badges.BadgeList(badges=body.badges)
|
||||
except ValidationError as e:
|
||||
first = e.errors()[0]
|
||||
raise XeniaError("signage.content_invalid", field=".".join(str(x) for x in first.get("loc", ())), reason=first.get("msg", ""))
|
||||
out = signage_badges.save(db, parsed.badges)
|
||||
db.commit()
|
||||
tell_all_screens(db)
|
||||
return {"badges": out, "icons": list(signage_badges.ICONS)}
|
||||
|
||||
|
||||
@router.get("/weather")
|
||||
def weather_status(db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
from services import weather
|
||||
@@ -1273,8 +1323,15 @@ class MenuPreviewBody(BaseModel):
|
||||
@router.get("/venue")
|
||||
def preview_venue(db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
"""What the widgets show (the same as a screen gets), for the editor's previews."""
|
||||
from services import weather
|
||||
return {"name": _setting(db, "venue.name") or None, "message": _setting(db, MESSAGE) or None, "weather": weather.current(db)}
|
||||
return _venue(db)
|
||||
|
||||
|
||||
def _venue(db) -> dict:
|
||||
"""What the widgets need of the venue: its name, the message of the day, the weather (None = hide
|
||||
it: no internet, no place, too old) and its badges (owner review 5)."""
|
||||
from services import signage_badges, weather
|
||||
return {"name": _setting(db, "venue.name") or None, "message": _setting(db, MESSAGE) or None,
|
||||
"weather": weather.current(db), "badges": signage_badges.load(db)}
|
||||
|
||||
|
||||
class SlidePreviewBody(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user