Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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