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
+7 -1
View File
@@ -187,7 +187,9 @@
"content_invalid": "Μια ρύθμιση της διαφάνειας δεν είναι έγκυρη ({{field}}: {{reason}}).",
"order_mismatch": "Η λίστα άλλαξε στο μεταξύ. Φορτώστε τη ξανά και δοκιμάστε πάλι.",
"weather_offline": "Η υπηρεσία καιρού δεν είναι διαθέσιμη: ο διακομιστής του καταστήματος χρειάζεται internet γι' αυτήν.",
"schedule_unknown": "Το πρόγραμμα {{schedule_id}} δεν βρέθηκε."
"schedule_unknown": "Το πρόγραμμα {{schedule_id}} δεν βρέθηκε.",
"scene_unknown": "Αυτή η σκηνή δεν υπάρχει πια.",
"screen_unknown": "Αυτή η οθόνη δεν υπάρχει πια."
},
"menu_tablet": {
"no_table": "Αυτό το tablet δεν είναι σε τραπέζι, οπότε δεν καλεί σερβιτόρο.",
@@ -358,5 +360,9 @@
"channel_price": {
"not_found": "Η τιμή καναλιού δεν βρέθηκε.",
"set_one_product": "Η σταθερή τιμή είναι για ένα προϊόν: επιλέξτε ένα προϊόν (χωρίς κατηγορίες) ή αλλάξτε την τιμή κατά ποσό ή ποσοστό."
},
"scene": {
"not_found": "Η σκηνή δεν βρέθηκε.",
"until_past": "Αυτή η ώρα έχει περάσει: διαλέξτε μια μεταγενέστερη."
}
}
+80 -12
View File
@@ -49,7 +49,8 @@
"qrCodes": "QR τραπεζιών",
"media": "Πολυμέσα",
"signage": "Προβολή",
"main": "Κύριο μενού"
"main": "Κύριο μενού",
"scenes": "Σκηνές"
},
"profile": {
"edit": "Επεξεργασία προφίλ",
@@ -1346,7 +1347,7 @@
"transition": "Μπαίνει με",
"transitionDefault": "Τη μετάβαση της λίστας",
"when": "Πότε εμφανίζεται",
"whenHint": "Κενό για πάντα. Διαλέξτε μέρες, ώρες (μπορεί να περνούν τα μεσάνυχτα) ή ημερομηνίες για να εμφανίζεται μόνο τότε.",
"whenHint": "Κενό για πάντα. Διαλέξτε ημέρες, ώρες (μπορεί να περνούν τα μεσάνυχτα) ή ημερομηνίες για να εμφανίζεται μόνο τότε. Αυτό στενεύει το πρόγραμμα της λίστας: μια διαφάνεια με ώρα εκτός των ωρών που παίζει η λίστα της δεν εμφανίζεται ποτέ.",
"days": "Μέρες",
"timeFrom": "Από (ώρα)",
"timeTo": "Έως (ώρα)",
@@ -1482,7 +1483,8 @@
"playlists": "Λίστες",
"screens": "Οθόνες",
"schedules": "Προγράμματα",
"settings": "Μήνυμα και καιρός"
"settings": "Μήνυμα και καιρός",
"slides": "Διαφάνειες"
},
"screens": {
"none": "Δεν υπάρχουν οθόνες προβολής ακόμα.",
@@ -1501,27 +1503,53 @@
"180": "Ανάποδα",
"270": "90° αριστερά"
},
"mismatch": "Μια λίστα εδώ φτιάχτηκε για το άλλο σχήμα"
"mismatch": "Μια λίστα εδώ φτιάχτηκε για το άλλο σχήμα",
"intro": "Κάθε οθόνη παίζει την προεπιλεγμένη λίστα της, εκτός αν ταιριάζει μια γραμμή προγράμματος γι' αυτήν (Οθόνες → Προγράμματα): τότε παίζει η λίστα εκείνης της γραμμής.",
"defaultPlaylist": "Προεπιλεγμένη λίστα",
"shape": "Σχήμα τηλεόρασης",
"nowScheduled": "Τώρα: {{name}} (από πρόγραμμα)",
"nowDefault": "Τώρα: {{name}} (η προεπιλογή της)",
"nowNothing": "Τώρα: τίποτα (κενή οθόνη)"
},
"schedules": {
"new": "Νέο πρόγραμμα",
"newName": "Νέο πρόγραμμα",
"created": "Το πρόγραμμα δημιουργήθηκε.",
"deleted": "Το πρόγραμμα διαγράφηκε.",
"none": "Δεν υπάρχουν προγράμματα ακόμα.",
"noneHint": "Ένα πρόγραμμα παίζει διαφορετικές λίστες σε διαφορετικές ώρες: μεσημέρι, βράδυ, Σαββατοκύριακα, γιορτές.",
"none": "Δεν υπάρχουν γραμμές προγράμματος ακόμα.",
"noneHint": "Χωρίς γραμμές κάθε οθόνη παίζει την προεπιλεγμένη λίστα της. Προσθέστε μια γραμμή για να παίζει άλλη λίστα το μεσημέρι, τα βράδια, τα Σαββατοκύριακα, τις αργίες ή σε λειτουργία πάρτι.",
"needPlaylist": "Φτιάξτε πρώτα μια λίστα.",
"nowPlaying": "τώρα: {{name}}",
"nowNothing": "τώρα: τίποτα",
"how": "Κάθε γραμμή παίζει τη λίστα της στις μέρες, στις ώρες (μπορεί να περνούν τα μεσάνυχτα) και στις ημερομηνίες της· κενό σημαίνει πάντα. Όταν ταιριάζουν δύο γραμμές, κερδίζει η μεγαλύτερη προτεραιότητα, μετά η πιο συγκεκριμένη (ημερομηνίες, μετά μέρες, μετά ώρες).",
"how": "Κάθε γραμμή παίζει τη λίστα της στις οθόνες της (καμία επιλεγμένη: σε όλες) τις ημέρες της, τις έξυπνες ημέρες, μεταξύ των ωρών της (μπορεί να περνούν τα μεσάνυχτα) και ημερομηνιών, και, αν διαλέξετε, μόνο όταν είναι ενεργή μια σκηνή. Κενό σημαίνει πάντα. Όταν ταιριάζουν δύο γραμμές σε μια οθόνη, κερδίζει η μεγαλύτερη προτεραιότητα, μετά η πιο συγκεκριμένη. Όταν δεν ταιριάζει καμία, η οθόνη παίζει την προεπιλεγμένη λίστα της (Οθόνες).",
"plays": "Παίζει",
"priority": "Προτεραιότητα",
"priorityHint": "Η μεγαλύτερη κερδίζει",
"priorityHint": "Όταν ταιριάζουν δύο γραμμές την ίδια ώρα σε μια οθόνη, κερδίζει ο μεγαλύτερος αριθμός (0 έως 100).",
"addLine": "Προσθήκη γραμμής",
"otherwise": "Τον υπόλοιπο χρόνο",
"otherwiseHint": "Όταν δεν ταιριάζει καμία γραμμή.",
"deleteTitle": "Διαγραφή «{{name}}»;",
"deleteBody": "Οι οθόνες που το έχουν γυρίζουν στη λίστα τους. Οι λίστες μένουν."
"deleteBody": "Οι οθόνες που το έχουν γυρίζουν στη λίστα τους. Οι λίστες μένουν.",
"onScreens": "Σε οθόνες",
"allScreens": "Όλες οι οθόνες",
"shortcuts": {
"everyday": "Κάθε μέρα",
"weekdays": "Καθημερινές",
"weekend": "Σαββατοκύριακο"
},
"smartDays": "Έξυπνες ημέρες",
"monthDays": {
"first": "1η του μήνα",
"last": "Τελευταία του μήνα",
"first_week": "Πρώτη εβδομάδα του μήνα",
"last_week": "Τελευταία εβδομάδα του μήνα",
"holiday": "Αργίες",
"not_holiday": "Όχι τις αργίες"
},
"scene": "Μόνο σε σκηνή",
"anyScene": "Πάντα (χωρίς σκηνή)",
"enabled": "Ενεργή",
"playingNow": "Παίζει τώρα σε: {{names}}"
},
"settings": {
"message": "Μήνυμα ημέρας",
@@ -1542,6 +1570,10 @@
"waiting": "Καμία πρόγνωση ακόμα.",
"refresh": "Ενημέρωση τώρα",
"forget": "Αφαίρεση πόλης"
},
"slidesTab": {
"title": "Έρχονται διαφάνειες για επαναχρησιμοποίηση",
"body": "Εδώ θα φτιάχνετε μεμονωμένες διαφάνειες, θα τις κρατάτε και θα τις προσθέτετε σε όποια λίστα θέλετε."
}
},
"overview": {
@@ -2303,15 +2335,18 @@
"order_channel": "Σημείο πώλησης",
"min_item_quantity": "Τουλάχιστον κάποια από το προϊόν",
"min_category_qty": "Τουλάχιστον κάποια από μια κατηγορία",
"min_order_value": "Σύνολο παραγγελίας τουλάχιστον"
"min_order_value": "Σύνολο παραγγελίας τουλάχιστον",
"scene_active": "Μια σκηνή είναι ενεργή"
},
"fields": {
"min_item_quantity": "Πόσα",
"min_category_qty": "Πόσα",
"min_order_value": "Ποσό",
"category_id": "Κατηγορία",
"price_group_id": "Ομάδα τιμών"
}
"price_group_id": "Ομάδα τιμών",
"scene_id": "Σκηνή"
},
"noScenes": "Δεν υπάρχουν σκηνές ακόμα: Διαχείριση → Σκηνές"
},
"actions": {
"add_percent": "± ποσοστό",
@@ -4017,5 +4052,38 @@
"renameYes_other": "Μετονομασία {{count}} τραπεζιών",
"andMore_one": "και {{count}} ακόμα",
"andMore_other": "και {{count}} ακόμα"
},
"scenes": {
"title": "Σκηνές",
"intro": "Λειτουργίες του καταστήματος, όπως «Λειτουργία πάρτι» ή «Βράδυ αγώνα». Όταν ενεργοποιείτε μία, αλλάζει αμέσως ό,τι την ακολουθεί: οι γραμμές των οθονών που παίζουν μόνο σε αυτήν (Οθόνες → Προγράμματα) και οι κανόνες τιμών ή οι προσφορές με τη συνθήκη «Μια σκηνή είναι ενεργή» (Προσφορές & τιμές). Μπορούν να είναι ενεργές πολλές μαζί.",
"new": "Νέα σκηνή",
"edit": "Επεξεργασία σκηνής",
"delete": "Διαγραφή",
"none": "Δεν υπάρχουν σκηνές ακόμα.",
"noneHint": "Φτιάξτε μία (π.χ. Λειτουργία πάρτι) και χρησιμοποιήστε την σε μια γραμμή προγράμματος οθονών ή σε έναν κανόνα τιμών.",
"on": "Ενεργή",
"onNow": "Ενεργή τώρα, μέχρι να την κλείσετε",
"onUntil": "Ενεργή έως {{time}}",
"turnedOn": "Η «{{name}}» ενεργοποιήθηκε.",
"turnedOff": "Η «{{name}}» απενεργοποιήθηκε.",
"for": "Όταν ενεργοποιηθεί, για",
"forOptions": {
"off": "Μέχρι να την κλείσετε",
"1": "1 ώρα",
"2": "2 ώρες",
"3": "3 ώρες",
"4": "4 ώρες",
"6": "6 ώρες",
"day": "Μέχρι το τέλος της ημέρας"
},
"name": "Όνομα",
"namePh": "π.χ. Λειτουργία πάρτι",
"description": "Περιγραφή (προαιρετικά)",
"descriptionPh": "π.χ. Παρασκευή και Σάββατο βράδυ μετά τις 23:00",
"colour": "Χρώμα",
"saved": "Η σκηνή αποθηκεύτηκε.",
"deleted": "Η σκηνή διαγράφηκε.",
"deleteTitle": "Διαγραφή «{{name}}»;",
"deleteBody": "Οι κανόνες τιμών με αυτήν παύουν να ισχύουν· οι γραμμές οθονών που έπαιζαν μόνο σε αυτήν απενεργοποιούνται."
}
}
+3 -5
View File
@@ -69,6 +69,9 @@
},
"system": {
"admin": "Συντήρηση μόνο από την υποστήριξη"
},
"scenes": {
"manage": "Δημιουργία σκηνών (λειτουργία πάρτι…) και ενεργοποίησή τους"
}
}
},
@@ -547,11 +550,6 @@
"hint": "Τι παίζει αυτή η οθόνη (Προβολή).",
"none": "Τίποτα (κενή οθόνη)"
},
"schedule": {
"label": "Πρόγραμμα",
"hint": "Παίζει τις λίστες του στις μέρες και ώρες τους· αντί για τη λίστα παραπάνω.",
"none": "Χωρίς πρόγραμμα (παίζει τη λίστα)"
},
"orientation": {
"label": "Προσανατολισμός",
"hint": "Πώς κρέμεται η τηλεόραση: οι διαφάνειες φτιάχνονται για αυτό το σχήμα.",
+7 -1
View File
@@ -187,7 +187,9 @@
"content_invalid": "This slide's setting isn't valid ({{field}}: {{reason}}).",
"order_mismatch": "The playlist changed in the meantime. Reload it and try again.",
"weather_offline": "The weather service can't be reached: the venue's server needs internet for it.",
"schedule_unknown": "Schedule {{schedule_id}} not found."
"schedule_unknown": "Schedule {{schedule_id}} not found.",
"scene_unknown": "That scene doesn't exist any more.",
"screen_unknown": "That screen doesn't exist any more."
},
"menu_tablet": {
"no_table": "This tablet isn't at a table, so it can't call a waiter.",
@@ -358,5 +360,9 @@
"channel_price": {
"not_found": "Channel price not found.",
"set_one_product": "A set price is for one product: pick one product (and no categories), or change the price by an amount or a percentage."
},
"scene": {
"not_found": "Scene not found.",
"until_past": "That time has already passed: pick a later one."
}
}
+80 -12
View File
@@ -49,7 +49,8 @@
"qrCodes": "Table QR codes",
"media": "Media",
"signage": "Signage",
"main": "Main menu"
"main": "Main menu",
"scenes": "Scenes"
},
"profile": {
"edit": "Edit profile",
@@ -1346,7 +1347,7 @@
"transition": "Comes in with",
"transitionDefault": "The playlist's transition",
"when": "When it shows",
"whenHint": "Leave empty for always. Pick days, hours (they may pass midnight) or dates to show it only then.",
"whenHint": "Leave empty for always. Pick days, hours (they may pass midnight) or dates to show it only then. This narrows the playlist's schedule: a slide whose time is outside the hours its playlist plays never shows.",
"days": "Days",
"timeFrom": "From (time)",
"timeTo": "To (time)",
@@ -1482,7 +1483,8 @@
"playlists": "Playlists",
"screens": "Screens",
"schedules": "Schedules",
"settings": "Message and weather"
"settings": "Message and weather",
"slides": "Slides"
},
"screens": {
"none": "No signage screens yet.",
@@ -1501,27 +1503,53 @@
"180": "Upside down",
"270": "90° left"
},
"mismatch": "A playlist here was made for the other shape"
"mismatch": "A playlist here was made for the other shape",
"intro": "Each screen plays its default playlist, unless a schedule line for it matches (Signage → Schedules): then that line's playlist plays.",
"defaultPlaylist": "Default playlist",
"shape": "TV shape",
"nowScheduled": "Now: {{name}} (by a schedule)",
"nowDefault": "Now: {{name}} (its default)",
"nowNothing": "Now: nothing (a blank screen)"
},
"schedules": {
"new": "New schedule",
"newName": "New schedule",
"created": "Schedule created.",
"deleted": "Schedule deleted.",
"none": "No schedules yet.",
"noneHint": "A schedule plays different playlists at different times: lunch, evenings, weekends, holidays.",
"none": "No schedule lines yet.",
"noneHint": "Without lines every screen plays its default playlist. Add a line to play another one at lunch, in the evenings, at weekends, on holidays or in party mode.",
"needPlaylist": "Make a playlist first.",
"nowPlaying": "now: {{name}}",
"nowNothing": "now: nothing",
"how": "Each line plays its playlist on its days, between its hours (they may pass midnight) and dates; empty means always. When two lines match, the higher priority wins, then the more specific one (dates, then days, then hours).",
"how": "Each line plays its playlist on its screens (none picked: every screen) on its days, smart days, between its hours (they may pass midnight) and dates, and, if you pick one, only while a scene is on. Empty means always. When two lines match on a screen, the higher priority wins, then the more specific one. When none matches, a screen plays its default playlist (Screens).",
"plays": "Plays",
"priority": "Priority",
"priorityHint": "Higher wins",
"priorityHint": "When two lines match at the same time on a screen, the higher number wins (0 to 100).",
"addLine": "Add a line",
"otherwise": "The rest of the time",
"otherwiseHint": "When no line matches.",
"deleteTitle": "Delete \"{{name}}\"?",
"deleteBody": "The screens on it go back to their playlist. The playlists stay."
"deleteBody": "The screens on it go back to their playlist. The playlists stay.",
"onScreens": "On screens",
"allScreens": "Every screen",
"shortcuts": {
"everyday": "Every day",
"weekdays": "Weekdays",
"weekend": "Weekend"
},
"smartDays": "Smart days",
"monthDays": {
"first": "1st of the month",
"last": "Last day of the month",
"first_week": "First week of the month",
"last_week": "Last week of the month",
"holiday": "Public holidays",
"not_holiday": "Not on public holidays"
},
"scene": "Only during a scene",
"anyScene": "Always (no scene)",
"enabled": "On",
"playingNow": "Playing now on {{names}}"
},
"settings": {
"message": "Message of the day",
@@ -1542,6 +1570,10 @@
"waiting": "No forecast yet.",
"refresh": "Fetch now",
"forget": "Remove the town"
},
"slidesTab": {
"title": "Slides to reuse are coming",
"body": "Here you will make single slides, keep them, and add them to any playlist."
}
},
"overview": {
@@ -2303,15 +2335,18 @@
"order_channel": "Sales point",
"min_item_quantity": "At least some of the product",
"min_category_qty": "At least some from a category",
"min_order_value": "Order total at least"
"min_order_value": "Order total at least",
"scene_active": "A scene is on"
},
"fields": {
"min_item_quantity": "How many",
"min_category_qty": "How many",
"min_order_value": "Amount",
"category_id": "Category",
"price_group_id": "Price group"
}
"price_group_id": "Price group",
"scene_id": "Scene"
},
"noScenes": "No scenes yet: Management → Scenes"
},
"actions": {
"add_percent": "± a percentage",
@@ -4017,5 +4052,38 @@
"renameYes_other": "Rename {{count}} tables",
"andMore_one": "and {{count}} more",
"andMore_other": "and {{count}} more"
},
"scenes": {
"title": "Scenes",
"intro": "Modes of the venue, like \"Party mode\" or \"Match night\". Turning one on changes at once what follows it: the signage lines that play only in it (Signage → Schedules) and the price rules or deals with the condition \"A scene is on\" (Offers & pricing). Several can be on together.",
"new": "New scene",
"edit": "Edit the scene",
"delete": "Delete",
"none": "No scenes yet.",
"noneHint": "Make one (e.g. Party mode), then use it in a signage schedule line or a price rule.",
"on": "On",
"onNow": "On now, until turned off",
"onUntil": "On until {{time}}",
"turnedOn": "\"{{name}}\" is on.",
"turnedOff": "\"{{name}}\" is off.",
"for": "When turned on, for",
"forOptions": {
"off": "Until turned off",
"1": "1 hour",
"2": "2 hours",
"3": "3 hours",
"4": "4 hours",
"6": "6 hours",
"day": "Until the end of the day"
},
"name": "Name",
"namePh": "e.g. Party mode",
"description": "Description (optional)",
"descriptionPh": "e.g. Friday and Saturday nights after 23:00",
"colour": "Colour",
"saved": "Scene saved.",
"deleted": "Scene deleted.",
"deleteTitle": "Delete \"{{name}}\"?",
"deleteBody": "Price rules with it stop applying; signage lines that played only in it are turned off."
}
}
+3 -5
View File
@@ -69,6 +69,9 @@
},
"system": {
"admin": "Support-only maintenance"
},
"scenes": {
"manage": "Make scenes (party mode…) and turn them on or off"
}
}
},
@@ -547,11 +550,6 @@
"hint": "What this screen plays (Signage).",
"none": "Nothing (a blank screen)"
},
"schedule": {
"label": "Schedule",
"hint": "Plays its playlists at their days and hours; used instead of the playlist above.",
"none": "No schedule (play the playlist)"
},
"orientation": {
"label": "Orientation",
"hint": "How the TV hangs: slides are built for this shape.",
+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]))
})