feat(backend): signage menu boards: any products, the board's own order, live prices (platform-v2 step 5.4b)
- MenuContent: select all / whole categories (with sub-categories, live: new products join) / single products, exclusions; grouped by category or not, headings; the board's own category and product order; a sales point's prices or none; photos, descriptions, badges (new, chef, offer, popular, spicy, vegetarian, vegan); sold-out crossed out or hidden; columns, items per page, seconds per page, font, colours, size, background. - services/signage_menu.resolve: the products in that order with customer-facing names, prices from pos_cart.unit_prices (what the counter charges right now), availability, card-size photos. GET /api/signage/screen includes each menu slide's `menu`. - Every request that changes the menu (the online menu's paths) also sends signage.changed to the screens with a menu board (main.py, off the loop). - tests: test_signage_menu.py (6); 515 passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,7 @@ from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from typing import List, Literal, Optional
|
||||
from typing import Dict, List, Literal, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Response
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
@@ -87,14 +87,53 @@ class TextContent(_Strict):
|
||||
background: Background = Field(default_factory=Background)
|
||||
|
||||
|
||||
Badge = Literal["new", "chef", "offer", "popular", "spicy", "vegetarian", "vegan"]
|
||||
|
||||
|
||||
class MenuContent(_Strict):
|
||||
"""The menu board's look; what it lists comes with step 5.4b."""
|
||||
"""A menu board (5.4b): which products (services/signage_menu.py resolves them), in the board's
|
||||
own order, with a sales point's live prices, and how it looks."""
|
||||
title: Optional[str] = Field(default=None, max_length=120)
|
||||
# what it lists
|
||||
select: Literal["all", "custom"] = "custom"
|
||||
category_ids: List[int] = Field(default_factory=list, max_length=200) # whole categories (live)
|
||||
product_ids: List[int] = Field(default_factory=list, max_length=1000) # single products
|
||||
exclude_ids: List[int] = Field(default_factory=list, max_length=1000)
|
||||
group_by_category: bool = True
|
||||
category_titles: bool = True # a heading over each group
|
||||
category_order: List[int] = Field(default_factory=list, max_length=200) # the board's own order
|
||||
product_order: List[int] = Field(default_factory=list, max_length=1000)
|
||||
# what each line shows
|
||||
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
|
||||
sold_out: Literal["strike", "hide"] = "strike"
|
||||
# how it's laid out (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)
|
||||
font: Font = "sans"
|
||||
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)
|
||||
background: Background = Field(default_factory=Background)
|
||||
|
||||
@field_validator("sales_point")
|
||||
@classmethod
|
||||
def _point(cls, v):
|
||||
from core import sales_points
|
||||
if v is not None and v not in sales_points.ALL:
|
||||
raise ValueError(f"one of {', '.join(sales_points.ALL)}")
|
||||
return v
|
||||
|
||||
@field_validator("badges")
|
||||
@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
|
||||
|
||||
|
||||
CONTENT = {"image": ImageContent, "video": VideoContent, "text": TextContent, "menu": MenuContent}
|
||||
Kind = Literal["menu", "image", "video", "text"]
|
||||
@@ -294,6 +333,14 @@ def _uses(db, media_id: int) -> list:
|
||||
media_store.register_usage("signage_slide", _uses)
|
||||
|
||||
|
||||
def menu_changed(db) -> None:
|
||||
"""Products, categories or prices changed (main.py, the same requests that push the online menu):
|
||||
the screens with a menu board on their playlist read it again."""
|
||||
playlists = {pid for (pid,) in db.query(SignageSlide.playlist_id).filter(SignageSlide.kind == "menu")}
|
||||
if playlists:
|
||||
_tell([d.id for d in _screens(db) if _screen_config(d).get("playlist") in playlists])
|
||||
|
||||
|
||||
# ── playlists ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@router.get("/playlists")
|
||||
@@ -479,9 +526,12 @@ def screen(db: Session = Depends(get_db), dev=Depends(require_device("signage"))
|
||||
p = db.get(SignagePlaylist, cfg["playlist"]) if cfg.get("playlist") else None
|
||||
playlist = None
|
||||
if p is not None:
|
||||
from services.signage_menu import resolve
|
||||
slides = [_slide_out(s) for s in p.slides if s.enabled]
|
||||
for s in slides:
|
||||
s["transition"] = s["transition"] or p.transition
|
||||
if s["kind"] == "menu":
|
||||
s["menu"] = resolve(db, s["content"]) # live prices and availability (5.4b)
|
||||
playlist = {"id": p.id, "name": p.name, "orientation": p.orientation, "transition": p.transition, "slides": slides,
|
||||
"media": _media_map(db, [i for s in slides for i in media_ids(s["content"])])}
|
||||
out = {"screen": {"id": dev.id, "name": dev.name, "orientation": cfg["orientation"], "rotation": cfg["rotation"]},
|
||||
|
||||
Reference in New Issue
Block a user