mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
support [[variable:type]] syntax
This commit is contained in:
parent
fa193fa888
commit
dc6f977304
@ -8,7 +8,7 @@ function luceneEscape(value) {
|
|||||||
export class TemplateSrv {
|
export class TemplateSrv {
|
||||||
variables: any[];
|
variables: any[];
|
||||||
|
|
||||||
private regex = /\$(\w+)|\[\[([\s\S]+?)\]\]|\${(\w+):?(\w+)?}/g;
|
private regex = /\$(\w+)|\[\[([\s\S]+?)(?::(\w+))?\]\]|\${(\w+)(?::(\w+))?}/g;
|
||||||
private index = {};
|
private index = {};
|
||||||
private grafanaVariables = {};
|
private grafanaVariables = {};
|
||||||
private builtIns = {};
|
private builtIns = {};
|
||||||
@ -143,8 +143,8 @@ export class TemplateSrv {
|
|||||||
|
|
||||||
str = _.escape(str);
|
str = _.escape(str);
|
||||||
this.regex.lastIndex = 0;
|
this.regex.lastIndex = 0;
|
||||||
return str.replace(this.regex, (match, g1, g2, g3) => {
|
return str.replace(this.regex, (match, g1, g2, g3, g4) => {
|
||||||
if (this.index[g1 || g2 || g3] || this.builtIns[g1 || g2 || g3]) {
|
if (this.index[g1 || g2 || g4] || this.builtIns[g1 || g2 || g4]) {
|
||||||
return '<span class="template-variable">' + match + '</span>';
|
return '<span class="template-variable">' + match + '</span>';
|
||||||
}
|
}
|
||||||
return match;
|
return match;
|
||||||
@ -170,11 +170,11 @@ export class TemplateSrv {
|
|||||||
var variable, systemValue, value;
|
var variable, systemValue, value;
|
||||||
this.regex.lastIndex = 0;
|
this.regex.lastIndex = 0;
|
||||||
|
|
||||||
return target.replace(this.regex, (match, g1, g2, g3, g4) => {
|
return target.replace(this.regex, (match, g1, g2, g3, g4, g5) => {
|
||||||
variable = this.index[g1 || g2 || g3];
|
variable = this.index[g1 || g2 || g4];
|
||||||
format = g4 || format;
|
format = g3 || g5 || format;
|
||||||
if (scopedVars) {
|
if (scopedVars) {
|
||||||
value = scopedVars[g1 || g2 || g3];
|
value = scopedVars[g1 || g2 || g4];
|
||||||
if (value) {
|
if (value) {
|
||||||
return this.formatValue(value.value, format, variable);
|
return this.formatValue(value.value, format, variable);
|
||||||
}
|
}
|
||||||
@ -215,15 +215,15 @@ export class TemplateSrv {
|
|||||||
var variable;
|
var variable;
|
||||||
this.regex.lastIndex = 0;
|
this.regex.lastIndex = 0;
|
||||||
|
|
||||||
return target.replace(this.regex, (match, g1, g2, g3) => {
|
return target.replace(this.regex, (match, g1, g2, g3, g4) => {
|
||||||
if (scopedVars) {
|
if (scopedVars) {
|
||||||
var option = scopedVars[g1 || g2 || g3];
|
var option = scopedVars[g1 || g2 || g4];
|
||||||
if (option) {
|
if (option) {
|
||||||
return option.text;
|
return option.text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
variable = this.index[g1 || g2 || g3];
|
variable = this.index[g1 || g2 || g4];
|
||||||
if (!variable) {
|
if (!variable) {
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user