A Jauge could only target a whole object, not a specific record — three gauges pointing at the same "value" field (e.g. Réputation/ Trésorerie/Confiance in one "jauge" object) all silently showed the most recent row's value, with no way to tell them apart. Add "Enregistrement (ligne) à suivre" (row_id) so a Jauge targets one specific row, and "Champ contenant le nom" (champ_nom) to show a label above the bar — both as dropdowns populated from the object's actual fields/rows (previously "Champ numérique à afficher" was free text the user had to type correctly by hand). No regression: without row_id the widget still falls back to the latest row, exactly as before. Extract data_definition_options() (rows+fields for a definition) out of routes/screens/screen_edit.py so controls_with_values.py can reuse it server-side for the initial render; a small client-side handler (bindJaugeDefinitionSelect) repopulates the same selects live when the tracked object is changed without leaving the panel. Verified live with Playwright: picking "jauge" then "Confiance" then "value"/"name" in the panel renders an 80%-filled, green-leaning bar labelled "Confiance" on /play — not the 20%/50% of the other rows.
28 lines
1.4 KiB
Python
28 lines
1.4 KiB
Python
import db
|
|
|
|
|
|
def data_definition_options(slug, definition_id):
|
|
"""Lignes et champs d'un objet de données, prêts à peupler un menu
|
|
déroulant — utilisé à la fois pour DEFINITIONS_DATA (tous les objets du
|
|
jeu, consommé côté client par les formulaires de la Logique de la
|
|
scène) et pour pré-remplir côté serveur les réglages qui dépendent d'un
|
|
objet déjà choisi sur un élément (ex: la Jauge — voir
|
|
controls_with_values.py). Chaque ligne est étiquetée avec la valeur de
|
|
son PREMIER champ (convention "premier champ = nom lisible", comme pour
|
|
un Répéteur), pour distinguer "Confiance" de "Trésorerie" plutôt que de
|
|
n'avoir que des numéros de ligne."""
|
|
if not definition_id or not slug:
|
|
return {"rows": [], "fields": []}
|
|
full = db.get_definition(slug, int(definition_id))
|
|
if not full:
|
|
return {"rows": [], "fields": []}
|
|
rows = db.list_rows(slug, full)
|
|
display_field = full["fields"][0]["name"] if full["fields"] else None
|
|
display_col = db.slugify(display_field).replace("-", "_") if display_field else None
|
|
row_options = [
|
|
{"id": r["id"], "label": f"{r.get(display_col)} (#{r['id']})" if display_col else f"Ligne #{r['id']}"}
|
|
for r in rows
|
|
]
|
|
field_options = [{"name": f["name"], "type": f["type"]} for f in full["fields"] if f["type"] != "relation"]
|
|
return {"rows": row_options, "fields": field_options}
|