From 6cb7646cfe87177fce9cb142c01c51be97e01557 Mon Sep 17 00:00:00 2001 From: Ivan Shanygin Date: Sun, 10 Dec 2023 16:53:35 +0300 Subject: [PATCH 1/2] Fix input selection --- client/scripts/storage.js | 4 +++ client/templates/main.html | 73 +++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 29 deletions(-) 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 b243b9da..3b057db3 100644 --- a/client/templates/main.html +++ b/client/templates/main.html @@ -423,7 +423,6 @@

} } click(e) { - deleteIdOnConnections() hideLayerInfo() super.click(e) } @@ -521,7 +520,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 { @@ -1132,14 +1131,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.log(e) + } } pathsWithWrittenID = [] + is_id_on_paths = false } function getSortableInputList(layerClass) { @@ -1156,7 +1161,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 i = 0; i < new_input_order.length; i++) { + for (let connection of connections) { + if (new_input_order[i] == 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-" let correct_id = id if (id.includes("node")) { @@ -1165,9 +1199,11 @@

const node = editor.getNodeFromId(correct_id) const connections = editor.getNodeFromId(correct_id).data.Connections const layer_dbid = editor.getNodeFromId(correct_id).data.DBID + input_selection_layer_id = correct_id + input_selection_layer_dbid = layer_dbid // Input selection - writeIdOnConnections(correct_id) + writeIdOnConnections(input_selection_layer_id) let sortable_list = getSortableInputList(node.class) let child = sortable_list.lastElementChild @@ -1202,30 +1238,7 @@

continue } } - - let newConnections = [] - for (let i = 0; i < new_input_order.length; i++) { - for (let connection of connections) { - if (new_input_order[i] == connection.split(";")[0]) { - newConnections[i] = connection - } - } - } - let new_inputs_object = { - new_parents: new_input_order, - layer_id: layer_dbid, - } - updateParentOrder(new_inputs_object).then(response => { - if (response.ok) { - editor.updateNodeDataFromId(correct_id, { - DBID: layer_dbid, - Connections: newConnections, - Parameters: editor.getNodeFromId(correct_id).data.Parameters, - }) - } else { - errorNotification("Failed to update input order.\n Server is not responding now.") - } - }) + matchConnectionsAfterSelection(new_input_order) }, }) @@ -1267,7 +1280,9 @@

document.querySelector("#special-layer-parameters").style.display = "none" document.querySelector("#relu-layer-parameters").style.display = "none" - deleteIdOnConnections() + if (is_id_on_paths) { + deleteIdOnConnections() + } } function addLabelText(path, labelText) { From 650c1f5c8426a76623c015d39e48b55cfeb5980f Mon Sep 17 00:00:00 2001 From: Ivan Shanygin Date: Thu, 14 Dec 2023 12:43:32 +0300 Subject: [PATCH 2/2] Clean up fix input selection --- client/templates/main.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/templates/main.html b/client/templates/main.html index 3b057db3..85715361 100644 --- a/client/templates/main.html +++ b/client/templates/main.html @@ -1140,7 +1140,7 @@

try { path.setAttribute("display", "none") } catch (e) { - console.log(e) + console.error(e) } } pathsWithWrittenID = [] @@ -1165,9 +1165,9 @@

function matchConnectionsAfterSelection(new_input_order) { let newConnections = [] let connections = editor.getNodeFromId(input_selection_layer_id).data.Connections - for (let i = 0; i < new_input_order.length; i++) { + for (let input of new_input_order) { for (let connection of connections) { - if (new_input_order[i] == connection.split(";")[0]) { + if (input == connection.split(";")[0]) { newConnections.push(connection) } }