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:
@@ -55,6 +55,9 @@ def _ref_exists(source: str, value: int, db) -> bool:
|
||||
if source == "signage_playlists":
|
||||
from models.signage import SignagePlaylist
|
||||
return db.get(SignagePlaylist, value) is not None
|
||||
if source == "signage_slides":
|
||||
from models.signage import SignageSavedSlide
|
||||
return db.get(SignageSavedSlide, value) is not None
|
||||
if source == "tables":
|
||||
from models.table import Table
|
||||
t = db.get(Table, value)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
"""The signage Slides library (owner 2026-11-21): slides kept with a name and a description, added
|
||||
to playlists as copies or shown alone as a screen's default (device config `slide`).
|
||||
|
||||
Revision ID: 0044_signage_saved_slides
|
||||
Revises: 0043_scenes_and_schedule_items
|
||||
Create Date: 2026-11-21 22:00:00
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from core.timeutil import UTCDateTime
|
||||
|
||||
revision = '0044_signage_saved_slides'
|
||||
down_revision = '0043_scenes_and_schedule_items'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
'signage_saved_slides',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=True),
|
||||
sa.Column('orientation', sa.String(), nullable=False),
|
||||
sa.Column('kind', sa.String(), nullable=False),
|
||||
sa.Column('duration_s', sa.Integer(), nullable=False),
|
||||
sa.Column('transition', sa.String(), nullable=True),
|
||||
sa.Column('video_to_end', sa.Boolean(), nullable=False),
|
||||
sa.Column('enabled', sa.Boolean(), nullable=False),
|
||||
sa.Column('days', sa.JSON(), nullable=True),
|
||||
sa.Column('time_from', sa.String(), nullable=True),
|
||||
sa.Column('time_to', sa.String(), nullable=True),
|
||||
sa.Column('date_from', sa.String(), nullable=True),
|
||||
sa.Column('date_to', sa.String(), nullable=True),
|
||||
sa.Column('content', sa.JSON(), nullable=False),
|
||||
sa.Column('created_at', UTCDateTime(), nullable=False),
|
||||
sa.Column('updated_at', UTCDateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_index('ix_signage_saved_slides_id', 'signage_saved_slides', ['id'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index('ix_signage_saved_slides_id', table_name='signage_saved_slides')
|
||||
op.drop_table('signage_saved_slides')
|
||||
@@ -40,7 +40,7 @@ import models.fees # noqa: F401 DeliveryArea, FeeRule (phase 3S, S.3)
|
||||
import models.refund # noqa: F401 Refund, RefundItem (step 3.3e)
|
||||
import models.media # noqa: F401 Media (media library, step 5.1)
|
||||
import models.display_look # noqa: F401 DisplayLook (customer display looks, step 5.3)
|
||||
import models.signage # noqa: F401 SignagePlaylist, SignageSlide (signage, step 5.4a)
|
||||
import models.signage # noqa: F401 SignagePlaylist, SignageSlide, SignageSavedSlide (signage, 5.4a; library 2026-11-21)
|
||||
import models.scene # noqa: F401 Scene (2026-11-21)
|
||||
import models.tablet_order # noqa: F401 TabletOrder (ordering from a menu tablet, step 6.6)
|
||||
import models.floor_plan # noqa: F401 FloorPlan, FloorItem (the table map, step 6.8)
|
||||
|
||||
@@ -78,3 +78,29 @@ class SignageScheduleItem(Base):
|
||||
position = Column(Integer, nullable=False, default=0)
|
||||
created_at = Column(UTCDateTime, default=utcnow, nullable=False)
|
||||
updated_at = Column(UTCDateTime, default=utcnow, onupdate=utcnow, nullable=False)
|
||||
|
||||
|
||||
class SignageSavedSlide(Base):
|
||||
"""A slide kept in the Slides library (owner 2026-11-21): built once, with a name and a short
|
||||
description, then added to playlists (a copy goes in) or shown alone on a screen that has it
|
||||
as its default (device config `slide`). The same fields as a playlist's slide, plus the shape
|
||||
it is built for (its preview and the picture-fit warnings)."""
|
||||
__tablename__ = "signage_saved_slides"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String, nullable=False)
|
||||
description = Column(String, nullable=True)
|
||||
orientation = Column(String, nullable=False, default="landscape") # landscape | portrait
|
||||
kind = Column(String, nullable=False) # menu | image | video | text | blank
|
||||
duration_s = Column(Integer, nullable=False, default=10)
|
||||
transition = Column(String, nullable=True)
|
||||
video_to_end = Column(Boolean, nullable=False, default=False)
|
||||
enabled = Column(Boolean, nullable=False, default=True)
|
||||
days = Column(JSON, nullable=True)
|
||||
time_from = Column(String, nullable=True)
|
||||
time_to = Column(String, nullable=True)
|
||||
date_from = Column(String, nullable=True)
|
||||
date_to = Column(String, nullable=True)
|
||||
content = Column(JSON, nullable=False, default=dict)
|
||||
created_at = Column(UTCDateTime, default=utcnow, nullable=False)
|
||||
updated_at = Column(UTCDateTime, default=utcnow, onupdate=utcnow, nullable=False)
|
||||
|
||||
@@ -27,6 +27,8 @@ MODULE = Module(
|
||||
device_app=DeviceApp(login_modes=('none',), scope=(), config=(
|
||||
# What it plays and how the TV hangs (5.4a); the editor builds for the screen's shape
|
||||
ConfigField('playlist', 'ref', default=None, choices_from='signage_playlists'),
|
||||
# ... or a library slide shown alone (owner 2026-11-21; a playlist wins when both are set)
|
||||
ConfigField('slide', 'ref', default=None, choices_from='signage_slides'),
|
||||
ConfigField('orientation', 'enum', default='landscape', choices=('landscape', 'portrait')),
|
||||
ConfigField('rotation', 'int', default=0, choices=(0, 90, 180, 270)),
|
||||
)),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -98,14 +98,14 @@ def lines_for(db, screen_id: int) -> list:
|
||||
.order_by(SignageScheduleItem.position, SignageScheduleItem.id) if not i.screen_ids or screen_id in i.screen_ids]
|
||||
|
||||
|
||||
def now_for(db, dev, local: datetime | None = None, scenes=None) -> tuple[int | None, bool]:
|
||||
def now_for(db, dev, local: datetime | None = None, scenes=None) -> tuple[int | str | None, bool]:
|
||||
"""(the playlist a screen plays now, whether a schedule line picked it)."""
|
||||
from core.timeutil import venue_now
|
||||
from routers.signage import _screen_config
|
||||
from routers.signage import _screen_config, default_of
|
||||
from services.scenes import active_ids
|
||||
local = local or venue_now()
|
||||
scenes = active_ids(db) if scenes is None else scenes
|
||||
default = _screen_config(dev).get("playlist")
|
||||
default = default_of(_screen_config(dev)) # a playlist id, or "slide:<id>" (a library slide)
|
||||
got = pick([entry_of(i) for i in lines_for(db, dev.id)], None, local, scenes)
|
||||
return (got, True) if got is not None else (default, False)
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
"""The signage Slides library and what came with it (owner 2026-11-21): slides kept with a name and a
|
||||
description, added to playlists as copies, shown alone as a screen's default (also behind a
|
||||
schedule); blank slides (a background and widgets); widgets moved and sized by hand (their own
|
||||
box); a menu board narrower than the screen, placed left / centre / right."""
|
||||
from tests.test_live import err, owner_h, pair # noqa: F401 (fixtures)
|
||||
from tests.test_media import jpeg, media_dir, up # noqa: F401 (fixture + helpers)
|
||||
from tests.test_signage import playlist, screens, sent, slide # noqa: F401 (fixtures + helpers)
|
||||
|
||||
|
||||
def keep(client, h, **body):
|
||||
r = client.post("/api/signage/library", headers=h, json={"name": "Logo", "kind": "blank", **body})
|
||||
assert r.status_code == 201, r.text
|
||||
return r.json()
|
||||
|
||||
|
||||
def test_the_library_keeps_slides(client, owner_h):
|
||||
s = keep(client, owner_h, description=" Our logo, big ", orientation="portrait", duration_s=15,
|
||||
content={"background": {"kind": "colour", "colour": "#102030"}, "widgets": [{"kind": "name", "position": "top-center"}]})
|
||||
assert s["kind"] == "blank" and s["orientation"] == "portrait" and s["description"] == "Our logo, big" and s["duration_s"] == 15
|
||||
assert s["content"]["widgets"][0]["size"] == "medium" and s["screens"] == []
|
||||
r = client.put(f"/api/signage/library/{s['id']}", headers=owner_h, json={"name": "Logo 2", "description": "", "days": [5, 6]})
|
||||
assert r.json()["name"] == "Logo 2" and r.json()["description"] is None and r.json()["days"] == [5, 6]
|
||||
assert err(client.put(f"/api/signage/library/{s['id']}", headers=owner_h, json={"kind": "text"})) == "signage.content_invalid"
|
||||
assert err(client.put(f"/api/signage/library/{s['id']}", headers=owner_h, json={"name": " "})) == "signage.content_invalid"
|
||||
assert err(client.post("/api/signage/library", headers=owner_h, json={"name": "x"})) == "signage.content_invalid" # no kind
|
||||
copy = client.post(f"/api/signage/library/{s['id']}/duplicate", headers=owner_h).json()
|
||||
assert copy["name"] == "Logo 2 (2)" and copy["content"] == r.json()["content"]
|
||||
listed = client.get("/api/signage/library", headers=owner_h).json()
|
||||
assert [x["name"] for x in listed["slides"]] == ["Logo 2", "Logo 2 (2)"] and listed["media"] == {}
|
||||
assert client.delete(f"/api/signage/library/{copy['id']}", headers=owner_h).status_code == 204
|
||||
assert err(client.get(f"/api/signage/library/{copy['id']}", headers=owner_h)) == "signage.slide_unknown"
|
||||
|
||||
|
||||
def test_a_library_slide_protects_its_pictures(client, owner_h, media_dir):
|
||||
pic = up(client, owner_h, jpeg(800, 800)).json()
|
||||
keep(client, owner_h, kind="image", name="Promo", content={"media_id": pic["id"]})
|
||||
r = client.delete(f"/api/media/{pic['id']}", headers=owner_h)
|
||||
assert r.status_code == 409, r.text
|
||||
|
||||
|
||||
def test_a_screen_shows_a_library_slide_when_nothing_else_plays(client, owner_h, screens, sent):
|
||||
s = keep(client, owner_h, content={"widgets": [{"kind": "qr", "position": "bottom-right"}]})
|
||||
tv = screens[1]
|
||||
r = client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"slide_id": s["id"]})
|
||||
assert r.status_code == 200, r.text
|
||||
assert r.json()["slide_id"] == s["id"] and r.json()["playlist_id"] is None
|
||||
assert r.json()["now"] == {"id": f"slide:{s['id']}", "name": "Logo", "scheduled": False, "slide": True}
|
||||
got = client.get("/api/signage/screen", headers=tv["h"]).json()
|
||||
pl = got["playlist"]
|
||||
assert pl["id"] == f"slide:{s['id']}" and [x["id"] for x in pl["slides"]] == [s["id"]]
|
||||
assert pl["slides"][0]["content"]["widgets"][0]["link"] # the QR's address, as in a playlist
|
||||
# a change to it reaches that screen only
|
||||
sent.clear()
|
||||
client.put(f"/api/signage/library/{s['id']}", headers=owner_h, json={"duration_s": 20})
|
||||
assert sent == [("signage.changed", [tv["id"]])]
|
||||
# behind a schedule: the slide is the fallback, under its own key
|
||||
p = playlist(client, owner_h, "Lunch")
|
||||
slide(client, owner_h, p["id"], "text", content={"title": "Lunch"})
|
||||
client.put("/api/signage/schedules", headers=owner_h, json={"lines": [
|
||||
{"playlist_id": p["id"], "screen_ids": [tv["id"]], "date_from": "2000-01-01", "date_to": "2000-01-02"}]})
|
||||
got = client.get("/api/signage/screen", headers=tv["h"]).json()
|
||||
assert got["schedule"]["fallback_playlist_id"] == f"slide:{s['id']}" and f"slide:{s['id']}" in got["playlists"]
|
||||
assert got["playlist"]["id"] == f"slide:{s['id']}"
|
||||
# a playlist as the default takes its place (one or the other)
|
||||
r = client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"playlist_id": p["id"]})
|
||||
assert r.json()["playlist_id"] == p["id"] and r.json()["slide_id"] is None
|
||||
r = client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"slide_id": s["id"]})
|
||||
assert r.json()["playlist_id"] is None and r.json()["slide_id"] == s["id"]
|
||||
# deleting the slide: the screen shows nothing and is told
|
||||
sent.clear()
|
||||
client.delete(f"/api/signage/library/{s['id']}", headers=owner_h)
|
||||
assert ("signage.changed", [tv["id"]]) in sent
|
||||
assert client.get("/api/signage/screens", headers=owner_h).json()[0]["slide_id"] is None
|
||||
|
||||
|
||||
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
|
||||
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
|
||||
r = client.put(f"/api/signage/slides/{s['id']}", headers=owner_h, json={"content": {"title": "x"}})
|
||||
assert err(r) == "signage.content_invalid" # a blank slide has no title
|
||||
|
||||
|
||||
def test_a_menu_board_narrower_than_the_screen(client, owner_h):
|
||||
p = playlist(client, owner_h)
|
||||
s = slide(client, owner_h, p["id"], "menu", content={"select": "all", "board_width": 60, "board_align": "center"})
|
||||
assert s["content"]["board_width"] == 60 and s["content"]["board_align"] == "center"
|
||||
assert slide(client, owner_h, p["id"], "menu")["content"]["board_width"] == 100
|
||||
r = client.put(f"/api/signage/slides/{s['id']}", headers=owner_h, json={"content": {"board_width": 20}})
|
||||
assert err(r) == "signage.content_invalid"
|
||||
Reference in New Issue
Block a user