diff --git a/app/static/js/grid_model_topology.js b/app/static/js/grid_model_topology.js index 1571e8ef..731f4663 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.