feat(signage): Slides library, widgets placed on the preview, blank slides, slide editor rework
- Slides library (Alembic 0044, /api/signage/library): slides kept with a name and a
description, added to playlists as copies ("Add a slide" → Your slides, "Keep in Slides"),
or shown alone as a screen's default (device config `slide`, played as "slide:<id>",
also as a schedule's fallback). Signage → Slides: gallery + a two-pane editor.
- Widgets moved and sized by hand on the preview (WidgetCanvas: handles, snapping, arrow
keys): position/size "custom" with a box the TV draws the same; alignment per widget.
- Blank slides (background + widgets); menu boards narrower and placed left/centre/right.
- Slide editor reworked: name | show, transition effect | seconds; sections; text look on
one row with ready colours; one card per widget, settings on one row.
- Questions inside the page (@xenia/ui ConfirmDialog/useConfirm), Switch boxed, Segmented
fill; the timeline's drop line; schedule lines run on weekdays or smart days, not both;
the playlist editor stays within 1080p with a long timeline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,8 +12,14 @@ Manager side (signage.manage):
|
||||
PUT /api/signage/slides/{id} change it
|
||||
DELETE /api/signage/slides/{id}
|
||||
POST /api/signage/slides/{id}/duplicate a copy right after it
|
||||
GET /api/signage/screens the paired screens: playlist, orientation, rotation
|
||||
PUT /api/signage/screens/{id} {playlist_id, orientation, rotation}
|
||||
GET /api/signage/library the Slides library (2026-11-21): kept slides
|
||||
POST /api/signage/library {name, description, orientation, kind, …slide fields}
|
||||
GET /api/signage/library/{id} one (a menu board resolved for its preview)
|
||||
PUT /api/signage/library/{id} change it (a screen showing it is told)
|
||||
DELETE /api/signage/library/{id} screens that had it as their default show nothing
|
||||
POST /api/signage/library/{id}/duplicate a copy
|
||||
GET /api/signage/screens the paired screens: playlist or slide, orientation, rotation
|
||||
PUT /api/signage/screens/{id} {playlist_id | slide_id, orientation, rotation}
|
||||
|
||||
The screen (a paired device running `signage`, no sign-in):
|
||||
GET /api/signage/screen its playlist resolved for playing
|
||||
@@ -29,13 +35,13 @@ import json
|
||||
from typing import Dict, List, Literal, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Response
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from core.access.deps import require, require_device
|
||||
from core.errors import XeniaError
|
||||
from database import get_db
|
||||
from models.signage import SignagePlaylist, SignageScheduleItem, SignageSlide
|
||||
from models.signage import SignagePlaylist, SignageSavedSlide, SignageScheduleItem, SignageSlide
|
||||
from services import media as media_store
|
||||
from services import video as video_store
|
||||
from services.ws_bus import broadcast_sync
|
||||
@@ -66,14 +72,34 @@ class Background(_Strict):
|
||||
|
||||
|
||||
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"]
|
||||
Position = Literal["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right", "top-bar", "bottom-bar", "custom"]
|
||||
|
||||
|
||||
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)
|
||||
|
||||
@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)
|
||||
return self
|
||||
|
||||
|
||||
class Widget(_Strict):
|
||||
"""Something small on a menu or text slide (5.4c), in a corner or a bar."""
|
||||
"""Something small on a menu, text or blank slide (5.4c), in a corner or a bar, or (moved and
|
||||
sized by hand on the editor's preview, 2026-11-21) in its own box: position and size "custom"."""
|
||||
kind: WidgetKind
|
||||
position: Position = "top-right"
|
||||
size: Literal["small", "medium", "large"] = "medium"
|
||||
size: Literal["small", "medium", "large", "custom"] = "medium"
|
||||
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
|
||||
date_style: Literal["short", "long"] = "long"
|
||||
@@ -83,6 +109,18 @@ class Widget(_Strict):
|
||||
qr_caption: Optional[str] = Field(default=None, max_length=80)
|
||||
weather_days: int = Field(default=1, ge=1, le=3) # today, or today + the next days
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _place(self):
|
||||
if self.position == "custom":
|
||||
if self.box is None:
|
||||
raise ValueError("a widget placed by hand needs its box")
|
||||
self.size = "custom"
|
||||
else:
|
||||
self.box = None
|
||||
if self.size == "custom":
|
||||
self.size = "medium"
|
||||
return self
|
||||
|
||||
@field_validator("qr_url")
|
||||
@classmethod
|
||||
def _url(cls, v):
|
||||
@@ -118,6 +156,12 @@ class TextContent(_Strict):
|
||||
widgets: List[Widget] = Field(default_factory=list, max_length=10)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Badge = Literal["new", "chef", "offer", "popular", "spicy", "vegetarian", "vegan"]
|
||||
|
||||
|
||||
@@ -143,6 +187,8 @@ class MenuContent(_Strict):
|
||||
language: Optional[Literal["el", "en"]] = None # 6.4: the menu's language on this board; None = as typed
|
||||
# how it's laid out (the player pages through what doesn't fit, 5.5b)
|
||||
columns: int = Field(default=2, ge=1, le=3)
|
||||
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
|
||||
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"
|
||||
@@ -168,8 +214,8 @@ class MenuContent(_Strict):
|
||||
return v
|
||||
|
||||
|
||||
CONTENT = {"image": ImageContent, "video": VideoContent, "text": TextContent, "menu": MenuContent}
|
||||
Kind = Literal["menu", "image", "video", "text"]
|
||||
CONTENT = {"image": ImageContent, "video": VideoContent, "text": TextContent, "menu": MenuContent, "blank": BlankContent}
|
||||
Kind = Literal["menu", "image", "video", "text", "blank"]
|
||||
|
||||
|
||||
# ── requests ───────────────────────────────────────────────────────────────────
|
||||
@@ -254,8 +300,16 @@ class SchedulesBody(BaseModel):
|
||||
lines: List[ScheduleLine] = Field(default_factory=list, max_length=200)
|
||||
|
||||
|
||||
class SavedSlideBody(SlideFields):
|
||||
"""A library slide: its name and description, the shape it is built for, its kind (new ones)."""
|
||||
kind: Optional[Kind] = None
|
||||
description: Optional[str] = Field(default=None, max_length=300)
|
||||
orientation: Optional[Orientation] = None
|
||||
|
||||
|
||||
class ScreenBody(BaseModel):
|
||||
playlist_id: Optional[int] = None # its default playlist
|
||||
slide_id: Optional[int] = None # … or a library slide (one or the other)
|
||||
orientation: Optional[Orientation] = None
|
||||
rotation: Optional[Literal[0, 90, 180, 270]] = None
|
||||
|
||||
@@ -367,6 +421,24 @@ def _screen_config(dev) -> dict:
|
||||
return effective(for_app("signage"), dev.config)
|
||||
|
||||
|
||||
def slide_key(slide_id: int) -> str:
|
||||
"""A library slide shown alone, where a playlist id goes (a screen's default, 2026-11-21)."""
|
||||
return f"slide:{slide_id}"
|
||||
|
||||
|
||||
def default_of(cfg: dict):
|
||||
"""A screen's default: its playlist's id, else "slide:<id>" for its library slide, else None."""
|
||||
if cfg.get("playlist"):
|
||||
return cfg["playlist"]
|
||||
if cfg.get("slide"):
|
||||
return slide_key(cfg["slide"])
|
||||
return None
|
||||
|
||||
|
||||
def _screens_showing_slide(db, slide_id: int) -> list[int]:
|
||||
return [d.id for d in _screens(db) if not _screen_config(d).get("playlist") and _screen_config(d).get("slide") == slide_id]
|
||||
|
||||
|
||||
def _screen_playlists(db, d) -> set:
|
||||
"""Every playlist a screen may play: its default and those of its schedule lines."""
|
||||
from services.signage_schedule import lines_for
|
||||
@@ -440,6 +512,14 @@ def _uses(db, media_id: int) -> list:
|
||||
media_store.register_usage("signage_slide", _uses)
|
||||
|
||||
|
||||
def _saved_uses(db, media_id: int) -> list:
|
||||
return [{"id": s.id, "name": s.name} for s in db.query(SignageSavedSlide).order_by(SignageSavedSlide.name)
|
||||
if media_id in media_ids(s.content or {})]
|
||||
|
||||
|
||||
media_store.register_usage("signage_saved_slide", _saved_uses)
|
||||
|
||||
|
||||
def _video_done(db, media_id: int) -> None:
|
||||
"""A video's playable version is ready (services/video.py): the screens playing it switch to it."""
|
||||
playlists = {s.playlist_id for s in db.query(SignageSlide).filter(SignageSlide.kind == "video")
|
||||
@@ -458,10 +538,11 @@ def tell_all_screens(db) -> None:
|
||||
|
||||
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."""
|
||||
the screens with a menu board on their playlist (or as their default slide) 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_playlists(db, d) & playlists])
|
||||
boards = {slide_key(sid) for (sid,) in db.query(SignageSavedSlide.id).filter(SignageSavedSlide.kind == "menu")}
|
||||
if playlists or boards:
|
||||
_tell([d.id for d in _screens(db) if _screen_playlists(db, d) & playlists or default_of(_screen_config(d)) in boards])
|
||||
|
||||
|
||||
# ── playlists ──────────────────────────────────────────────────────────────────
|
||||
@@ -607,6 +688,112 @@ def duplicate_slide(slide_id: int, db: Session = Depends(get_db), user=Depends(r
|
||||
return _slide_out(copy)
|
||||
|
||||
|
||||
# ── the Slides library (owner 2026-11-21) ──────────────────────────────────────
|
||||
|
||||
def _saved(db, sid: int) -> SignageSavedSlide:
|
||||
s = db.get(SignageSavedSlide, sid)
|
||||
if s is None:
|
||||
raise XeniaError("signage.slide_unknown", slide_id=sid)
|
||||
return s
|
||||
|
||||
|
||||
def _saved_out(s: SignageSavedSlide, db=None) -> dict:
|
||||
out = {"id": s.id, "name": s.name, "description": s.description, "orientation": s.orientation, "kind": s.kind,
|
||||
"duration_s": s.duration_s, "transition": s.transition, "video_to_end": bool(s.video_to_end), "enabled": bool(s.enabled),
|
||||
"days": s.days or [], "time_from": s.time_from, "time_to": s.time_to, "date_from": s.date_from, "date_to": s.date_to,
|
||||
"content": s.content or {}}
|
||||
if db is not None:
|
||||
if s.kind == "menu":
|
||||
from services.signage_menu import resolve
|
||||
out["menu"] = resolve(db, out["content"])
|
||||
showing = set(_screens_showing_slide(db, s.id))
|
||||
out["screens"] = [{"id": d.id, "name": d.name} for d in _screens(db) if d.id in showing]
|
||||
return out
|
||||
|
||||
|
||||
def _saved_name(body) -> str:
|
||||
name = (body.name or "").strip()
|
||||
if not name:
|
||||
raise XeniaError("signage.content_invalid", field="name", reason="required")
|
||||
return name
|
||||
|
||||
|
||||
@router.get("/library")
|
||||
def list_saved(db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
"""Every kept slide, with its menu resolved (the gallery's previews) and the media they show."""
|
||||
rows = db.query(SignageSavedSlide).order_by(SignageSavedSlide.name, SignageSavedSlide.id).all()
|
||||
return {"slides": [_saved_out(s, db) for s in rows],
|
||||
"media": _media_map(db, [i for s in rows for i in media_ids(s.content or {})])}
|
||||
|
||||
|
||||
@router.post("/library", status_code=201)
|
||||
def create_saved(body: SavedSlideBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
if body.kind is None:
|
||||
raise XeniaError("signage.content_invalid", field="kind", reason="required")
|
||||
name = _saved_name(body)
|
||||
s = SignageSavedSlide(name=name, kind=body.kind, orientation=body.orientation or "landscape", duration_s=10, enabled=True,
|
||||
video_to_end=body.kind == "video", content=_content(db, body.kind, None))
|
||||
_apply(db, s, body)
|
||||
s.name = name
|
||||
s.description = (body.description or "").strip() or None
|
||||
db.add(s)
|
||||
db.commit()
|
||||
db.refresh(s)
|
||||
return _saved_out(s, db)
|
||||
|
||||
|
||||
@router.get("/library/{slide_id}")
|
||||
def get_saved(slide_id: int, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
s = _saved(db, slide_id)
|
||||
out = _saved_out(s, db)
|
||||
out["media"] = _media_map(db, media_ids(s.content or {}))
|
||||
return out
|
||||
|
||||
|
||||
@router.put("/library/{slide_id}")
|
||||
def update_saved(slide_id: int, body: SavedSlideBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
s = _saved(db, slide_id)
|
||||
if body.kind is not None and body.kind != s.kind:
|
||||
raise XeniaError("signage.content_invalid", field="kind", reason="a slide keeps its kind")
|
||||
name = _saved_name(body) if "name" in body.model_fields_set else s.name
|
||||
_apply(db, s, body)
|
||||
s.name = name
|
||||
if "description" in body.model_fields_set:
|
||||
s.description = (body.description or "").strip() or None
|
||||
if body.orientation is not None:
|
||||
s.orientation = body.orientation
|
||||
db.commit()
|
||||
db.refresh(s)
|
||||
_tell(_screens_showing_slide(db, s.id))
|
||||
return _saved_out(s, db)
|
||||
|
||||
|
||||
@router.delete("/library/{slide_id}", status_code=204)
|
||||
def delete_saved(slide_id: int, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
s = _saved(db, slide_id)
|
||||
showing = _screens_showing_slide(db, s.id)
|
||||
for d in _screens(db):
|
||||
if (d.config or {}).get("slide") == s.id:
|
||||
d.config = {**(d.config or {}), "slide": None}
|
||||
db.delete(s)
|
||||
db.commit()
|
||||
_tell(showing)
|
||||
return Response(status_code=204)
|
||||
|
||||
|
||||
@router.post("/library/{slide_id}/duplicate", status_code=201)
|
||||
def duplicate_saved(slide_id: int, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
s = _saved(db, slide_id)
|
||||
copy = SignageSavedSlide(name=f"{s.name} (2)"[:80], description=s.description, orientation=s.orientation, kind=s.kind,
|
||||
duration_s=s.duration_s, transition=s.transition, video_to_end=s.video_to_end, enabled=s.enabled,
|
||||
days=s.days, time_from=s.time_from, time_to=s.time_to, date_from=s.date_from, date_to=s.date_to,
|
||||
content=json.loads(json.dumps(s.content or {})))
|
||||
db.add(copy)
|
||||
db.commit()
|
||||
db.refresh(copy)
|
||||
return _saved_out(copy, db)
|
||||
|
||||
|
||||
# ── screens ────────────────────────────────────────────────────────────────────
|
||||
|
||||
def _screen_out(db, d) -> dict:
|
||||
@@ -614,13 +801,20 @@ def _screen_out(db, d) -> dict:
|
||||
from services.signage_schedule import now_for
|
||||
cfg = _screen_config(d)
|
||||
p = db.get(SignagePlaylist, cfg["playlist"]) if cfg.get("playlist") else None
|
||||
sl = db.get(SignageSavedSlide, cfg["slide"]) if cfg.get("slide") and not p else None
|
||||
now_id, scheduled = now_for(db, d)
|
||||
now_p = db.get(SignagePlaylist, now_id) if now_id else None
|
||||
if isinstance(now_id, str):
|
||||
now = {"id": now_id, "name": sl.name, "scheduled": False, "slide": True} if sl else None
|
||||
else:
|
||||
now_p = db.get(SignagePlaylist, now_id) if now_id else None
|
||||
now = {"id": now_p.id, "name": now_p.name, "scheduled": scheduled} if now_p else None
|
||||
ids = _screen_playlists(db, d)
|
||||
shapes = {x.orientation for x in db.query(SignagePlaylist).filter(SignagePlaylist.id.in_(ids))} if ids else set()
|
||||
if sl:
|
||||
shapes.add(sl.orientation)
|
||||
return {"id": d.id, "name": d.name, "playlist_id": p.id if p else None, "playlist_name": p.name if p else None,
|
||||
"orientation": cfg["orientation"], "rotation": cfg["rotation"],
|
||||
"now": {"id": now_p.id, "name": now_p.name, "scheduled": scheduled} if now_p else None,
|
||||
"slide_id": sl.id if sl else None, "slide_name": sl.name if sl else None,
|
||||
"orientation": cfg["orientation"], "rotation": cfg["rotation"], "now": now,
|
||||
"orientation_mismatch": any(o != cfg["orientation"] for o in shapes)}
|
||||
|
||||
|
||||
@@ -638,7 +832,12 @@ def update_screen(device_id: int, body: ScreenBody, db: Session = Depends(get_db
|
||||
raise XeniaError("signage.not_a_screen", device_id=device_id)
|
||||
cfg = dict(d.config or {})
|
||||
for key in body.model_fields_set:
|
||||
cfg[{"playlist_id": "playlist"}.get(key, key)] = getattr(body, key)
|
||||
cfg[{"playlist_id": "playlist", "slide_id": "slide"}.get(key, key)] = getattr(body, key)
|
||||
# the default is a playlist or a library slide, never both
|
||||
if "playlist_id" in body.model_fields_set and body.playlist_id is not None:
|
||||
cfg["slide"] = None
|
||||
if "slide_id" in body.model_fields_set and body.slide_id is not None:
|
||||
cfg["playlist"] = None
|
||||
d.config = validate(for_app("signage"), cfg, db)
|
||||
db.commit()
|
||||
broadcast_sync("device.updated", {}, device_ids=[d.id])
|
||||
@@ -663,6 +862,30 @@ def _resolved(db, p: SignagePlaylist) -> dict:
|
||||
"media": _media_map(db, [i for s in slides for i in media_ids(s["content"])])}
|
||||
|
||||
|
||||
def _resolved_slide(db, s: SignageSavedSlide, orientation: str) -> dict:
|
||||
"""A library slide shown alone as a screen's default: a playlist of that one slide."""
|
||||
from services.signage_menu import resolve
|
||||
one = _saved_out(s)
|
||||
one["transition"] = one["transition"] or "fade"
|
||||
if one["kind"] == "menu":
|
||||
one["menu"] = resolve(db, one["content"])
|
||||
for w in one["content"].get("widgets") or []:
|
||||
if w["kind"] == "qr":
|
||||
w["link"] = _qr_link(w)
|
||||
slides = [one] if s.enabled else []
|
||||
return {"id": slide_key(s.id), "name": s.name, "orientation": orientation, "transition": "fade", "slides": slides,
|
||||
"media": _media_map(db, media_ids(one["content"]))}
|
||||
|
||||
|
||||
def _default_resolved(db, cfg: dict):
|
||||
d = default_of(cfg)
|
||||
if isinstance(d, str):
|
||||
s = db.get(SignageSavedSlide, cfg["slide"])
|
||||
return d, (_resolved_slide(db, s, cfg["orientation"]) if s else None)
|
||||
p = db.get(SignagePlaylist, d) if d else None
|
||||
return d, (_resolved(db, p) if p else None)
|
||||
|
||||
|
||||
@router.get("/screen")
|
||||
def screen(db: Session = Depends(get_db), dev=Depends(require_device("signage"))):
|
||||
"""What this screen plays: its settings and its playlist with every slide and media address.
|
||||
@@ -678,19 +901,20 @@ def screen(db: Session = Depends(get_db), dev=Depends(require_device("signage"))
|
||||
cfg = _screen_config(dev)
|
||||
lines = lines_for(db, dev.id)
|
||||
schedule, playlists, playlist = None, None, None
|
||||
default = cfg.get("playlist")
|
||||
default, fallback = _default_resolved(db, cfg)
|
||||
if lines:
|
||||
ids = _screen_playlists(db, dev)
|
||||
playlists = {str(p.id): _resolved(db, p) for p in
|
||||
(db.query(SignagePlaylist).filter(SignagePlaylist.id.in_(ids)).all() if ids else [])}
|
||||
if isinstance(default, str) and fallback:
|
||||
playlists[default] = fallback # its library slide, under "slide:<id>"
|
||||
scenes = sorted(active_ids(db))
|
||||
entries = [entry_of(i) for i in lines]
|
||||
now_id = pick(entries, default, venue_now(), scenes)
|
||||
playlist = playlists.get(str(now_id)) if now_id else None
|
||||
schedule = {"entries": entries, "fallback_playlist_id": default, "scenes": scenes, "timezone": venue_tz().key}
|
||||
else:
|
||||
p = db.get(SignagePlaylist, default) if default else None
|
||||
playlist = _resolved(db, p) if p is not None else None
|
||||
playlist = fallback
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user