Merge branch 'built_in_template_variables'

This commit is contained in:
Torkel Ödegaard
2017-01-11 12:10:33 +01:00
15 changed files with 151 additions and 96 deletions

View File

@@ -17,6 +17,11 @@ function (angular, _, kbn) {
this._grafanaVariables = {};
this._adhocVariables = {};
// default built ins
this._builtIns = {};
this._builtIns['__interval'] = {text: '1s', value: '1s'};
this._builtIns['__interval_ms'] = {text: '100', value: '100'};
this.init = function(variables) {
this.variables = variables;
this.updateTemplateData();
@@ -42,6 +47,7 @@ function (angular, _, kbn) {
this._index[variable.name] = variable;
}
};
this.variableInitialized = function(variable) {
@@ -103,10 +109,10 @@ function (angular, _, kbn) {
return this.distributeVariable(value, variable.name);
}
default: {
if (typeof value === 'string') {
return value;
if (_.isArray(value)) {
return '{' + value.join(',') + '}';
}
return '{' + value.join(',') + '}';
return value;
}
}
};
@@ -135,7 +141,7 @@ function (angular, _, kbn) {
str = _.escape(str);
this._regex.lastIndex = 0;
return str.replace(this._regex, function(match, g1, g2) {
if (self._index[g1 || g2]) {
if (self._index[g1 || g2] || self._builtIns[g1 || g2]) {
return '<span class="template-variable">' + match + '</span>';
}
return match;