Phase 4 : ajout dynamique d'une ligne à l'exécution
Nouveau sentinel LAST_INSERTED_ROW_ID = -3 (screens/flow/constants.py), aux côtés de CLICKED_ROW_ID = -1 — même principe : un id de ligne n'existe qu'APRÈS l'insertion, jamais connu à la création du nœud. Permet d'enchaîner un nœud "Ajouter une ligne" (crée une ligne VIDE) puis un ou plusieurs nœuds "Modifier une donnée" déjà existants (ciblant "➕ Dernière ligne ajoutée" dans le sélecteur "Ligne concernée", partagé avec les conditions) pour renseigner ses champs — réutilise 100% du mécanisme actuel, aucun nouveau format de payload multi-champs. screens/data_actions/apply_add_row_action.py : db.get_definition + db.insert_row(slug, definition, {}, player_id) — la ligne appartient au joueur qui agit pour un objet per_player (Phase 1). Nouvelles routes (créateur ET publique, comme prévu dès la Phase 1) : POST /game/<slug>/flow/nodes/<id>/run-add-row et son miroir /jouer/<slug>/.../run-add-row — renvoient {"ok", "row_id"}. routes/flow/flow_node_run_data.py (+ son miroir public) : résout aussi LAST_INSERTED_ROW_ID (en plus de CLICKED_ROW_ID déjà en place) via last_inserted_row_id transmis par le client. static/js/play/actions.js : runActionNode branche "ajouter_ligne" -> fetch la nouvelle route, pose window.lastInsertedRowId, puis refreshRuntimeData() (un Répéteur lié affiche la nouvelle ligne au prochain rendu, confirmé par l'audit préalable — aucun ajustement du mécanisme de rafraîchissement nécessaire). La branche "modifier_donnee" transmet désormais aussi last_inserted_row_id, comme clicked_row_id. templates/screen_edit.html + static/js/screen_edit/flow-editor.js : nouveau type d'action "Ajouter une ligne à un objet" (juste un sélecteur d'objet, aucun champ à remplir — le rappel du fonctionnement enchaîné est affiché directement dans le formulaire) ; le sélecteur "Ligne concernée" (partagé Condition/Modifier une donnée) gagne l'option "➕ Dernière ligne ajoutée" à côté de "🖱️ Ligne cliquée". Vérifié : 259 tests passent (4 nouveaux, dont un bout-en-bout via HTTP qui enchaîne réellement les deux nœuds et vérifie le champ renseigné, et un qui verrouille l'isolation par joueur de la ligne créée), 13 tests node:test toujours au vert, syntaxe JS validée. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
727c3c97ba
commit
92fbfbc9dd
@@ -6,5 +6,6 @@ from . import (
|
||||
flow_edge_delete,
|
||||
flow_node_run_data,
|
||||
flow_node_run_variable,
|
||||
flow_node_run_add_row,
|
||||
runtime_payload,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
from flask import jsonify
|
||||
|
||||
import screens
|
||||
|
||||
from core.flask_app import app
|
||||
|
||||
|
||||
@app.route("/game/<slug>/flow/nodes/<int:node_id>/run-add-row", methods=["POST"])
|
||||
def flow_node_run_add_row(slug, node_id):
|
||||
"""Exécuté côté serveur au moment du clic, en mode jouable, pour un
|
||||
nœud Action de type "ajouter_ligne" (Phase 4) — même principe que
|
||||
flow_node_run_data.py, mais crée une ligne VIDE plutôt que d'en
|
||||
modifier une existante. Renvoie l'id de la nouvelle ligne, à
|
||||
transmettre par le client (voir runActionNode() dans
|
||||
static/js/play/actions.js) aux nœuds suivants qui la ciblent via
|
||||
LAST_INSERTED_ROW_ID."""
|
||||
node = screens.get_flow_node(slug, node_id)
|
||||
if not node or node.get("node_type") != "action" or node.get("action_type") != "ajouter_ligne":
|
||||
return jsonify({"ok": False}), 400
|
||||
row_id = screens.apply_add_row_action(slug, node)
|
||||
return jsonify({"ok": row_id is not None, "row_id": row_id})
|
||||
@@ -22,5 +22,13 @@ def flow_node_run_data(slug, node_id):
|
||||
if node.get("target_row_id") == screens.CLICKED_ROW_ID:
|
||||
body = request.get_json(silent=True) or {}
|
||||
node = {**node, "target_row_id": body.get("clicked_row_id")}
|
||||
elif node.get("target_row_id") == screens.LAST_INSERTED_ROW_ID:
|
||||
# Phase 4 — enchaînement "Ajouter une ligne" -> "Modifier une
|
||||
# donnée" : la vraie ligne (créée juste avant par le nœud
|
||||
# précédent, voir flow_node_run_add_row.py) n'est connue qu'au
|
||||
# moment du clic, transmise par le client (voir runActionNode()
|
||||
# dans static/js/play/actions.js).
|
||||
body = request.get_json(silent=True) or {}
|
||||
node = {**node, "target_row_id": body.get("last_inserted_row_id")}
|
||||
ok = screens.apply_data_action(slug, node)
|
||||
return jsonify({"ok": ok})
|
||||
|
||||
@@ -21,4 +21,5 @@ def game_play(slug):
|
||||
runtime_payload_url=url_for("runtime_payload", slug=slug),
|
||||
flow_node_run_data_url=url_for("flow_node_run_data", slug=slug, node_id=999999),
|
||||
flow_node_run_variable_url=url_for("flow_node_run_variable", slug=slug, node_id=999999),
|
||||
flow_node_run_add_row_url=url_for("flow_node_run_add_row", slug=slug, node_id=999999),
|
||||
)
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
from . import game_play_public, runtime_payload_public, flow_node_run_data_public, flow_node_run_variable_public
|
||||
from . import (
|
||||
game_play_public,
|
||||
runtime_payload_public,
|
||||
flow_node_run_data_public,
|
||||
flow_node_run_variable_public,
|
||||
flow_node_run_add_row_public,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
from flask import jsonify, abort
|
||||
|
||||
import db
|
||||
import screens
|
||||
|
||||
from core.flask_app import app
|
||||
from core.player_identity import get_or_create_player_id, set_player_id_cookie
|
||||
|
||||
|
||||
@app.route("/jouer/<slug>/flow/nodes/<int:node_id>/run-add-row", methods=["POST"])
|
||||
def flow_node_run_add_row_public(slug, node_id):
|
||||
"""Miroir public de routes/flow/flow_node_run_add_row.py (aperçu
|
||||
créateur) — voir routes/public_play/game_play_public.py pour le
|
||||
principe général."""
|
||||
if not db.is_public_played(slug):
|
||||
abort(404)
|
||||
player_id, is_new = get_or_create_player_id()
|
||||
node = screens.get_flow_node(slug, node_id)
|
||||
if not node or node.get("node_type") != "action" or node.get("action_type") != "ajouter_ligne":
|
||||
return jsonify({"ok": False}), 400
|
||||
row_id = screens.apply_add_row_action(slug, node, player_id)
|
||||
resp = app.make_response(jsonify({"ok": row_id is not None, "row_id": row_id}))
|
||||
if is_new:
|
||||
set_player_id_cookie(resp, player_id)
|
||||
return resp
|
||||
@@ -22,6 +22,10 @@ def flow_node_run_data_public(slug, node_id):
|
||||
if node.get("target_row_id") == screens.CLICKED_ROW_ID:
|
||||
body = request.get_json(silent=True) or {}
|
||||
node = {**node, "target_row_id": body.get("clicked_row_id")}
|
||||
elif node.get("target_row_id") == screens.LAST_INSERTED_ROW_ID:
|
||||
# Phase 4 — voir routes/flow/flow_node_run_data.py.
|
||||
body = request.get_json(silent=True) or {}
|
||||
node = {**node, "target_row_id": body.get("last_inserted_row_id")}
|
||||
ok = screens.apply_data_action(slug, node, player_id)
|
||||
resp = app.make_response(jsonify({"ok": ok}))
|
||||
if is_new:
|
||||
|
||||
@@ -29,6 +29,7 @@ def game_play_public(slug):
|
||||
runtime_payload_url=url_for("runtime_payload_public", slug=slug),
|
||||
flow_node_run_data_url=url_for("flow_node_run_data_public", slug=slug, node_id=999999),
|
||||
flow_node_run_variable_url=url_for("flow_node_run_variable_public", slug=slug, node_id=999999),
|
||||
flow_node_run_add_row_url=url_for("flow_node_run_add_row_public", slug=slug, node_id=999999),
|
||||
)
|
||||
)
|
||||
if is_new:
|
||||
|
||||
@@ -37,6 +37,10 @@ def screen_edit(slug, screen_id):
|
||||
|
||||
definitions = db.list_definitions(slug)
|
||||
definitions_data = {str(d["id"]): screens.data_definition_options(slug, d["id"]) for d in definitions}
|
||||
# Phase 4 — nodeLabel() (static/js/screen_edit/flow-editor.js) affiche
|
||||
# le nom de l'objet visé par un nœud "Ajouter une ligne" ; DEFINITIONS_DATA
|
||||
# (ci-dessus) ne porte que lignes/champs, jamais le nom lui-même.
|
||||
definitions_names = {d["id"]: d["name"] for d in definitions}
|
||||
|
||||
# list_flow_blocks() rattache paresseusement les nœuds "orphelins"
|
||||
# (block_id NULL, jeux créés avant les blocs) à un "Bloc principal" —
|
||||
@@ -94,4 +98,5 @@ def screen_edit(slug, screen_id):
|
||||
custom_events_map_json=json.dumps(custom_events_map),
|
||||
blocks_view=blocks_view,
|
||||
flow_blocks_json=json.dumps(flow_blocks),
|
||||
definitions_names_json=json.dumps(definitions_names),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user