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:
@@ -26,14 +26,55 @@ const mins = hhmm => {
|
||||
return h * 60 + m
|
||||
}
|
||||
|
||||
// ── smart days (owner 2026-11-21): the same as local_backend/core/calendar_days.py ──────────
|
||||
export const MONTH_DAYS = ['first', 'last', 'first_week', 'last_week', 'holiday', 'not_holiday']
|
||||
const FIXED_HOLIDAYS = ['01-01', '01-06', '03-25', '05-01', '08-15', '10-28', '12-25', '12-26']
|
||||
const FROM_EASTER = [-48, -2, 0, 1, 50] // Clean Monday, Good Friday, Easter Sunday, Easter Monday, Whit Monday
|
||||
const iso = d => d.toISOString().slice(0, 10)
|
||||
|
||||
/** The Orthodox Easter Sunday of a year, "YYYY-MM-DD" (Meeus' Julian algorithm + 13 days, 1900-2099). */
|
||||
export function orthodoxEaster(year) {
|
||||
const a = year % 4
|
||||
const b = year % 7
|
||||
const c = year % 19
|
||||
const d = (19 * c + 15) % 30
|
||||
const e = (2 * a + 4 * b - d + 34) % 7
|
||||
const month = Math.floor((d + e + 114) / 31)
|
||||
const day = ((d + e + 114) % 31) + 1
|
||||
return iso(new Date(Date.UTC(year, month - 1, day + 13)))
|
||||
}
|
||||
|
||||
/** A Greek public holiday (nationwide), for a "YYYY-MM-DD" date. */
|
||||
export function isHoliday(date) {
|
||||
if (FIXED_HOLIDAYS.includes(date.slice(5))) return true
|
||||
const easter = new Date(`${orthodoxEaster(Number(date.slice(0, 4)))}T00:00:00Z`)
|
||||
return FROM_EASTER.some(n => iso(new Date(easter.getTime() + n * 86400000)) === date)
|
||||
}
|
||||
|
||||
/** Does a "YYYY-MM-DD" day pass a line's smart days (empty = every day)? Any one is enough; "not_holiday" keeps holidays out. */
|
||||
export function monthDaysOk(tokens, date) {
|
||||
const list = (tokens || []).filter(t => MONTH_DAYS.includes(t))
|
||||
if (!list.length) return true
|
||||
const hol = isHoliday(date)
|
||||
if (list.includes('not_holiday') && hol) return false
|
||||
const wanted = list.filter(t => t !== 'not_holiday')
|
||||
if (!wanted.length) return true
|
||||
const [y, m, d] = date.split('-').map(Number)
|
||||
const last = new Date(Date.UTC(y, m, 0)).getUTCDate()
|
||||
return wanted.some(t => (t === 'first' && d === 1) || (t === 'last' && d === last) || (t === 'first_week' && d <= 7)
|
||||
|| (t === 'last_week' && d > last - 7) || (t === 'holiday' && hol))
|
||||
}
|
||||
|
||||
function dayOk(w, local) {
|
||||
const days = w.days || []
|
||||
return (!days.length || days.includes(local.weekday)) &&
|
||||
(!w.date_from || local.date >= w.date_from) && (!w.date_to || local.date <= w.date_to)
|
||||
(!w.date_from || local.date >= w.date_from) && (!w.date_to || local.date <= w.date_to) && monthDaysOk(w.month_days, local.date)
|
||||
}
|
||||
|
||||
/** Does a window (days, time_from / time_to that may pass midnight, date_from / date_to) cover `local`? */
|
||||
export function matches(w, local) {
|
||||
/** Does a window (days, smart days, time_from / time_to that may pass midnight, date_from / date_to,
|
||||
* a scene that must be on) cover `local`? */
|
||||
export function matches(w, local, scenes) {
|
||||
if (w.scene_id != null && !(scenes || []).includes(w.scene_id)) return false
|
||||
let start = mins(w.time_from)
|
||||
let end = mins(w.time_to)
|
||||
if (start == null && end == null) return dayOk(w, local)
|
||||
@@ -45,14 +86,14 @@ export function matches(w, local) {
|
||||
return false
|
||||
}
|
||||
|
||||
const specific = e => ((e.date_from || e.date_to) ? 4 : 0) + (e.days?.length ? 2 : 0) + ((e.time_from || e.time_to) ? 1 : 0)
|
||||
const specific = e => ((e.date_from || e.date_to) ? 4 : 0) + ((e.days?.length || e.month_days?.length) ? 2 : 0) + ((e.time_from || e.time_to) ? 1 : 0)
|
||||
|
||||
/** The playlist a schedule plays at `local`: highest priority, then the most specific, then the later entry. */
|
||||
export function pick(entries, fallback, local) {
|
||||
export function pick(entries, fallback, local, scenes) {
|
||||
let best = null
|
||||
let bestKey = null
|
||||
;(entries || []).forEach((e, i) => {
|
||||
if (e.playlist_id == null || !matches(e, local)) return
|
||||
if (e.playlist_id == null || !matches(e, local, scenes)) return
|
||||
const key = [e.priority || 0, specific(e), i]
|
||||
if (!bestKey || key[0] > bestKey[0] || (key[0] === bestKey[0] && (key[1] > bestKey[1] || (key[1] === bestKey[1] && key[2] > bestKey[2])))) {
|
||||
best = e.playlist_id
|
||||
@@ -62,11 +103,12 @@ export function pick(entries, fallback, local) {
|
||||
return best ?? fallback ?? null
|
||||
}
|
||||
|
||||
/** The playlist to play now from the screen's answer (GET /api/signage/screen). */
|
||||
/** The playlist to play now from the screen's answer (GET /api/signage/screen): a schedule line
|
||||
* (with the scenes that were on when it last heard from the server), else the screen's default. */
|
||||
export function playlistNow(data, now = new Date()) {
|
||||
if (!data) return null
|
||||
if (!data.schedule) return data.playlist || null
|
||||
const id = pick(data.schedule.entries, data.schedule.fallback_playlist_id, localNow(data.schedule.timezone, now))
|
||||
const id = pick(data.schedule.entries, data.schedule.fallback_playlist_id, localNow(data.schedule.timezone, now), data.schedule.scenes)
|
||||
return id != null ? data.playlists?.[String(id)] ?? null : null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user