From 1d2ed0398c88d9392dd28ed64ee6d40be29d0219 Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Fri, 29 Mar 2019 14:36:15 -0700 Subject: [PATCH] Default routing (#2342) * Working version of default navigation to last child * Implemented as separate route to clean up code a bit --- src/MCT.js | 2 +- src/ui/router/Browse.js | 59 ++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/MCT.js b/src/MCT.js index 40e13fdf89..cdf93e46e4 100644 --- a/src/MCT.js +++ b/src/MCT.js @@ -356,7 +356,7 @@ define([ legacyRegistry.enable('adapter'); this.router.route(/^\/$/, () => { - this.router.setPath('/browse/mine'); + this.router.setPath('/browse/'); }); /** diff --git a/src/ui/router/Browse.js b/src/ui/router/Browse.js index 83162d8d85..22a74ff679 100644 --- a/src/ui/router/Browse.js +++ b/src/ui/router/Browse.js @@ -9,11 +9,27 @@ define([ let browseObject; let unobserve = undefined; + openmct.router.route(/^\/browse\/?$/, navigateToFirstChildOfRoot); + + openmct.router.route(/^\/browse\/(.*)$/, (path, results, params) => { + let navigatePath = results[1]; + navigateToPath(navigatePath, params.view); + }); + + openmct.router.on('change:params', function (newParams, oldParams, changed) { + if (changed.view && browseObject) { + let provider = openmct + .objectViews + .getByProviderKey(changed.view); + viewObject(browseObject, provider); + } + }); + function viewObject(object, viewProvider) { openmct.layout.$refs.browseObject.show(object, viewProvider.key, true); openmct.layout.$refs.browseBar.domainObject = object; openmct.layout.$refs.browseBar.viewKey = viewProvider.key; - }; + } function navigateToPath(path, currentViewKey) { navigateCall++; @@ -24,13 +40,12 @@ define([ unobserve = undefined; } + //Split path into object identifiers if (!Array.isArray(path)) { path = path.split('/'); } - return Promise.all(path.map((keyString)=>{ - return openmct.objects.get(keyString); - })).then((objects)=>{ + return pathToObjects(path).then((objects)=>{ if (currentNavigation !== navigateCall) { return; // Prevent race. } @@ -79,23 +94,25 @@ define([ }); } - openmct.router.route(/^\/browse\/(.*)$/, (path, results, params) => { - let navigatePath = results[1]; - if (!navigatePath) { - navigatePath = 'mine'; - } - navigateToPath(navigatePath, params.view); - }); - - openmct.router.on('change:params', function (newParams, oldParams, changed) { - if (changed.view && browseObject) { - let provider = openmct - .objectViews - .getByProviderKey(changed.view); - viewObject(browseObject, provider); - } - }); + function pathToObjects(path) { + return Promise.all(path.map((keyString)=>{ + return openmct.objects.get(keyString); + })); + } + function navigateToFirstChildOfRoot() { + openmct.objects.get('ROOT').then(rootObject => { + openmct.composition.get(rootObject).load() + .then(children => { + let lastChild = children[children.length - 1]; + if (!lastChild) { + console.error('Unable to navigate to anything. No root objects found.'); + } else { + let lastChildId = openmct.objects.makeKeyString(lastChild.identifier); + openmct.router.setPath(`#/browse/${lastChildId}`); + } + }); + }); + } } - });