feat(signage): reviews typed in by hand and their widget; Add a widget at the top of the widgets, the list in layers (new widgets on top)
Reviews (name, stars, text, date, where) under Signage -> Message & settings, shown one at a time by the reviews widget (a minimum of stars, seconds each); not pulled from Google (owner's choice). The widgets section: one "Add a widget" menu at its top instead of a button per kind; the cards are layers, the top one drawn over the others, so a new widget goes on top; the arrows bring forward / send backward. Plan 6R.19, F-113. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ MODULE = Module(
|
||||
),
|
||||
settings=(
|
||||
SettingDef('signage.message', '', 'The message of the day on every signage screen with a message widget (Signage > Message of the day).'),
|
||||
SettingDef('signage.reviews', '[]', 'The reviews the venue typed in for the reviews widget (6R.19; JSON list; Signage > Message & settings).', type='json'),
|
||||
SettingDef('signage.weather.place', '', 'The place whose weather the screens show (picked from a town search in Signage).'),
|
||||
SettingDef('signage.weather.latitude', '', 'Latitude of the weather place.'),
|
||||
SettingDef('signage.weather.longitude', '', 'Longitude of the weather place.'),
|
||||
|
||||
@@ -18,6 +18,7 @@ Manager side (signage.manage):
|
||||
PUT /api/signage/library/{id} change it (a screen showing it is told)
|
||||
DELETE /api/signage/library/{id} screens that had it as their default show nothing
|
||||
POST /api/signage/library/{id}/duplicate a copy
|
||||
GET /api/signage/reviews the venue's reviews (6R.19); PUT: all of them at once
|
||||
GET /api/signage/screens the paired screens: playlist or slide, orientation, rotation,
|
||||
picture area (insets), fit, the window size it reported
|
||||
PUT /api/signage/screens/{id} {playlist_id | slide_id, orientation, rotation, area_*, fit}
|
||||
@@ -52,6 +53,7 @@ from services.ws_bus import broadcast_sync
|
||||
router = APIRouter()
|
||||
KEY = "signage.manage"
|
||||
MESSAGE = "signage.message"
|
||||
REVIEWS = "signage.reviews" # the venue's reviews, typed in by hand (6R.19)
|
||||
MAX_WIDGETS = "signage.max_widgets" # widgets a slide may hold (owner review 6: Performance; 10 recommended)
|
||||
MAX_WIDGETS_CAP = 50 # never more, whatever the setting
|
||||
AREA_MAX = 4000 # px a screen's picture area may cut off one edge (6R.13)
|
||||
@@ -83,7 +85,8 @@ class Background(_Strict):
|
||||
|
||||
|
||||
WidgetKind = Literal["logo", "name", "date", "clock", "message", "qr", "weather", "text", "menu", "stack",
|
||||
"shape", "ticker", "countdown", "hours", "wifi", "contact"] # 6R.15
|
||||
"shape", "ticker", "countdown", "hours", "wifi", "contact", # 6R.15
|
||||
"reviews"] # 6R.19
|
||||
WHEN = r"^(\d{4}-\d{2}-\d{2}T)?([01]\d|2[0-3]):[0-5]\d$" # a countdown's moment: "HH:MM" (every day) or "YYYY-MM-DDTHH:MM"
|
||||
ContactKey = Literal["phone", "phone2", "email", "address", "website", "google", "facebook", "instagram", "tiktok", "tripadvisor", "whatsapp", "viber"]
|
||||
Position = Literal["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right", "top-bar", "bottom-bar", "custom"]
|
||||
@@ -308,6 +311,11 @@ class Widget(_Strict):
|
||||
wifi_password: bool = True
|
||||
# contact details (from the identity): which, in this order
|
||||
contact_fields: List[ContactKey] = Field(default_factory=lambda: ["phone", "website", "instagram"], max_length=12)
|
||||
# reviews (6R.19): the venue's, typed in under Message & settings; one at a time, turning
|
||||
reviews_seconds: int = Field(default=8, ge=3, le=120)
|
||||
reviews_min: int = Field(default=4, ge=1, le=5) # only reviews with at least these stars
|
||||
reviews_stars: bool = True
|
||||
reviews_name: bool = True
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _place(self):
|
||||
@@ -1434,6 +1442,46 @@ def put_performance(body: PerformanceBody, db: Session = Depends(get_db), user=D
|
||||
return {"max_widgets": body.max_widgets, "recommended": 10, "cap": MAX_WIDGETS_CAP}
|
||||
|
||||
|
||||
class Review(_Strict):
|
||||
"""A review the venue typed in (6R.19): who, how many stars, what they wrote, when, where it was posted."""
|
||||
name: str = Field(min_length=1, max_length=60)
|
||||
stars: int = Field(ge=1, le=5)
|
||||
text: str = Field(min_length=1, max_length=400)
|
||||
date: Optional[str] = Field(default=None, pattern=DATE)
|
||||
source: Optional[str] = Field(default=None, max_length=40) # "Google", "Tripadvisor"…
|
||||
|
||||
@field_validator("name", "text", "source")
|
||||
@classmethod
|
||||
def _trim(cls, v):
|
||||
v = " ".join(str(v).split()) if v is not None else None
|
||||
return v or None
|
||||
|
||||
|
||||
class ReviewsBody(BaseModel):
|
||||
reviews: List[Review] = Field(default_factory=list, max_length=100)
|
||||
|
||||
|
||||
def reviews(db) -> list:
|
||||
"""The venue's reviews as stored (a broken value reads as none)."""
|
||||
try:
|
||||
return ReviewsBody(reviews=json.loads(_setting(db, REVIEWS) or "[]")).model_dump()["reviews"]
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
@router.get("/reviews")
|
||||
def get_reviews(db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
return {"reviews": reviews(db)}
|
||||
|
||||
|
||||
@router.put("/reviews")
|
||||
def put_reviews(body: ReviewsBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
_save_setting(db, REVIEWS, json.dumps(body.model_dump()["reviews"], ensure_ascii=False))
|
||||
db.commit()
|
||||
tell_all_screens(db)
|
||||
return {"reviews": reviews(db)}
|
||||
|
||||
|
||||
class BadgesBody(BaseModel):
|
||||
badges: list = Field(default_factory=list)
|
||||
|
||||
@@ -1531,7 +1579,7 @@ def _venue(db) -> dict:
|
||||
ident.pop("name", None)
|
||||
return {"name": _setting(db, "venue.name") or None, "message": _setting(db, MESSAGE) or None,
|
||||
"weather": weather.current(db), "badges": signage_badges.load(db), "identity": ident, "timezone": venue_tz().key,
|
||||
"hours": hours_out(db)}
|
||||
"hours": hours_out(db), "reviews": reviews(db)}
|
||||
|
||||
|
||||
class SlidePreviewBody(BaseModel):
|
||||
|
||||
@@ -84,3 +84,18 @@ def test_new_widgets_are_typed(client, owner_h):
|
||||
bad = client.post(f"/api/signage/playlists/{p['id']}/slides", headers=owner_h,
|
||||
json={"kind": "blank", "content": {"widgets": [{"kind": "contact", "contact_fields": ["fax"]}]}})
|
||||
assert err(bad) == "signage.content_invalid"
|
||||
|
||||
|
||||
def test_reviews_typed_in_by_hand(client, owner_h, screens, sent):
|
||||
body = {"reviews": [{"name": " Maria K. ", "stars": 5, "text": "Best octopus on the island", "date": "2026-11-01", "source": "Google"},
|
||||
{"name": "John", "stars": 3, "text": "OK"}]}
|
||||
sent.clear()
|
||||
r = client.put("/api/signage/reviews", headers=owner_h, json=body)
|
||||
assert r.status_code == 200, r.text
|
||||
got = r.json()["reviews"]
|
||||
assert got[0]["name"] == "Maria K." and got[0]["text"] == "Best octopus on the island" and got[1]["date"] is None
|
||||
assert ("signage.changed", sorted([screens[1]["id"], screens[2]["id"]])) in sent
|
||||
assert client.get("/api/signage/screen", headers=screens[1]["h"]).json()["venue"]["reviews"][0]["stars"] == 5
|
||||
assert client.get("/api/signage/reviews", headers=owner_h).json()["reviews"][1]["name"] == "John"
|
||||
assert client.put("/api/signage/reviews", headers=owner_h, json={"reviews": [{"name": "x", "stars": 6, "text": "y"}]}).status_code == 422
|
||||
assert client.put("/api/signage/reviews", headers=owner_h, json={"reviews": [{"name": "x", "stars": 5, "text": ""}]}).status_code == 422
|
||||
|
||||
Reference in New Issue
Block a user