mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 22:17:49 +00:00
WIP refactor for new telem api
This commit is contained in:
parent
26a7fee869
commit
b60eb6d6ae
@ -61,7 +61,7 @@ define([
|
|||||||
values: [
|
values: [
|
||||||
{
|
{
|
||||||
name: 'Time',
|
name: 'Time',
|
||||||
key: 'time',
|
key: 'utc',
|
||||||
format: 'utc',
|
format: 'utc',
|
||||||
hints: {
|
hints: {
|
||||||
domain: 1
|
domain: 1
|
||||||
@ -71,7 +71,9 @@ define([
|
|||||||
name: 'Image',
|
name: 'Image',
|
||||||
key: 'url',
|
key: 'url',
|
||||||
format: 'image',
|
format: 'image',
|
||||||
hints: {}
|
hints: {
|
||||||
|
image: 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -92,7 +94,7 @@ define([
|
|||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
callback({
|
callback({
|
||||||
time: Date.now(),
|
utc: Date.now(),
|
||||||
url: IMAGE_SAMPLES[index]
|
url: IMAGE_SAMPLES[index]
|
||||||
});
|
});
|
||||||
index += 1;
|
index += 1;
|
||||||
|
@ -53,7 +53,10 @@ define([
|
|||||||
"policies": [
|
"policies": [
|
||||||
{
|
{
|
||||||
"category": "view",
|
"category": "view",
|
||||||
"implementation": ImageryViewPolicy
|
"implementation": ImageryViewPolicy,
|
||||||
|
"depends": [
|
||||||
|
"openmct"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"controllers": [
|
"controllers": [
|
||||||
@ -62,7 +65,7 @@ define([
|
|||||||
"implementation": ImageryController,
|
"implementation": ImageryController,
|
||||||
"depends": [
|
"depends": [
|
||||||
"$scope",
|
"$scope",
|
||||||
"telemetryHandler"
|
"openmct"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -34,10 +34,8 @@
|
|||||||
<div class="l-image-main-controlbar flex-elem l-flex-row">
|
<div class="l-image-main-controlbar flex-elem l-flex-row">
|
||||||
<div class="left flex-elem grows">
|
<div class="left flex-elem grows">
|
||||||
<a class="s-button show-thumbs sm hidden icon-thumbs-strip"
|
<a class="s-button show-thumbs sm hidden icon-thumbs-strip"
|
||||||
ng-click="showThumbsBubble = (showThumbsBubble)? false:true"></a>
|
ng-click="showThumbsBubble = (showThumbsBubble) ? false:true"></a>
|
||||||
<span class="l-timezone">{{imagery.getZone()}}</span>
|
|
||||||
<span class="l-time">{{imagery.getTime()}}</span>
|
<span class="l-time">{{imagery.getTime()}}</span>
|
||||||
<span class="l-date">{{imagery.getDate()}}</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="right flex-elem">
|
<div class="right flex-elem">
|
||||||
<a class="s-button pause-play"
|
<a class="s-button pause-play"
|
||||||
|
@ -37,63 +37,66 @@ define(
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @memberof platform/features/imagery
|
* @memberof platform/features/imagery
|
||||||
*/
|
*/
|
||||||
function ImageryController($scope, telemetryHandler) {
|
function ImageryController($scope, openmct) {
|
||||||
var self = this;
|
this.$scope = $scope;
|
||||||
|
this.openmct = openmct;
|
||||||
|
this.date = "";
|
||||||
|
this.time = "";
|
||||||
|
this.zone = "";
|
||||||
|
this.imageUrl = "";
|
||||||
|
|
||||||
function releaseSubscription() {
|
this.$scope.filters = {
|
||||||
if (self.handle) {
|
|
||||||
self.handle.unsubscribe();
|
|
||||||
self.handle = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateValuesCallback() {
|
|
||||||
return self.updateValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new subscription; telemetrySubscriber gets
|
|
||||||
// to do the meaningful work here.
|
|
||||||
function subscribe(domainObject) {
|
|
||||||
releaseSubscription();
|
|
||||||
self.date = "";
|
|
||||||
self.time = "";
|
|
||||||
self.zone = "";
|
|
||||||
self.imageUrl = "";
|
|
||||||
self.handle = domainObject && telemetryHandler.handle(
|
|
||||||
domainObject,
|
|
||||||
updateValuesCallback,
|
|
||||||
true // Lossless
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.filters = {
|
|
||||||
brightness: 100,
|
brightness: 100,
|
||||||
contrast: 100
|
contrast: 100
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.subscribe = this.subscribe.bind(this);
|
||||||
|
this.stopListening = this.stopListening.bind(this);
|
||||||
|
this.updateValues = this.updateValues.bind(this);
|
||||||
|
|
||||||
// Subscribe to telemetry when a domain object becomes available
|
// Subscribe to telemetry when a domain object becomes available
|
||||||
$scope.$watch('domainObject', subscribe);
|
this.subscribe(this.$scope.domainObject);
|
||||||
|
|
||||||
// Unsubscribe when the plot is destroyed
|
// Unsubscribe when the plot is destroyed
|
||||||
$scope.$on("$destroy", releaseSubscription);
|
this.$scope.$on("$destroy", this.stopListening);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageryController.prototype.subscribe = function (domainObject) {
|
||||||
|
this.date = "";
|
||||||
|
this.imageUrl = "";
|
||||||
|
this.openmct.objects.get(domainObject.getId())
|
||||||
|
.then(function (object) {
|
||||||
|
this.domainObject = object;
|
||||||
|
var metadata = this.openmct
|
||||||
|
.telemetry
|
||||||
|
.getMetadata(this.domainObject);
|
||||||
|
var timeKey = this.openmct.time.timeSystem().key;
|
||||||
|
this.timeFormat = this.openmct
|
||||||
|
.telemetry
|
||||||
|
.getValueFormatter(metadata.value(timeKey));
|
||||||
|
this.imageFormat = this.openmct
|
||||||
|
.telemetry
|
||||||
|
.getValueFormatter(metadata.valuesForHints(['image'])[0]);
|
||||||
|
this.unsubscribe = this.openmct.telemetry
|
||||||
|
.subscribe(this.domainObject, this.updateValues);
|
||||||
|
}.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
ImageryController.prototype.stopListening = function () {
|
||||||
|
if (this.unsubscribe) {
|
||||||
|
this.unsubscribe();
|
||||||
|
delete this.unsubscribe;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update displayable values to reflect latest image telemetry
|
// Update displayable values to reflect latest image telemetry
|
||||||
ImageryController.prototype.updateValues = function () {
|
ImageryController.prototype.updateValues = function (datum) {
|
||||||
var imageObject =
|
if (this.isPaused) {
|
||||||
this.handle && this.handle.getTelemetryObjects()[0],
|
this.nextValue = datum;
|
||||||
timestamp,
|
return;
|
||||||
m;
|
|
||||||
if (imageObject && !this.isPaused) {
|
|
||||||
timestamp = this.handle.getDomainValue(imageObject);
|
|
||||||
m = timestamp !== undefined ?
|
|
||||||
moment.utc(timestamp) :
|
|
||||||
undefined;
|
|
||||||
this.date = m ? m.format(DATE_FORMAT) : "";
|
|
||||||
this.time = m ? m.format(TIME_FORMAT) : "";
|
|
||||||
this.zone = m ? "UTC" : "";
|
|
||||||
this.imageUrl = this.handle.getRangeValue(imageObject);
|
|
||||||
}
|
}
|
||||||
|
this.time = this.timeFormat.format(datum);
|
||||||
|
this.image = this.imageFormat.format(datum);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,31 +108,12 @@ define(
|
|||||||
return this.time;
|
return this.time;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the date portion (month, year) of the
|
|
||||||
* timestamp associated with the incoming image telemetry.
|
|
||||||
* @returns {string} the date
|
|
||||||
*/
|
|
||||||
ImageryController.prototype.getDate = function () {
|
|
||||||
return this.date;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the time zone for the displayed time/date corresponding
|
|
||||||
* to the timestamp associated with the incoming image
|
|
||||||
* telemetry.
|
|
||||||
* @returns {string} the time
|
|
||||||
*/
|
|
||||||
ImageryController.prototype.getZone = function () {
|
|
||||||
return this.zone;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the URL of the image telemetry to display.
|
* Get the URL of the image telemetry to display.
|
||||||
* @returns {string} URL for telemetry image
|
* @returns {string} URL for telemetry image
|
||||||
*/
|
*/
|
||||||
ImageryController.prototype.getImageUrl = function () {
|
ImageryController.prototype.getImageUrl = function () {
|
||||||
return this.imageUrl;
|
return this.image;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,8 +125,8 @@ define(
|
|||||||
ImageryController.prototype.paused = function (state) {
|
ImageryController.prototype.paused = function (state) {
|
||||||
if (arguments.length > 0 && state !== this.isPaused) {
|
if (arguments.length > 0 && state !== this.isPaused) {
|
||||||
this.isPaused = state;
|
this.isPaused = state;
|
||||||
// Switch to latest image
|
this.updateValues(this.nextValue);
|
||||||
this.updateValues();
|
delete this.nextValue;
|
||||||
}
|
}
|
||||||
return this.isPaused;
|
return this.isPaused;
|
||||||
};
|
};
|
||||||
|
@ -20,8 +20,11 @@
|
|||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
define(
|
define([
|
||||||
function () {
|
'../../../../../src/api/objects/object-utils'
|
||||||
|
], function (
|
||||||
|
objectUtils
|
||||||
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Policy preventing the Imagery view from being made available for
|
* Policy preventing the Imagery view from being made available for
|
||||||
@ -29,24 +32,24 @@ define(
|
|||||||
* @implements {Policy.<View, DomainObject>}
|
* @implements {Policy.<View, DomainObject>}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function ImageryViewPolicy() {
|
function ImageryViewPolicy(openmct) {
|
||||||
|
this.openmct = openmct;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasImageTelemetry(domainObject) {
|
ImageryViewPolicy.prototype.hasImageTelemetry = function (domainObject) {
|
||||||
var telemetry = domainObject &&
|
var newDO = objectUtils.toNewFormat(
|
||||||
domainObject.getCapability('telemetry'),
|
domainObject.getModel(),
|
||||||
metadata = telemetry ? telemetry.getMetadata() : {},
|
domainObject.getId()
|
||||||
ranges = metadata.ranges || [];
|
);
|
||||||
|
|
||||||
return ranges.some(function (range) {
|
var metadata = this.openmct.telemetry.getMetadata(newDO);
|
||||||
return range.format === 'imageUrl' ||
|
var values = metadata.valuesForHints(['image']);
|
||||||
range.format === 'image';
|
return values.length >= 1;
|
||||||
});
|
};
|
||||||
}
|
|
||||||
|
|
||||||
ImageryViewPolicy.prototype.allow = function (view, domainObject) {
|
ImageryViewPolicy.prototype.allow = function (view, domainObject) {
|
||||||
if (view.key === 'imagery') {
|
if (view.key === 'imagery') {
|
||||||
return hasImageTelemetry(domainObject);
|
return this.hasImageTelemetry(domainObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -25,48 +25,45 @@ define(
|
|||||||
function (ImageryController) {
|
function (ImageryController) {
|
||||||
|
|
||||||
describe("The Imagery controller", function () {
|
describe("The Imagery controller", function () {
|
||||||
var mockScope,
|
var $scope,
|
||||||
mockTelemetryHandler,
|
openmct,
|
||||||
mockHandle,
|
oldDomainObject,
|
||||||
mockDomainObject,
|
newDomainObject,
|
||||||
|
unsubscribe,
|
||||||
|
callback,
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
function invokeWatch(expr, value) {
|
|
||||||
mockScope.$watch.calls.forEach(function (call) {
|
|
||||||
if (call.args[0] === expr) {
|
|
||||||
call.args[1](value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockScope = jasmine.createSpyObj('$scope', ['$on', '$watch']);
|
$scope = jasmine.createSpyObj('$scope', ['$on', '$watch']);
|
||||||
mockTelemetryHandler = jasmine.createSpyObj(
|
oldDomainObject = jasmine.createSpyObj(
|
||||||
'telemetryHandler',
|
|
||||||
['handle']
|
|
||||||
);
|
|
||||||
mockHandle = jasmine.createSpyObj(
|
|
||||||
'handle',
|
|
||||||
[
|
|
||||||
'getDomainValue',
|
|
||||||
'getRangeValue',
|
|
||||||
'getTelemetryObjects',
|
|
||||||
'unsubscribe'
|
|
||||||
]
|
|
||||||
);
|
|
||||||
mockDomainObject = jasmine.createSpyObj(
|
|
||||||
'domainObject',
|
'domainObject',
|
||||||
['getId', 'getModel', 'getCapability']
|
['getId']
|
||||||
);
|
);
|
||||||
|
|
||||||
mockTelemetryHandler.handle.andReturn(mockHandle);
|
oldDomainObject.getId.andReturn('testID');
|
||||||
mockHandle.getTelemetryObjects.andReturn([mockDomainObject]);
|
openmct = {
|
||||||
|
objects: jasmine.createSpyObj('objectAPI', [
|
||||||
|
'get'
|
||||||
|
]),
|
||||||
|
time: jasmine.createSpyObj('timeAPI', [
|
||||||
|
'timeSystem'
|
||||||
|
]),
|
||||||
|
telemetry: jasmine.createSpyObj('telemetryAPI', [
|
||||||
|
'subscribe'
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
unsubscribe = jasmine.createSpy('unsubscribe');
|
||||||
|
openmct.telemetry.subscribe.andReturn(unsubcribe);
|
||||||
|
openmct.time.timeSystem.andReturn({
|
||||||
|
key: 'testKey'
|
||||||
|
});
|
||||||
|
openmct.objects.get.andReturn(Promise.resolve(newDomainObject));
|
||||||
|
|
||||||
controller = new ImageryController(
|
controller = new ImageryController(
|
||||||
mockScope,
|
$scope,
|
||||||
mockTelemetryHandler
|
openmct
|
||||||
);
|
);
|
||||||
invokeWatch('domainObject', mockDomainObject);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("unsubscribes when scope is destroyed", function () {
|
it("unsubscribes when scope is destroyed", function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user