Hide vue plots from showing up in the view-switcher and in the preview window (#3725)

* Hide vue plots from showing up in the view-switcher and in the preview window.
This commit is contained in:
Shefali Joshi 2021-03-03 11:33:31 -08:00 committed by GitHub
parent b68f79f427
commit b8ded0a16e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 101 additions and 47 deletions

View File

@ -71,10 +71,10 @@ define(
openmct.editor.cancel(); openmct.editor.cancel();
} }
function isFirstViewEditable(domainObject) { function isFirstViewEditable(domainObject, objectPath) {
let firstView = openmct.objectViews.get(domainObject)[0]; let firstView = openmct.objectViews.get(domainObject, objectPath)[0];
return firstView && firstView.canEdit && firstView.canEdit(domainObject); return firstView && firstView.canEdit && firstView.canEdit(domainObject, objectPath);
} }
function navigateAndEdit(object) { function navigateAndEdit(object) {
@ -88,7 +88,7 @@ define(
window.location.href = url; window.location.href = url;
if (isFirstViewEditable(object.useCapability('adapter'))) { if (isFirstViewEditable(object.useCapability('adapter'), objectPath)) {
openmct.editor.edit(); openmct.editor.edit();
} }
} }

View File

@ -32,7 +32,7 @@ define([], function () {
if (Object.prototype.hasOwnProperty.call(view, 'provider')) { if (Object.prototype.hasOwnProperty.call(view, 'provider')) {
const domainObject = legacyObject.useCapability('adapter'); const domainObject = legacyObject.useCapability('adapter');
return view.provider.canView(domainObject); return view.provider.canView(domainObject, this.openmct.router.path);
} }
return true; return true;

View File

@ -98,7 +98,7 @@ describe("The LAD Table", () => {
}); });
it("should provide a table view only for lad table objects", () => { it("should provide a table view only for lad table objects", () => {
let applicableViews = openmct.objectViews.get(mockObj.ladTable); let applicableViews = openmct.objectViews.get(mockObj.ladTable, []);
let ladTableView = applicableViews.find( let ladTableView = applicableViews.find(
(viewProvider) => viewProvider.key === ladTableKey (viewProvider) => viewProvider.key === ladTableKey
@ -185,7 +185,7 @@ describe("The LAD Table", () => {
end: bounds.end end: bounds.end
}); });
applicableViews = openmct.objectViews.get(mockObj.ladTable); applicableViews = openmct.objectViews.get(mockObj.ladTable, []);
ladTableViewProvider = applicableViews.find((viewProvider) => viewProvider.key === ladTableKey); ladTableViewProvider = applicableViews.find((viewProvider) => viewProvider.key === ladTableKey);
ladTableView = ladTableViewProvider.view(mockObj.ladTable, [mockObj.ladTable]); ladTableView = ladTableViewProvider.view(mockObj.ladTable, [mockObj.ladTable]);
ladTableView.show(child, true); ladTableView.show(child, true);
@ -296,7 +296,7 @@ describe("The LAD Table Set", () => {
}); });
it("should provide a lad table set view only for lad table set objects", () => { it("should provide a lad table set view only for lad table set objects", () => {
let applicableViews = openmct.objectViews.get(mockObj.ladTableSet); let applicableViews = openmct.objectViews.get(mockObj.ladTableSet, []);
let ladTableSetView = applicableViews.find( let ladTableSetView = applicableViews.find(
(viewProvider) => viewProvider.key === ladTableSetKey (viewProvider) => viewProvider.key === ladTableSetKey
@ -391,7 +391,7 @@ describe("The LAD Table Set", () => {
end: bounds.end end: bounds.end
}); });
applicableViews = openmct.objectViews.get(mockObj.ladTableSet); applicableViews = openmct.objectViews.get(mockObj.ladTableSet, []);
ladTableSetViewProvider = applicableViews.find((viewProvider) => viewProvider.key === ladTableSetKey); ladTableSetViewProvider = applicableViews.find((viewProvider) => viewProvider.key === ladTableSetKey);
ladTableSetView = ladTableSetViewProvider.view(mockObj.ladTableSet, [mockObj.ladTableSet]); ladTableSetView = ladTableSetViewProvider.view(mockObj.ladTableSet, [mockObj.ladTableSet]);
ladTableSetView.show(child, true); ladTableSetView.show(child, true);

View File

@ -67,11 +67,11 @@ describe("AutoflowTabularPlugin", () => {
}); });
it("applies its view to the type from options", () => { it("applies its view to the type from options", () => {
expect(provider.canView(testObject)).toBe(true); expect(provider.canView(testObject, [])).toBe(true);
}); });
it("does not apply to other types", () => { it("does not apply to other types", () => {
expect(provider.canView({ type: 'foo' })).toBe(false); expect(provider.canView({ type: 'foo' }, [])).toBe(false);
}); });
describe("provides a view which", () => { describe("provides a view which", () => {

View File

@ -136,7 +136,7 @@ describe('the plugin', function () {
} }
}; };
const applicableViews = openmct.objectViews.get(testViewObject); const applicableViews = openmct.objectViews.get(testViewObject, []);
let conditionSetView = applicableViews.find((viewProvider) => viewProvider.key === 'conditionSet.view'); let conditionSetView = applicableViews.find((viewProvider) => viewProvider.key === 'conditionSet.view');
expect(conditionSetView).toBeDefined(); expect(conditionSetView).toBeDefined();
}); });

View File

@ -83,7 +83,7 @@ describe('the plugin', function () {
} }
}; };
const applicableViews = openmct.objectViews.get(testViewObject); const applicableViews = openmct.objectViews.get(testViewObject, []);
let displayLayoutViewProvider = applicableViews.find((viewProvider) => viewProvider.key === 'layout.view'); let displayLayoutViewProvider = applicableViews.find((viewProvider) => viewProvider.key === 'layout.view');
expect(displayLayoutViewProvider).toBeDefined(); expect(displayLayoutViewProvider).toBeDefined();
}); });

