From dc6f977304c509d58b47f7e990ad2a3ea79666f7 Mon Sep 17 00:00:00 2001 From: Dan Cech Date: Thu, 22 Feb 2018 18:39:54 -0500 Subject: [PATCH] support [[variable:type]] syntax --- .../app/features/templating/template_srv.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index f29e133238e..a5b5418a564 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -8,7 +8,7 @@ function luceneEscape(value) { export class TemplateSrv { variables: any[]; - private regex = /\$(\w+)|\[\[([\s\S]+?)\]\]|\${(\w+):?(\w+)?}/g; + private regex = /\$(\w+)|\[\[([\s\S]+?)(?::(\w+))?\]\]|\${(\w+)(?::(\w+))?}/g; private index = {}; private grafanaVariables = {}; private builtIns = {}; @@ -143,8 +143,8 @@ export class TemplateSrv { str = _.escape(str); this.regex.lastIndex = 0; - return str.replace(this.regex, (match, g1, g2, g3) => { - if (this.index[g1 || g2 || g3] || this.builtIns[g1 || g2 || g3]) { + return str.replace(this.regex, (match, g1, g2, g3, g4) => { + if (this.index[g1 || g2 || g4] || this.builtIns[g1 || g2 || g4]) { return '' + match + ''; } return match; @@ -170,11 +170,11 @@ export class TemplateSrv { var variable, systemValue, value; this.regex.lastIndex = 0; - return target.replace(this.regex, (match, g1, g2, g3, g4) => { - variable = this.index[g1 || g2 || g3]; - format = g4 || format; + return target.replace(this.regex, (match, g1, g2, g3, g4, g5) => { + variable = this.index[g1 || g2 || g4]; + format = g3 || g5 || format; if (scopedVars) { - value = scopedVars[g1 || g2 || g3]; + value = scopedVars[g1 || g2 || g4]; if (value) { return this.formatValue(value.value, format, variable); } @@ -215,15 +215,15 @@ export class TemplateSrv { var variable; 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) { - var option = scopedVars[g1 || g2 || g3]; + var option = scopedVars[g1 || g2 || g4]; if (option) { return option.text; } } - variable = this.index[g1 || g2 || g3]; + variable = this.index[g1 || g2 || g4]; if (!variable) { return match; }