Skip to content

Commit

Permalink
[MMGIS] Modify Independent time contexts, open in new tab action, and…
Browse files Browse the repository at this point in the history
… expose overlay plots to support MMGIS pivoting (#6025)

* Expose overlay plot so that it can be imported by an external plugin

* If the current object has an independentContext, ignore any upstream independentContext

* Accept any custom url param in open in new tab action
  • Loading branch information
khalidadil authored Dec 2, 2022
1 parent a168ce2 commit 19892aa
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/api/time/IndependentTimeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,13 @@ class IndependentTimeContext extends TimeContext {
}

getUpstreamContext() {
let timeContext = this.globalTimeContext;
const objectKey = this.openmct.objects.makeKeyString(this.objectPath[this.objectPath.length - 1].identifier);
const doesObjectHaveTimeContext = this.globalTimeContext.independentContexts.get(objectKey);
if (doesObjectHaveTimeContext) {
return undefined;
}

let timeContext = this.globalTimeContext;
this.objectPath.some((item, index) => {
const key = this.openmct.objects.makeKeyString(item.identifier);
//last index is the view object itself
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/openInNewTabAction/openInNewTabAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default class OpenInNewTab {

this._openmct = openmct;
}
invoke(objectPath) {
let url = objectPathToUrl(this._openmct, objectPath);
invoke(objectPath, urlParams = undefined) {
let url = objectPathToUrl(this._openmct, objectPath, urlParams);
window.open(url);
}
}
2 changes: 0 additions & 2 deletions src/plugins/plot/MctPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,8 @@ export default {
},
setTimeContext() {
this.stopFollowingTimeContext();
this.timeContext = this.openmct.time.getContextForView(this.path);
this.followTimeContext();
},
followTimeContext() {
this.updateDisplayBounds(this.timeContext.bounds());
Expand Down
26 changes: 22 additions & 4 deletions src/tools/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,27 @@
* Module defining url handling.
*/

export function paramsToArray(openmct) {
// parse urlParams from an object to an array.
function getUrlParams(openmct, customUrlParams = {}) {
let urlParams = openmct.router.getParams();
Object.entries(customUrlParams).forEach((urlParam) => {
const [key, value] = urlParam;
urlParams[key] = value;
});

if (urlParams['tc.mode'] === 'fixed') {
delete urlParams['tc.startDelta'];
delete urlParams['tc.endDelta'];
} else if (urlParams['tc.mode'] === 'local') {
delete urlParams['tc.startBound'];
delete urlParams['tc.endBound'];
}

return urlParams;
}

export function paramsToArray(openmct, customUrlParams = {}) {
// parse urlParams from an object to an array.
let urlParams = getUrlParams(openmct, customUrlParams);
let newTabParams = [];
for (let key in urlParams) {
if ({}.hasOwnProperty.call(urlParams, key)) {
Expand All @@ -42,9 +60,9 @@ export function identifierToString(openmct, objectPath) {
return '#/browse/' + openmct.objects.getRelativePath(objectPath);
}

export default function objectPathToUrl(openmct, objectPath) {
export default function objectPathToUrl(openmct, objectPath, customUrlParams = {}) {
let url = identifierToString(openmct, objectPath);
let urlParams = paramsToArray(openmct);
let urlParams = paramsToArray(openmct, customUrlParams);
if (urlParams.length) {
url += '?' + urlParams.join('&');
}
Expand Down
9 changes: 9 additions & 0 deletions src/tools/urlSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,14 @@ describe('the url tool', function () {
const constructedURL = objectPathToUrl(openmct, mockObjectPath);
expect(constructedURL).toContain('#/browse/mock-parent-folder/mock-folder');
});
it('can take params to set a custom url', () => {
const customParams = {
'tc.startBound': 1669911059,
'tc.endBound': 1669911082,
'tc.mode': 'fixed'
};
const constructedURL = objectPathToUrl(openmct, mockObjectPath, customParams);
expect(constructedURL).toContain('tc.startBound=1669911059&tc.endBound=1669911082&tc.mode=fixed');
});
});
});
4 changes: 3 additions & 1 deletion src/ui/components/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

import ObjectView from './ObjectView.vue';
import StackedPlot from '../../plugins/plot/stackedPlot/StackedPlot.vue';
import Plot from '../../plugins/plot/Plot.vue';

export default {
ObjectView,
StackedPlot
StackedPlot,
Plot
};

0 comments on commit 19892aa

Please # to comment.