mirror of
https://github.com/nasa/openmct.git
synced 2025-05-31 14:40:48 +00:00
Default routing (#2342)
* Working version of default navigation to last child * Implemented as separate route to clean up code a bit
This commit is contained in:
parent
5a00e0c549
commit
1d2ed0398c
@ -356,7 +356,7 @@ define([
|
|||||||
legacyRegistry.enable('adapter');
|
legacyRegistry.enable('adapter');
|
||||||
|
|
||||||
this.router.route(/^\/$/, () => {
|
this.router.route(/^\/$/, () => {
|
||||||
this.router.setPath('/browse/mine');
|
this.router.setPath('/browse/');
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,11 +9,27 @@ define([
|
|||||||
let browseObject;
|
let browseObject;
|
||||||
let unobserve = undefined;
|
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) {
|
function viewObject(object, viewProvider) {
|
||||||
openmct.layout.$refs.browseObject.show(object, viewProvider.key, true);
|
openmct.layout.$refs.browseObject.show(object, viewProvider.key, true);
|
||||||
openmct.layout.$refs.browseBar.domainObject = object;
|
openmct.layout.$refs.browseBar.domainObject = object;
|
||||||
openmct.layout.$refs.browseBar.viewKey = viewProvider.key;
|
openmct.layout.$refs.browseBar.viewKey = viewProvider.key;
|
||||||
};
|
}
|
||||||
|
|
||||||
function navigateToPath(path, currentViewKey) {
|
function navigateToPath(path, currentViewKey) {
|
||||||
navigateCall++;
|
navigateCall++;
|
||||||
@ -24,13 +40,12 @@ define([
|
|||||||
unobserve = undefined;
|
unobserve = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Split path into object identifiers
|
||||||
if (!Array.isArray(path)) {
|
if (!Array.isArray(path)) {
|
||||||
path = path.split('/');
|
path = path.split('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(path.map((keyString)=>{
|
return pathToObjects(path).then((objects)=>{
|
||||||
return openmct.objects.get(keyString);
|
|
||||||
})).then((objects)=>{
|
|
||||||
if (currentNavigation !== navigateCall) {
|
if (currentNavigation !== navigateCall) {
|
||||||
return; // Prevent race.
|
return; // Prevent race.
|
||||||
}
|
}
|
||||||
@ -79,23 +94,25 @@ define([
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
openmct.router.route(/^\/browse\/(.*)$/, (path, results, params) => {
|
function pathToObjects(path) {
|
||||||
let navigatePath = results[1];
|
return Promise.all(path.map((keyString)=>{
|
||||||
if (!navigatePath) {
|
return openmct.objects.get(keyString);
|
||||||
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 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}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user