mirror of
https://github.com/nasa/openmct.git
synced 2025-01-31 16:36:13 +00:00
Merge pull request #1459 from nasa/open1458
[Plot] Add current conductor bounds to telemetry requests via the old API.
This commit is contained in:
commit
12d1302138
@ -21,11 +21,9 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
define([
|
define([
|
||||||
"./src/ConductorTelemetryDecorator",
|
|
||||||
"./src/ConductorRepresenter",
|
"./src/ConductorRepresenter",
|
||||||
'legacyRegistry'
|
'legacyRegistry'
|
||||||
], function (
|
], function (
|
||||||
ConductorTelemetryDecorator,
|
|
||||||
ConductorRepresenter,
|
ConductorRepresenter,
|
||||||
legacyRegistry
|
legacyRegistry
|
||||||
) {
|
) {
|
||||||
@ -39,16 +37,6 @@ define([
|
|||||||
"openmct"
|
"openmct"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"components": [
|
|
||||||
{
|
|
||||||
"type": "decorator",
|
|
||||||
"provides": "telemetryService",
|
|
||||||
"implementation": ConductorTelemetryDecorator,
|
|
||||||
"depends": [
|
|
||||||
"openmct"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
|
||||||
* Administration. All rights reserved.
|
|
||||||
*
|
|
||||||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
* Open MCT Web includes source code licensed under additional open source
|
|
||||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
||||||
* this source code distribution or the Licensing information page available
|
|
||||||
* at runtime from the About dialog for additional information.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
define(
|
|
||||||
function () {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decorates the `telemetryService` such that requests are
|
|
||||||
* mediated by the time conductor. This is a modified version of the
|
|
||||||
* decorator used in the old TimeConductor that integrates with the
|
|
||||||
* new TimeConductor API.
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
* @memberof platform/features/conductor
|
|
||||||
* @implements {TelemetryService}
|
|
||||||
* @param {platform/features/conductor.TimeConductor} conductor
|
|
||||||
* the service which exposes the global time conductor
|
|
||||||
* @param {TelemetryService} telemetryService the decorated service
|
|
||||||
*/
|
|
||||||
function ConductorTelemetryDecorator(openmct, telemetryService) {
|
|
||||||
this.conductor = openmct.conductor;
|
|
||||||
this.telemetryService = telemetryService;
|
|
||||||
|
|
||||||
this.amendRequests = ConductorTelemetryDecorator.prototype.amendRequests.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
function amendRequest(request, bounds, timeSystem) {
|
|
||||||
request = request || {};
|
|
||||||
request.start = bounds.start;
|
|
||||||
request.end = bounds.end;
|
|
||||||
request.domain = timeSystem.metadata.key;
|
|
||||||
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConductorTelemetryDecorator.prototype.amendRequests = function (requests) {
|
|
||||||
var bounds = this.conductor.bounds(),
|
|
||||||
timeSystem = this.conductor.timeSystem();
|
|
||||||
|
|
||||||
return (requests || []).map(function (request) {
|
|
||||||
return amendRequest(request, bounds, timeSystem);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ConductorTelemetryDecorator.prototype.requestTelemetry = function (requests) {
|
|
||||||
return this.telemetryService
|
|
||||||
.requestTelemetry(this.amendRequests(requests));
|
|
||||||
};
|
|
||||||
|
|
||||||
ConductorTelemetryDecorator.prototype.subscribe = function (callback, requests) {
|
|
||||||
var unsubscribeFunc = this.telemetryService.subscribe(callback, this.amendRequests(requests)),
|
|
||||||
conductor = this.conductor,
|
|
||||||
self = this;
|
|
||||||
|
|
||||||
function amendRequests() {
|
|
||||||
return self.amendRequests(requests);
|
|
||||||
}
|
|
||||||
|
|
||||||
conductor.on('bounds', amendRequests);
|
|
||||||
return function () {
|
|
||||||
unsubscribeFunc();
|
|
||||||
conductor.off('bounds', amendRequests);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
return ConductorTelemetryDecorator;
|
|
||||||
}
|
|
||||||
);
|
|
@ -139,7 +139,9 @@ define(
|
|||||||
type = domainObject.getCapability("type"),
|
type = domainObject.getCapability("type"),
|
||||||
typeRequest = (type && type.getDefinition().telemetry) || {},
|
typeRequest = (type && type.getDefinition().telemetry) || {},
|
||||||
modelTelemetry = domainObject.getModel().telemetry,
|
modelTelemetry = domainObject.getModel().telemetry,
|
||||||
fullRequest = Object.create(typeRequest);
|
fullRequest = Object.create(typeRequest),
|
||||||
|
bounds,
|
||||||
|
timeSystem;
|
||||||
|
|
||||||
// Add properties from the telemetry field of this
|
// Add properties from the telemetry field of this
|
||||||
// specific domain object.
|
// specific domain object.
|
||||||
@ -160,6 +162,19 @@ define(
|
|||||||
fullRequest.key = domainObject.getId();
|
fullRequest.key = domainObject.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.start === undefined && request.end === undefined) {
|
||||||
|
bounds = this.openmct.conductor.bounds();
|
||||||
|
fullRequest.start = bounds.start;
|
||||||
|
fullRequest.end = bounds.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.domain === undefined) {
|
||||||
|
timeSystem = this.openmct.conductor.timeSystem();
|
||||||
|
if (timeSystem !== undefined) {
|
||||||
|
fullRequest.domain = timeSystem.metadata.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return fullRequest;
|
return fullRequest;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -97,7 +97,22 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
mockAPI = {
|
mockAPI = {
|
||||||
telemetry: mockTelemetryAPI
|
telemetry: mockTelemetryAPI,
|
||||||
|
conductor: {
|
||||||
|
bounds: function () {
|
||||||
|
return {
|
||||||
|
start: 0,
|
||||||
|
end: 1
|
||||||
|
};
|
||||||
|
},
|
||||||
|
timeSystem: function () {
|
||||||
|
return {
|
||||||
|
metadata: {
|
||||||
|
key: 'mockTimeSystem'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
telemetry = new TelemetryCapability(
|
telemetry = new TelemetryCapability(
|
||||||
@ -133,7 +148,8 @@ define(
|
|||||||
id: "testId", // from domain object
|
id: "testId", // from domain object
|
||||||
source: "testSource", // from model
|
source: "testSource", // from model
|
||||||
key: "testKey", // from model
|
key: "testKey", // from model
|
||||||
start: 42 // from argument
|
start: 42, // from argument
|
||||||
|
domain: 'mockTimeSystem'
|
||||||
}]);
|
}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -150,7 +166,10 @@ define(
|
|||||||
expect(telemetry.getMetadata()).toEqual({
|
expect(telemetry.getMetadata()).toEqual({
|
||||||
id: "testId", // from domain object
|
id: "testId", // from domain object
|
||||||
source: "testSource",
|
source: "testSource",
|
||||||
key: "testKey"
|
key: "testKey",
|
||||||
|
start: 0,
|
||||||
|
end: 1,
|
||||||
|
domain: 'mockTimeSystem'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -164,7 +183,10 @@ define(
|
|||||||
expect(telemetry.getMetadata()).toEqual({
|
expect(telemetry.getMetadata()).toEqual({
|
||||||
id: "testId", // from domain object
|
id: "testId", // from domain object
|
||||||
source: "testSource", // from model
|
source: "testSource", // from model
|
||||||
key: "testId" // from domain object
|
key: "testId", // from domain object
|
||||||
|
start: 0,
|
||||||
|
end: 1,
|
||||||
|
domain: 'mockTimeSystem'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -243,7 +265,10 @@ define(
|
|||||||
[{
|
[{
|
||||||
id: "testId", // from domain object
|
id: "testId", // from domain object
|
||||||
source: "testSource",
|
source: "testSource",
|
||||||
key: "testKey"
|
key: "testKey",
|
||||||
|
start: 0,
|
||||||
|
end: 1,
|
||||||
|
domain: 'mockTimeSystem'
|
||||||
}]
|
}]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -260,8 +285,28 @@ define(
|
|||||||
expect(mockUnsubscribe).not.toHaveBeenCalled();
|
expect(mockUnsubscribe).not.toHaveBeenCalled();
|
||||||
subscription(); // should be an unsubscribe function
|
subscription(); // should be an unsubscribe function
|
||||||
expect(mockUnsubscribe).toHaveBeenCalled();
|
expect(mockUnsubscribe).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("applies time conductor bounds if request bounds not defined", function () {
|
||||||
|
var fullRequest = telemetry.buildRequest({});
|
||||||
|
var mockBounds = mockAPI.conductor.bounds();
|
||||||
|
|
||||||
|
expect(fullRequest.start).toBe(mockBounds.start);
|
||||||
|
expect(fullRequest.end).toBe(mockBounds.end);
|
||||||
|
|
||||||
|
fullRequest = telemetry.buildRequest({start: 10, end: 20});
|
||||||
|
|
||||||
|
expect(fullRequest.start).toBe(10);
|
||||||
|
expect(fullRequest.end).toBe(20);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("applies domain from time system if none defined", function () {
|
||||||
|
var fullRequest = telemetry.buildRequest({});
|
||||||
|
var mockTimeSystem = mockAPI.conductor.timeSystem();
|
||||||
|
expect(fullRequest.domain).toBe(mockTimeSystem.metadata.key);
|
||||||
|
|
||||||
|
fullRequest = telemetry.buildRequest({domain: 'someOtherDomain'});
|
||||||
|
expect(fullRequest.domain).toBe('someOtherDomain');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user