Commit a8486806 by Torkel Ödegaard

Merge branch 'multiselect-repeatby-datasource' of…

Merge branch 'multiselect-repeatby-datasource' of https://github.com/jdoupe/grafana into jdoupe-multiselect-repeatby-datasource
parents 5f6838ab 3f27d3ea
...@@ -79,9 +79,28 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -79,9 +79,28 @@ class MetricsPanelCtrl extends PanelCtrl {
delete this.error; delete this.error;
this.loading = true; this.loading = true;
// set "mydatasource" to whatever the panel has defined
let mydatasource = this.panel.datasource;
let datasourceVarName = '';
// look for data source variables
for (let i = 0; i < this.templateSrv.variables.length; i++) {
const variable = this.templateSrv.variables[i];
if (variable.type !== 'datasource') {
continue;
}
datasourceVarName = variable.name;
}
// if a data source variable was found, use its value
if (datasourceVarName !== '' && this.panel.scopedVars && this.panel.scopedVars[datasourceVarName]) {
mydatasource = this.panel.scopedVars[datasourceVarName].value;
}
// load datasource service // load datasource service
this.datasourceSrv this.datasourceSrv
.get(this.panel.datasource) .get(mydatasource)
.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))
......
...@@ -40,6 +40,10 @@ export class DatasourceSrv { ...@@ -40,6 +40,10 @@ export class DatasourceSrv {
} }
loadDatasource(name: string): Promise<DataSourceApi> { loadDatasource(name: string): Promise<DataSourceApi> {
// if there are multiple datasources provided, just use the first one
const re = /{([^,}]+).*/;
name = name.replace(re, '$1');
const dsConfig = config.datasources[name]; const dsConfig = config.datasources[name];
if (!dsConfig) { if (!dsConfig) {
return this.$q.reject({ message: 'Datasource named ' + name + ' was not found' }); return this.$q.reject({ message: 'Datasource named ' + name + ' was not found' });
......
...@@ -6,6 +6,8 @@ export class DatasourceVariable implements Variable { ...@@ -6,6 +6,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;
skipUrlSync: boolean; skipUrlSync: boolean;
...@@ -18,6 +20,8 @@ export class DatasourceVariable implements Variable { ...@@ -18,6 +20,8 @@ export class DatasourceVariable implements Variable {
regex: '', regex: '',
options: [], options: [],
query: '', query: '',
multi: false,
includeAll: false,
refresh: 1, refresh: 1,
skipUrlSync: false, skipUrlSync: false,
}; };
...@@ -69,9 +73,16 @@ export class DatasourceVariable implements Variable { ...@@ -69,9 +73,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);
...@@ -84,6 +95,9 @@ export class DatasourceVariable implements Variable { ...@@ -84,6 +95,9 @@ export class DatasourceVariable implements Variable {
} }
getValueForUrl() { getValueForUrl() {
if (this.current.text === 'All') {
return 'All';
}
return this.current.value; return this.current.value;
} }
} }
...@@ -91,5 +105,6 @@ export class DatasourceVariable implements Variable { ...@@ -91,5 +105,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