From 2339560363d1c9b28f3a4d5ffb5459af6c6aed7d Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Fri, 24 Jun 2016 21:30:03 -0700 Subject: [PATCH] [Time Conductor] Bounds updated when date selected from date selector. Fixes #1018 --- platform/commonUI/general/bundle.js | 1 + .../src/controllers/TimeRangeController.js | 32 +++++++++++-------- .../controllers/TimeRangeControllerSpec.js | 6 ++++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/platform/commonUI/general/bundle.js b/platform/commonUI/general/bundle.js index daadacbc45..a7dccb0326 100644 --- a/platform/commonUI/general/bundle.js +++ b/platform/commonUI/general/bundle.js @@ -204,6 +204,7 @@ define([ "implementation": TimeRangeController, "depends": [ "$scope", + "$timeout", "formatService", "DEFAULT_TIME_FORMAT", "now" diff --git a/platform/commonUI/general/src/controllers/TimeRangeController.js b/platform/commonUI/general/src/controllers/TimeRangeController.js index 740a253712..9d1087c8a8 100644 --- a/platform/commonUI/general/src/controllers/TimeRangeController.js +++ b/platform/commonUI/general/src/controllers/TimeRangeController.js @@ -53,7 +53,7 @@ define([ * format has been otherwise specified * @param {Function} now a function to return current system time */ - function TimeRangeController($scope, formatService, defaultFormat, now) { + function TimeRangeController($scope, $timeout, formatService, defaultFormat, now) { this.$scope = $scope; this.formatService = formatService; this.defaultFormat = defaultFormat; @@ -66,6 +66,7 @@ define([ this.formatter = formatService.getFormat(defaultFormat); this.formStartChanged = false; this.formEndChanged = false; + this.$timeout = $timeout; this.$scope.ticks = []; @@ -259,18 +260,23 @@ define([ }; TimeRangeController.prototype.updateBoundsFromForm = function () { - if (this.formStartChanged) { - this.$scope.ngModel.outer.start = - this.$scope.ngModel.inner.start = - this.$scope.formModel.start; - this.formStartChanged = false; - } - if (this.formEndChanged) { - this.$scope.ngModel.outer.end = - this.$scope.ngModel.inner.end = - this.$scope.formModel.end; - this.formEndChanged = false; - } + var self = this; + + //Allow Angular to trigger watches and determine whether values have changed. + this.$timeout(function () { + if (self.formStartChanged) { + self.$scope.ngModel.outer.start = + self.$scope.ngModel.inner.start = + self.$scope.formModel.start; + self.formStartChanged = false; + } + if (self.formEndChanged) { + self.$scope.ngModel.outer.end = + self.$scope.ngModel.inner.end = + self.$scope.formModel.end; + self.formEndChanged = false; + } + }); }; TimeRangeController.prototype.onFormStartChange = function ( diff --git a/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js b/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js index 718dd2664f..f7fc1b6f34 100644 --- a/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js +++ b/platform/commonUI/general/test/controllers/TimeRangeControllerSpec.js @@ -33,6 +33,7 @@ define( var mockScope, mockFormatService, testDefaultFormat, + mockTimeout, mockNow, mockFormat, controller; @@ -54,6 +55,10 @@ define( } beforeEach(function () { + mockTimeout = function (fn) { + return fn(); + }; + mockScope = jasmine.createSpyObj( "$scope", ["$apply", "$watch", "$watchCollection"] @@ -78,6 +83,7 @@ define( controller = new TimeRangeController( mockScope, + mockTimeout, mockFormatService, testDefaultFormat, mockNow