diff --git a/platform/commonUI/browse/res/templates/back-arrow.html b/platform/commonUI/browse/res/templates/back-arrow.html index c73b4cbdb2..3ed0ec061b 100644 --- a/platform/commonUI/browse/res/templates/back-arrow.html +++ b/platform/commonUI/browse/res/templates/back-arrow.html @@ -23,6 +23,6 @@ { + ng-class="checkRoot(); atRoot ? 'hidden' : ''" + ng-click='backArrow()'>{ diff --git a/platform/commonUI/browse/src/BrowseController.js b/platform/commonUI/browse/src/BrowseController.js index d1f89d43fb..4e97ee6f87 100644 --- a/platform/commonUI/browse/src/BrowseController.js +++ b/platform/commonUI/browse/src/BrowseController.js @@ -134,28 +134,70 @@ define( // is not the root, then user is navigated to // parent function navigateToParent() { - var parent = navigationService.getNavigation().getCapability('context').getParent(), - grandparent; - if (parent.getId() !== ROOT_ID) { - grandparent = parent.getCapability('context').getParent().getId(); - navigateTo(parent); - if (grandparent && grandparent !== ROOT_ID) { - $scope.atRoot = false; - } else { + var context = navigationService.getNavigation().getCapability('context'), + parentContext, + parent, + grandparentId; + + // Checks if the current object has a context + if (context) { + + // Sets the parent and the parent context + // which is checked + parent = context.getParent(); + parentContext = parent.getCapability('context'); + + if ((parent.getId() !== ROOT_ID) && parentContext) { + // Gets the grandparent id + grandparentId = parentContext.getParent().getId(); + + // Navigates to the parent + navigateTo(parent); + + // Checks after navigation if the user is located at the + // root (grandparent of original selected object, after + // navigation, user is at parent of original object and + // child of grandparent) + if (grandparentId && grandparentId !== ROOT_ID) { + $scope.atRoot = false; + return; + } + + // Set at root if no grandparent exists and + // if grandparent is ROOT, after navigation $scope.atRoot = true; } - } else { - $scope.atRoot = true; } } function checkRoot() { - var parent = navigationService.getNavigation().getCapability('context').getParent(); - if (parent.getId() !== ROOT_ID) { - $scope.atRoot = false; - } else { - $scope.atRoot = true; + var context = navigationService.getNavigation().getCapability('context'), + parentContext, + parent, + grandparent; + + // Checks if the current object has a context + if (context) { + parent = context.getParent(); + parentContext = parent.getCapability('context'); + if ((parent.getId() !== ROOT_ID) && parentContext) { + grandparent = parentContext.getParent(); + + // Checks if the grandparent exists + // if it does not exist (for example in search), + // than do not show the back button + if (grandparent) { + $scope.atRoot = false; + return; + } + } } + + // In any other situation where the context or parent + // context does not exist or the user is at ROOT, than + // hide the back arrow + $scope.atRoot = true; + } // Load the root object, put it in the scope. diff --git a/platform/commonUI/browse/test/BrowseControllerSpec.js b/platform/commonUI/browse/test/BrowseControllerSpec.js index 136b44cd30..e5e54e32d6 100644 --- a/platform/commonUI/browse/test/BrowseControllerSpec.js +++ b/platform/commonUI/browse/test/BrowseControllerSpec.js @@ -304,6 +304,19 @@ define( ); mockScope.checkRoot(); + + mockDomainObject.getCapability.andReturn(undefined); + mockNavigationService.getNavigation.andReturn(mockDomainObject); + + controller = new BrowseController( + mockScope, + mockRoute, + mockLocation, + mockObjectService, + mockNavigationService + ); + + mockScope.checkRoot(); }); // Mocks the back arrow call that diff --git a/platform/commonUI/general/res/templates/tree-node.html b/platform/commonUI/general/res/templates/tree-node.html index 1d5559e668..cd77d001a2 100644 --- a/platform/commonUI/general/res/templates/tree-node.html +++ b/platform/commonUI/general/res/templates/tree-node.html @@ -29,8 +29,9 @@ key="'label'" mct-object="domainObject" ng-model="ngModel" - ng-click="!treeNode.checkMobile() || model.composition == undefined ? - ngModel.selectedObject = domainObject : toggle.toggle(); treeNode.trackExpansion()" + ng-click="!treeNode.checkMobile() || model.composition == undefined || + model.composition.length == 0 ? treeNode.setObject(ngModel, domainObject) : toggle.toggle(); + treeNode.trackExpansion()" >