Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Jul 27, 2016
1 parent aa4a5e5 commit c1bbc4f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 33 deletions.
7 changes: 0 additions & 7 deletions platform/commonUI/formats/src/UTCTimeFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ define([
"YYYY-MM-DD"
];

var MS = 1,
SECONDS = 1000 * MS,
MINUTES = 60 * SECONDS,
HOURS = 60 * MINUTES,
DAYS = 24 * HOURS,
MONTHS = (365 / 12) * DAYS;

/**
* @typedef Scale
* @property {number} min the minimum scale value, in ms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ define(
[],
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(
conductor,
scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
validate: tcController.validation.validateStart
}"
ng-model="formModel"
ng-mouseup="changing['start'] = true"
ng-blur="changing['start'] = false; tcController.updateBoundsFromForm(formModel)"
ng-blur="tcController.updateBoundsFromForm(formModel)"
field="'start'"
class="time-range-input">
</mct-control>
Expand Down Expand Up @@ -52,8 +51,7 @@
validate: tcController.validation.validateEnd
}"
ng-model="formModel"
ng-mouseup="changing['end'] = true"
ng-blur="changing['end'] = false; tcController.updateBoundsFromForm(formModel)"
ng-blur="tcController.updateBoundsFromForm(formModel)"
field="'end'"
class="time-range-input">
</mct-control>
Expand Down
11 changes: 4 additions & 7 deletions platform/features/conductor-v2/src/TimeConductor.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ define(['EventEmitter'], function (EventEmitter) {
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
* time conductor ticks, regularly updating the bounds from a timing
Expand Down Expand Up @@ -117,7 +111,10 @@ define(['EventEmitter'], function (EventEmitter) {
*/
TimeConductor.prototype.bounds = function (newBounds) {
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
this.boundsVal = JSON.parse(JSON.stringify(newBounds));
/**
Expand Down
39 changes: 24 additions & 15 deletions platform/features/conductor-v2/src/ui/TimeConductorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,33 @@ define(
* @private
*/
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 = {
selected: undefined,
format: undefined,
options: []
};
/*
Represents the various modes, and the currently
selected mode in the view
*/
$scope.modeModel = {
selected: undefined,
options: this.modes
};
/*
Time Conductor bounds in the form
*/
$scope.formModel = {
start: 0,
end: 0
};
$scope.changing = {
'start': false,
'end': false
};

$scope.$watch('modeModel.selected', this.setMode);
$scope.$watch('timeSystem', this.setTimeSystem);
Expand All @@ -105,12 +115,8 @@ define(
* @param bounds
*/
TimeConductorController.prototype.setBounds = function (bounds) {
if (!this.$scope.changing['start']) {
this.$scope.formModel.start = bounds.start;
}
if (!this.$scope.changing['end']) {
this.$scope.formModel.end = bounds.end;
}
this.$scope.formModel.start = bounds.start;
this.$scope.formModel.end = bounds.end;
};

/**
Expand All @@ -119,7 +125,10 @@ define(
* @param 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) {
this.conductor.bounds(newBounds);
Expand Down Expand Up @@ -151,7 +160,7 @@ define(
*/
TimeConductorController.prototype.setMode = function (newMode, oldMode) {
if (newMode !== oldMode) {
if (oldMode && oldMode.destroy) {
if (oldMode) {
oldMode.destroy();
}
newMode.initialize();
Expand All @@ -167,14 +176,14 @@ define(
this.$scope.timeSystemModel.selected = timeSystem;
//Use default format
this.$scope.timeSystemModel.format = timeSystem.formats()[0];
this.setDefaultsFromTimeSystem(newMode.selectedTimeSystem());
this.setDeltasFromTimeSystem(timeSystem);
}
};

/**
* @private
*/
TimeConductorController.prototype.setDefaultsFromTimeSystem = function (timeSystem) {
TimeConductorController.prototype.setDeltasFromTimeSystem = function (timeSystem) {
var defaults = timeSystem.defaults()[0];
var deltas = defaults.deltas;

Expand Down Expand Up @@ -214,7 +223,7 @@ define(
this.$scope.timeSystemModel.selected = newTimeSystem;
var mode = this.$scope.modeModel.selected;
mode.selectedTimeSystem(newTimeSystem);
this.setDefaultsFromTimeSystem(newTimeSystem);
this.setDeltasFromTimeSystem(newTimeSystem);
}
};

Expand Down

0 comments on commit c1bbc4f

Please sign in to comment.