From eaa95144535ee29650989d1a8dfbdea30ce1c567 Mon Sep 17 00:00:00 2001 From: "Aayush Arora (angularboy)" Date: Sat, 30 Jun 2018 00:27:45 +0530 Subject: [PATCH] Object has no children fix (#2038) * Added files for PR 1904 * Added new lines * space fix * Implemented changes * Space fix * checkstyle fix Fixes #1826 --- platform/commonUI/general/bundle.js | 2 +- .../src/controllers/TreeNodeController.js | 10 +++++----- .../commonUI/general/src/directives/MCTTree.js | 5 +++-- .../commonUI/general/src/ui/TreeNodeView.js | 18 ++++++++++-------- platform/commonUI/general/src/ui/TreeView.js | 8 +++++--- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/platform/commonUI/general/bundle.js b/platform/commonUI/general/bundle.js index bfd1533a0e..585bdee090 100644 --- a/platform/commonUI/general/bundle.js +++ b/platform/commonUI/general/bundle.js @@ -401,7 +401,7 @@ define([ { "key": "mctTree", "implementation": MCTTree, - "depends": ['gestureService'] + "depends": ['gestureService', 'openmct'] }, { "key": "mctPreview", diff --git a/platform/commonUI/general/src/controllers/TreeNodeController.js b/platform/commonUI/general/src/controllers/TreeNodeController.js index 92ca09d938..b9b9487664 100644 --- a/platform/commonUI/general/src/controllers/TreeNodeController.js +++ b/platform/commonUI/general/src/controllers/TreeNodeController.js @@ -79,8 +79,8 @@ define( // a recursive step for subsequent ids in the paths, // until we exceed path length or hit a mismatch. return (index >= nodePath.length) || - ((navPath[index] === nodePath[index]) && - checkPath(nodePath, navPath, index + 1)); + ((navPath[index] === nodePath[index]) && + checkPath(nodePath, navPath, index + 1)); } // Consider the currently-navigated object and update @@ -89,9 +89,9 @@ define( var nodeObject = $scope.domainObject, navObject = selectedObject, nodeContext = nodeObject && - nodeObject.getCapability('context'), + nodeObject.getCapability('context'), navContext = navObject && - navObject.getCapability('context'), + navObject.getCapability('context'), nodePath, navPath; @@ -110,7 +110,7 @@ define( // within the navigation path; otherwise, navigation // has happened in some other subtree. if (navPath.length >= nodePath.length && - checkPath(nodePath, navPath)) { + checkPath(nodePath, navPath)) { // nodePath is along the navPath; if it's // at the end of the path, highlight; diff --git a/platform/commonUI/general/src/directives/MCTTree.js b/platform/commonUI/general/src/directives/MCTTree.js index 62ca79a016..ef0a615fcb 100644 --- a/platform/commonUI/general/src/directives/MCTTree.js +++ b/platform/commonUI/general/src/directives/MCTTree.js @@ -24,7 +24,7 @@ define([ 'angular', '../ui/TreeView' ], function (angular, TreeView) { - function MCTTree(gestureService) { + function MCTTree(gestureService, openmct) { function link(scope, element) { if (!scope.allowSelection) { scope.allowSelection = function () { @@ -34,8 +34,9 @@ define([ if (!scope.onSelection) { scope.onSelection = function () {}; } + var currentSelection = scope.selectedObject; - var treeView = new TreeView(gestureService); + var treeView = new TreeView(gestureService, openmct); function setSelection(domainObject, event) { if (currentSelection === domainObject) { diff --git a/platform/commonUI/general/src/ui/TreeNodeView.js b/platform/commonUI/general/src/ui/TreeNodeView.js index 48d71f503e..944f4b9c6c 100644 --- a/platform/commonUI/general/src/ui/TreeNodeView.js +++ b/platform/commonUI/general/src/ui/TreeNodeView.js @@ -27,9 +27,9 @@ define([ './TreeLabelView' ], function ($, nodeTemplate, ToggleView, TreeLabelView) { - function TreeNodeView(gestureService, subtreeFactory, selectFn) { + function TreeNodeView(gestureService, subtreeFactory, selectFn, openmct) { this.li = $('
  • '); - + this.openmct = openmct; this.statusClasses = []; this.toggleView = new ToggleView(false); @@ -81,11 +81,14 @@ define([ } this.activeObject = domainObject; - - if (domainObject && domainObject.hasCapability('composition')) { - $(this.toggleView.elements()).removeClass('no-children'); - } else { - $(this.toggleView.elements()).addClass('no-children'); + if (domainObject && domainObject.hasCapability('adapter')) { + var obj = domainObject.useCapability('adapter'); + var hasComposition = this.openmct.composition.get(obj) !== undefined; + if (hasComposition) { + $(this.toggleView.elements()).removeClass('no-children'); + } else { + $(this.toggleView.elements()).addClass('no-children'); + } } if (domainObject && domainObject.hasCapability('status')) { @@ -150,6 +153,5 @@ define([ return this.li; }; - return TreeNodeView; }); diff --git a/platform/commonUI/general/src/ui/TreeView.js b/platform/commonUI/general/src/ui/TreeView.js index c99629f1b9..8ee922c287 100644 --- a/platform/commonUI/general/src/ui/TreeView.js +++ b/platform/commonUI/general/src/ui/TreeView.js @@ -26,17 +26,18 @@ define([ 'text!../../res/templates/tree/wait-node.html' ], function ($, TreeNodeView, spinnerTemplate) { - function TreeView(gestureService, selectFn) { + function TreeView(gestureService, openmct, selectFn) { this.ul = $(''); this.nodeViews = []; this.callbacks = []; this.selectFn = selectFn || this.value.bind(this); this.gestureService = gestureService; this.pending = false; + this.openmct = openmct; } TreeView.prototype.newTreeView = function () { - return new TreeView(this.gestureService, this.selectFn); + return new TreeView(this.gestureService, this.openmct, this.selectFn); }; TreeView.prototype.setSize = function (sz) { @@ -46,7 +47,8 @@ define([ nodeView = new TreeNodeView( this.gestureService, this.newTreeView.bind(this), - this.selectFn + this.selectFn, + this.openmct ); this.nodeViews.push(nodeView); this.ul.append($(nodeView.elements()));