mirror of
https://github.com/nasa/openmct.git
synced 2025-03-18 01:55:17 +00:00
Added local caching of query responses for REMS data. Also added code to mux simultaneous initial requests for data into a single http request.
This commit is contained in:
parent
9e5689f7dd
commit
b3981e6158
57
demo/bundle.js
Normal file
57
demo/bundle.js
Normal file
@ -0,0 +1,57 @@
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
define([
|
||||
"./src/DemoConductorRepresenter",
|
||||
"./src/DemoInitializer",
|
||||
"./src/ConductorServiceDecorator",
|
||||
'legacyRegistry'
|
||||
], function (
|
||||
DemoConductorRepresenter,
|
||||
DemoInitializer,
|
||||
ConductorServiceDecorator,
|
||||
legacyRegistry
|
||||
) {
|
||||
"use strict";
|
||||
|
||||
legacyRegistry.register("demo", {
|
||||
"name": "Live Demo configuration",
|
||||
"description": "Adds demo data types, and demo-specific behavior",
|
||||
"extensions": {
|
||||
"representers": [
|
||||
{
|
||||
"implementation": DemoConductorRepresenter,
|
||||
"depends": ["$q", "views[]"],
|
||||
"priority": "fallback"
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"implementation": ConductorServiceDecorator,
|
||||
"provides": "conductorService",
|
||||
"type": "decorator"
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
});
|
41
demo/src/ConductorServiceDecorator.js
Normal file
41
demo/src/ConductorServiceDecorator.js
Normal file
@ -0,0 +1,41 @@
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
/*global define,Promise*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
function ConductorServiceDecorator(conductorService) {
|
||||
conductorService.getConductor().displayStart(Date.UTC(2012,8,7));
|
||||
|
||||
return {
|
||||
getConductor: function () {
|
||||
return conductorService.getConductor();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return ConductorServiceDecorator;
|
||||
}
|
||||
);
|
101
demo/src/DemoConductorRepresenter.js
Normal file
101
demo/src/DemoConductorRepresenter.js
Normal file
@ -0,0 +1,101 @@
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[
|
||||
"zepto"
|
||||
],
|
||||
function ($) {
|
||||
"use strict";
|
||||
|
||||
function DemoConductorRepresenter(
|
||||
$q,
|
||||
views,
|
||||
scope,
|
||||
element
|
||||
) {
|
||||
this.$q = $q;
|
||||
this.scope = scope;
|
||||
this.element = element;
|
||||
this.views = views;
|
||||
}
|
||||
|
||||
function fastPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return fastPromise(callback(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function and(array) {
|
||||
return array.reduce(function (previous, next) {
|
||||
return previous && next;
|
||||
}, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given object OR all of its descendants have the
|
||||
* conductor enabled
|
||||
* @param object
|
||||
* @returns {*}
|
||||
*/
|
||||
DemoConductorRepresenter.prototype.showConductor = function (object) {
|
||||
var self = this;
|
||||
|
||||
//Does the object itself allow the time conductor?
|
||||
if (object.getModel().showConductor) {
|
||||
return fastPromise(object.getModel().showConductor);
|
||||
} else {
|
||||
//If not, do all of its constituents allow time conductor?
|
||||
if (object.hasCapability('composition')) {
|
||||
return object.useCapability('composition').then(function (composition) {
|
||||
return self.$q.all(composition.map(self.showConductor.bind(self))).then(and);
|
||||
});
|
||||
} else {
|
||||
//if no, hide time conductor
|
||||
return fastPromise(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param representation
|
||||
* @param representedObject
|
||||
*/
|
||||
DemoConductorRepresenter.prototype.represent = function (representation, representedObject) {
|
||||
if (this.views.indexOf(representation) !== -1) {
|
||||
this.showConductor(representedObject).then(function (show) {
|
||||
if (!show || representation.type === 'folder') {
|
||||
$('.l-time-controller').hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
DemoConductorRepresenter.prototype.destroy = function destroy() {
|
||||
|
||||
};
|
||||
|
||||
return DemoConductorRepresenter;
|
||||
});
|
33
demo/src/DemoInitializer.js
Normal file
33
demo/src/DemoInitializer.js
Normal file
@ -0,0 +1,33 @@
|
||||
/*****************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
function (){
|
||||
"use strict";
|
||||
|
||||
function DemoInitializer(conductorService) {
|
||||
conductorService.getConductor().displayStart(Date.UTC(2012,8,7));
|
||||
}
|
||||
return DemoInitializer;
|
||||
}
|
||||
);
|
@ -50,6 +50,7 @@ define(
|
||||
models[makeId(measurement)] = {
|
||||
type: "msl.measurement",
|
||||
name: measurement.name,
|
||||
showConductor: true,
|
||||
telemetry: {
|
||||
key: measurement.identifier,
|
||||
ranges: [{
|
||||
|
@ -44,7 +44,7 @@ define(
|
||||
*/
|
||||
function RemsTelemetryServerAdapter($q, $http, $log, REMS_WS_URL) {
|
||||
this.localDataURI = module.uri.substring(0, module.uri.lastIndexOf('/') + 1) + LOCAL_DATA;
|
||||
this.deferreds = {};
|
||||
this.requestDeferred = undefined;
|
||||
this.REMS_WS_URL = REMS_WS_URL;
|
||||
this.$q = $q;
|
||||
this.$http = $http;
|
||||
@ -70,10 +70,6 @@ define(
|
||||
|
||||
function processResponse(response){
|
||||
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...
|
||||
*/
|
||||
@ -109,20 +105,42 @@ define(
|
||||
});
|
||||
}
|
||||
|
||||
function packageAndResolve(results){
|
||||
deferred.resolve({id: id, values: results});
|
||||
function packageResults(results){
|
||||
return {id: id, values: results};
|
||||
}
|
||||
|
||||
|
||||
this.$q.when(this.cache || this.$http.get(this.REMS_WS_URL))
|
||||
return this.request()
|
||||
.catch(fallbackToLocal)
|
||||
.then(processResponse)
|
||||
.then(filterResults)
|
||||
.then(packageAndResolve);
|
||||
|
||||
return deferred.promise;
|
||||
.then(packageResults);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a request for data, or uses local cache (if available).
|
||||
* Allows only one HTTP request at a time.
|
||||
* @private
|
||||
* @returns {Function|promise}
|
||||
*/
|
||||
RemsTelemetryServerAdapter.prototype.request = function () {
|
||||
var self = this;
|
||||
|
||||
if (this.requestDeferred) {
|
||||
return this.requestDeferred.promise;
|
||||
} else {
|
||||
this.requestDeferred = this.$q.defer();
|
||||
this.$q.when(this.cache || this.$http.get(this.REMS_WS_URL))
|
||||
.then(function(response){
|
||||
self.cache = response;
|
||||
self.requestDeferred.resolve(response);
|
||||
self.requestDeferred = undefined;
|
||||
return response;
|
||||
})
|
||||
.catch(this.requestDeferred.reject);
|
||||
return this.requestDeferred.promise;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests historical telemetry for the named data attribute. In
|
||||
* the case of REMS, this data source exposes multiple different
|
||||
|
6
main.js
6
main.js
@ -80,6 +80,7 @@ define([
|
||||
'./platform/features/plot/bundle',
|
||||
'./platform/features/timeline/bundle',
|
||||
'./platform/features/table/bundle',
|
||||
'./platform/features/conductor/bundle',
|
||||
'./platform/forms/bundle',
|
||||
'./platform/identity/bundle',
|
||||
'./platform/persistence/aggregator/bundle',
|
||||
@ -93,7 +94,10 @@ define([
|
||||
|
||||
'./example/imagery/bundle',
|
||||
'./example/eventGenerator/bundle',
|
||||
'./example/generator/bundle'
|
||||
'./example/generator/bundle',
|
||||
'./example/msl/bundle',
|
||||
|
||||
'./demo/bundle',
|
||||
], function (Main, legacyRegistry) {
|
||||
'use strict';
|
||||
|
||||
|
@ -57,11 +57,10 @@ define([
|
||||
"depends": [
|
||||
"conductorService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"services": [
|
||||
},
|
||||
{
|
||||
"key": "conductorService",
|
||||
"provides": "conductorService",
|
||||
"type": "provider",
|
||||
"implementation": ConductorService,
|
||||
"depends": [
|
||||
"now",
|
||||
|
Loading…
x
Reference in New Issue
Block a user