feat(signage,scenes): schedule lines with screens and smart days, screens' defaults, horizontal timeline, scenes
- Scenes (Alembic 0043, models/scene.py, /api/scenes, core.scenes.manage): named modes on or off (optionally until a time); price rules / deals get the condition "a scene is on"; signage lines can play only during a scene; turning one on tells every screen and pushes the online menu. - Signage schedules are lines (signage_schedule_items): playlist, screens ([] = every screen), priority, days, smart days (1st / last day, first / last week, Greek public holidays or not: core/calendar_days.py, mirrored in @xenia/signage), hours, dates, scene. No line → the screen's default playlist. 0043 turns the old named schedules into lines for their screens. - Screens: default playlist, TV shape, turn; what plays now and why. - Manager: tabs Screens · Playlists · Schedules · Slides (placeholder) · Message and weather; schedule lines with playlist / screens / priority / delete on one line; the playlist editor's horizontal timeline of fixed cards, the slide's basics beside its preview (one height), then its content; Management → Scenes; the scene condition in pricing. - Tests: backend (lines, smart days, scenes, prices), player logic, e2e. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
"""Scenes (owner 2026-11-21): list them (everyone in the dashboard), make, change, delete and turn
|
||||
them on or off (`core.scenes.manage`). services/scenes.py says what follows a scene."""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Response
|
||||
from pydantic import BaseModel, Field
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from core.access.deps import require
|
||||
from core.errors import XeniaError
|
||||
from core.timeutil import utcnow
|
||||
from database import get_db
|
||||
from models.scene import Scene
|
||||
from services import scenes as svc
|
||||
|
||||
router = APIRouter()
|
||||
VIEW = "core.dashboard.access"
|
||||
KEY = "core.scenes.manage"
|
||||
COLOUR = r"^#[0-9a-fA-F]{6}$"
|
||||
|
||||
|
||||
class SceneBody(BaseModel):
|
||||
name: str = Field(min_length=1, max_length=60)
|
||||
color: Optional[str] = Field(default=None, pattern=COLOUR)
|
||||
description: Optional[str] = Field(default=None, max_length=200)
|
||||
|
||||
|
||||
class ActiveBody(BaseModel):
|
||||
active: bool
|
||||
until: Optional[datetime] = None # on until then (UTC); None: until turned off
|
||||
|
||||
|
||||
def _scene(db, sid: int) -> Scene:
|
||||
s = db.get(Scene, sid)
|
||||
if s is None:
|
||||
raise XeniaError("scene.not_found", scene_id=sid)
|
||||
return s
|
||||
|
||||
|
||||
@router.get("")
|
||||
def list_scenes(db: Session = Depends(get_db), user=Depends(require(VIEW))):
|
||||
return [svc.out(s) for s in db.query(Scene).order_by(Scene.sort_order, Scene.id)]
|
||||
|
||||
|
||||
@router.post("", status_code=201)
|
||||
def create_scene(body: SceneBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
s = Scene(name=body.name.strip(), color=body.color, description=(body.description or "").strip() or None,
|
||||
sort_order=db.query(Scene).count())
|
||||
db.add(s)
|
||||
db.commit()
|
||||
db.refresh(s)
|
||||
svc.changed(db)
|
||||
return svc.out(s)
|
||||
|
||||
|
||||
@router.put("/{scene_id}")
|
||||
def update_scene(scene_id: int, body: SceneBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
s = _scene(db, scene_id)
|
||||
s.name, s.color, s.description = body.name.strip(), body.color, (body.description or "").strip() or None
|
||||
db.commit()
|
||||
svc.changed(db)
|
||||
return svc.out(s)
|
||||
|
||||
|
||||
@router.put("/{scene_id}/active")
|
||||
def set_active(scene_id: int, body: ActiveBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
s = _scene(db, scene_id)
|
||||
if body.active and body.until is not None and svc._aware(body.until) <= utcnow():
|
||||
raise XeniaError("scene.until_past")
|
||||
s.is_active = body.active
|
||||
s.activated_at = utcnow() if body.active else None
|
||||
s.until = body.until if body.active else None
|
||||
db.commit()
|
||||
svc.changed(db)
|
||||
return svc.out(s)
|
||||
|
||||
|
||||
@router.delete("/{scene_id}", status_code=204)
|
||||
def delete_scene(scene_id: int, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
"""The signage lines that played only in it are turned off (they would otherwise play always)."""
|
||||
s = _scene(db, scene_id)
|
||||
from models.signage import SignageScheduleItem
|
||||
for item in db.query(SignageScheduleItem).filter(SignageScheduleItem.scene_id == s.id):
|
||||
item.scene_id = None
|
||||
item.enabled = False
|
||||
db.delete(s)
|
||||
db.commit()
|
||||
svc.changed(db)
|
||||
return Response(status_code=204)
|
||||
Reference in New Issue
Block a user