mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 14:18:16 +00:00
[Examples] Modified MSL data source to use a single cached connection. Fixes #1480
This commit is contained in:
@ -92,7 +92,7 @@ define([
|
|||||||
{
|
{
|
||||||
"key":"rems.adapter",
|
"key":"rems.adapter",
|
||||||
"implementation": RemsTelemetryServerAdapter,
|
"implementation": RemsTelemetryServerAdapter,
|
||||||
"depends": ["$q", "$http", "$log", "REMS_WS_URL"]
|
"depends": ["$http", "$log", "REMS_WS_URL"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"components": [
|
"components": [
|
||||||
|
@ -42,14 +42,12 @@ define(
|
|||||||
* @param REMS_WS_URL The location of the REMS telemetry data.
|
* @param REMS_WS_URL The location of the REMS telemetry data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function RemsTelemetryServerAdapter($q, $http, $log, REMS_WS_URL) {
|
function RemsTelemetryServerAdapter($http, $log, REMS_WS_URL) {
|
||||||
this.localDataURI = module.uri.substring(0, module.uri.lastIndexOf('/') + 1) + LOCAL_DATA;
|
this.localDataURI = module.uri.substring(0, module.uri.lastIndexOf('/') + 1) + LOCAL_DATA;
|
||||||
this.deferreds = {};
|
|
||||||
this.REMS_WS_URL = REMS_WS_URL;
|
this.REMS_WS_URL = REMS_WS_URL;
|
||||||
this.$q = $q;
|
|
||||||
this.$http = $http;
|
this.$http = $http;
|
||||||
this.$log = $log;
|
this.$log = $log;
|
||||||
this.cache = undefined;
|
this.promise = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,15 +63,10 @@ define(
|
|||||||
*/
|
*/
|
||||||
RemsTelemetryServerAdapter.prototype.requestHistory = function(request) {
|
RemsTelemetryServerAdapter.prototype.requestHistory = function(request) {
|
||||||
var self = this,
|
var self = this,
|
||||||
id = request.key,
|
id = request.key;
|
||||||
deferred = this.$q.defer();
|
|
||||||
|
|
||||||
function processResponse(response){
|
function processResponse(response){
|
||||||
var data = [];
|
var data = [];
|
||||||
/*
|
|
||||||
* Currently all data is returned for entire history of the mission. Cache response to avoid unnecessary re-queries.
|
|
||||||
*/
|
|
||||||
self.cache = response;
|
|
||||||
/*
|
/*
|
||||||
* History data is organised by Sol. Iterate over sols...
|
* History data is organised by Sol. Iterate over sols...
|
||||||
*/
|
*/
|
||||||
@ -110,17 +103,15 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function packageAndResolve(results){
|
function packageAndResolve(results){
|
||||||
deferred.resolve({id: id, values: results});
|
return {id: id, values: results};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.$q.when(this.cache || this.$http.get(this.REMS_WS_URL))
|
return (this.promise = this.promise || this.$http.get(this.REMS_WS_URL))
|
||||||
.catch(fallbackToLocal)
|
.catch(fallbackToLocal)
|
||||||
.then(processResponse)
|
.then(processResponse)
|
||||||
.then(filterResults)
|
.then(filterResults)
|
||||||
.then(packageAndResolve);
|
.then(packageAndResolve);
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,7 +123,6 @@ define(
|
|||||||
* @returns {Promise | Array<RemsTelemetryValue>} that resolves with an Array of {@link RemsTelemetryValue} objects for the request data key.
|
* @returns {Promise | Array<RemsTelemetryValue>} that resolves with an Array of {@link RemsTelemetryValue} objects for the request data key.
|
||||||
*/
|
*/
|
||||||
RemsTelemetryServerAdapter.prototype.history = function(request) {
|
RemsTelemetryServerAdapter.prototype.history = function(request) {
|
||||||
var id = request.key;
|
|
||||||
return this.requestHistory(request);
|
return this.requestHistory(request);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user