From d74ac5f2bc32e691eda322264bab455a36a08dd9 Mon Sep 17 00:00:00 2001 From: josihoppe <116898820+josihoppe@users.noreply.github.com> Date: Mon, 24 Nov 2025 16:51:51 +0100 Subject: [PATCH 1/2] added js check to see if the nodes are connected before saving --- app/static/js/grid_model_topology.js | 41 ++++++++++++++++++++++ app/templates/scenario/scenario_step2.html | 6 ++++ 2 files changed, 47 insertions(+) diff --git a/app/static/js/grid_model_topology.js b/app/static/js/grid_model_topology.js index 1571e8ef..27a75a0a 100644 --- a/app/static/js/grid_model_topology.js +++ b/app/static/js/grid_model_topology.js @@ -747,3 +747,44 @@ function computeCOP(event){ alert(error.message); }); } + + +function validateNodeConnections(editor) { + const nodes = editor.export().drawflow.Home.data; + + for (const nodeId in nodes) { + const node = nodes[nodeId]; + const name = node.name; // "...-demand", "bus--...", sources are the rest + let inputCount = 0; + let outputCount = 0; + + for (const inputName in node.inputs) { + inputCount += node.inputs[inputName].connections.length; + } + for (const outputName in node.outputs) { + outputCount += node.outputs[outputName].connections.length; + } + // Sink + if (name.endsWith("demand")) { + if (inputCount < 1) { + alert(`Sink "${node.data.name}" must have at least 1 input.`); + return false; + } + continue; + } + // Bus + if (name.startsWith("bus--")) { + if (inputCount < 1 || outputCount < 1) { + alert(`Bus "${node.data.name}" must have at least 1 input AND 1 output.`); + return false; + } + continue; + } + // Source + if (outputCount < 1) { + alert(`Source "${node.data.name}" must have at least 1 output.`); + return false; + } + } + return true; +} diff --git a/app/templates/scenario/scenario_step2.html b/app/templates/scenario/scenario_step2.html index 2e13f706..6309246b 100644 --- a/app/templates/scenario/scenario_step2.html +++ b/app/templates/scenario/scenario_step2.html @@ -217,6 +217,12 @@

{{ group_names|get_item:group_name|title }}

// warn in case of empty model if (node_list.length == 0 && !confirm('No components in model. Continue?')) return; + // Check that all nodes are connected to at least one bus + if (!validateNodeConnections(editor)) { + console.log("connections are false") + return; + } + // Check if there are duplicate node names in the model // and prevent user from saving the model if there are. // Might also be handled in backend when saving names. From cdc4440fd17243b8c5844a4f961fdc8511a44bf5 Mon Sep 17 00:00:00 2001 From: josihoppe <116898820+josihoppe@users.noreply.github.com> Date: Tue, 9 Dec 2025 18:08:31 +0100 Subject: [PATCH 2/2] fixed check for busses, wrong naming convention used --- app/static/js/grid_model_topology.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/static/js/grid_model_topology.js b/app/static/js/grid_model_topology.js index 27a75a0a..731f4663 100644 --- a/app/static/js/grid_model_topology.js +++ b/app/static/js/grid_model_topology.js @@ -773,7 +773,7 @@ function validateNodeConnections(editor) { continue; } // Bus - if (name.startsWith("bus--")) { + if (name.startsWith("bus")) { if (inputCount < 1 || outputCount < 1) { alert(`Bus "${node.data.name}" must have at least 1 input AND 1 output.`); return false;