From 09dfaf98755bbb30aed53074537aba1393d08a95 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Mon, 29 Feb 2016 17:42:38 +0900 Subject: [PATCH] timeFrom and timeShift templating --- public/app/core/directives/ng_model_on_blur.js | 3 +++ public/app/features/panel/metrics_panel_ctrl.ts | 10 +++++++--- public/app/plugins/panel/singlestat/module.ts | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/public/app/core/directives/ng_model_on_blur.js b/public/app/core/directives/ng_model_on_blur.js index 1e3ebc38a25..6f4a55b53f0 100644 --- a/public/app/core/directives/ng_model_on_blur.js +++ b/public/app/core/directives/ng_model_on_blur.js @@ -47,6 +47,9 @@ function (coreModule, kbn, rangeUtil) { if (ctrl.$isEmpty(modelValue)) { return true; } + if (viewValue.indexOf('$') === 0) { + return true; // allow template variable + } var info = rangeUtil.describeTextRange(viewValue); return info.invalid !== true; }; diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 537bdbbcbdb..e1ad782fa74 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -17,6 +17,7 @@ class MetricsPanelCtrl extends PanelCtrl { $timeout: any; datasourceSrv: any; timeSrv: any; + templateSrv: any; timing: any; range: any; rangeRaw: any; @@ -34,6 +35,7 @@ class MetricsPanelCtrl extends PanelCtrl { this.$q = $injector.get('$q'); this.datasourceSrv = $injector.get('datasourceSrv'); this.timeSrv = $injector.get('timeSrv'); + this.templateSrv = $injector.get('templateSrv'); if (!this.panel.targets) { this.panel.targets = [{}]; @@ -119,7 +121,8 @@ class MetricsPanelCtrl extends PanelCtrl { // check panel time overrrides if (this.panel.timeFrom) { - var timeFromInfo = rangeUtil.describeTextRange(this.panel.timeFrom); + var timeFromInterpolated = this.templateSrv.replace(this.panel.timeFrom, this.panel.scopedVars); + var timeFromInfo = rangeUtil.describeTextRange(timeFromInterpolated); if (timeFromInfo.invalid) { this.timeInfo = 'invalid time override'; return; @@ -136,13 +139,14 @@ class MetricsPanelCtrl extends PanelCtrl { } if (this.panel.timeShift) { - var timeShiftInfo = rangeUtil.describeTextRange(this.panel.timeShift); + var timeShiftInterpolated = this.templateSrv.replace(this.panel.timeShift, this.panel.scopedVars); + var timeShiftInfo = rangeUtil.describeTextRange(timeShiftInterpolated); if (timeShiftInfo.invalid) { this.timeInfo = 'invalid timeshift'; return; } - var timeShift = '-' + this.panel.timeShift; + var timeShift = '-' + timeShiftInterpolated; this.timeInfo += ' timeshift ' + timeShift; this.range.from = dateMath.parseDateMath(timeShift, this.range.from, false); this.range.to = dateMath.parseDateMath(timeShift, this.range.to, true); diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 7f576cc3f2d..6f692c700de 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -50,7 +50,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { unitFormats: any[]; /** @ngInject */ - constructor($scope, $injector, private $location, private linkSrv, private templateSrv) { + constructor($scope, $injector, private $location, private linkSrv) { super($scope, $injector); _.defaults(this.panel, panelDefaults); }