From 0ff5ff5dbe8ebc492385f6b49ce355d29daa29f1 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Wed, 25 Nov 2015 04:05:40 -0800 Subject: [PATCH 1/3] Enabled refresh interval for absolute time range --- public/app/features/dashboard/timeSrv.js | 7 +------ public/test/specs/time_srv_specs.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/public/app/features/dashboard/timeSrv.js b/public/app/features/dashboard/timeSrv.js index e0e0ed47dab..1aff02bea90 100644 --- a/public/app/features/dashboard/timeSrv.js +++ b/public/app/features/dashboard/timeSrv.js @@ -93,12 +93,7 @@ define([ this.setTime = function(time) { _.extend(this.time, time); - // disable refresh if we have an absolute time - if (moment.isMoment(time.to)) { - this.old_refresh = this.dashboard.refresh || this.old_refresh; - this.setAutoRefresh(false); - } - else if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) { + if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) { this.setAutoRefresh(this.old_refresh); this.old_refresh = null; } diff --git a/public/test/specs/time_srv_specs.js b/public/test/specs/time_srv_specs.js index 4f065af6cf8..8c110483b47 100644 --- a/public/test/specs/time_srv_specs.js +++ b/public/test/specs/time_srv_specs.js @@ -78,17 +78,24 @@ define([ }); describe('setTime', function() { - it('should return disable refresh for absolute times', function() { + it('should return disable refresh if refresh is disabled for any range', function() { _dashboard.refresh = false; ctx.service.setTime({from: '2011-01-01', to: '2015-01-01' }); expect(_dashboard.refresh).to.be(false); }); + it('should restore refresh for absolute time range', function() { + _dashboard.refresh = '30s'; + + ctx.service.setTime({from: '2011-01-01', to: '2015-01-01' }); + expect(_dashboard.refresh).to.be('30s'); + }); + it('should restore refresh after relative time range is set', function() { _dashboard.refresh = '10s'; ctx.service.setTime({from: moment([2011,1,1]), to: moment([2015,1,1])}); - expect(_dashboard.refresh).to.be(false); + expect(_dashboard.refresh).to.be('10s'); ctx.service.setTime({from: '2011-01-01', to: 'now' }); expect(_dashboard.refresh).to.be('10s'); }); From 712a420217f48d13908ed2b571b419031be7c3f1 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 29 Nov 2015 03:12:48 -0800 Subject: [PATCH 2/3] Fixed refresh setting for absolute time --- public/app/features/dashboard/timeSrv.js | 9 +++++++-- public/app/features/dashboard/timepicker/timepicker.ts | 2 +- public/test/specs/time_srv_specs.js | 9 ++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/public/app/features/dashboard/timeSrv.js b/public/app/features/dashboard/timeSrv.js index 1aff02bea90..691bfd07904 100644 --- a/public/app/features/dashboard/timeSrv.js +++ b/public/app/features/dashboard/timeSrv.js @@ -90,10 +90,15 @@ define([ timer.cancel(this.refresh_timer); }; - this.setTime = function(time) { + this.setTime = function(time, enableRefresh) { _.extend(this.time, time); - if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) { + // disable refresh if zoom in or zoom out + if (!enableRefresh && moment.isMoment(time.to)) { + this.old_refresh = this.dashboard.refresh || this.old_refresh; + this.setAutoRefresh(false); + } + else if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) { this.setAutoRefresh(this.old_refresh); this.old_refresh = null; } diff --git a/public/app/features/dashboard/timepicker/timepicker.ts b/public/app/features/dashboard/timepicker/timepicker.ts index c6d2680ce02..0f99210f3fa 100644 --- a/public/app/features/dashboard/timepicker/timepicker.ts +++ b/public/app/features/dashboard/timepicker/timepicker.ts @@ -115,7 +115,7 @@ export class TimePickerCtrl { this.timeSrv.setAutoRefresh(this.refresh.value); } - this.timeSrv.setTime(this.timeRaw); + this.timeSrv.setTime(this.timeRaw, true); this.$rootScope.appEvent('hide-dash-editor'); } diff --git a/public/test/specs/time_srv_specs.js b/public/test/specs/time_srv_specs.js index 8c110483b47..d645df3fd1e 100644 --- a/public/test/specs/time_srv_specs.js +++ b/public/test/specs/time_srv_specs.js @@ -92,10 +92,17 @@ define([ expect(_dashboard.refresh).to.be('30s'); }); + it('should restore refresh for absolute time range', function() { + _dashboard.refresh = '30s'; + + ctx.service.setTime({from: '2011-01-01', to: '2015-01-01' }); + expect(_dashboard.refresh).to.be('30s'); + }); + it('should restore refresh after relative time range is set', function() { _dashboard.refresh = '10s'; ctx.service.setTime({from: moment([2011,1,1]), to: moment([2015,1,1])}); - expect(_dashboard.refresh).to.be('10s'); + expect(_dashboard.refresh).to.be(false); ctx.service.setTime({from: '2011-01-01', to: 'now' }); expect(_dashboard.refresh).to.be('10s'); }); From 8cdaa044e1eda21afa34f47caa18503d6a590e0d Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 29 Nov 2015 03:14:26 -0800 Subject: [PATCH 3/3] Removed repeating test --- public/test/specs/time_srv_specs.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/public/test/specs/time_srv_specs.js b/public/test/specs/time_srv_specs.js index d645df3fd1e..9943aae6cc3 100644 --- a/public/test/specs/time_srv_specs.js +++ b/public/test/specs/time_srv_specs.js @@ -92,13 +92,6 @@ define([ expect(_dashboard.refresh).to.be('30s'); }); - it('should restore refresh for absolute time range', function() { - _dashboard.refresh = '30s'; - - ctx.service.setTime({from: '2011-01-01', to: '2015-01-01' }); - expect(_dashboard.refresh).to.be('30s'); - }); - it('should restore refresh after relative time range is set', function() { _dashboard.refresh = '10s'; ctx.service.setTime({from: moment([2011,1,1]), to: moment([2015,1,1])});