feat(signage): stacks, menu and text widgets, widget order (owner review 2)
- Stacks: horizontal / vertical, 2-6 parts with % shares; each part shows a widget, a stack one level deep, or a whole Slides-library slide - Menu widget (a board's list in its box), text widget, weather for tomorrow / the day after and in picture / degrees / both styles - Widgets' order (arrows, drag with a drop line), drawn in list order; arrow keys move the picked widget from its card too - Server: extras by widget path (QR links, menus, embedded slides), POST /preview/slide, resolve(keep_hidden) so hidden products stay greyed in the editor's list; screens told when an embedded slide changes - Editor rows tidied: framed sliders, colours as fields, text look on one row, Switch boxed toggles from its whole frame Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
"""Signage widgets, owner review 2026-11-21: a text of its own, a menu widget (a board's list in the
|
||||
widget's place), stacks (parts side by side or one over the other, each with a widget, another
|
||||
stack one level deep, or a whole library slide), weather for tomorrow / the day after and in three
|
||||
styles; products hidden from a board stay in the editor's list (greyed), never on the TV."""
|
||||
from tests.test_live import err, owner_h, pair # noqa: F401 (fixtures)
|
||||
from tests.test_signage import playlist, screens, sent, slide # noqa: F401 (fixtures + helpers)
|
||||
from tests.test_signage_menu import menu, names # noqa: F401 (fixture + helper)
|
||||
|
||||
BOX = {"x": 5, "y": 10, "w": 90, "h": 80}
|
||||
|
||||
|
||||
def stack(*cells, direction="row"):
|
||||
return {"kind": "stack", "direction": direction, "position": "custom", "box": BOX, "cells": list(cells)}
|
||||
|
||||
|
||||
def keep(client, h, **body):
|
||||
r = client.post("/api/signage/library", headers=h, json={"name": "Promo", "kind": "text", **body})
|
||||
assert r.status_code == 201, r.text
|
||||
return r.json()
|
||||
|
||||
|
||||
def test_text_weather_and_stack_widgets_are_checked(client, owner_h):
|
||||
p = playlist(client, owner_h)
|
||||
s = slide(client, owner_h, p["id"], "blank", content={"widgets": [
|
||||
{"kind": "text", "text": "Happy hour 18-20"},
|
||||
{"kind": "weather", "weather_from": 1, "weather_days": 3, "weather_style": "icon"},
|
||||
stack({"share": 30, "widget": {"kind": "clock"}}, {"share": 70, "widget": stack({"share": 50}, {"share": 50}, direction="column")}),
|
||||
]})
|
||||
ws = s["content"]["widgets"]
|
||||
assert ws[0]["text"] == "Happy hour 18-20"
|
||||
assert ws[1]["weather_from"] == 1 and ws[1]["weather_days"] == 2 and ws[1]["weather_style"] == "icon" # the forecast has 3 days
|
||||
assert [c["share"] for c in ws[2]["cells"]] == [30, 70] and ws[2]["cells"][1]["widget"]["direction"] == "column"
|
||||
assert ws[0]["cells"] == [] and ws[0]["board"] is None
|
||||
url = f"/api/signage/playlists/{p['id']}/slides"
|
||||
bad = [
|
||||
stack(), # no parts
|
||||
stack({"share": 50, "widget": {"kind": "clock"}, "slide_id": 1}), # a widget and a slide
|
||||
stack({"share": 50, "widget": stack({"share": 50, "widget": stack({"share": 100})})}), # three stacks deep
|
||||
stack(*[{"share": 10}] * 7), # more than 6 parts
|
||||
]
|
||||
for w in bad:
|
||||
assert err(client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": [w]}})) == "signage.content_invalid", w
|
||||
assert err(client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": [stack({"share": 100, "slide_id": 999})]}})) == "signage.slide_unknown"
|
||||
|
||||
|
||||
def test_a_stack_shows_a_library_slide_and_a_menu_widget(client, owner_h, screens, sent, menu, db):
|
||||
promo = keep(client, owner_h, content={"title": "Fresh fish", "widgets": [{"kind": "qr", "position": "bottom-right"}]})
|
||||
p = playlist(client, owner_h, "Split")
|
||||
tv = screens[1]
|
||||
client.put(f"/api/signage/screens/{tv['id']}", headers=owner_h, json={"playlist_id": p["id"]})
|
||||
board = {"kind": "menu", "board": {"category_ids": [menu["cats"]["drinks"]], "exclude_ids": [menu["beer"].id], "columns": 1}}
|
||||
s = slide(client, owner_h, p["id"], "blank", content={"widgets": [
|
||||
{"kind": "qr", "position": "top-left"},
|
||||
stack({"share": 25, "widget": board}, {"share": 75, "slide_id": promo["id"]}),
|
||||
]})
|
||||
# the screen: extras by widget path (the QR's link, the menu's products, the slide inside the part)
|
||||
got = client.get("/api/signage/screen", headers=tv["h"]).json()["playlist"]["slides"][0]
|
||||
ex = got["extras"]
|
||||
assert ex["0"]["link"] and got["content"]["widgets"][0]["link"] == ex["0"]["link"]
|
||||
assert names(ex["1.0"]["menu"]) == [] and ex["1.0"]["menu"]["count"] == 0 # Beer hidden; Wine: delivery only
|
||||
inner = ex["1.1"]["slide"]
|
||||
assert inner["id"] == promo["id"] and inner["kind"] == "text" and inner["content"]["title"] == "Fresh fish"
|
||||
assert inner["extras"]["0"]["link"] # its own widgets' extras
|
||||
# the editor: the hidden product stays in the list, marked
|
||||
ed = client.get(f"/api/signage/playlists/{p['id']}", headers=owner_h).json()["slides"][0]["extras"]["1.0"]["menu"]
|
||||
assert [(i["name"], i.get("hidden", False)) for g in ed["groups"] for i in g["items"]] == [("Beer", True)] and ed["count"] == 0
|
||||
# a change to the library slide reaches the screens that show it inside a stack
|
||||
sent.clear()
|
||||
client.put(f"/api/signage/library/{promo['id']}", headers=owner_h, json={"content": {"title": "Fresh octopus"}})
|
||||
assert sent == [("signage.changed", [tv["id"]])]
|
||||
assert client.get("/api/signage/screen", headers=tv["h"]).json()["playlist"]["slides"][0]["extras"]["1.1"]["slide"]["content"]["title"] == "Fresh octopus"
|
||||
# products change: a slide with a menu widget is told too
|
||||
import routers.signage as sg
|
||||
sent.clear()
|
||||
sg.menu_changed(db)
|
||||
assert sent == [("signage.changed", [tv["id"]])]
|
||||
# the library slide deleted: the part shows nothing, the screen is told
|
||||
sent.clear()
|
||||
client.delete(f"/api/signage/library/{promo['id']}", headers=owner_h)
|
||||
assert sent == [("signage.changed", [tv["id"]])]
|
||||
assert "1.1" not in client.get("/api/signage/screen", headers=tv["h"]).json()["playlist"]["slides"][0]["extras"]
|
||||
assert s["content"]["widgets"][1]["cells"][1]["slide_id"] == promo["id"]
|
||||
|
||||
|
||||
def test_the_editor_previews_any_slide(client, owner_h, menu):
|
||||
promo = keep(client, owner_h, content={"title": "Inside"})
|
||||
r = client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "blank", "content": {"widgets": [
|
||||
stack({"share": 50, "widget": {"kind": "menu", "board": {"product_ids": [menu["steak"].id], "exclude_ids": [menu["steak"].id]}}},
|
||||
{"share": 50, "slide_id": promo["id"]})]}})
|
||||
assert r.status_code == 200, r.text
|
||||
got = r.json()
|
||||
assert [i.get("hidden") for g in got["extras"]["0.0"]["menu"]["groups"] for i in g["items"]] == [True]
|
||||
assert got["extras"]["0.1"]["slide"]["content"]["title"] == "Inside" and got["menu"] is None and got["media"] == {}
|
||||
r = client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "menu", "content": {"select": "all", "exclude_ids": [menu["beer"].id]}})
|
||||
m = r.json()["menu"]
|
||||
assert "Beer" in [i["name"] for g in m["groups"] for i in g["items"] if i.get("hidden")] and m["count"] == 3
|
||||
assert err(client.post("/api/signage/preview/slide", headers=owner_h, json={"kind": "text", "content": {"widgets": [stack()]}})) == "signage.content_invalid"
|
||||
Reference in New Issue
Block a user