Skip to content

Commit

Permalink
Merge pull request elastic#8389 from elastic/jasper/backport/8383/5.x
Browse files Browse the repository at this point in the history
[backport] PR elastic#8383 to 5.x - Update absolute time picker when time selection changes.
  • Loading branch information
stacey-gammon authored Sep 20, 2016
2 parents 632c7fa + 5a356db commit 7e82f9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/ui/public/directives/__tests__/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ describe('timepicker directive', function () {
done();
});


it('should parse the time of scope.from and scope.to to set its own variables', function (done) {
$scope.setQuick('now-30m', 'now');
$scope.setMode('absolute');
Expand All @@ -409,6 +408,22 @@ describe('timepicker directive', function () {
done();
});

it('should update its own variables if timefilter time is updated', function (done) {
$scope.setMode('absolute');
$scope.$digest();

const startDate = moment('1980-01-01T00:11:02.001Z');
const endDate = moment('1983-10-11T0=40:03:32.051Z');

$parentScope.timefilter.time.from = startDate;
$parentScope.timefilter.time.to = endDate;
$parentScope.$digest();

expect($scope.absolute.from.valueOf()).to.be(startDate.valueOf());
expect($scope.absolute.to.valueOf()).to.be(endDate.valueOf());
done();
});

it('should disable the "Go" button if from > to', function (done) {
$scope.absolute.from = moment('2012-02-01');
$scope.absolute.to = moment('2012-02-11');
Expand Down
12 changes: 12 additions & 0 deletions src/ui/public/timepicker/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshInter
{text: 'Years ago', value: 'y'},
];

$scope.$watch('from', function (date) {
if (moment.isMoment(date) && $scope.mode === 'absolute') {
$scope.absolute.from = date;
}
});

$scope.$watch('to', function (date) {
if (moment.isMoment(date) && $scope.mode === 'absolute') {
$scope.absolute.to = date;
}
});

$scope.$watch('absolute.from', function (date) {
if (_.isDate(date)) $scope.absolute.from = moment(date);
});
Expand Down

0 comments on commit 7e82f9a

Please sign in to comment.