Repository: incubator-brooklyn Updated Branches: refs/heads/master 7b89b6644 -> fa131b105
Prevent infinite expand-all of recursive group members. Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/5ada3e21 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/5ada3e21 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/5ada3e21 Branch: refs/heads/master Commit: 5ada3e2135bcd0f175bf5c251c4b3f35b28c32fb Parents: c9f45a3 Author: Alasdair Hodge <[email protected]> Authored: Wed Oct 7 11:35:09 2015 +0100 Committer: Alasdair Hodge <[email protected]> Committed: Wed Oct 7 14:33:57 2015 +0100 ---------------------------------------------------------------------- .../webapp/assets/js/view/application-tree.js | 29 ++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5ada3e21/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js b/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js index 1d31953..2f7a3d0 100644 --- a/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js +++ b/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js @@ -282,10 +282,11 @@ define([ return false; }, - showChildrenOf: function($treeBox, recurse) { + showChildrenOf: function($treeBox, recurse, excludedEntityIds) { + excludedEntityIds = excludedEntityIds || []; + var idToExpand = $treeBox.data('entityId'); var $wrapper = $treeBox.children('.entity_tree_node_wrapper'); var $childContainer = $treeBox.children('.node-children'); - var idToExpand = $treeBox.data('entityId'); var model = this.collection.get(idToExpand); if (model == null) { // not yet loaded; parallel thread should load @@ -311,16 +312,28 @@ define([ } }); + // Avoid infinite recursive expansion using a "taboo list" of indirect entities already expanded in this + // operation. Example: a group that contains itself or one of its own ancestors. Such cycles can only + // originate via "indirect" subordinates. + var expandIfNotExcluded = function($treebox, excludedEntityIds, defer) { + if ($treebox.hasClass('indirect')) { + var id = $treebox.data('entityId'); + if (_.contains(excludedEntityIds, id)) + return; + excludedEntityIds.push(id); + } + var doExpand = function() { that.showChildrenOf($treebox, recurse, excludedEntityIds); }; + if (defer) _.defer(doExpand); + else doExpand(); + }; + if (this.collection.includeEntities(_.union(children, members))) { // we have to load entities before we can proceed this.collection.fetch({ success: function() { if (recurse) { $childContainer.children('.tree-box').each(function () { - var $treebox = $(this); - _.defer(function() { - that.showChildrenOf($treebox, recurse); - }); + expandIfNotExcluded($(this), excludedEntityIds, true); }); } } @@ -331,8 +344,8 @@ define([ $wrapper.find('.tree-node-state').removeClass('icon-chevron-right').addClass('icon-chevron-down'); if (recurse) { $childContainer.children('.tree-box').each(function () { - that.showChildrenOf($(this), recurse); - }) + expandIfNotExcluded($(this), excludedEntityIds, false); + }); } },
