mirror of
https://github.com/nasa/openmct.git
synced 2025-02-07 11:30:28 +00:00
Merge pull request #1625 from nasa/example-historical-imagery
Example historical imagery
This commit is contained in:
commit
a3520ba51e
@ -48,6 +48,56 @@ define([
|
|||||||
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18748.jpg"
|
"https://www.hq.nasa.gov/alsj/a16/AS16-117-18748.jpg"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function pointForTimestamp(timestamp) {
|
||||||
|
return {
|
||||||
|
utc: Math.floor(timestamp / 5000) * 5000,
|
||||||
|
url: IMAGE_SAMPLES[Math.floor(timestamp / 5000) % IMAGE_SAMPLES.length]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var realtimeProvider = {
|
||||||
|
supportsSubscribe: function (domainObject) {
|
||||||
|
return domainObject.type === 'example.imagery';
|
||||||
|
},
|
||||||
|
subscribe: function (domainObject, callback) {
|
||||||
|
var interval = setInterval(function () {
|
||||||
|
callback(pointForTimestamp(Date.now()));
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
return function (interval) {
|
||||||
|
clearInterval(interval);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var historicalProvider = {
|
||||||
|
supportsRequest: function (domainObject, options) {
|
||||||
|
return domainObject.type === 'example.imagery'
|
||||||
|
&& options.strategy !== 'latest';
|
||||||
|
},
|
||||||
|
request: function (domainObject, options) {
|
||||||
|
var start = options.start;
|
||||||
|
var end = options.end;
|
||||||
|
var data = [];
|
||||||
|
while (start < end) {
|
||||||
|
data.push(pointForTimestamp(start));
|
||||||
|
start += 5000;
|
||||||
|
}
|
||||||
|
return Promise.resolve(data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var ladProvider = {
|
||||||
|
supportsRequest: function (domainObject, options) {
|
||||||
|
return domainObject.type === 'example.imagery' &&
|
||||||
|
options.strategy === 'latest';
|
||||||
|
},
|
||||||
|
request: function (domainObject, options) {
|
||||||
|
return Promise.resolve([pointForTimestamp(Date.now())]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return function install(openmct) {
|
return function install(openmct) {
|
||||||
openmct.types.addType('example.imagery', {
|
openmct.types.addType('example.imagery', {
|
||||||
key: 'example.imagery',
|
key: 'example.imagery',
|
||||||
@ -80,31 +130,9 @@ define([
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
openmct.telemetry.addProvider({
|
openmct.telemetry.addProvider(realtimeProvider);
|
||||||
supportsSubscribe: function (domainObject) {
|
openmct.telemetry.addProvider(historicalProvider);
|
||||||
return domainObject.type === 'example.imagery';
|
openmct.telemetry.addProvider(ladProvider);
|
||||||
},
|
|
||||||
subscribe: function (domainObject, callback) {
|
|
||||||
var index = 0,
|
|
||||||
end = IMAGE_SAMPLES.length,
|
|
||||||
interval;
|
|
||||||
|
|
||||||
interval = setInterval(function () {
|
|
||||||
if (index >= end) {
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
callback({
|
|
||||||
utc: Date.now(),
|
|
||||||
url: IMAGE_SAMPLES[index]
|
|
||||||
});
|
|
||||||
index += 1;
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
return function (interval) {
|
|
||||||
clearInterval(interval);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,14 @@ define(
|
|||||||
.getValueFormatter(metadata.valuesForHints(['image'])[0]);
|
.getValueFormatter(metadata.valuesForHints(['image'])[0]);
|
||||||
this.unsubscribe = this.openmct.telemetry
|
this.unsubscribe = this.openmct.telemetry
|
||||||
.subscribe(this.domainObject, this.updateValues);
|
.subscribe(this.domainObject, this.updateValues);
|
||||||
|
this.openmct.telemetry
|
||||||
|
.request(this.domainObject, {
|
||||||
|
strategy: 'latest',
|
||||||
|
size: 1
|
||||||
|
})
|
||||||
|
.then(function (values) {
|
||||||
|
this.updateValues(values[0]);
|
||||||
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -133,4 +141,3 @@ define(
|
|||||||
return ImageryController;
|
return ImageryController;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -30,10 +30,10 @@ define(
|
|||||||
oldDomainObject,
|
oldDomainObject,
|
||||||
newDomainObject,
|
newDomainObject,
|
||||||
unsubscribe,
|
unsubscribe,
|
||||||
callback,
|
|
||||||
metadata,
|
metadata,
|
||||||
prefix,
|
prefix,
|
||||||
controller;
|
controller,
|
||||||
|
hasLoaded;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
$scope = jasmine.createSpyObj('$scope', ['$on', '$watch']);
|
$scope = jasmine.createSpyObj('$scope', ['$on', '$watch']);
|
||||||
@ -53,6 +53,7 @@ define(
|
|||||||
]),
|
]),
|
||||||
telemetry: jasmine.createSpyObj('telemetryAPI', [
|
telemetry: jasmine.createSpyObj('telemetryAPI', [
|
||||||
'subscribe',
|
'subscribe',
|
||||||
|
'request',
|
||||||
'getValueFormatter',
|
'getValueFormatter',
|
||||||
'getMetadata'
|
'getMetadata'
|
||||||
])
|
])
|
||||||
@ -79,84 +80,104 @@ define(
|
|||||||
});
|
});
|
||||||
return formatter;
|
return formatter;
|
||||||
});
|
});
|
||||||
|
hasLoaded = false;
|
||||||
|
openmct.telemetry.request.andCallFake(function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
hasLoaded = true;
|
||||||
|
}, 10);
|
||||||
|
return Promise.resolve([{
|
||||||
|
timestamp: 1434600258123,
|
||||||
|
value: 'some/url'
|
||||||
|
}]);
|
||||||
|
});
|
||||||
metadata.value.andReturn("timestamp");
|
metadata.value.andReturn("timestamp");
|
||||||
metadata.valuesForHints.andReturn(["value"]);
|
metadata.valuesForHints.andReturn(["value"]);
|
||||||
|
|
||||||
controller = new ImageryController($scope, openmct);
|
controller = new ImageryController($scope, openmct);
|
||||||
|
|
||||||
waitsFor(function () {
|
});
|
||||||
return openmct.telemetry.subscribe.calls.length > 0;
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
runs(function () {
|
describe("when loaded", function () {
|
||||||
callback =
|
var callback;
|
||||||
openmct.telemetry.subscribe.mostRecentCall.args[1];
|
beforeEach(function () {
|
||||||
|
waitsFor(function () {
|
||||||
|
return hasLoaded;
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
|
||||||
|
runs(function () {
|
||||||
|
callback =
|
||||||
|
openmct.telemetry.subscribe.mostRecentCall.args[1];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it("subscribes to telemetry", function () {
|
|
||||||
expect(openmct.telemetry.subscribe).toHaveBeenCalledWith(
|
|
||||||
newDomainObject,
|
|
||||||
jasmine.any(Function)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("unsubscribes when scope is destroyed", function () {
|
it("uses LAD telemetry", function () {
|
||||||
expect(unsubscribe).not.toHaveBeenCalled();
|
expect(openmct.telemetry.request).toHaveBeenCalledWith(
|
||||||
|
newDomainObject,
|
||||||
// Find the $destroy listener and call it
|
{
|
||||||
$scope.$on.calls.forEach(function (call) {
|
strategy: 'latest',
|
||||||
if (call.args[0] === '$destroy') {
|
size: 1
|
||||||
call.args[1]();
|
}
|
||||||
}
|
);
|
||||||
|
expect(controller.getTime()).toEqual(prefix + 1434600258123);
|
||||||
|
expect(controller.getImageUrl()).toEqual('some/url');
|
||||||
});
|
});
|
||||||
expect(unsubscribe).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("exposes the latest telemetry values", function () {
|
|
||||||
// 06/18/2015 4:04am UTC
|
|
||||||
var testTimestamp = 1434600258123,
|
|
||||||
testUrl = "some/url",
|
|
||||||
nextTimestamp = 1434600259456, // 4:05.456
|
|
||||||
nextUrl = "some/other/url";
|
|
||||||
|
|
||||||
// Call back with telemetry data
|
it("exposes the latest telemetry values", function () {
|
||||||
callback({ timestamp: testTimestamp, value: testUrl });
|
callback({
|
||||||
|
timestamp: 1434600259456,
|
||||||
|
value: "some/other/url"
|
||||||
|
});
|
||||||
|
|
||||||
expect(controller.getTime()).toEqual(prefix + testTimestamp);
|
expect(controller.getTime()).toEqual(prefix + 1434600259456);
|
||||||
expect(controller.getImageUrl()).toEqual(testUrl);
|
expect(controller.getImageUrl()).toEqual("some/other/url");
|
||||||
|
});
|
||||||
|
|
||||||
callback({ timestamp: nextTimestamp, value: nextUrl });
|
it("allows updates to be paused and unpaused", function () {
|
||||||
|
var newTimestamp = 1434600259456,
|
||||||
|
newUrl = "some/other/url",
|
||||||
|
initialTimestamp = controller.getTime(),
|
||||||
|
initialUrl = controller.getImageUrl();
|
||||||
|
|
||||||
expect(controller.getTime()).toEqual(prefix + nextTimestamp);
|
expect(initialTimestamp).not.toBe(prefix + newTimestamp);
|
||||||
expect(controller.getImageUrl()).toEqual(nextUrl);
|
expect(initialUrl).not.toBe(newUrl);
|
||||||
});
|
expect(controller.paused()).toBeFalsy();
|
||||||
|
|
||||||
it("allows updates to be paused", function () {
|
controller.paused(true);
|
||||||
// 06/18/2015 4:04am UTC
|
expect(controller.paused()).toBeTruthy();
|
||||||
var testTimestamp = 1434600258123,
|
callback({ timestamp: newTimestamp, value: newUrl });
|
||||||
testUrl = "some/url",
|
|
||||||
nextTimestamp = 1434600259456, // 4:05.456
|
|
||||||
nextUrl = "some/other/url";
|
|
||||||
|
|
||||||
// Call back with telemetry data
|
expect(controller.getTime()).toEqual(initialTimestamp);
|
||||||
callback({ timestamp: testTimestamp, value: testUrl });
|
expect(controller.getImageUrl()).toEqual(initialUrl);
|
||||||
|
|
||||||
expect(controller.getTime()).toEqual(prefix + testTimestamp);
|
controller.paused(false);
|
||||||
expect(controller.getImageUrl()).toEqual(testUrl);
|
expect(controller.paused()).toBeFalsy();
|
||||||
|
expect(controller.getTime()).toEqual(prefix + newTimestamp);
|
||||||
|
expect(controller.getImageUrl()).toEqual(newUrl);
|
||||||
|
});
|
||||||
|
|
||||||
expect(controller.paused()).toBeFalsy();
|
it("subscribes to telemetry", function () {
|
||||||
controller.paused(true); // Pause!
|
expect(openmct.telemetry.subscribe).toHaveBeenCalledWith(
|
||||||
expect(controller.paused()).toBeTruthy();
|
newDomainObject,
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
callback({ timestamp: nextTimestamp, value: nextUrl });
|
it("unsubscribes when scope is destroyed", function () {
|
||||||
|
expect(unsubscribe).not.toHaveBeenCalled();
|
||||||
|
|
||||||
expect(controller.getTime()).toEqual(prefix + testTimestamp);
|
$scope.$on.calls.forEach(function (call) {
|
||||||
expect(controller.getImageUrl()).toEqual(testUrl);
|
if (call.args[0] === '$destroy') {
|
||||||
|
call.args[1]();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(unsubscribe).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("initially shows an empty string for date/time", function () {
|
it("initially shows an empty string for date/time", function () {
|
||||||
// Do not invoke callback...
|
|
||||||
expect(controller.getTime()).toEqual("");
|
expect(controller.getTime()).toEqual("");
|
||||||
expect(controller.getImageUrl()).toEqual("");
|
expect(controller.getImageUrl()).toEqual("");
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user