View File

@ -235,7 +235,7 @@ describe("The Imagery View Layout", () => {
}); });
it("should provide an imagery view only for imagery producing objects", () => { it("should provide an imagery view only for imagery producing objects", () => {
let applicableViews = openmct.objectViews.get(imageryObject); let applicableViews = openmct.objectViews.get(imageryObject, []);
let imageryView = applicableViews.find( let imageryView = applicableViews.find(
viewProvider => viewProvider.key === imageryKey viewProvider => viewProvider.key === imageryKey
); );
@ -265,7 +265,7 @@ describe("The Imagery View Layout", () => {
end: bounds.end + 100 end: bounds.end + 100
}); });
applicableViews = openmct.objectViews.get(imageryObject); applicableViews = openmct.objectViews.get(imageryObject, []);
imageryViewProvider = applicableViews.find(viewProvider => viewProvider.key === imageryKey); imageryViewProvider = applicableViews.find(viewProvider => viewProvider.key === imageryKey);
imageryView = imageryViewProvider.view(imageryObject); imageryView = imageryViewProvider.view(imageryObject);
imageryView.show(child); imageryView.show(child);

View File

@ -101,7 +101,7 @@ describe("Notebook plugin:", () => {
creatable: true creatable: true
}; };
const applicableViews = openmct.objectViews.get(notebookViewObject); const applicableViews = openmct.objectViews.get(notebookViewObject, []);
notebookViewProvider = applicableViews.find(viewProvider => viewProvider.key === notebookObject.key); notebookViewProvider = applicableViews.find(viewProvider => viewProvider.key === notebookObject.key);
notebookView = notebookViewProvider.view(notebookViewObject); notebookView = notebookViewProvider.view(notebookViewObject);

View File

@ -82,7 +82,7 @@ describe('the plugin', function () {
type: "plan" type: "plan"
}; };
const applicableViews = openmct.objectViews.get(testViewObject); const applicableViews = openmct.objectViews.get(testViewObject, []);
let planView = applicableViews.find((viewProvider) => viewProvider.key === 'plan.view'); let planView = applicableViews.find((viewProvider) => viewProvider.key === 'plan.view');
expect(planView).toBeDefined(); expect(planView).toBeDefined();
}); });
@ -135,7 +135,7 @@ describe('the plugin', function () {
} }
}; };
const applicableViews = openmct.objectViews.get(planDomainObject); const applicableViews = openmct.objectViews.get(planDomainObject, []);
planView = applicableViews.find((viewProvider) => viewProvider.key === 'plan.view'); planView = applicableViews.find((viewProvider) => viewProvider.key === 'plan.view');
let view = planView.view(planDomainObject, mockObjectPath); let view = planView.view(planDomainObject, mockObjectPath);
view.show(child, true); view.show(child, true);

