feat(signage): new widgets (shape, scrolling text, countdown, opening hours, Wi-Fi, contact details); the venue's opening hours on the server, edited on the Schedule page
Shapes: rectangle, circle, triangle, polygon, star or own corners, fill or gradient, border. Countdown: to a time every day or a date, from now / a span before / a set time, in venue time (the slide shows what is left right now). Opening hours, Wi-Fi (with a join-the-network code) and contact details read the venue's identity and opening hours (GET/PUT /api/identity/hours; Schedule -> Opening hours, shaded on its timeline); the editor warns with a link when they're missing. Plan 6R.15, F-112. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
"""The venue's identity (6R.14, owner 2026-11-22): set once, used by every app that shows the venue.
|
||||
|
||||
GET /api/identity its name, slogan, colours, logos, Wi-Fi and contact details (anyone who opens the manager)
|
||||
PUT /api/identity all of it at once (core.settings.manage)
|
||||
GET /api/identity its name, slogan, colours, logos, Wi-Fi and contact details (anyone who opens the manager)
|
||||
PUT /api/identity all of it at once (core.settings.manage)
|
||||
GET /api/identity/hours the opening hours, Monday first (6R.15)
|
||||
PUT /api/identity/hours {days: [[{from, to}], … 7], note} (core.settings.manage or core.staff.manage: the Schedule page)
|
||||
|
||||
Stored as the settings `venue.name` (the name everything already shows) and `venue.identity` (JSON,
|
||||
the rest). Logos are media library pictures, protected while used. Signage screens get it with
|
||||
@@ -17,12 +19,14 @@ from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from core.access.deps import require
|
||||
from core.access.deps import require, require_any
|
||||
from core.errors import XeniaError
|
||||
from database import get_db
|
||||
|
||||
router = APIRouter()
|
||||
KEY = "venue.identity"
|
||||
HOURS = "venue.opening_hours"
|
||||
TIME = r"^([01]\d|2[0-3]):[0-5]\d$"
|
||||
HEX = r"^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$"
|
||||
LOGOS = ("main", "light", "dark", "icon")
|
||||
|
||||
@@ -191,3 +195,57 @@ def put_identity(body: IdentityBody, db: Session = Depends(get_db), user=Depends
|
||||
except Exception:
|
||||
pass # signage not installed / off: nothing to tell
|
||||
return identity_out(db)
|
||||
|
||||
|
||||
# ── opening hours (6R.15): edited on the Schedule page, shown by signage's opening hours widget ──
|
||||
|
||||
class Span(_Strict):
|
||||
"""Open from … to … (venue time; `to` before `from` passes midnight)."""
|
||||
from_: str = Field(alias="from", pattern=TIME)
|
||||
to: str = Field(pattern=TIME)
|
||||
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
||||
|
||||
|
||||
class Hours(_Strict):
|
||||
days: List[List[Span]] = Field(default_factory=lambda: [[] for _ in range(7)]) # Monday first; [] = closed
|
||||
note: Optional[str] = Field(default=None, max_length=120) # "Closed on holidays"
|
||||
|
||||
@field_validator("days")
|
||||
@classmethod
|
||||
def _seven(cls, v):
|
||||
if len(v) != 7 or any(len(d) > 3 for d in v):
|
||||
raise ValueError("seven days, up to three spans a day")
|
||||
return v
|
||||
|
||||
@field_validator("note")
|
||||
@classmethod
|
||||
def _note(cls, v):
|
||||
return _text(v, 120)
|
||||
|
||||
|
||||
def hours_out(db) -> dict:
|
||||
"""{days: [[{from, to}]…7], note, set}: `set` false while no day has hours."""
|
||||
try:
|
||||
h = Hours(**json.loads(_setting(db, HOURS) or "{}"))
|
||||
except Exception:
|
||||
h = Hours()
|
||||
days = [[{"from": x.from_, "to": x.to} for x in d] for d in h.days]
|
||||
return {"days": days, "note": h.note, "set": any(days)}
|
||||
|
||||
|
||||
@router.get("/hours")
|
||||
def get_hours(db: Session = Depends(get_db), user=Depends(require("core.dashboard.access"))):
|
||||
return hours_out(db)
|
||||
|
||||
|
||||
@router.put("/hours")
|
||||
def put_hours(body: Hours, db: Session = Depends(get_db), user=Depends(require_any("core.settings.manage", "core.staff.manage"))):
|
||||
days = [[{"from": x.from_, "to": x.to} for x in sorted(d, key=lambda x: x.from_)] for d in body.days]
|
||||
_save(db, HOURS, json.dumps({"days": days, "note": body.note}, ensure_ascii=False))
|
||||
db.commit()
|
||||
try:
|
||||
from routers.signage import tell_all_screens
|
||||
tell_all_screens(db)
|
||||
except Exception:
|
||||
pass
|
||||
return hours_out(db)
|
||||
|
||||
@@ -82,7 +82,10 @@ class Background(_Strict):
|
||||
fit: Literal["cover", "contain"] = "cover"
|
||||
|
||||
|
||||
WidgetKind = Literal["logo", "name", "date", "clock", "message", "qr", "weather", "text", "menu", "stack"]
|
||||
WidgetKind = Literal["logo", "name", "date", "clock", "message", "qr", "weather", "text", "menu", "stack",
|
||||
"shape", "ticker", "countdown", "hours", "wifi", "contact"] # 6R.15
|
||||
WHEN = r"^(\d{4}-\d{2}-\d{2}T)?([01]\d|2[0-3]):[0-5]\d$" # a countdown's moment: "HH:MM" (every day) or "YYYY-MM-DDTHH:MM"
|
||||
ContactKey = Literal["phone", "phone2", "email", "address", "website", "google", "facebook", "instagram", "tiktok", "tripadvisor", "whatsapp", "viber"]
|
||||
Position = Literal["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right", "top-bar", "bottom-bar", "custom"]
|
||||
|
||||
|
||||
@@ -251,7 +254,7 @@ class Widget(_Strict):
|
||||
box: Optional[Box] = None # position "custom"
|
||||
align: Literal["auto", "left", "center", "right"] = "auto" # inside its place; auto: by its corner / box
|
||||
media_id: Optional[int] = None # logo: a picture
|
||||
text: Optional[str] = Field(default=None, max_length=200) # message: this text instead of the venue's
|
||||
text: Optional[str] = Field(default=None, max_length=500) # message: this text instead of the venue's; text, ticker, a countdown's / hours' title
|
||||
date_style: Literal["short", "long"] = "long"
|
||||
clock_seconds: bool = False
|
||||
qr_target: Literal["ordering", "menu", "custom"] = "ordering"
|
||||
@@ -274,6 +277,37 @@ class Widget(_Strict):
|
||||
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)
|
||||
# a shape (6R.15): in its box; a fill (flat, or a gradient to fill_to at fill_angle), a border
|
||||
shape: Literal["rectangle", "circle", "triangle", "polygon", "star", "custom"] = "rectangle"
|
||||
shape_sides: int = Field(default=6, ge=3, le=12) # polygon: its sides; star: its points
|
||||
shape_inner: int = Field(default=45, ge=15, le=90) # star: its inner corners, % of the outer
|
||||
shape_points: Optional[str] = Field(default=None, max_length=600) # custom: "x,y x,y …" in % of its box
|
||||
fill: Optional[str] = Field(default=None, pattern=HEX)
|
||||
fill_to: Optional[str] = Field(default=None, pattern=HEX) # None: one colour
|
||||
fill_angle: int = Field(default=180, ge=0, le=359)
|
||||
stroke: Optional[str] = Field(default=None, pattern=HEX)
|
||||
stroke_width: int = Field(default=0, ge=0, le=20) # steps of ½ % of the shape's shorter side
|
||||
radius: int = Field(default=0, ge=0, le=50) # rectangle: rounded corners, % of its shorter side
|
||||
# scrolling text
|
||||
ticker_speed: int = Field(default=4, ge=1, le=10)
|
||||
ticker_direction: Literal["left", "right"] = "left"
|
||||
# a countdown: to a time every day or a date and time (venue time); it counts from now, from a span
|
||||
# before, or from a time; before that it shows the whole span or nothing; at the end a text or nothing
|
||||
countdown_to: Optional[str] = Field(default=None, pattern=WHEN)
|
||||
countdown_start: Literal["now", "before", "at"] = "now"
|
||||
countdown_before: int = Field(default=120, ge=1, le=10080) # minutes
|
||||
countdown_at: Optional[str] = Field(default=None, pattern=WHEN)
|
||||
countdown_waiting: Literal["full", "hide"] = "full"
|
||||
countdown_done: Optional[str] = Field(default=None, max_length=80)
|
||||
countdown_done_hide: bool = False
|
||||
# the opening hours (from the Schedule page): the week, or today only; days with the same hours on one line
|
||||
hours_style: Literal["week", "today"] = "week"
|
||||
hours_group: bool = True
|
||||
# Wi-Fi (from the identity): its code to join, the password written out
|
||||
wifi_qr: bool = True
|
||||
wifi_password: bool = True
|
||||
# contact details (from the identity): which, in this order
|
||||
contact_fields: List[ContactKey] = Field(default_factory=lambda: ["phone", "website", "instagram"], max_length=12)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _place(self):
|
||||
@@ -1491,12 +1525,13 @@ def _venue(db) -> dict:
|
||||
it: no internet, no place, too old) and its badges (owner review 5); its identity (6R.14: slogan,
|
||||
colours, logos, Wi-Fi, contact) and time zone."""
|
||||
from core.timeutil import venue_tz
|
||||
from routers.identity import identity_out
|
||||
from routers.identity import hours_out, identity_out
|
||||
from services import signage_badges, weather
|
||||
ident = identity_out(db)
|
||||
ident.pop("name", None)
|
||||
return {"name": _setting(db, "venue.name") or None, "message": _setting(db, MESSAGE) or None,
|
||||
"weather": weather.current(db), "badges": signage_badges.load(db), "identity": ident, "timezone": venue_tz().key}
|
||||
"weather": weather.current(db), "badges": signage_badges.load(db), "identity": ident, "timezone": venue_tz().key,
|
||||
"hours": hours_out(db)}
|
||||
|
||||
|
||||
class SlidePreviewBody(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user