From 554f972a25f483e22db5d74aeb3fd3a9cbe89129 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Fri, 31 Mar 2017 14:31:15 +0900 Subject: [PATCH] support panel repeat for datasource template variable (#7711) * support panel repeat for datasource template variable * support All option --- public/app/core/services/datasource_srv.js | 4 ++-- public/app/features/panel/metrics_panel_ctrl.ts | 2 +- .../features/templating/datasource_variable.ts | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/public/app/core/services/datasource_srv.js b/public/app/core/services/datasource_srv.js index e722aae355b..bb187a7d5fb 100644 --- a/public/app/core/services/datasource_srv.js +++ b/public/app/core/services/datasource_srv.js @@ -14,12 +14,12 @@ function (angular, _, coreModule, config) { this.datasources = {}; }; - this.get = function(name) { + this.get = function(name, scopedDsVars) { if (!name) { return this.get(config.defaultDatasource); } - name = templateSrv.replace(name); + name = templateSrv.replace(name, scopedDsVars || {}); if (name === 'default') { return this.get(config.defaultDatasource); diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index b42d4a8b02a..6f066723741 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -92,7 +92,7 @@ class MetricsPanelCtrl extends PanelCtrl { // load datasource service this.setTimeQueryStart(); - this.datasourceSrv.get(this.panel.datasource) + this.datasourceSrv.get(this.panel.datasource, this.panel.scopedVars) .then(this.updateTimeRange.bind(this)) .then(this.issueQueries.bind(this)) .then(this.handleQueryResult.bind(this)) diff --git a/public/app/features/templating/datasource_variable.ts b/public/app/features/templating/datasource_variable.ts index 41f2262ab4a..66b0ab2eff9 100644 --- a/public/app/features/templating/datasource_variable.ts +++ b/public/app/features/templating/datasource_variable.ts @@ -10,6 +10,8 @@ export class DatasourceVariable implements Variable { query: string; options: any; current: any; + multi: boolean; + includeAll: boolean; refresh: any; defaults = { @@ -21,6 +23,8 @@ export class DatasourceVariable implements Variable { regex: '', options: [], query: '', + multi: false, + includeAll: false, refresh: 1, }; @@ -71,9 +75,16 @@ export class DatasourceVariable implements Variable { } this.options = options; + if (this.includeAll) { + this.addAllOption(); + } return this.variableSrv.validateVariableSelectionState(this); } + addAllOption() { + this.options.unshift({text: 'All', value: "$__all"}); + } + dependsOn(variable) { if (this.regex) { return containsVariable(this.regex, variable.name); @@ -86,6 +97,9 @@ export class DatasourceVariable implements Variable { } getValueForUrl() { + if (this.current.text === 'All') { + return 'All'; + } return this.current.value; } } @@ -93,5 +107,6 @@ export class DatasourceVariable implements Variable { variableTypes['datasource'] = { name: 'Datasource', ctor: DatasourceVariable, + supportsMulti: true, description: 'Enabled you to dynamically switch the datasource for multiple panels', };