From a52ee84aede53ff2cb5a3e667e4ef03df1fd3acb Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 19 Sep 2018 12:10:24 +0200 Subject: [PATCH] Drop invalid connections if type_source is unavailable --- .../mvc/workflow/workflow-connector.js | 7 +++++- .../mvc/workflow/workflow-terminals.js | 23 ++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/client/galaxy/scripts/mvc/workflow/workflow-connector.js b/client/galaxy/scripts/mvc/workflow/workflow-connector.js index 21c9e92da6c..8ae6ed9cddb 100644 --- a/client/galaxy/scripts/mvc/workflow/workflow-connector.js +++ b/client/galaxy/scripts/mvc/workflow/workflow-connector.js @@ -1,3 +1,5 @@ +import * as Toastr from "libs/toastr"; + function Connector(handle1, handle2) { this.canvas = null; this.dragging = false; @@ -30,8 +32,11 @@ $.extend(Connector.prototype, { } $(this.canvas).remove(); }, - destroyIfInvalid: function() { + destroyIfInvalid: function(warn) { if (this.handle1 && this.handle2 && !this.handle2.attachable(this.handle1)) { + if (warn) { + Toastr.warning("Destroying a connection because collection type has changed."); + } this.destroy(); } }, diff --git a/client/galaxy/scripts/mvc/workflow/workflow-terminals.js b/client/galaxy/scripts/mvc/workflow/workflow-terminals.js index 8bce14bafd6..f7504f728a3 100644 --- a/client/galaxy/scripts/mvc/workflow/workflow-terminals.js +++ b/client/galaxy/scripts/mvc/workflow/workflow-terminals.js @@ -1,6 +1,5 @@ // TODO; tie into Galaxy state? window.workflow_globals = window.workflow_globals || {}; -import * as Toastr from "libs/toastr"; function CollectionTypeDescription(collectionType) { this.collectionType = collectionType; @@ -131,7 +130,9 @@ var Terminal = Backbone.Model.extend({ if (this.node) { this.node.markChanged(); this.resetMappingIfNeeded(); - this.resetCollectionTypeSource(); + if (!connector.dragging) { + this.resetCollectionTypeSource(); + } } }, redraw: function() { @@ -181,9 +182,8 @@ var Terminal = Backbone.Model.extend({ let node = this.node; _.each(node.output_terminals, function(output_terminal) { let type_source = output_terminal.attributes.collection_type_source; - if (type_source) { + if (type_source && output_terminal.attributes.collection_type) { output_terminal.attributes.collection_type = null; - output_terminal.collectionType = ANY_COLLECTION_TYPE_DESCRIPTION; output_terminal.update(output_terminal.attributes); } }); @@ -454,7 +454,7 @@ var InputCollectionTerminal = BaseInputTerminal.extend({ } else { let node = this.node; _.each(node.output_terminals, function(output_terminal) { - if (output_terminal.attributes.collection_type_source) { + if (output_terminal.attributes.collection_type_source && !connector.dragging) { output_terminal.attributes.collection_type = other.attributes.collection_type; output_terminal.update(output_terminal.attributes); } @@ -544,14 +544,15 @@ var OutputCollectionTerminal = Terminal.extend({ newCollectionType = ANY_COLLECTION_TYPE_DESCRIPTION; } - if (newCollectionType.collectionType != this.collectionType.collectionType) { - _.each(this.connectors, connector => { - // TODO: consider checking if connection valid before removing... - Toastr.warning("Destroying a connection because collection type has changed."); - connector.destroy(); + let oldCollectionType = this.collectionType; + this.collectionType = newCollectionType; + // we need to iterate over a copy, as we slice this.connectors in the process of destroying connections + var connectors = this.connectors.slice(0); + if (newCollectionType.collectionType != oldCollectionType.collectionType) { + _.each(connectors, connector => { + connector.destroyIfInvalid(true); }); } - this.collectionType = newCollectionType; } });