Disambiguate same-type widgets in the button-assignment dropdowns
Two widgets of the same type (e.g. two Photos widgets) both showed up
as plain "Photos" with no way to tell which was which. The buttons API
now includes each widget's grid placement plus the frame's grid dims;
the UI derives a rough position ("top-left", "right", etc.) from that
and only appends a number+position suffix when a type actually
repeats on the frame, leaving the common single-widget-per-type case
unchanged.
This commit is contained in:
@@ -46,6 +46,35 @@ def test_get_buttons_reflects_the_default_migration_mapping(client, db_session):
|
||||
assert data["back"] == [{"id": data["back"][0]["id"], "widget_id": photo_widget.id, "action": "back"}]
|
||||
|
||||
|
||||
def test_get_buttons_includes_placement_and_grid_dims(client, db_session):
|
||||
"""Two widgets of the same type otherwise look identical in the
|
||||
assignment UI ("Photos" / "Photos") -- the client tells them apart
|
||||
using x/y/w/h against the frame's grid dims (see
|
||||
static/frame_config.js's buildWidgetNames), so the API needs to
|
||||
actually hand those over."""
|
||||
client.post("/setup", data={"username": "alice", "password": "hunter22"})
|
||||
frame = db_session.get(Frame, 1)
|
||||
photo_widget = db_session.query(Widget).filter_by(frame_id=frame.id, widget_type="photos").one()
|
||||
photo_widget.x, photo_widget.y, photo_widget.w, photo_widget.h = 0, 0, 4, 5
|
||||
db_session.commit()
|
||||
second = Widget(frame_id=frame.id, widget_type="photos", x=4, y=0, w=4, h=5,
|
||||
sort_order=1, created_at=time.time())
|
||||
db_session.add(second)
|
||||
db_session.flush()
|
||||
from app.models import PhotoWidgetConfig
|
||||
db_session.add(PhotoWidgetConfig(widget_id=second.id))
|
||||
db_session.commit()
|
||||
|
||||
resp = client.get("/api/frames/1/buttons")
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
|
||||
assert data["grid"] == {"cols": 8, "rows": 5}
|
||||
by_id = {w["id"]: w for w in data["widgets"]}
|
||||
assert by_id[photo_widget.id]["x"] == 0 and by_id[photo_widget.id]["w"] == 4
|
||||
assert by_id[second.id]["x"] == 4 and by_id[second.id]["w"] == 4
|
||||
|
||||
|
||||
def test_put_replaces_the_whole_list_in_order(client, db_session):
|
||||
client.post("/setup", data={"username": "alice", "password": "hunter22"})
|
||||
frame = db_session.get(Frame, 1)
|
||||
|
||||
Reference in New Issue
Block a user