From f02f1d47f1fcffbc482f4c0ab48556770e55d47e Mon Sep 17 00:00:00 2001 From: Pete Richards <peter.l.richards@nasa.gov> Date: Thu, 27 Apr 2017 14:10:28 -0700 Subject: [PATCH] [Browse] Handle missing path and nav to root When no path is specified, don't throw error. Navigate to default, as expected. When navigating to root, navigate to the last child of root instead. This handles cases where DEFAULT_PATH is not found (e.g. deployments without "mine"). --- .../commonUI/browse/src/BrowseController.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/platform/commonUI/browse/src/BrowseController.js b/platform/commonUI/browse/src/BrowseController.js index 9442ba9fca..b89ed1c14a 100644 --- a/platform/commonUI/browse/src/BrowseController.js +++ b/platform/commonUI/browse/src/BrowseController.js @@ -113,11 +113,22 @@ define( $location.path('/browse/' + currentIds); } + function getLastChildIfRoot(object) { + if (object.getId() !== 'ROOT') { + return object; + } + return object.useCapability('composition') + .then(function (composees) { + return composees[composees.length - 1]; + }); + } + function navigateToPath(path) { return getObject('ROOT') .then(function (root) { return findViaComposition(root, path); }) + .then(getLastChildIfRoot) .then(function (object) { navigationService.setNavigation(object); }); @@ -147,10 +158,14 @@ define( // navigate to the path ourselves, which results in it being // properly set. $scope.$on('$routeChangeStart', function (event, route) { - if (route.$$route === $route.current.$$route && - route.pathParams.ids !== $route.current.pathParams.ids) { - event.preventDefault(); - navigateToPath(route.pathParams.ids.split('/')); + if (route.$$route === $route.current.$$route) { + if (route.pathParams.ids && + route.pathParams.ids !== $route.current.pathParams.ids) { + event.preventDefault(); + navigateToPath(route.pathParams.ids.split('/')); + } else { + navigateToPath([]); + } } });