View File

@ -32,12 +32,12 @@ export default function OverlayPlotViewProvider(openmct) {
key: 'plot-overlay', key: 'plot-overlay',
name: 'Overlay Plot', name: 'Overlay Plot',
cssClass: 'icon-telemetry', cssClass: 'icon-telemetry',
canView(domainObject) { canView(domainObject, objectPath) {
return domainObject.type === 'telemetry.plot.overlay'; return isCompactView(objectPath) && domainObject.type === 'telemetry.plot.overlay';
}, },
canEdit(domainObject) { canEdit(domainObject, objectPath) {
return domainObject.type === 'telemetry.plot.overlay'; return isCompactView(objectPath) && domainObject.type === 'telemetry.plot.overlay';
}, },
view: function (domainObject, objectPath) { view: function (domainObject, objectPath) {

View File

@ -47,8 +47,8 @@ export default function PlotViewProvider(openmct) {
key: 'plot-simple', key: 'plot-simple',
name: 'Plot', name: 'Plot',
cssClass: 'icon-telemetry', cssClass: 'icon-telemetry',
canView(domainObject) { canView(domainObject, objectPath) {
return hasTelemetry(domainObject, openmct); return isCompactView(objectPath) && hasTelemetry(domainObject, openmct);
}, },
view: function (domainObject, objectPath) { view: function (domainObject, objectPath) {

View File

@ -33,8 +33,27 @@ describe("the plugin", function () {
let openmct; let openmct;
let telemetryPromise; let telemetryPromise;
let cleanupFirst; let cleanupFirst;
let mockObjectPath;
beforeEach((done) => { beforeEach((done) => {
mockObjectPath = [
{
name: 'mock folder',
type: 'fake-folder',
identifier: {
key: 'mock-folder',
namespace: ''
}
},
{
name: 'mock parent folder',
type: 'time-strip',
identifier: {
key: 'mock-parent-folder',
namespace: ''
}
}
];
const testTelemetry = [ const testTelemetry = [
{ {
'utc': 1, 'utc': 1,
@ -134,7 +153,7 @@ describe("the plugin", function () {
} }
}; };
const applicableViews = openmct.objectViews.get(testTelemetryObject); const applicableViews = openmct.objectViews.get(testTelemetryObject, mockObjectPath);
let plotView = applicableViews.find((viewProvider) => viewProvider.key === "plot-simple"); let plotView = applicableViews.find((viewProvider) => viewProvider.key === "plot-simple");
expect(plotView).toBeDefined(); expect(plotView).toBeDefined();
}); });
@ -150,7 +169,7 @@ describe("the plugin", function () {
} }
}; };
const applicableViews = openmct.objectViews.get(testTelemetryObject); const applicableViews = openmct.objectViews.get(testTelemetryObject, mockObjectPath);
let plotView = applicableViews.find((viewProvider) => viewProvider.key === "plot-overlay"); let plotView = applicableViews.find((viewProvider) => viewProvider.key === "plot-overlay");
expect(plotView).toBeDefined(); expect(plotView).toBeDefined();
}); });
@ -166,7 +185,7 @@ describe("the plugin", function () {
} }
}; };
const applicableViews = openmct.objectViews.get(testTelemetryObject); const applicableViews = openmct.objectViews.get(testTelemetryObject, mockObjectPath);
let plotView = applicableViews.find((viewProvider) => viewProvider.key === "plot-stacked"); let plotView = applicableViews.find((viewProvider) => viewProvider.key === "plot-stacked");
expect(plotView).toBeDefined(); expect(plotView).toBeDefined();
}); });
@ -218,7 +237,7 @@ describe("the plugin", function () {
} }
}; };
applicableViews = openmct.objectViews.get(testTelemetryObject); applicableViews = openmct.objectViews.get(testTelemetryObject, mockObjectPath);
plotViewProvider = applicableViews.find((viewProvider) => viewProvider.key === "plot-simple"); plotViewProvider = applicableViews.find((viewProvider) => viewProvider.key === "plot-simple");
plotView = plotViewProvider.view(testTelemetryObject, [testTelemetryObject]); plotView = plotViewProvider.view(testTelemetryObject, [testTelemetryObject]);
plotView.show(child, true); plotView.show(child, true);

