diff --git a/demo/src/DemoConductorRepresenter.js b/demo/src/conductor/ConductorPolicy.js similarity index 57% rename from demo/src/DemoConductorRepresenter.js rename to demo/src/conductor/ConductorPolicy.js index b0080ed390..20b8de910b 100644 --- a/demo/src/DemoConductorRepresenter.js +++ b/demo/src/conductor/ConductorPolicy.js @@ -22,22 +22,16 @@ /*global define*/ define( - [ - "zepto" - ], - function ($) { + [], + function () { "use strict"; - function DemoConductorRepresenter( - $q, - views, - scope, - element - ) { + /** + * A policy that will test whether a given object OR all of its + * support historical telemetry + */ + function ConductorPolicy($q) { this.$q = $q; - this.scope = scope; - this.element = element; - this.views = views; } function fastPromise(value) { @@ -55,47 +49,33 @@ define( } /** - * Test whether the given object OR all of its descendants have the - * conductor enabled - * @param object - * @returns {*} + * @param {DomainObject} candidate + * @returns {Promise} a promise resolved with true if the object + * supports historical telemetry */ - DemoConductorRepresenter.prototype.showConductor = function (object) { + ConductorPolicy.prototype.allow = function (candidate) { var self = this; //Does the object itself allow the time conductor? - if (object.getModel().showConductor) { - return fastPromise(object.getModel().showConductor); + if (candidate.hasCapability('telemetry') && candidate.getCapability('telemetry').getMetadata().historical) { + return fastPromise(true); } 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); + if (candidate.hasCapability('composition')) { + return candidate.useCapability('composition').then(function (composition) { + if (composition.length === 0 ) { + return fastPromise(false); + } else { + return self.$q.all(composition.map(self.allow.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; - }); + return ConductorPolicy; + } +); \ No newline at end of file diff --git a/demo/src/ConductorServiceDecorator.js b/demo/src/conductor/ConductorServiceDecorator.js similarity index 88% rename from demo/src/ConductorServiceDecorator.js rename to demo/src/conductor/ConductorServiceDecorator.js index 8f58219172..cb3824935e 100644 --- a/demo/src/ConductorServiceDecorator.js +++ b/demo/src/conductor/ConductorServiceDecorator.js @@ -27,15 +27,14 @@ define( "use strict"; function ConductorServiceDecorator(conductorService) { + this.conductorService = conductorService; conductorService.getConductor().displayStart(Date.UTC(2012,8,7)); - - return { - getConductor: function () { - return conductorService.getConductor(); - } - }; } + ConductorServiceDecorator.prototype.getConductor = function () { + return this.conductorService.getConductor(); + }; + return ConductorServiceDecorator; } ); \ No newline at end of file diff --git a/demo/src/conductor/DemoConductorRepresenter.js b/demo/src/conductor/DemoConductorRepresenter.js new file mode 100644 index 0000000000..9db16360a3 --- /dev/null +++ b/demo/src/conductor/DemoConductorRepresenter.js @@ -0,0 +1,72 @@ +/***************************************************************************** + * 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", + "./ConductorPolicy", + "../../platform/features/conductor/src/ConductorRepresenter" + ], + function ($, ConductorPolicy, ConductorRepresenter) { + "use strict"; + + function DemoConductorRepresenter( + $q, + $compile, + conductorService, + views, + throttle, + scope, + element + ) { + this.scope = scope; + this.element = element; + this.views = views; + this.conductorPolicy = new ConductorPolicy($q); + + ConductorRepresenter.call(this, + throttle, + conductorService, + $compile, + views, + scope, + element); + } + + DemoConductorRepresenter.prototype = Object.create(ConductorRepresenter.prototype); + + DemoConductorRepresenter.prototype.represent = function (representation, representedObject) { + var self = this; + if (this.views.indexOf(representation) !== -1) { + this.conductorPolicy.allow(representedObject).then(function (show) { + if (show && representation.type !== 'folder') { + ConductorRepresenter.prototype.represent.call(self, representation, representedObject); + } + }); + } + }; + + DemoConductorRepresenter.prototype.destroy = function destroy() {}; + + return DemoConductorRepresenter; + }); diff --git a/demo/src/conductor/DemoTelemetryDecorator.js b/demo/src/conductor/DemoTelemetryDecorator.js new file mode 100644 index 0000000000..909269e5ac --- /dev/null +++ b/demo/src/conductor/DemoTelemetryDecorator.js @@ -0,0 +1,54 @@ +/***************************************************************************** + * 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 DemoTelemetryDecorator(telemetryService) { + this.telemetryService = telemetryService; + } + + function processRequest(request ) { + if (!request.historical) { + ['start', 'end', 'domain'].forEach(function (attribute){ + delete request[attribute]; + }); + } + return request; + } + + DemoTelemetryDecorator.prototype.requestTelemetry = function (requests) { + return this.telemetryService + .requestTelemetry(requests.map(processRequest)); + }; + + DemoTelemetryDecorator.prototype.subscribe = function (callback, requests) { + return this.telemetryService + .subscribe(callback, requests.map(processRequest)); + }; + + return DemoTelemetryDecorator; + } +); \ No newline at end of file