|
|
@@ -7,7 +7,7 @@ import config from 'app/core/config';
|
|
|
import { importPluginModule } from './plugin_loader';
|
|
|
|
|
|
// Types
|
|
|
-import { DataSourceApi, DataSourceSelectItem } from '@grafana/ui/src/types';
|
|
|
+import { DataSourceApi, DataSourceSelectItem, ScopedVars } from '@grafana/ui/src/types';
|
|
|
|
|
|
export class DatasourceSrv {
|
|
|
datasources: { [name: string]: DataSourceApi };
|
|
|
@@ -21,12 +21,17 @@ export class DatasourceSrv {
|
|
|
this.datasources = {};
|
|
|
}
|
|
|
|
|
|
- get(name?: string): Promise<DataSourceApi> {
|
|
|
+ get(name?: string, scopedVars?: ScopedVars): Promise<DataSourceApi> {
|
|
|
if (!name) {
|
|
|
return this.get(config.defaultDatasource);
|
|
|
}
|
|
|
|
|
|
- name = this.templateSrv.replace(name);
|
|
|
+ name = this.templateSrv.replace(name, scopedVars, (value, variable) => {
|
|
|
+ if (Array.isArray(value)) {
|
|
|
+ return value[0];
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ });
|
|
|
|
|
|
if (name === 'default') {
|
|
|
return this.get(config.defaultDatasource);
|
|
|
@@ -40,10 +45,6 @@ export class DatasourceSrv {
|
|
|
}
|
|
|
|
|
|
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];
|
|
|
if (!dsConfig) {
|
|
|
return this.$q.reject({ message: 'Datasource named ' + name + ' was not found' });
|