---------

**Commit 1:**
Update absolute time picker when time selection changes.

Listen for changes made to timefilter.time and update the absolute time
picker accordingly.

* Original sha: 12f61e1eb9
* Authored by Stacey-Gammon <gammon@elastic.co> on 2016-09-20T19:41:50Z
This commit is contained in:
Elastic Jasper 2016-09-20 16:32:17 -04:00
parent d621f5c429
commit 48ef86cfbf
2 changed files with 28 additions and 1 deletions

View file

@ -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');
@ -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');

View file

@ -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);
});