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.
41 lines
2.3 KiB
Python
41 lines
2.3 KiB
Python
import db
|
|
|
|
from .widget_meta import widget_meta
|
|
from .control_value import _control_value
|
|
from .data_definition_options import data_definition_options
|
|
from ..element_types.list_element_types import list_element_types
|
|
|
|
|
|
def controls_with_values(slug, el):
|
|
"""Pour le panneau de propriétés : la liste des réglages du widget de
|
|
cet élément, chacun avec sa valeur actuelle déjà résolue. Le réglage
|
|
"définition_id" du Répéteur de données (et de la Jauge) a besoin du jeu
|
|
courant pour lister les objets disponibles — d'où le paramètre slug."""
|
|
meta = widget_meta(el.get("widget"))
|
|
attributes = el.get("attributes") or {}
|
|
# Pour la Jauge : quel enregistrement suivre (row_id) et quels champs
|
|
# afficher (champ/champ_nom) ne peuvent être proposés qu'une fois un
|
|
# objet choisi (definition_id, déjà sur CET élément) — voir
|
|
# render_jauge.py. La mise à jour EN DIRECT quand on change d'objet
|
|
# sans quitter le panneau est gérée côté client (onJaugeDefinitionChange
|
|
# dans screen_edit.html), ceci ne couvre que le premier affichage/une
|
|
# navigation vers un élément déjà réglé.
|
|
jauge_options = data_definition_options(slug, attributes.get("_definition_id"))
|
|
result = []
|
|
for control in meta.get("controls", []):
|
|
control = dict(control)
|
|
if control["key"] == "definition_id":
|
|
defs = db.list_definitions(slug)
|
|
control["options"] = [("", "(sélectionner un objet)")] + [(str(d["id"]), d["name"]) for d in defs]
|
|
if control["key"] == "template_type_id":
|
|
types = list_element_types(slug)
|
|
control["options"] = [("", "(aucun — utiliser le modèle de texte ci-dessous)")] + [(str(t["id"]), t["name"]) for t in types]
|
|
if control["key"] == "row_id":
|
|
control["options"] = [("", "(sélectionner un objet d'abord)")] + [(str(r["id"]), r["label"]) for r in jauge_options["rows"]]
|
|
if control["key"] == "champ":
|
|
control["options"] = [("", "(sélectionner un objet d'abord)")] + [(f["name"], f["name"]) for f in jauge_options["fields"]]
|
|
if control["key"] == "champ_nom":
|
|
control["options"] = [("", "— aucun —")] + [(f["name"], f["name"]) for f in jauge_options["fields"]]
|
|
result.append({**control, "value": _control_value(el, control)})
|
|
return result
|