mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(templating): progress on template system rewrite #6048
This commit is contained in:
56
public/app/features/templating/datasource_variable.ts
Normal file
56
public/app/features/templating/datasource_variable.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
///<reference path="../../headers/common.d.ts" />
|
||||
|
||||
import _ from 'lodash';
|
||||
import kbn from 'app/core/utils/kbn';
|
||||
import {Variable} from './variable';
|
||||
import {VariableSrv, variableConstructorMap} from './variable_srv';
|
||||
|
||||
export class DatasourceVariable implements Variable {
|
||||
regex: any;
|
||||
query: string;
|
||||
options: any;
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private model, private datasourceSrv) {
|
||||
_.extend(this, model);
|
||||
}
|
||||
|
||||
setValue(option) {
|
||||
}
|
||||
|
||||
updateOptions() {
|
||||
var options = [];
|
||||
var sources = this.datasourceSrv.getMetricSources({skipVariables: true});
|
||||
var regex;
|
||||
|
||||
if (this.regex) {
|
||||
regex = kbn.stringToJsRegex(this.regex);
|
||||
}
|
||||
|
||||
for (var i = 0; i < sources.length; i++) {
|
||||
var source = sources[i];
|
||||
// must match on type
|
||||
if (source.meta.id !== this.query) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (regex && !regex.exec(source.name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
options.push({text: source.name, value: source.name});
|
||||
}
|
||||
|
||||
if (options.length === 0) {
|
||||
options.push({text: 'No data sources found', value: ''});
|
||||
}
|
||||
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
dependsOn(variableName) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
variableConstructorMap['datasource'] = DatasourceVariable;
|
||||
Reference in New Issue
Block a user