diff --git a/public/app/core/utils/rangeutil.ts b/public/app/core/utils/rangeutil.ts index 89dba7b01a4..b87dd4969a1 100644 --- a/public/app/core/utils/rangeutil.ts +++ b/public/app/core/utils/rangeutil.ts @@ -56,13 +56,19 @@ _.each(rangeOptions, function (frame) { }); function getRelativeTimesList(timepickerSettings, currentDisplay) { - return _.groupBy(rangeOptions, (option: any) => { + var groups = _.groupBy(rangeOptions, (option: any) => { option.active = option.display === currentDisplay; return option.section; }); - // return _.map(timepickerSettings.time_options, function(duration: string) { - // return describeTextRange(duration); + + // _.each(timepickerSettings.time_options, (duration: string) => { + // let info = describeTextRange(duration); + // if (info.section) { + // groups[info.section].push(info); + // } // }); + + return groups; } function formatDate(date) { @@ -94,6 +100,7 @@ _.each(rangeOptions, function (frame) { let span = spans[unit]; if (span) { opt.display = 'Last ' + amount + ' ' + span.display; + opt.section = span.section; if (amount > 1) { opt.display += 's'; } diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index 892eebbb927..543fad9de22 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -109,7 +109,7 @@
- +
diff --git a/public/app/features/dashboard/timepicker/settings.html b/public/app/features/dashboard/timepicker/settings.html index b382c593094..fed0094086c 100644 --- a/public/app/features/dashboard/timepicker/settings.html +++ b/public/app/features/dashboard/timepicker/settings.html @@ -1,24 +1,24 @@
-
-
    -
  • - Relative times -
  • -
  • - -
  • -
-
-
+ + + + + + + + + + +
  • Auto-refresh
  • - +
@@ -34,7 +34,7 @@
  • @@ -43,13 +43,6 @@
  • -
    - -

    -
    - - For these changes to fully take effect save and reload the dashboard. -

    diff --git a/public/app/features/dashboard/timepicker/timepicker.ts b/public/app/features/dashboard/timepicker/timepicker.ts index 4e1c9f61bce..3714890fd36 100644 --- a/public/app/features/dashboard/timepicker/timepicker.ts +++ b/public/app/features/dashboard/timepicker/timepicker.ts @@ -111,7 +111,6 @@ export class TimePickerCtrl { this.timeSrv.setAutoRefresh(this.refresh.value); } - debugger; this.timeSrv.setTime(this.timeRaw); this.$rootScope.appEvent('hide-dash-editor'); } @@ -133,7 +132,7 @@ export class TimePickerCtrl { var range = {from: timespan.from, to: timespan.to}; - if (this.panel.nowDelay) { + if (this.panel.nowDelay && range.to === 'now') { range.to = 'now-' + this.panel.nowDelay; } @@ -149,7 +148,11 @@ export function settingsDirective() { restrict: 'E', templateUrl: 'app/features/dashboard/timepicker/settings.html', controller: TimePickerCtrl, - scope: true, + bindToController: true, + controllerAs: 'ctrl', + scope: { + dashboard: "=" + } }; } diff --git a/public/test/specs/core/utils/rangeutil_specs.ts b/public/test/specs/core/utils/rangeutil_specs.ts index 8dd407f8f3d..5ff1639a204 100644 --- a/public/test/specs/core/utils/rangeutil_specs.ts +++ b/public/test/specs/core/utils/rangeutil_specs.ts @@ -6,6 +6,22 @@ import moment = require('moment') describe("rangeUtil", () => { + describe("Can get range grouped list of ranges", () => { + it('when custom settings should return default range list', () => { + var groups = rangeUtil.getRelativeTimesList({time_options: []}, 'Last 5 minutes'); + expect(_.keys(groups).length).to.be(4) + expect(groups[3][0].active).to.be(true) + }); + + // it('should add custom options to right section', () => { + // var groups = rangeUtil.getRelativeTimesList({ + // time_options: ['12m', '15d'] + // }, ''); + // var value = _.findWhere(groups["3"], {display: 'Last 12 minutes'}); + // expect(value).to.not.be(undefined) + // }); + }); + describe("Can get range text described", () => { it('should handle simple old expression with only amount and unit', () => { var info = rangeUtil.describeTextRange('5m');