Skip to content

Commit

Permalink
Refactoring based on feedback
Browse files Browse the repository at this point in the history
Refactoring controller

Migrating functions off controller onto service class

Simplified modes

Adding comments

Removed unnecessary validation

Fixing testing issues
  • Loading branch information
akhenry committed Aug 23, 2016
1 parent 4ae6da0 commit 4cf6126
Show file tree
Hide file tree
Showing 20 changed files with 564 additions and 649 deletions.
5 changes: 1 addition & 4 deletions example/localTimeSystem/src/LADTickSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ define(['../../../platform/features/conductor-v2/conductor/src/timeSystems/Local

this.metadata = {
key: 'test-lad',
mode: 'LAD',
cssclass: 'icon-clock',
label: 'Latest Available Data',
name: 'Latest available data',
Expand All @@ -38,9 +39,5 @@ define(['../../../platform/features/conductor-v2/conductor/src/timeSystems/Local
}
LADTickSource.prototype = Object.create(LocalClock.prototype);

LADTickSource.prototype.type = function () {
return 'data';
};

return LADTickSource;
});
6 changes: 3 additions & 3 deletions platform/features/conductor-v2/compatibility/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ define([
"key": "conductorService",
"implementation": ConductorService,
"depends": [
"timeConductorService"
"timeConductor"
]
}
],
"representers": [
{
"implementation": ConductorRepresenter,
"depends": [
"timeConductorService"
"timeConductor"
]
}
],
Expand All @@ -57,7 +57,7 @@ define([
"provides": "telemetryService",
"implementation": ConductorTelemetryDecorator,
"depends": [
"timeConductorService"
"timeConductor"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ define(
* @constructor
*/
function ConductorRepresenter(
conductorService,
timeConductor,
scope,
element
) {
this.conductor = conductorService.conductor();
this.conductor = timeConductor;
this.scope = scope;
this.element = element;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ define(
* the service which exposes the global time conductor
* @param {TelemetryService} telemetryService the decorated service
*/
function ConductorTelemetryDecorator(conductorService, telemetryService) {
this.conductor = conductorService.conductor();
function ConductorTelemetryDecorator(timeConductor, telemetryService) {
this.conductor = timeConductor;
this.telemetryService = telemetryService;

this.amendRequests = ConductorTelemetryDecorator.prototype.amendRequests.bind(this);
Expand Down
28 changes: 15 additions & 13 deletions platform/features/conductor-v2/conductor/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
*****************************************************************************/

define([
"./src/ui/TimeConductorService",
"./src/ui/TimeConductorViewService",
"./src/ui/TimeConductorController",
"./src/ui/MCTConductorAxis",
"./src/TimeConductor",
"./src/ui/MctConductorAxis",
"./src/ui/NumberFormat",
"text!./res/templates/time-conductor.html",
"text!./res/templates/mode-selector/mode-selector.html",
"text!./res/templates/mode-selector/mode-menu.html",
'legacyRegistry'
], function (
TimeConductorService,
TimeConductorViewService,
TimeConductorController,
TimeConductor,
MCTConductorAxis,
NumberFormat,
timeConductorTemplate,
Expand All @@ -45,16 +47,15 @@ define([
"services": [
{
"key": "timeConductor",
"implementation": function (timeConductorService) {
return timeConductorService.conductor();
},
"depends": [
"timeConductorService"
]
"implementation": TimeConductor
},
{
"key": "timeConductorService",
"implementation": TimeConductorService
"key": "timeConductorViewService",
"implementation": TimeConductorViewService,
"depends": [
"timeConductor",
"timeSystems[]"
]
}
],
"controllers": [
Expand All @@ -63,7 +64,8 @@ define([
"implementation": TimeConductorController,
"depends": [
"$scope",
"timeConductorService",
"timeConductor",
"timeConductorViewService",
"timeSystems[]"
]
}
Expand All @@ -73,7 +75,7 @@ define([
"key": "mctConductorAxis",
"implementation": MCTConductorAxis,
"depends": [
"timeConductorService",
"timeConductor",
"formatService"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- Holds inputs and ticks -->
<div class="l-time-conductor-inputs-and-ticks l-row-elem flex-elem no-margin">
<form class="l-time-conductor-inputs-holder"
ng-submit="tcController.updateBoundsFromForm(formModel)">
ng-submit="tcController.updateBoundsFromForm(boundsModel)">
<span class="l-time-range-w start-w">
<span class="l-time-range-input-w start-date">
<span class="title"></span>
Expand All @@ -20,8 +20,8 @@
format: timeSystemModel.format,
validate: tcController.validation.validateStart
}"
ng-model="formModel"
ng-blur="tcController.updateBoundsFromForm(formModel)"
ng-model="boundsModel"
ng-blur="tcController.updateBoundsFromForm(boundsModel)"
field="'start'"
class="time-range-input">
</mct-control>
Expand All @@ -34,8 +34,8 @@
format: timeSystemModel.deltaFormat,
validate: tcController.validation.validateStartDelta
}"
ng-model="formModel"
ng-blur="tcController.updateDeltasFromForm(formModel)"
ng-model="boundsModel"
ng-blur="tcController.updateDeltasFromForm(boundsModel)"
field="'startDelta'"
class="hrs-min-input">
</mct-control>
Expand All @@ -50,8 +50,8 @@
format: timeSystemModel.format,
validate: tcController.validation.validateEnd
}"
ng-model="formModel"
ng-blur="tcController.updateBoundsFromForm(formModel)"
ng-model="boundsModel"
ng-blur="tcController.updateBoundsFromForm(boundsModel)"
ng-disabled="modeModel.selectedKey !== 'fixed'"
field="'end'"
class="time-range-input">
Expand All @@ -65,8 +65,8 @@
format: timeSystemModel.deltaFormat,
validate: tcController.validation.validateEndDelta
}"
ng-model="formModel"
ng-blur="tcController.updateDeltasFromForm(formModel)"
ng-model="boundsModel"
ng-blur="tcController.updateDeltasFromForm(boundsModel)"
field="'endDelta'"
class="hrs-min-input">
</mct-control>
Expand Down Expand Up @@ -100,7 +100,7 @@
</mct-control>
<!-- Zoom control -->
<div class="l-time-conductor-zoom-w grows flex-elem l-flex-row">
<span class="time-conductor-zoom-current-range flex-elem flex-fixed holder">Mars Minutes</span>
<span class="time-conductor-zoom-current-range flex-elem flex-fixed holder"></span>
<input class="time-conductor-zoom flex-elem" type="range" />
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions platform/features/conductor-v2/conductor/src/TimeConductor.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ define(['EventEmitter'], function (EventEmitter) {
* Time System
* */
this.emit('timeSystem', this.system);
// Do something with bounds here. Try and convert between
// time systems? Or just set defaults when time system changes?
// eg.
this.bounds(bounds);
} else if (arguments.length === 1) {
throw new Error('Must set bounds when changing time system');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ define(['./TickSource'], function (TickSource) {
TickSource.call(this);

this.metadata = {
key: 'real-time',
key: 'local',
mode: 'realtime',
cssclass: 'icon-clock',
label: 'Real-time',
name: 'Real-time Mode',
Expand Down Expand Up @@ -84,9 +85,5 @@ define(['./TickSource'], function (TickSource) {
}.bind(this);
};

LocalClock.prototype.type = function () {
return 'clock';
};

return LocalClock;
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,5 @@ define([], function () {
throw new Error('Not implemented');
};

/**
* What does this source tick on? A clock, or data availability.
* Information is required to support time conductor modes.
* @returns {string} type One of 'clock' or 'data'
*/
TickSource.prototype.type = function () {
throw new Error('Not implemented');
}

return TickSource;
});
27 changes: 12 additions & 15 deletions platform/features/conductor-v2/conductor/src/ui/MctConductorAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ define(
* labelled 'ticks'. It requires 'start' and 'end' integer values to
* be specified as attributes.
*/
function MCTConductorAxis(conductorService, formatService) {
var conductor = conductorService.conductor();

function MCTConductorAxis(conductor, formatService) {
function link(scope, element, attrs, ngModelController) {
var target = element[0].firstChild,
height = target.offsetHeight,
Expand All @@ -45,25 +43,24 @@ define(
.attr('width', '100%')
.attr('height', height);
var xAxis = d3.axisTop();
var xScale = d3.scaleUtc();

// draw x axis with labels and move to the bottom of the chart area
var axisElement = vis.append("g")
.attr("transform", "translate(0," + (height - padding) + ")");

function setScale() {
var xScale = undefined;
var width = target.offsetWidth;
var timeSystem = conductor.timeSystem();
var bounds = conductor.bounds();

if (timeSystem.isUTCBased()) {
xScale = d3.scaleUtc();
xScale.domain([new Date(bounds.start), new Date(bounds.end)]);
} else {
xScale = d3.scaleLinear();
xScale.domain([bounds.start, bounds.end]);
}

xScale.range([padding, width - padding * 2]);
xAxis.scale(xScale);
axisElement.call(xAxis);
}

Expand All @@ -73,6 +70,13 @@ define(
var format = formatService.getFormat(key);
var b = conductor.bounds();

if (timeSystem.isUTCBased()) {
xScale = d3.scaleUtc();
} else {
xScale = d3.scaleLinear();
}

xAxis.scale(xScale);
//Define a custom format function
xAxis.tickFormat(function (tickValue) {
// Normalize date representations to numbers
Expand All @@ -97,23 +101,16 @@ define(
setScale();
});

setScale();

if (conductor.timeSystem() !== undefined) {
changeTimeSystem(conductor.timeSystem());
setScale();
}
}

return {
// Only show at the element level
restrict: "E",

template: "<div class=\"l-axis-holder\" mct-resize=\"resize()\"></div>",

// ngOptions is terminal, so we need to be higher priority
priority: 1000,

// Link function
link: link
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

define([
'moment'
], function (
moment
) {
define([], function () {

/**
* Formatter for basic numbers. Provides basic support for non-UTC
Expand Down
Loading

0 comments on commit 4cf6126

Please sign in to comment.