mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +00:00
[Plot] Update policy to detect any range
Update policy to detect any range. As a simple way to prevent detecting messages, it will not apply when every range is a string format. fixes https://github.com/nasa/openmct/issues/1713
This commit is contained in:
@ -118,7 +118,10 @@ define([
|
|||||||
"policies": [
|
"policies": [
|
||||||
{
|
{
|
||||||
"category": "view",
|
"category": "view",
|
||||||
"implementation": PlotViewPolicy
|
"implementation": PlotViewPolicy,
|
||||||
|
"depends": [
|
||||||
|
"openmct"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"representations": [
|
"representations": [
|
||||||
|
@ -30,30 +30,25 @@ define(
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @memberof platform/features/plot
|
* @memberof platform/features/plot
|
||||||
*/
|
*/
|
||||||
function PlotViewPolicy() {
|
function PlotViewPolicy(openmct) {
|
||||||
|
this.openmct = openmct;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasNumericTelemetry(domainObject) {
|
PlotViewPolicy.prototype.hasNumericTelemetry = function (domainObject) {
|
||||||
var telemetry = domainObject &&
|
var adaptedObject = domainObject.useCapability('adapter');
|
||||||
domainObject.getCapability('telemetry'),
|
var metadata = this.openmct.telemetry.getMetadata(adaptedObject);
|
||||||
metadata = telemetry ? telemetry.getMetadata() : {},
|
var rangeValues = metadata.valuesForHints(['range']);
|
||||||
ranges = metadata.ranges || [];
|
if (rangeValues.length === 0) {
|
||||||
|
return false;
|
||||||
// Generally, we want to allow Plot for telemetry-providing
|
}
|
||||||
// objects (most telemetry is plottable.) We only want to
|
return !rangeValues.every(function (value) {
|
||||||
// suppress this for telemetry which only has explicitly
|
return value.format === 'string';
|
||||||
// non-numeric values.
|
|
||||||
return ranges.length === 0 || ranges.some(function (range) {
|
|
||||||
// Assume format is numeric if it is undefined
|
|
||||||
// (numeric telemetry is the common case)
|
|
||||||
return range.format === undefined ||
|
|
||||||
range.format === 'number';
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
PlotViewPolicy.prototype.allow = function (view, domainObject) {
|
PlotViewPolicy.prototype.allow = function (view, domainObject) {
|
||||||
if (view.key === 'plot') {
|
if (view.key === 'plot') {
|
||||||
return hasNumericTelemetry(domainObject);
|
return this.hasNumericTelemetry(domainObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -27,51 +27,71 @@ define(
|
|||||||
describe("Plot view policy", function () {
|
describe("Plot view policy", function () {
|
||||||
var testView,
|
var testView,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockTelemetry,
|
openmct,
|
||||||
testMetadata,
|
telemetryMetadata,
|
||||||
policy;
|
policy;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
testView = { key: "plot" };
|
testView = { key: "plot" };
|
||||||
testMetadata = {};
|
|
||||||
mockDomainObject = jasmine.createSpyObj(
|
mockDomainObject = jasmine.createSpyObj(
|
||||||
'domainObject',
|
'domainObject',
|
||||||
['getId', 'getModel', 'getCapability']
|
['useCapability']
|
||||||
);
|
);
|
||||||
mockTelemetry = jasmine.createSpyObj(
|
mockDomainObject.useCapability.andReturn('adaptedObject');
|
||||||
'telemetry',
|
openmct = {
|
||||||
['getMetadata']
|
telemetry: jasmine.createSpyObj('telemetryAPI', [
|
||||||
);
|
'getMetadata'
|
||||||
mockDomainObject.getCapability.andCallFake(function (c) {
|
])
|
||||||
return c === 'telemetry' ? mockTelemetry : undefined;
|
};
|
||||||
});
|
telemetryMetadata = jasmine.createSpyObj('telemetryMetadata', [
|
||||||
mockTelemetry.getMetadata.andReturn(testMetadata);
|
'valuesForHints'
|
||||||
|
]);
|
||||||
policy = new PlotViewPolicy();
|
telemetryMetadata.valuesForHints.andReturn([]);
|
||||||
|
openmct.telemetry.getMetadata.andReturn(telemetryMetadata);
|
||||||
|
policy = new PlotViewPolicy(openmct);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows the imagery view for domain objects with numeric telemetry", function () {
|
it('fetches metadata from telem api', function () {
|
||||||
testMetadata.ranges = [{ key: "foo", format: "number" }];
|
policy.allow(testView, mockDomainObject);
|
||||||
expect(policy.allow(testView, mockDomainObject)).toBeTruthy();
|
expect(mockDomainObject.useCapability)
|
||||||
|
.toHaveBeenCalledWith('adapter');
|
||||||
|
expect(openmct.telemetry.getMetadata)
|
||||||
|
.toHaveBeenCalledWith('adaptedObject');
|
||||||
|
expect(telemetryMetadata.valuesForHints)
|
||||||
|
.toHaveBeenCalledWith(['range']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows the imagery view for domain objects with unspecified telemetry", function () {
|
it('returns false if no ranges exist', function () {
|
||||||
testMetadata.ranges = [{ key: "foo" }];
|
telemetryMetadata.valuesForHints.andReturn([]);
|
||||||
expect(policy.allow(testView, mockDomainObject)).toBeTruthy();
|
expect(policy.allow(testView, mockDomainObject)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("disallows the imagery view for domain objects without image telemetry", function () {
|
it('returns true if any ranges exist', function () {
|
||||||
testMetadata.ranges = [{ key: "foo", format: "somethingElse" }];
|
telemetryMetadata.valuesForHints.andReturn([{}]);
|
||||||
expect(policy.allow(testView, mockDomainObject)).toBeFalsy();
|
expect(policy.allow(testView, mockDomainObject)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false if all ranges are strings', function () {
|
||||||
|
telemetryMetadata.valuesForHints.andReturn([{
|
||||||
|
format: 'string'
|
||||||
|
}, {
|
||||||
|
format: 'string'
|
||||||
|
}]);
|
||||||
|
expect(policy.allow(testView, mockDomainObject)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true if only some ranges are strings', function () {
|
||||||
|
telemetryMetadata.valuesForHints.andReturn([{
|
||||||
|
format: 'string'
|
||||||
|
}, {}]);
|
||||||
|
expect(policy.allow(testView, mockDomainObject)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows other views", function () {
|
it("allows other views", function () {
|
||||||
testView.key = "somethingElse";
|
testView.key = "somethingElse";
|
||||||
testMetadata.ranges = [{ key: "foo", format: "somethingElse" }];
|
expect(policy.allow(testView, mockDomainObject)).toBe(true);
|
||||||
expect(policy.allow(testView, mockDomainObject)).toBeTruthy();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user