WIP refactor for new telem api

This commit is contained in:
Pete Richards 2017-05-22 18:30:01 -07:00
parent 26a7fee869
commit b60eb6d6ae
6 changed files with 109 additions and 122 deletions

View File

@ -61,7 +61,7 @@ define([
values: [
{
name: 'Time',
key: 'time',
key: 'utc',
format: 'utc',
hints: {
domain: 1
@ -71,7 +71,9 @@ define([
name: 'Image',
key: 'url',
format: 'image',
hints: {}
hints: {
image: 1
}
}
]
}
@ -92,7 +94,7 @@ define([
index = 0;
}
callback({
time: Date.now(),
utc: Date.now(),
url: IMAGE_SAMPLES[index]
});
index += 1;

View File

@ -53,7 +53,10 @@ define([
"policies": [
{
"category": "view",
"implementation": ImageryViewPolicy
"implementation": ImageryViewPolicy,
"depends": [
"openmct"
]
}
],
"controllers": [
@ -62,7 +65,7 @@ define([
"implementation": ImageryController,
"depends": [
"$scope",
"telemetryHandler"
"openmct"
]
}
],

View File

@ -34,10 +34,8 @@
<div class="l-image-main-controlbar flex-elem l-flex-row">
<div class="left flex-elem grows">
<a class="s-button show-thumbs sm hidden icon-thumbs-strip"
ng-click="showThumbsBubble = (showThumbsBubble)? false:true"></a>
<span class="l-timezone">{{imagery.getZone()}}</span>
ng-click="showThumbsBubble = (showThumbsBubble) ? false:true"></a>
<span class="l-time">{{imagery.getTime()}}</span>
<span class="l-date">{{imagery.getDate()}}</span>
</div>
<div class="right flex-elem">
<a class="s-button pause-play"

View File

@ -37,63 +37,66 @@ define(
* @constructor
* @memberof platform/features/imagery
*/
function ImageryController($scope, telemetryHandler) {
var self = this;
function ImageryController($scope, openmct) {
this.$scope = $scope;
this.openmct = openmct;
this.date = "";
this.time = "";
this.zone = "";
this.imageUrl = "";
function releaseSubscription() {
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 = {
this.$scope.filters = {
brightness: 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
$scope.$watch('domainObject', subscribe);
this.subscribe(this.$scope.domainObject);
// 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
ImageryController.prototype.updateValues = function () {
var imageObject =
this.handle && this.handle.getTelemetryObjects()[0],
timestamp,
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);
ImageryController.prototype.updateValues = function (datum) {
if (this.isPaused) {
this.nextValue = datum;
return;
}
this.time = this.timeFormat.format(datum);
this.image = this.imageFormat.format(datum);
};
/**
@ -105,31 +108,12 @@ define(
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.
* @returns {string} URL for telemetry image
*/
ImageryController.prototype.getImageUrl = function () {
return this.imageUrl;
return this.image;
};
/**
@ -141,8 +125,8 @@ define(
ImageryController.prototype.paused = function (state) {
if (arguments.length > 0 && state !== this.isPaused) {
this.isPaused = state;
// Switch to latest image
this.updateValues();
this.updateValues(this.nextValue);
delete this.nextValue;
}
return this.isPaused;
};

View File

@ -20,8 +20,11 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/
define(
function () {
define([
'../../../../../src/api/objects/object-utils'
], function (
objectUtils
) {
/**
* Policy preventing the Imagery view from being made available for
@ -29,24 +32,24 @@ define(
* @implements {Policy.<View, DomainObject>}
* @constructor
*/
function ImageryViewPolicy() {
function ImageryViewPolicy(openmct) {
this.openmct = openmct;
}
function hasImageTelemetry(domainObject) {
var telemetry = domainObject &&
domainObject.getCapability('telemetry'),
metadata = telemetry ? telemetry.getMetadata() : {},
ranges = metadata.ranges || [];
ImageryViewPolicy.prototype.hasImageTelemetry = function (domainObject) {
var newDO = objectUtils.toNewFormat(
domainObject.getModel(),
domainObject.getId()
);
return ranges.some(function (range) {
return range.format === 'imageUrl' ||
range.format === 'image';
});
}
var metadata = this.openmct.telemetry.getMetadata(newDO);
var values = metadata.valuesForHints(['image']);
return values.length >= 1;
};
ImageryViewPolicy.prototype.allow = function (view, domainObject) {
if (view.key === 'imagery') {
return hasImageTelemetry(domainObject);
return this.hasImageTelemetry(domainObject);
}
return true;

View File

@ -25,48 +25,45 @@ define(
function (ImageryController) {
describe("The Imagery controller", function () {
var mockScope,
mockTelemetryHandler,
mockHandle,
mockDomainObject,
var $scope,
openmct,
oldDomainObject,
newDomainObject,
unsubscribe,
callback,
controller;
function invokeWatch(expr, value) {
mockScope.$watch.calls.forEach(function (call) {
if (call.args[0] === expr) {
call.args[1](value);
}
});
}
beforeEach(function () {
mockScope = jasmine.createSpyObj('$scope', ['$on', '$watch']);
mockTelemetryHandler = jasmine.createSpyObj(
'telemetryHandler',
['handle']
);
mockHandle = jasmine.createSpyObj(
'handle',
[
'getDomainValue',
'getRangeValue',
'getTelemetryObjects',
'unsubscribe'
]
);
mockDomainObject = jasmine.createSpyObj(
$scope = jasmine.createSpyObj('$scope', ['$on', '$watch']);
oldDomainObject = jasmine.createSpyObj(
'domainObject',
['getId', 'getModel', 'getCapability']
['getId']
);
mockTelemetryHandler.handle.andReturn(mockHandle);
mockHandle.getTelemetryObjects.andReturn([mockDomainObject]);
oldDomainObject.getId.andReturn('testID');
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(
mockScope,
mockTelemetryHandler
$scope,
openmct
);
invokeWatch('domainObject', mockDomainObject);
});
it("unsubscribes when scope is destroyed", function () {