diff --git a/client/scripts/storage.js b/client/scripts/storage.js index df5f10c4..bb149e5d 100644 --- a/client/scripts/storage.js +++ b/client/scripts/storage.js @@ -14,3 +14,7 @@ let last_selected_node_id // layer's drawflow id let last_changed_parameters_layer_id let layer_drag_offset_X = 0 let layer_drag_offset_Y = 0 + +let is_id_on_paths = false // Is there written id's on connections +let input_selection_layer_id +let input_selection_layer_dbid diff --git a/client/templates/main.html b/client/templates/main.html index f7fcc3a0..e66c979c 100644 --- a/client/templates/main.html +++ b/client/templates/main.html @@ -440,7 +440,6 @@
} } click(e) { - deleteIdOnConnections() hideLayerInfo() super.click(e) } @@ -538,7 +537,7 @@ if (response.ok) { editor.updateNodeDataFromId(connection.input_id, { DBID: data2.DBID, - Connections: data2.Connections.concat(`${data1.DBID};${connection.output_id}`), // "db_id;drawflow_id" + Connections: [].concat(`${data1.DBID};${connection.output_id}`, data2.Connections), // "db_id;drawflow_id" Parameters: data2.Parameters, }) } else { @@ -1160,14 +1159,20 @@ const tmp = addLabelText(htmlConnection, connection.split(";")[0]) // Writes id on connection pathsWithWrittenID.push(tmp) } + is_id_on_paths = true } // Remove id written on connection function deleteIdOnConnections() { for (let path of pathsWithWrittenID) { - path.setAttribute("display", "none") + try { + path.setAttribute("display", "none") + } catch (e) { + console.error(e) + } } pathsWithWrittenID = [] + is_id_on_paths = false } function getSortableInputList(layer) { @@ -1187,7 +1192,36 @@ function hideResult() { document.getElementById("predict-result-wrapper").style.display = "none" } + + function matchConnectionsAfterSelection(new_input_order) { + let newConnections = [] + let connections = editor.getNodeFromId(input_selection_layer_id).data.Connections + for (let input of new_input_order) { + for (let connection of connections) { + if (input == connection.split(";")[0]) { + newConnections.push(connection) + } + } + } + let new_inputs_object = { + new_parents: new_input_order, + layer_id: input_selection_layer_dbid, + } + updateParentOrder(new_inputs_object).then(response => { + if (response.ok) { + editor.updateNodeDataFromId(input_selection_layer_id, { + DBID: input_selection_layer_dbid, + Connections: newConnections, + Parameters: editor.getNodeFromId(input_selection_layer_id).data.Parameters, + }) + } else { + errorNotification("Failed to update input order.\n Server is not responding now.") + } + }) + } + function showLayerInfo(id) { + hideLayerInfo() // id format "node-