View File

@ -32,12 +32,12 @@ export default function StackedPlotViewProvider(openmct) {
key: 'plot-stacked', key: 'plot-stacked',
name: 'Stacked Plot', name: 'Stacked Plot',
cssClass: 'icon-telemetry', cssClass: 'icon-telemetry',
canView(domainObject) { canView(domainObject, objectPath) {
return domainObject.type === 'telemetry.plot.stacked'; return isCompactView(objectPath) && domainObject.type === 'telemetry.plot.stacked';
}, },
canEdit(domainObject) { canEdit(domainObject, objectPath) {
return domainObject.type === 'telemetry.plot.stacked'; return isCompactView(objectPath) && domainObject.type === 'telemetry.plot.stacked';
}, },
view: function (domainObject, objectPath) { view: function (domainObject, objectPath) {

View File

@ -103,7 +103,7 @@ describe("the plugin", () => {
} }
}; };
const applicableViews = openmct.objectViews.get(testTelemetryObject); const applicableViews = openmct.objectViews.get(testTelemetryObject, []);
let tableView = applicableViews.find((viewProvider) => viewProvider.key === 'table'); let tableView = applicableViews.find((viewProvider) => viewProvider.key === 'table');
expect(tableView).toBeDefined(); expect(tableView).toBeDefined();
}); });
@ -174,7 +174,7 @@ describe("the plugin", () => {
openmct.router.path = [testTelemetryObject]; openmct.router.path = [testTelemetryObject];
applicableViews = openmct.objectViews.get(testTelemetryObject); applicableViews = openmct.objectViews.get(testTelemetryObject, []);
tableViewProvider = applicableViews.find((viewProvider) => viewProvider.key === 'table'); tableViewProvider = applicableViews.find((viewProvider) => viewProvider.key === 'table');
tableView = tableViewProvider.view(testTelemetryObject, [testTelemetryObject]); tableView = tableViewProvider.view(testTelemetryObject, [testTelemetryObject]);
tableView.show(child, true); tableView.show(child, true);

View File

@ -87,9 +87,9 @@ const unknownObjectType = {
} }
}; };
function getViewKey(domainObject, openmct) { function getViewKey(domainObject, objectPath, openmct) {
let viewKey = ''; let viewKey = '';
const plotView = openmct.objectViews.get(domainObject).find((view) => { const plotView = openmct.objectViews.get(domainObject, objectPath).find((view) => {
return view.key.startsWith('plot-') && view.key !== 'plot-single'; return view.key.startsWith('plot-') && view.key !== 'plot-single';
}); });
if (plotView) { if (plotView) {
@ -136,7 +136,7 @@ export default {
let type = this.openmct.types.get(domainObject.type) || unknownObjectType; let type = this.openmct.types.get(domainObject.type) || unknownObjectType;
let keyString = this.openmct.objects.makeKeyString(domainObject.identifier); let keyString = this.openmct.objects.makeKeyString(domainObject.identifier);
let objectPath = [domainObject].concat(this.objectPath.slice()); let objectPath = [domainObject].concat(this.objectPath.slice());
let viewKey = getViewKey(domainObject, this.openmct); let viewKey = getViewKey(domainObject, objectPath, this.openmct);
let rowCount = 0; let rowCount = 0;
if (domainObject.type === 'plan') { if (domainObject.type === 'plan') {
rowCount = Object.keys(getValidatedPlan(domainObject)).length; rowCount = Object.keys(getValidatedPlan(domainObject)).length;

View File

@ -29,8 +29,27 @@ describe('the plugin', function () {
let element; let element;
let child; let child;
let openmct; let openmct;
let mockObjectPath;
beforeEach((done) => { beforeEach((done) => {
mockObjectPath = [
{
name: 'mock folder',
type: 'fake-folder',
identifier: {
key: 'mock-folder',
namespace: ''
}
},
{
name: 'mock parent folder',
type: 'time-strip',
identifier: {
key: 'mock-parent-folder',
namespace: ''
}
}
];
const appHolder = document.createElement('div'); const appHolder = document.createElement('div');
appHolder.style.width = '640px'; appHolder.style.width = '640px';
appHolder.style.height = '480px'; appHolder.style.height = '480px';
@ -87,7 +106,7 @@ describe('the plugin', function () {
type: "time-strip" type: "time-strip"
}; };
const applicableViews = openmct.objectViews.get(testViewObject); const applicableViews = openmct.objectViews.get(testViewObject, mockObjectPath);
timelineView = applicableViews.find((viewProvider) => viewProvider.key === 'time-strip.view'); timelineView = applicableViews.find((viewProvider) => viewProvider.key === 'time-strip.view');
let view = timelineView.view(testViewObject, element); let view = timelineView.view(testViewObject, element);
view.show(child, true); view.show(child, true);

View File

@ -320,7 +320,8 @@ export default {
let provider = this.openmct.objectViews.getByProviderKey(this.getViewKey()); let provider = this.openmct.objectViews.getByProviderKey(this.getViewKey());
if (!provider) { if (!provider) {
provider = this.openmct.objectViews.get(this.domainObject)[0]; let objectPath = this.currentObjectPath || this.objectPath;
provider = this.openmct.objectViews.get(this.domainObject, objectPath)[0];
if (!provider) { if (!provider) {
return; return;
} }
@ -329,10 +330,11 @@ export default {
return provider; return provider;
}, },
editIfEditable(event) { editIfEditable(event) {
let objectPath = this.currentObjectPath || this.objectPath;
let provider = this.getViewProvider(); let provider = this.getViewProvider();
if (provider if (provider
&& provider.canEdit && provider.canEdit
&& provider.canEdit(this.domainObject) && provider.canEdit(this.domainObject, objectPath)
&& this.isEditingAllowed() && this.isEditingAllowed()
&& !this.openmct.editor.isEditing()) { && !this.openmct.editor.isEditing()) {
this.openmct.editor.edit(); this.openmct.editor.edit();

View File

@ -159,10 +159,14 @@ export default {
return this.views.filter(v => v.key === this.viewKey)[0] || {}; return this.views.filter(v => v.key === this.viewKey)[0] || {};
}, },
views() { views() {
if (this.openmct.router.started !== true) {
return [];
}
return this return this
.openmct .openmct
.objectViews .objectViews
.get(this.domainObject) .get(this.domainObject, this.openmct.router.path)
.map((p) => { .map((p) => {
return { return {
key: p.key, key: p.key,
@ -197,7 +201,7 @@ export default {
if (currentViewKey !== undefined) { if (currentViewKey !== undefined) {
let currentViewProvider = this.openmct.objectViews.getByProviderKey(currentViewKey); let currentViewProvider = this.openmct.objectViews.getByProviderKey(currentViewKey);
return currentViewProvider.canEdit && currentViewProvider.canEdit(this.domainObject); return currentViewProvider.canEdit && currentViewProvider.canEdit(this.domainObject, this.openmct.router.path);
} }
return false; return false;

View File

@ -58,7 +58,7 @@ export default {
}; };
}, },
mounted() { mounted() {
this.views = this.openmct.objectViews.get(this.domainObject).map((view) => { this.views = this.openmct.objectViews.get(this.domainObject, this.objectPath).map((view) => {
view.callBack = () => { view.callBack = () => {
return this.setView(view); return this.setView(view);
}; };

View File

@ -39,10 +39,16 @@ define(['EventEmitter'], function (EventEmitter) {
/** /**
* @private for platform-internal use * @private for platform-internal use
* @param {*} item the object to be viewed * @param {*} item the object to be viewed
* @param {array} objectPath - The current contextual object path of the view object
* eg current domainObject is located under MyItems which is under Root
* @returns {module:openmct.ViewProvider[]} any providers * @returns {module:openmct.ViewProvider[]} any providers
* which can provide views of this object * which can provide views of this object
*/ */
ViewRegistry.prototype.get = function (item) { ViewRegistry.prototype.get = function (item, objectPath) {
if (objectPath === undefined) {
throw "objectPath must be provided to get applicable views for an object";
}
function byPriority(providerA, providerB) { function byPriority(providerA, providerB) {
let priorityA = providerA.priority ? providerA.priority(item) : DEFAULT_VIEW_PRIORITY; let priorityA = providerA.priority ? providerA.priority(item) : DEFAULT_VIEW_PRIORITY;
let priorityB = providerB.priority ? providerB.priority(item) : DEFAULT_VIEW_PRIORITY; let priorityB = providerB.priority ? providerB.priority(item) : DEFAULT_VIEW_PRIORITY;
@ -52,7 +58,7 @@ define(['EventEmitter'], function (EventEmitter) {
return this.getAllProviders() return this.getAllProviders()
.filter(function (provider) { .filter(function (provider) {
return provider.canView(item); return provider.canView(item, objectPath);
}).sort(byPriority); }).sort(byPriority);
}; };
@ -181,6 +187,8 @@ define(['EventEmitter'], function (EventEmitter) {
* @memberof module:openmct.ViewProvider# * @memberof module:openmct.ViewProvider#
* @param {module:openmct.DomainObject} domainObject the domain object * @param {module:openmct.DomainObject} domainObject the domain object
* to be viewed * to be viewed
* @param {array} objectPath - The current contextual object path of the view object
* eg current domainObject is located under MyItems which is under Root
* @returns {boolean} 'true' if the view applies to the provided object, * @returns {boolean} 'true' if the view applies to the provided object,
* otherwise 'false'. * otherwise 'false'.
*/ */
@ -201,6 +209,8 @@ define(['EventEmitter'], function (EventEmitter) {
* @memberof module:openmct.ViewProvider# * @memberof module:openmct.ViewProvider#
* @param {module:openmct.DomainObject} domainObject the domain object * @param {module:openmct.DomainObject} domainObject the domain object
* to be edited * to be edited
* @param {array} objectPath - The current contextual object path of the view object
* eg current domainObject is located under MyItems which is under Root
* @returns {boolean} 'true' if the view can be used to edit the provided object, * @returns {boolean} 'true' if the view can be used to edit the provided object,
* otherwise 'false'. * otherwise 'false'.
*/ */

View File

@ -100,13 +100,13 @@ define([
document.title = browseObject.name; //change document title to current object in main view document.title = browseObject.name; //change document title to current object in main view
if (currentProvider && currentProvider.canView(browseObject)) { if (currentProvider && currentProvider.canView(browseObject, openmct.router.path)) {
viewObject(browseObject, currentProvider); viewObject(browseObject, currentProvider);
return; return;
} }
let defaultProvider = openmct.objectViews.get(browseObject)[0]; let defaultProvider = openmct.objectViews.get(browseObject, openmct.router.path)[0];
if (defaultProvider) { if (defaultProvider) {
openmct.router.updateParams({ openmct.router.updateParams({
view: defaultProvider.key view: defaultProvider.key