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 @@