[Time Controller] Simplify ConductorRepresenter

WTD-1515
This commit is contained in:
Victor Woeltjen 2015-09-04 11:53:51 -07:00
parent 8a76c3a425
commit 5c1d209eff

View File

@ -46,75 +46,75 @@ define(
* @implements {Representer} * @implements {Representer}
* @constructor * @constructor
*/ */
function ConductorRepresenter($interval, conductorService, $compile, views, scope, element) { function ConductorRepresenter(conductorService, $compile, views, scope, element) {
var conductorScope; var conductorScope;
// Angular doesn't like objects to retain references to scope // Angular doesn't like objects to retain references to scopes
this.getScope = function () { return scope; }; this.getScope = function () {
return scope;
};
this.conductorScope = function (s) { this.conductorScope = function (s) {
return (conductorScope = arguments.length > 0 ? s : conductorScope); return (conductorScope = arguments.length > 0 ? s : conductorScope);
}; };
this.conductorService = conductorService; this.conductorService = conductorService;
this.element = element; this.element = element;
this.showing = false;
this.views = views; this.views = views;
this.$compile = $compile; this.$compile = $compile;
this.$interval = $interval;
this.originalHeight = element.css('height');
this.hadAbs = element.hasClass('abs');
} }
// Update the time conductor from the scope // Update the time conductor from the scope
ConductorRepresenter.prototype.wireScope = function () { function wireScope(conductor, conductorScope, repScope) {
var scope = this.conductorScope(),
conductor = this.conductorService.getConductor(),
self = this;
function updateConductorOuter() { function updateConductorOuter() {
conductor.queryStart(scope.conductor.outer[0]); conductor.queryStart(conductorScope.conductor.outer[0]);
conductor.queryEnd(scope.conductor.outer[1]); conductor.queryEnd(conductorScope.conductor.outer[1]);
self.getScope().$broadcast('telemetry:query:bounds', { repScope.$broadcast('telemetry:query:bounds', {
start: conductor.queryStart(), start: conductor.queryStart(),
end: conductor.queryEnd() end: conductor.queryEnd()
}); });
} }
function updateConductorInner() { function updateConductorInner() {
conductor.displayStart(scope.conductor.inner[0]); conductor.displayStart(conductorScope.conductor.inner[0]);
conductor.displayEnd(scope.conductor.inner[1]); conductor.displayEnd(conductorScope.conductor.inner[1]);
self.getScope().$broadcast('telemetry:display:bounds', { repScope.$broadcast('telemetry:display:bounds', {
start: conductor.displayStart(), start: conductor.displayStart(),
end: conductor.displayEnd() end: conductor.displayEnd()
}); });
} }
scope.conductor = { conductorScope.conductor = {
outer: [ conductor.queryStart(), conductor.queryEnd() ], outer: [ conductor.queryStart(), conductor.queryEnd() ],
inner: [ conductor.displayStart(), conductor.displayEnd() ] inner: [ conductor.displayStart(), conductor.displayEnd() ]
}; };
scope.$watch('conductor.outer[0]', updateConductorOuter); conductorScope.$watch('conductor.outer[0]', updateConductorOuter);
scope.$watch('conductor.outer[1]', updateConductorOuter); conductorScope.$watch('conductor.outer[1]', updateConductorOuter);
scope.$watch('conductor.inner[0]', updateConductorInner); conductorScope.$watch('conductor.inner[0]', updateConductorInner);
scope.$watch('conductor.inner[1]', updateConductorInner); conductorScope.$watch('conductor.inner[1]', updateConductorInner);
}; }
// Handle a specific representation of a specific domain object // Handle a specific representation of a specific domain object
ConductorRepresenter.prototype.represent = function represent(representation, representedObject) { ConductorRepresenter.prototype.represent = function represent(representation, representedObject) {
this.destroy(); this.destroy();
if (this.views.indexOf(representation) !== -1 && !GLOBAL_SHOWING) { if (this.views.indexOf(representation) !== -1 && !GLOBAL_SHOWING) {
// Track original states
this.originalHeight = this.element.css('height');
this.hadAbs = this.element.hasClass('abs');
// Create a new scope for the conductor // Create a new scope for the conductor
this.conductorScope(this.getScope().$new()); this.conductorScope(this.getScope().$new());
this.wireScope(); this.wireScope(
this.conductorService.getConductor(),
this.conductorScope(),
this.getScope()
);
this.conductorElement = this.conductorElement =
this.$compile(TEMPLATE)(this.conductorScope()); this.$compile(TEMPLATE)(this.conductorScope());
this.element.after(this.conductorElement[0]); this.element.after(this.conductorElement[0]);
this.element.addClass('abs'); this.element.addClass('abs');
this.element.css('bottom', CONDUCTOR_HEIGHT); this.element.css('bottom', CONDUCTOR_HEIGHT);
this.showing = true;
GLOBAL_SHOWING = true; GLOBAL_SHOWING = true;
} }
}; };
@ -123,7 +123,7 @@ define(
ConductorRepresenter.prototype.destroy = function destroy() { ConductorRepresenter.prototype.destroy = function destroy() {
// We may not have decided to show in the first place, // We may not have decided to show in the first place,
// so circumvent any unnecessary cleanup // so circumvent any unnecessary cleanup
if (!this.showing) { if (!this.conductorElement) {
return; return;
} }
@ -145,7 +145,6 @@ define(
this.conductorScope(undefined); this.conductorScope(undefined);
} }
this.showing = false;
GLOBAL_SHOWING = false; GLOBAL_SHOWING = false;
}; };