Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app/static/js/grid_model_topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions app/templates/scenario/scenario_step2.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ <h3>{{ group_names|get_item:group_name|title }}</h3>
// 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.
Expand Down