Commit 554f972a by Mitsuhiro Tanda Committed by Torkel Ödegaard

support panel repeat for datasource template variable (#7711)

* support panel repeat for datasource template variable

* support All option
parent 6e304e6e
...@@ -14,12 +14,12 @@ function (angular, _, coreModule, config) { ...@@ -14,12 +14,12 @@ function (angular, _, coreModule, config) {
this.datasources = {}; this.datasources = {};
}; };
this.get = function(name) { this.get = function(name, scopedDsVars) {
if (!name) { if (!name) {
return this.get(config.defaultDatasource); return this.get(config.defaultDatasource);
} }
name = templateSrv.replace(name); name = templateSrv.replace(name, scopedDsVars || {});
if (name === 'default') { if (name === 'default') {
return this.get(config.defaultDatasource); return this.get(config.defaultDatasource);
......
...@@ -92,7 +92,7 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -92,7 +92,7 @@ class MetricsPanelCtrl extends PanelCtrl {
// load datasource service // load datasource service
this.setTimeQueryStart(); this.setTimeQueryStart();
this.datasourceSrv.get(this.panel.datasource) this.datasourceSrv.get(this.panel.datasource, this.panel.scopedVars)
.then(this.updateTimeRange.bind(this)) .then(this.updateTimeRange.bind(this))
.then(this.issueQueries.bind(this)) .then(this.issueQueries.bind(this))
.then(this.handleQueryResult.bind(this)) .then(this.handleQueryResult.bind(this))
......
...@@ -10,6 +10,8 @@ export class DatasourceVariable implements Variable { ...@@ -10,6 +10,8 @@ export class DatasourceVariable implements Variable {
query: string; query: string;
options: any; options: any;
current: any; current: any;
multi: boolean;
includeAll: boolean;
refresh: any; refresh: any;
defaults = { defaults = {
...@@ -21,6 +23,8 @@ export class DatasourceVariable implements Variable { ...@@ -21,6 +23,8 @@ export class DatasourceVariable implements Variable {
regex: '', regex: '',
options: [], options: [],
query: '', query: '',
multi: false,
includeAll: false,
refresh: 1, refresh: 1,
}; };
...@@ -71,9 +75,16 @@ export class DatasourceVariable implements Variable { ...@@ -71,9 +75,16 @@ export class DatasourceVariable implements Variable {
} }
this.options = options; this.options = options;
if (this.includeAll) {
this.addAllOption();
}
return this.variableSrv.validateVariableSelectionState(this); return this.variableSrv.validateVariableSelectionState(this);
} }
addAllOption() {
this.options.unshift({text: 'All', value: "$__all"});
}
dependsOn(variable) { dependsOn(variable) {
if (this.regex) { if (this.regex) {
return containsVariable(this.regex, variable.name); return containsVariable(this.regex, variable.name);
...@@ -86,6 +97,9 @@ export class DatasourceVariable implements Variable { ...@@ -86,6 +97,9 @@ export class DatasourceVariable implements Variable {
} }
getValueForUrl() { getValueForUrl() {
if (this.current.text === 'All') {
return 'All';
}
return this.current.value; return this.current.value;
} }
} }
...@@ -93,5 +107,6 @@ export class DatasourceVariable implements Variable { ...@@ -93,5 +107,6 @@ export class DatasourceVariable implements Variable {
variableTypes['datasource'] = { variableTypes['datasource'] = {
name: 'Datasource', name: 'Datasource',
ctor: DatasourceVariable, ctor: DatasourceVariable,
supportsMulti: true,
description: 'Enabled you to dynamically switch the datasource for multiple panels', description: 'Enabled you to dynamically switch the datasource for multiple panels',
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment