Code cleanup

This commit is contained in:
Henry 2016-07-27 10:38:04 -04:00
parent aa4a5e56f9
commit c1bbc4f01d
5 changed files with 42 additions and 33 deletions

View File

@ -34,13 +34,6 @@ define([
"YYYY-MM-DD" "YYYY-MM-DD"
]; ];
var MS = 1,
SECONDS = 1000 * MS,
MINUTES = 60 * SECONDS,
HOURS = 60 * MINUTES,
DAYS = 24 * HOURS,
MONTHS = (365 / 12) * DAYS;
/** /**
* @typedef Scale * @typedef Scale
* @property {number} min the minimum scale value, in ms * @property {number} min the minimum scale value, in ms

View File

@ -24,6 +24,18 @@ define(
[], [],
function () { function () {
/**
* Representer that provides a compatibility layer between the new
* time conductor and existing representations / views. Listens to
* the v2 time conductor API and generates v1 style events using the
* Angular event bus. This is transitional code code and will be
* removed.
*
* Deprecated immediately as this is temporary code
*
* @deprecated
* @constructor
*/
function ConductorRepresenter( function ConductorRepresenter(
conductor, conductor,
scope, scope,

View File

@ -21,8 +21,7 @@
validate: tcController.validation.validateStart validate: tcController.validation.validateStart
}" }"
ng-model="formModel" ng-model="formModel"
ng-mouseup="changing['start'] = true" ng-blur="tcController.updateBoundsFromForm(formModel)"
ng-blur="changing['start'] = false; tcController.updateBoundsFromForm(formModel)"
field="'start'" field="'start'"
class="time-range-input"> class="time-range-input">
</mct-control> </mct-control>
@ -52,8 +51,7 @@
validate: tcController.validation.validateEnd validate: tcController.validation.validateEnd
}" }"
ng-model="formModel" ng-model="formModel"
ng-mouseup="changing['end'] = true" ng-blur="tcController.updateBoundsFromForm(formModel)"
ng-blur="changing['end'] = false; tcController.updateBoundsFromForm(formModel)"
field="'end'" field="'end'"
class="time-range-input"> class="time-range-input">
</mct-control> </mct-control>

View File

@ -72,12 +72,6 @@ define(['EventEmitter'], function (EventEmitter) {
return true; return true;
}; };
function throwOnError(validationResult) {
if (validationResult !== true) {
throw new Error(validationResult);
}
}
/** /**
* Get or set the follow mode of the time conductor. In follow mode the * Get or set the follow mode of the time conductor. In follow mode the
* time conductor ticks, regularly updating the bounds from a timing * time conductor ticks, regularly updating the bounds from a timing
@ -117,7 +111,10 @@ define(['EventEmitter'], function (EventEmitter) {
*/ */
TimeConductor.prototype.bounds = function (newBounds) { TimeConductor.prototype.bounds = function (newBounds) {
if (arguments.length > 0) { if (arguments.length > 0) {
throwOnError(this.validateBounds(newBounds)); var validationResult = this.validateBounds(newBounds);
if (validationResult !== true){
throw new Error(validationResult);
}
//Create a copy to avoid direct mutation of conductor bounds //Create a copy to avoid direct mutation of conductor bounds
this.boundsVal = JSON.parse(JSON.stringify(newBounds)); this.boundsVal = JSON.parse(JSON.stringify(newBounds));
/** /**

View File

@ -70,23 +70,33 @@ define(
* @private * @private
*/ */
TimeConductorController.prototype.initializeScope = function ($scope) { TimeConductorController.prototype.initializeScope = function ($scope) {
/*
Represents the various time system options, and the currently
selected time system in the view. Additionally holds the
default format from the selected time system for convenience
of access from the template.
*/
$scope.timeSystemModel = { $scope.timeSystemModel = {
selected: undefined, selected: undefined,
format: undefined, format: undefined,
options: [] options: []
}; };
/*
Represents the various modes, and the currently
selected mode in the view
*/
$scope.modeModel = { $scope.modeModel = {
selected: undefined, selected: undefined,
options: this.modes options: this.modes
}; };
/*
Time Conductor bounds in the form
*/
$scope.formModel = { $scope.formModel = {
start: 0, start: 0,
end: 0 end: 0
}; };
$scope.changing = {
'start': false,
'end': false
};
$scope.$watch('modeModel.selected', this.setMode); $scope.$watch('modeModel.selected', this.setMode);
$scope.$watch('timeSystem', this.setTimeSystem); $scope.$watch('timeSystem', this.setTimeSystem);
@ -105,12 +115,8 @@ define(
* @param bounds * @param bounds
*/ */
TimeConductorController.prototype.setBounds = function (bounds) { TimeConductorController.prototype.setBounds = function (bounds) {
if (!this.$scope.changing['start']) { this.$scope.formModel.start = bounds.start;
this.$scope.formModel.start = bounds.start; this.$scope.formModel.end = bounds.end;
}
if (!this.$scope.changing['end']) {
this.$scope.formModel.end = bounds.end;
}
}; };
/** /**
@ -119,7 +125,10 @@ define(
* @param formModel * @param formModel
*/ */
TimeConductorController.prototype.updateBoundsFromForm = function (formModel) { TimeConductorController.prototype.updateBoundsFromForm = function (formModel) {
var newBounds = {start: formModel.start, end: formModel.end}; var newBounds = {
start: formModel.start,
end: formModel.end
};
if (this.conductor.validateBounds(newBounds) === true) { if (this.conductor.validateBounds(newBounds) === true) {
this.conductor.bounds(newBounds); this.conductor.bounds(newBounds);
@ -151,7 +160,7 @@ define(
*/ */
TimeConductorController.prototype.setMode = function (newMode, oldMode) { TimeConductorController.prototype.setMode = function (newMode, oldMode) {
if (newMode !== oldMode) { if (newMode !== oldMode) {
if (oldMode && oldMode.destroy) { if (oldMode) {
oldMode.destroy(); oldMode.destroy();
} }
newMode.initialize(); newMode.initialize();
@ -167,14 +176,14 @@ define(
this.$scope.timeSystemModel.selected = timeSystem; this.$scope.timeSystemModel.selected = timeSystem;
//Use default format //Use default format
this.$scope.timeSystemModel.format = timeSystem.formats()[0]; this.$scope.timeSystemModel.format = timeSystem.formats()[0];
this.setDefaultsFromTimeSystem(newMode.selectedTimeSystem()); this.setDeltasFromTimeSystem(timeSystem);
} }
}; };
/** /**
* @private * @private
*/ */
TimeConductorController.prototype.setDefaultsFromTimeSystem = function (timeSystem) { TimeConductorController.prototype.setDeltasFromTimeSystem = function (timeSystem) {
var defaults = timeSystem.defaults()[0]; var defaults = timeSystem.defaults()[0];
var deltas = defaults.deltas; var deltas = defaults.deltas;
@ -214,7 +223,7 @@ define(
this.$scope.timeSystemModel.selected = newTimeSystem; this.$scope.timeSystemModel.selected = newTimeSystem;
var mode = this.$scope.modeModel.selected; var mode = this.$scope.modeModel.selected;
mode.selectedTimeSystem(newTimeSystem); mode.selectedTimeSystem(newTimeSystem);
this.setDefaultsFromTimeSystem(newTimeSystem); this.setDeltasFromTimeSystem(newTimeSystem);
} }
}; };