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:
2026-11-20 19:22:47 +02:00
co-authored by Claude Opus 5.5
parent abab158b7c
commit 60e6a16217
44 changed files with 1429 additions and 533 deletions
+50 -8
View File
@@ -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
}
+17
View File
@@ -119,3 +119,20 @@ test('weather codes → icons', () => {
assert.equal(weatherIcon(45), 'fog')
assert.equal(weatherIcon(null), 'cloud')
})
test('smart days and scenes, the same dates as the server (owner 2026-11-21)', async () => {
const { isHoliday, matches, monthDaysOk, orthodoxEaster, pick } = await import('../src/logic.js')
assert.deepEqual([2025, 2026, 2027].map(orthodoxEaster), ['2025-04-20', '2026-04-12', '2027-05-02'])
assert.ok(isHoliday('2026-03-25') && isHoliday('2026-02-23') && isHoliday('2026-04-10') && isHoliday('2026-04-13'))
assert.ok(isHoliday('2026-06-01') && !isHoliday('2026-06-02'))
assert.ok(monthDaysOk(['first'], '2026-11-01') && !monthDaysOk(['first'], '2026-11-02'))
assert.ok(monthDaysOk(['last'], '2026-02-28') && !monthDaysOk(['last'], '2026-02-27'))
assert.ok(monthDaysOk(['first_week'], '2026-11-07') && !monthDaysOk(['first_week'], '2026-11-08'))
assert.ok(monthDaysOk(['last_week'], '2026-11-24') && !monthDaysOk(['last_week'], '2026-11-23'))
assert.ok(!monthDaysOk(['not_holiday'], '2026-12-25') && monthDaysOk(['not_holiday'], '2026-12-24'))
const sat = { weekday: 5, minutes: 13 * 60, date: '2026-11-21' }
const entries = [{ playlist_id: 40, date_from: '2026-11-21', date_to: '2026-11-21', priority: 5 }, { playlist_id: 50, scene_id: 1, priority: 9 }]
assert.equal(pick(entries, 99, sat), 40)
assert.equal(pick(entries, 99, sat, [1]), 50)
assert.ok(!matches({ scene_id: 2 }, sat, [1]))
})