diff --git a/demo/bundle.js b/demo/bundle.js new file mode 100644 index 0000000000..c7a3bd0f75 --- /dev/null +++ b/demo/bundle.js @@ -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" + } + ] + } + }); +}); diff --git a/demo/src/ConductorServiceDecorator.js b/demo/src/ConductorServiceDecorator.js new file mode 100644 index 0000000000..8f58219172 --- /dev/null +++ b/demo/src/ConductorServiceDecorator.js @@ -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; + } +); \ No newline at end of file diff --git a/demo/src/DemoConductorRepresenter.js b/demo/src/DemoConductorRepresenter.js new file mode 100644 index 0000000000..b0080ed390 --- /dev/null +++ b/demo/src/DemoConductorRepresenter.js @@ -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; + }); diff --git a/demo/src/DemoInitializer.js b/demo/src/DemoInitializer.js new file mode 100644 index 0000000000..4cb2e97fe5 --- /dev/null +++ b/demo/src/DemoInitializer.js @@ -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; + } +); diff --git a/example/msl/src/RemsTelemetryModelProvider.js b/example/msl/src/RemsTelemetryModelProvider.js index cf45b22d4e..382b8931f5 100644 --- a/example/msl/src/RemsTelemetryModelProvider.js +++ b/example/msl/src/RemsTelemetryModelProvider.js @@ -50,6 +50,7 @@ define( models[makeId(measurement)] = { type: "msl.measurement", name: measurement.name, + showConductor: true, telemetry: { key: measurement.identifier, ranges: [{ diff --git a/example/msl/src/RemsTelemetryServerAdapter.js b/example/msl/src/RemsTelemetryServerAdapter.js index 7ccb25f07d..f2dc9ac88b 100644 --- a/example/msl/src/RemsTelemetryServerAdapter.js +++ b/example/msl/src/RemsTelemetryServerAdapter.js @@ -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 diff --git a/main.js b/main.js index 33e45c0125..f2913d540c 100644 --- a/main.js +++ b/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'; diff --git a/platform/features/conductor/bundle.js b/platform/features/conductor/bundle.js index 9987be5c68..9661f668df 100644 --- a/platform/features/conductor/bundle.js +++ b/platform/features/conductor/bundle.js @@ -57,11 +57,10 @@ define([ "depends": [ "conductorService" ] - } - ], - "services": [ + }, { - "key": "conductorService", + "provides": "conductorService", + "type": "provider", "implementation": ConductorService, "depends": [ "now",