Repository: nifi
Updated Branches:
  refs/heads/master e1742c5a0 -> 043591118


NIFI-1198: - Updating the connection source and destination when appropriate 
(deletion and (re)connection).

Signed-off-by: joewitt <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/04359111
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/04359111
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/04359111

Branch: refs/heads/master
Commit: 04359111869a252039bfce42eccbada8e83a8594
Parents: e1742c5
Author: Matt Gilman <[email protected]>
Authored: Tue Nov 24 14:23:18 2015 -0500
Committer: joewitt <[email protected]>
Committed: Wed Nov 25 14:50:56 2015 -0500

----------------------------------------------------------------------
 .../src/main/webapp/js/nf/canvas/nf-actions.js  | 70 +++-----------------
 .../main/webapp/js/nf/canvas/nf-canvas-utils.js | 38 +++++++++++
 .../js/nf/canvas/nf-connection-configuration.js | 37 ++---------
 .../main/webapp/js/nf/canvas/nf-connection.js   | 20 +++++-
 4 files changed, 69 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/04359111/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-actions.js
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-actions.js
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-actions.js
index e1ed3fe..df1784f 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-actions.js
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-actions.js
@@ -768,34 +768,8 @@ nf.Actions = (function () {
                         // remove the component/connection in question
                         
nf[selectionData.type].remove(selectionData.component.id);
 
-                        // if the source processor is part of the response, we
-                        // have just removed a relationship. must update the 
status
-                        // of the source processor in case its validity has 
changed
-                        if (nf.CanvasUtils.isConnection(selection)) {
-                            var sourceComponentId = 
nf.CanvasUtils.getConnectionSourceComponentId(selectionData.component);
-                            var source = d3.select('#id-' + sourceComponentId);
-                            var sourceData = source.datum();
-
-                            // update the source status if necessary
-                            if (nf.CanvasUtils.isProcessor(source)) {
-                                nf.Processor.reload(sourceData.component);
-                            } else if (nf.CanvasUtils.isInputPort(source)) {
-                                nf.Port.reload(sourceData.component);
-                            } else if 
(nf.CanvasUtils.isRemoteProcessGroup(source)) {
-                                
nf.RemoteProcessGroup.reload(sourceData.component);
-                            }
-
-                            var destinationComponentId = 
nf.CanvasUtils.getConnectionDestinationComponentId(selectionData.component);
-                            var destination = d3.select('#id-' + 
destinationComponentId);
-                            var destinationData = destination.datum();
-
-                            // update the destination component accordingly
-                            if (nf.CanvasUtils.isProcessor(destination)) {
-                                nf.Processor.reload(destinationData.component);
-                            } else if 
(nf.CanvasUtils.isRemoteProcessGroup(destination)) {
-                                
nf.RemoteProcessGroup.reload(destinationData.component);
-                            }
-                        } else {
+                        // if the selection is a connection, reload the source 
and destination accordingly
+                        if (nf.CanvasUtils.isConnection(selection) === false) {
                             var connections = 
nf.Connection.getComponentConnections(selectionData.component.id);
                             if (connections.length > 0) {
                                 var ids = [];
@@ -846,40 +820,16 @@ nf.Actions = (function () {
                                 }
                             });
 
-                            // refresh all component types as necessary 
(handle components that have been removed)
+                            // remove all the non connections in the snippet 
first
                             components.forEach(function (type, ids) {
-                                nf[type].remove(ids);
+                                if (type !== 'Connection') {
+                                    nf[type].remove(ids);
+                                }
                             });
-
-                            // if some connections were removed
-                            if (snippet.connections > 0) {
-                                selection.filter(function (d) {
-                                    return d.type === 'Connection';
-                                }).each(function (d) {
-                                    // add the source to refresh if its not 
already going to be refreshed
-                                    var sourceComponentId = 
nf.CanvasUtils.getConnectionSourceComponentId(d.component);
-                                    var source = d3.select('#id-' + 
sourceComponentId);
-                                    var sourceData = source.datum();
-
-                                    // update the source status if necessary - 
if the source was already removed
-                                    // as part of this operation the reloading 
has no affect
-                                    if (nf.CanvasUtils.isProcessor(source)) {
-                                        
nf.Processor.reload(sourceData.component);
-                                    } else if 
(nf.CanvasUtils.isInputPort(source)) {
-                                        nf.Port.reload(sourceData.component);
-                                    } else if 
(nf.CanvasUtils.isRemoteProcessGroup(source)) {
-                                        
nf.RemoteProcessGroup.reload(sourceData.component);
-                                    }
-
-                                    // add the destination to refresh if its 
not already going to be refreshed
-                                    var destinationComponentId = 
nf.CanvasUtils.getConnectionDestinationComponentId(d.component);
-                                    var destination = d3.select('#id-' + 
destinationComponentId);
-                                    var destinationData = destination.datum();
-
-                                    if 
(nf.CanvasUtils.isRemoteProcessGroup(destination)) {
-                                        
nf.RemoteProcessGroup.reload(destinationData.component);
-                                    }
-                                });
+                            
+                            // then remove all the connections
+                            if (components.has('Connection')) {
+                                
nf.Connection.remove(components.get('Connection'));
                             }
 
                             // refresh the birdseye/toolbar

http://git-wip-us.apache.org/repos/asf/nifi/blob/04359111/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-utils.js
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-utils.js
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-utils.js
index 1be551f..e2cc46e 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-utils.js
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-canvas-utils.js
@@ -956,6 +956,44 @@ nf.CanvasUtils = (function () {
         },
         
         /**
+         * Reloads a connection's source and destination.
+         * 
+         * @param {string} sourceComponentId          The connection source id
+         * @param {string} destinationComponentId     The connection 
destination id
+         */
+        reloadConnectionSourceAndDestination: function (sourceComponentId, 
destinationComponentId) {
+            if (nf.Common.isBlank(sourceComponentId) === false) {
+                var source = d3.select('#id-' + sourceComponentId);
+                if (source.empty() === false) {
+                    var sourceData = source.datum();
+
+                    // update the source status if necessary
+                    if (nf.CanvasUtils.isProcessor(source)) {
+                        nf.Processor.reload(sourceData.component);
+                    } else if (nf.CanvasUtils.isInputPort(source)) {
+                        nf.Port.reload(sourceData.component);
+                    } else if (nf.CanvasUtils.isRemoteProcessGroup(source)) {
+                        nf.RemoteProcessGroup.reload(sourceData.component);
+                    }
+                }
+            }
+
+            if (nf.Common.isBlank(destinationComponentId) === false) {
+                var destination = d3.select('#id-' + destinationComponentId);
+                if (destination.empty() === false) {
+                    var destinationData = destination.datum();
+
+                    // update the destination component accordingly
+                    if (nf.CanvasUtils.isProcessor(destination)) {
+                        nf.Processor.reload(destinationData.component);
+                    } else if 
(nf.CanvasUtils.isRemoteProcessGroup(destination)) {
+                        
nf.RemoteProcessGroup.reload(destinationData.component);
+                    }
+                }
+            }
+        },
+        
+        /**
          * Returns the component id of the source of this processor. If the 
connection is attached
          * to a port in a [sub|remote] group, the component id will be that of 
the group. Otherwise
          * it is the component itself.

http://git-wip-us.apache.org/repos/asf/nifi/blob/04359111/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection-configuration.js
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection-configuration.js
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection-configuration.js
index 1bafa7d..9f83fae 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection-configuration.js
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection-configuration.js
@@ -860,21 +860,8 @@ nf.ConnectionConfiguration = (function () {
                     'connections': [response.connection]
                 }, true);
 
-                // update the source component accordingly
-                if (nf.CanvasUtils.isProcessor(source)) {
-                    nf.Processor.reload(sourceData.component);
-                } else if (nf.CanvasUtils.isInputPort(source)) {
-                    nf.Port.reload(sourceData.component);
-                } else if (nf.CanvasUtils.isRemoteProcessGroup(source)) {
-                    nf.RemoteProcessGroup.reload(sourceData.component);
-                }
-
-                // update the destination component accordingly
-                if (nf.CanvasUtils.isProcessor(destination)) {
-                    nf.Processor.reload(destinationData.component);
-                } else if (nf.CanvasUtils.isRemoteProcessGroup(destination)) {
-                    nf.RemoteProcessGroup.reload(destinationData.component);
-                }
+                // reload the connections source/destination components
+                
nf.CanvasUtils.reloadConnectionSourceAndDestination(sourceComponentId, 
destinationComponentId);
 
                 // update component visibility
                 nf.Canvas.View.updateVisibility();
@@ -899,13 +886,10 @@ nf.ConnectionConfiguration = (function () {
 
         // get the source details
         var sourceComponentId = $('#connection-source-component-id').val();
-        var source = d3.select('#id-' + sourceComponentId);
-        var sourceData = source.datum();
 
         // get the destination details
         var destinationComponentId = 
$('#connection-destination-component-id').val();
         var destination = d3.select('#id-' + destinationComponentId);
-        var destinationData = destination.datum();
         var destinationType = 
nf.CanvasUtils.getConnectableTypeForDestination(destination);
 
         // get the destination details
@@ -950,21 +934,8 @@ nf.ConnectionConfiguration = (function () {
                     // update this connection
                     nf.Connection.set(connection);
 
-                    // update the source component accordingly
-                    if (nf.CanvasUtils.isProcessor(source)) {
-                        nf.Processor.reload(sourceData.component);
-                    } else if (nf.CanvasUtils.isInputPort(source)) {
-                        nf.Port.reload(sourceData.component);
-                    } else if (nf.CanvasUtils.isRemoteProcessGroup(source)) {
-                        nf.RemoteProcessGroup.reload(sourceData.component);
-                    }
-
-                    // update the destination component accordingly
-                    if (nf.CanvasUtils.isProcessor(destination)) {
-                        nf.Processor.reload(destinationData.component);
-                    } else if 
(nf.CanvasUtils.isRemoteProcessGroup(destination)) {
-                        
nf.RemoteProcessGroup.reload(destinationData.component);
-                    }
+                    // reload the connections source/destination components
+                    
nf.CanvasUtils.reloadConnectionSourceAndDestination(sourceComponentId, 
destinationComponentId);
                 }
             }).fail(function (xhr, status, error) {
                 if (xhr.status === 400 || xhr.status === 404 || xhr.status === 
409) {

http://git-wip-us.apache.org/repos/asf/nifi/blob/04359111/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection.js
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection.js
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection.js
index c8a96c0..ec0ed4f 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection.js
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-connection.js
@@ -1033,6 +1033,12 @@ nf.Connection = (function () {
 
     // removes the specified connections
     var removeConnections = function (removed) {
+        // consider reloading source/destination of connection being removed
+        removed.each(function (d) {
+            
nf.CanvasUtils.reloadConnectionSourceAndDestination(d.component.source.id, 
d.component.destination.id);
+        });
+        
+        // remove the connection
         removed.remove();
     };
 
@@ -1142,6 +1148,7 @@ nf.Connection = (function () {
                         // get the corresponding connection
                         var connection = d3.select(this.parentNode);
                         var connectionData = connection.datum();
+                        var previousDestinationId = 
connectionData.component.destination.id;
 
                         // attempt to select a new destination
                         var destination = 
d3.select('g.connectable-destination');
@@ -1153,7 +1160,10 @@ nf.Connection = (function () {
                             // prompt for the new port if appropriate
                             if (nf.CanvasUtils.isProcessGroup(destination) || 
nf.CanvasUtils.isRemoteProcessGroup(destination)) {
                                 // user will select new port and updated 
connect details will be set accordingly
-                                
nf.ConnectionConfiguration.showConfiguration(connection, 
destination).fail(function () {
+                                
nf.ConnectionConfiguration.showConfiguration(connection, 
destination).done(function () {
+                                    // reload the previous destination
+                                    
nf.CanvasUtils.reloadConnectionSourceAndDestination(null, 
previousDestinationId);
+                                }).fail(function () {
                                     // reset the connection
                                     connection.call(updateConnections, true, 
false);
                                 });
@@ -1192,13 +1202,17 @@ nf.Connection = (function () {
                                     data: updatedConnectionData,
                                     dataType: 'json'
                                 }).done(function (response) {
-                                    var connectionData = response.connection;
+                                    var updatedConnectionData = 
response.connection;
 
                                     // update the revision
                                     nf.Client.setRevision(response.revision);
 
                                     // refresh to update the label
-                                    nf.Connection.set(connectionData);
+                                    nf.Connection.set(updatedConnectionData);
+                                    
+                                    // reload the previous destination and the 
new source/destination
+                                    
nf.CanvasUtils.reloadConnectionSourceAndDestination(null, 
previousDestinationId);
+                                    
nf.CanvasUtils.reloadConnectionSourceAndDestination(updatedConnectionData.source.id,
 updatedConnectionData.destination.id);
                                 }).fail(function (xhr, status, error) {
                                     if (xhr.status === 400 || xhr.status === 
404 || xhr.status === 409) {
                                         nf.Dialog.showOkDialog({

Reply via email to