From 2a193943346dd921794ba938c510df805dd10ae8 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 19 Jul 2016 19:54:52 -0700 Subject: [PATCH] Added compatibility layer to support existing plots and historical tables --- main.js | 1 + .../conductor-v2-compatibility/bundle.js | 55 ++++++++++++++ .../src/ConductorRepresenter.js | 75 +++++++++++++++++++ .../src/ConductorTelemetryDecorator.js | 71 ++++++++++++++++++ platform/features/plot/src/PlotController.js | 19 +++-- .../controllers/HistoricalTableController.js | 22 ++++++ .../controllers/TelemetryTableController.js | 5 -- 7 files changed, 236 insertions(+), 12 deletions(-) create mode 100644 platform/features/conductor-v2-compatibility/bundle.js create mode 100644 platform/features/conductor-v2-compatibility/src/ConductorRepresenter.js create mode 100644 platform/features/conductor-v2-compatibility/src/ConductorTelemetryDecorator.js diff --git a/main.js b/main.js index 5873209adea..19ad4c6118e 100644 --- a/main.js +++ b/main.js @@ -91,6 +91,7 @@ define([ './platform/features/plot/bundle', './platform/features/timeline/bundle', './platform/features/conductor-v2/bundle', + './platform/features/conductor-v2-compatibility/bundle', './platform/features/table/bundle', './platform/forms/bundle', './platform/identity/bundle', diff --git a/platform/features/conductor-v2-compatibility/bundle.js b/platform/features/conductor-v2-compatibility/bundle.js new file mode 100644 index 00000000000..967a1894889 --- /dev/null +++ b/platform/features/conductor-v2-compatibility/bundle.js @@ -0,0 +1,55 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + +define([ + "./src/ConductorTelemetryDecorator", + "./src/ConductorRepresenter", + 'legacyRegistry' +], function ( + ConductorTelemetryDecorator, + ConductorRepresenter, + legacyRegistry +) { + + legacyRegistry.register("platform/features/conductor-v2-compatibility", { + "extensions": { + "representers": [ + { + "implementation": ConductorRepresenter, + "depends": [ + "timeConductor" + ] + } + ], + "components": [ + { + "type": "decorator", + "provides": "telemetryService", + "implementation": ConductorTelemetryDecorator, + "depends": [ + "timeConductor" + ] + } + ] + } + }); +}); diff --git a/platform/features/conductor-v2-compatibility/src/ConductorRepresenter.js b/platform/features/conductor-v2-compatibility/src/ConductorRepresenter.js new file mode 100644 index 00000000000..973a0e8ba4f --- /dev/null +++ b/platform/features/conductor-v2-compatibility/src/ConductorRepresenter.js @@ -0,0 +1,75 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + +define( + [], + function () { + + function ConductorRepresenter( + conductor, + scope, + element + ) { + this.conductor = conductor; + this.scope = scope; + this.element = element; + + this.boundsListener = this.boundsListener.bind(this); + this.timeSystemListener = this.timeSystemListener.bind(this); + } + + ConductorRepresenter.prototype.boundsListener = function (bounds) { + this.scope.$broadcast('telemetry:display:bounds', { + start: bounds.start, + end: bounds.end, + domain: this.conductor.timeSystem().metadata.key + }, this.conductor.follow()); + }; + + ConductorRepresenter.prototype.timeSystemListener = function (timeSystem) { + var bounds = this.conductor.bounds(); + this.scope.$broadcast('telemetry:display:bounds', { + start: bounds.start, + end: bounds.end, + domain: timeSystem.metadata.key + }); + }; + + // Handle a specific representation of a specific domain object + ConductorRepresenter.prototype.represent = function represent(representation) { + if (representation.key === 'browse-object') { + this.destroy(); + + this.conductor.on("bounds", this.boundsListener); + this.conductor.on("timeSystem", this.timeSystemListener); + } + }; + + ConductorRepresenter.prototype.destroy = function destroy() { + this.conductor.off("bounds", this.boundsListener); + this.conductor.off("timeSystem", this.timeSystemListener); + }; + + return ConductorRepresenter; + } +); + diff --git a/platform/features/conductor-v2-compatibility/src/ConductorTelemetryDecorator.js b/platform/features/conductor-v2-compatibility/src/ConductorTelemetryDecorator.js new file mode 100644 index 00000000000..e661091b54d --- /dev/null +++ b/platform/features/conductor-v2-compatibility/src/ConductorTelemetryDecorator.js @@ -0,0 +1,71 @@ +/***************************************************************************** + * 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. + *****************************************************************************/ + +define( + function () { + + /** + * Decorates the `telemetryService` such that requests are + * mediated by the time conductor. This is a modified version of the + * decorator used in the old TimeConductor that integrates with the + * new TimeConductor API. + * + * @constructor + * @memberof platform/features/conductor + * @implements {TelemetryService} + * @param {platform/features/conductor.TimeConductor} conductor + * the service which exposes the global time conductor + * @param {TelemetryService} telemetryService the decorated service + */ + function ConductorTelemetryDecorator(conductor, telemetryService) { + this.conductor = conductor; + this.telemetryService = telemetryService; + } + + ConductorTelemetryDecorator.prototype.amendRequests = function (requests) { + var bounds = this.conductor.bounds(), + timeSystem = this.conductor.timeSystem(); + + function amendRequest(request) { + request = request || {}; + request.start = bounds.start; + request.end = bounds.end; + request.domain = timeSystem.metadata.key; + return request; + } + + return (requests || []).map(amendRequest); + }; + + ConductorTelemetryDecorator.prototype.requestTelemetry = function (requests) { + return this.telemetryService + .requestTelemetry(this.amendRequests(requests)); + }; + + ConductorTelemetryDecorator.prototype.subscribe = function (callback, requests) { + return this.telemetryService + .subscribe(callback, requests); + }; + + return ConductorTelemetryDecorator; + } +); diff --git a/platform/features/plot/src/PlotController.js b/platform/features/plot/src/PlotController.js index 2525657501d..1168c7b5731 100644 --- a/platform/features/plot/src/PlotController.js +++ b/platform/features/plot/src/PlotController.js @@ -227,13 +227,18 @@ define( } // Respond to a display bounds change (requery for data) - function changeDisplayBounds(event, bounds) { - var domainAxis = $scope.axes[0]; - - domainAxis.chooseOption(bounds.domain); - updateDomainFormat(); - setBasePanZoom(bounds); - requery(); + function changeDisplayBounds(event, bounds, follow) { + //'hack' for follow mode + if (follow === true){ + setBasePanZoom(bounds); + } else { + var domainAxis = $scope.axes[0]; + + domainAxis.chooseOption(bounds.domain); + updateDomainFormat(); + setBasePanZoom(bounds); + requery(); + } } this.modeOptions = new PlotModeOptions([], subPlotFactory); diff --git a/platform/features/table/src/controllers/HistoricalTableController.js b/platform/features/table/src/controllers/HistoricalTableController.js index 5441d5587fc..c6b05ba5369 100644 --- a/platform/features/table/src/controllers/HistoricalTableController.js +++ b/platform/features/table/src/controllers/HistoricalTableController.js @@ -63,6 +63,28 @@ define( this.$scope.loading = false; }; + /** + * @private + */ + HistoricalTableController.prototype.registerChangeListeners = function () { + TableController.prototype.registerChangeListeners.call(this); + //Change of bounds in time conductor + this.changeListeners.push(this.$scope.$on('telemetry:display:bounds', + this.boundsChange.bind(this)) + ); + }; + + /** + * @private + */ + HistoricalTableController.prototype.boundsChange = function (event, bounds, follow) { + // If in follow mode, don't bother re-subscribing, data will be + // received from existing subscription. + if (follow!==true) { + this.subscribe(); + } + }; + /** * Processes an array of objects, formatting the telemetry available * for them and setting it on scope when done diff --git a/platform/features/table/src/controllers/TelemetryTableController.js b/platform/features/table/src/controllers/TelemetryTableController.js index 459a61c8b07..6145155a665 100644 --- a/platform/features/table/src/controllers/TelemetryTableController.js +++ b/platform/features/table/src/controllers/TelemetryTableController.js @@ -96,11 +96,6 @@ define( } }) ); - - //Change of bounds in time conductor - this.changeListeners.push(this.$scope.$on('telemetry:display:bounds', - this.subscribe.bind(this)) - ); }; /**