From c1bbc4f01d0d664f22126cb266d9eb0544864e90 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 27 Jul 2016 10:38:04 -0400 Subject: [PATCH] Code cleanup --- .../commonUI/formats/src/UTCTimeFormat.js | 7 ---- .../src/ConductorRepresenter.js | 12 ++++++ .../res/templates/time-conductor.html | 6 +-- .../conductor-v2/src/TimeConductor.js | 11 ++---- .../src/ui/TimeConductorController.js | 39 ++++++++++++------- 5 files changed, 42 insertions(+), 33 deletions(-) diff --git a/platform/commonUI/formats/src/UTCTimeFormat.js b/platform/commonUI/formats/src/UTCTimeFormat.js index 03176272d12..4b80dd11abd 100644 --- a/platform/commonUI/formats/src/UTCTimeFormat.js +++ b/platform/commonUI/formats/src/UTCTimeFormat.js @@ -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 diff --git a/platform/features/conductor-v2-compatibility/src/ConductorRepresenter.js b/platform/features/conductor-v2-compatibility/src/ConductorRepresenter.js index fb91a6b4e06..999e8c2bdbd 100644 --- a/platform/features/conductor-v2-compatibility/src/ConductorRepresenter.js +++ b/platform/features/conductor-v2-compatibility/src/ConductorRepresenter.js @@ -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, diff --git a/platform/features/conductor-v2/res/templates/time-conductor.html b/platform/features/conductor-v2/res/templates/time-conductor.html index f8a2ca81400..16f98401342 100644 --- a/platform/features/conductor-v2/res/templates/time-conductor.html +++ b/platform/features/conductor-v2/res/templates/time-conductor.html @@ -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"> @@ -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"> diff --git a/platform/features/conductor-v2/src/TimeConductor.js b/platform/features/conductor-v2/src/TimeConductor.js index 31f432f4c2b..3e87e5f1c02 100644 --- a/platform/features/conductor-v2/src/TimeConductor.js +++ b/platform/features/conductor-v2/src/TimeConductor.js @@ -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 @@ -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)); /** diff --git a/platform/features/conductor-v2/src/ui/TimeConductorController.js b/platform/features/conductor-v2/src/ui/TimeConductorController.js index 5967fbf194a..e1e1d7a40d1 100644 --- a/platform/features/conductor-v2/src/ui/TimeConductorController.js +++ b/platform/features/conductor-v2/src/ui/TimeConductorController.js @@ -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); @@ -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; }; /** @@ -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); @@ -151,7 +160,7 @@ define( */ TimeConductorController.prototype.setMode = function (newMode, oldMode) { if (newMode !== oldMode) { - if (oldMode && oldMode.destroy) { + if (oldMode) { oldMode.destroy(); } newMode.initialize(); @@ -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; @@ -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); } };