2015-09-02 15:57:52 -07:00
|
|
|
/*****************************************************************************
|
|
|
|
* 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";
|
|
|
|
|
|
|
|
var CONDUCTOR_HEIGHT = "100px",
|
|
|
|
TEMPLATE = [
|
2015-09-03 11:40:40 -07:00
|
|
|
'<div style=',
|
|
|
|
'"position: absolute; bottom: 0; width: 100%; ',
|
|
|
|
'overflow: hidden; ',
|
|
|
|
'height: ' + CONDUCTOR_HEIGHT + '">',
|
2015-09-03 15:13:03 -07:00
|
|
|
"<mct-include key=\"'time-controller'\" ng-model='conductor'>",
|
|
|
|
"</mct-include>",
|
2015-09-02 15:57:52 -07:00
|
|
|
'</div>'
|
2015-09-03 11:44:11 -07:00
|
|
|
].join(''),
|
|
|
|
GLOBAL_SHOWING = false;
|
2015-09-02 15:57:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ConductorRepresenter attaches the universal time conductor
|
|
|
|
* to views.
|
|
|
|
*
|
|
|
|
* @implements {Representer}
|
|
|
|
* @constructor
|
2015-09-04 15:44:18 -07:00
|
|
|
* @memberof platform/features/conductor
|
|
|
|
* @param {platform/features/conductor.ConductorService} conductorService
|
|
|
|
* service which provides the active time conductor
|
|
|
|
* @param $compile Angular's $compile
|
|
|
|
* @param {ViewDefinition[]} views all defined views
|
|
|
|
* @param {Scope} the scope of the representation
|
|
|
|
* @param element the jqLite-wrapped representation element
|
2015-09-02 15:57:52 -07:00
|
|
|
*/
|
2015-09-04 11:53:51 -07:00
|
|
|
function ConductorRepresenter(conductorService, $compile, views, scope, element) {
|
2015-09-10 10:16:28 -07:00
|
|
|
this.scope = scope;
|
2015-09-03 15:13:03 -07:00
|
|
|
this.conductorService = conductorService;
|
2015-09-02 15:57:52 -07:00
|
|
|
this.element = element;
|
|
|
|
this.views = views;
|
|
|
|
this.$compile = $compile;
|
|
|
|
}
|
|
|
|
|
2015-09-10 10:54:44 -07:00
|
|
|
// Combine start/end times into a single object
|
|
|
|
function bounds(start, end) {
|
|
|
|
return { start: start, end: end };
|
|
|
|
}
|
2015-09-10 10:16:28 -07:00
|
|
|
|
2015-09-03 15:13:03 -07:00
|
|
|
// Update the time conductor from the scope
|
2015-09-04 11:53:51 -07:00
|
|
|
function wireScope(conductor, conductorScope, repScope) {
|
2015-09-03 15:59:46 -07:00
|
|
|
function updateConductorOuter() {
|
2015-09-10 10:54:44 -07:00
|
|
|
conductor.queryStart(conductorScope.conductor.outer.start);
|
|
|
|
conductor.queryEnd(conductorScope.conductor.outer.end);
|
|
|
|
repScope.$broadcast(
|
|
|
|
'telemetry:query:bounds',
|
|
|
|
bounds(conductor.queryStart(), conductor.queryEnd())
|
|
|
|
);
|
2015-09-03 15:59:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateConductorInner() {
|
2015-09-10 10:54:44 -07:00
|
|
|
conductor.displayStart(conductorScope.conductor.inner.start);
|
|
|
|
conductor.displayEnd(conductorScope.conductor.inner.end);
|
|
|
|
repScope.$broadcast(
|
|
|
|
'telemetry:display:bounds',
|
|
|
|
bounds(conductor.displayStart(), conductor.displayEnd())
|
|
|
|
);
|
2015-09-03 15:13:03 -07:00
|
|
|
}
|
|
|
|
|
2015-09-04 11:53:51 -07:00
|
|
|
conductorScope.conductor = {
|
2015-09-10 10:54:44 -07:00
|
|
|
outer: bounds(conductor.queryStart(), conductor.queryEnd()),
|
|
|
|
inner: bounds(conductor.displayStart(), conductor.displayEnd())
|
2015-09-03 15:13:03 -07:00
|
|
|
};
|
|
|
|
|
2015-09-10 10:54:44 -07:00
|
|
|
conductorScope
|
|
|
|
.$watch('conductor.outer.start', updateConductorOuter);
|
|
|
|
conductorScope
|
|
|
|
.$watch('conductor.outer.end', updateConductorOuter);
|
|
|
|
conductorScope
|
|
|
|
.$watch('conductor.inner.start', updateConductorInner);
|
|
|
|
conductorScope
|
|
|
|
.$watch('conductor.inner.end', updateConductorInner);
|
2015-09-04 15:31:47 -07:00
|
|
|
|
|
|
|
repScope.$on('telemetry:view', updateConductorInner);
|
2015-09-04 11:53:51 -07:00
|
|
|
}
|
2015-09-03 15:13:03 -07:00
|
|
|
|
2015-09-10 10:16:28 -07:00
|
|
|
ConductorRepresenter.prototype.conductorScope = function (s) {
|
|
|
|
return (this.cScope = arguments.length > 0 ?
|
|
|
|
s : this.cScope);
|
|
|
|
};
|
|
|
|
|
2015-09-02 15:57:52 -07:00
|
|
|
// Handle a specific representation of a specific domain object
|
|
|
|
ConductorRepresenter.prototype.represent = function represent(representation, representedObject) {
|
2015-09-03 11:44:11 -07:00
|
|
|
this.destroy();
|
2015-09-02 15:57:52 -07:00
|
|
|
|
2015-09-03 11:44:11 -07:00
|
|
|
if (this.views.indexOf(representation) !== -1 && !GLOBAL_SHOWING) {
|
2015-09-04 11:53:51 -07:00
|
|
|
// Track original states
|
|
|
|
this.originalHeight = this.element.css('height');
|
|
|
|
this.hadAbs = this.element.hasClass('abs');
|
|
|
|
|
2015-09-02 15:57:52 -07:00
|
|
|
// Create a new scope for the conductor
|
2015-09-10 10:16:28 -07:00
|
|
|
this.conductorScope(this.scope.$new());
|
2015-09-04 12:44:49 -07:00
|
|
|
wireScope(
|
2015-09-04 11:53:51 -07:00
|
|
|
this.conductorService.getConductor(),
|
|
|
|
this.conductorScope(),
|
2015-09-10 10:16:28 -07:00
|
|
|
this.scope
|
2015-09-04 11:53:51 -07:00
|
|
|
);
|
2015-09-02 15:57:52 -07:00
|
|
|
this.conductorElement =
|
|
|
|
this.$compile(TEMPLATE)(this.conductorScope());
|
|
|
|
this.element.after(this.conductorElement[0]);
|
|
|
|
this.element.addClass('abs');
|
|
|
|
this.element.css('bottom', CONDUCTOR_HEIGHT);
|
2015-09-03 11:44:11 -07:00
|
|
|
GLOBAL_SHOWING = true;
|
2015-09-02 15:57:52 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Respond to the destruction of the current representation.
|
|
|
|
ConductorRepresenter.prototype.destroy = function destroy() {
|
2015-09-03 11:44:11 -07:00
|
|
|
// We may not have decided to show in the first place,
|
|
|
|
// so circumvent any unnecessary cleanup
|
2015-09-04 11:53:51 -07:00
|
|
|
if (!this.conductorElement) {
|
2015-09-03 11:44:11 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-02 15:57:52 -07:00
|
|
|
// Restore the original size of the mct-representation
|
|
|
|
if (!this.hadAbs) {
|
|
|
|
this.element.removeClass('abs');
|
|
|
|
}
|
|
|
|
this.element.css('height', this.originalHeight);
|
|
|
|
|
|
|
|
// ...and remove the conductor
|
|
|
|
if (this.conductorElement) {
|
|
|
|
this.conductorElement.remove();
|
|
|
|
this.conductorElement = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, destroy its scope
|
|
|
|
if (this.conductorScope()) {
|
|
|
|
this.conductorScope().$destroy();
|
|
|
|
this.conductorScope(undefined);
|
|
|
|
}
|
|
|
|
|
2015-09-03 11:44:11 -07:00
|
|
|
GLOBAL_SHOWING = false;
|
2015-09-02 15:57:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return ConductorRepresenter;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|