Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
abf498fc
Unverified
Commit
abf498fc
authored
Feb 23, 2018
by
Dan Cech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve maintainability
parent
dc6f9773
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
+15
-9
public/app/features/templating/template_srv.ts
+15
-9
No files found.
public/app/features/templating/template_srv.ts
View file @
abf498fc
...
@@ -8,6 +8,12 @@ function luceneEscape(value) {
...
@@ -8,6 +8,12 @@ function luceneEscape(value) {
export
class
TemplateSrv
{
export
class
TemplateSrv
{
variables
:
any
[];
variables
:
any
[];
/*
* This regex matches 3 types of variable reference with an optional format specifier
* \$(\w+) $var1
* \[\[([\s\S]+?)(?::(\w+))?\]\] [[var2]] or [[var2:fmt2]]
* \${(\w+)(?::(\w+))?} ${var3} or ${var3:fmt3}
*/
private
regex
=
/
\$(\w
+
)
|
\[\[([\s\S]
+
?)(?:
:
(\w
+
))?\]\]
|
\$
{
(\w
+
)(?:
:
(\w
+
))?
}/g
;
private
regex
=
/
\$(\w
+
)
|
\[\[([\s\S]
+
?)(?:
:
(\w
+
))?\]\]
|
\$
{
(\w
+
)(?:
:
(\w
+
))?
}/g
;
private
index
=
{};
private
index
=
{};
private
grafanaVariables
=
{};
private
grafanaVariables
=
{};
...
@@ -143,8 +149,8 @@ export class TemplateSrv {
...
@@ -143,8 +149,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
,
g4
)
=>
{
return
str
.
replace
(
this
.
regex
,
(
match
,
var1
,
var2
,
fmt2
,
var3
)
=>
{
if
(
this
.
index
[
g1
||
g2
||
g4
]
||
this
.
builtIns
[
g1
||
g2
||
g4
])
{
if
(
this
.
index
[
var1
||
var2
||
var3
]
||
this
.
builtIns
[
var1
||
var2
||
var3
])
{
return
'<span class="template-variable">'
+
match
+
'</span>'
;
return
'<span class="template-variable">'
+
match
+
'</span>'
;
}
}
return
match
;
return
match
;
...
@@ -170,11 +176,11 @@ export class TemplateSrv {
...
@@ -170,11 +176,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
,
g5
)
=>
{
return
target
.
replace
(
this
.
regex
,
(
match
,
var1
,
var2
,
fmt2
,
var3
,
fmt3
)
=>
{
variable
=
this
.
index
[
g1
||
g2
||
g4
];
variable
=
this
.
index
[
var1
||
var2
||
var3
];
format
=
g3
||
g5
||
format
;
format
=
fmt2
||
fmt3
||
format
;
if
(
scopedVars
)
{
if
(
scopedVars
)
{
value
=
scopedVars
[
g1
||
g2
||
g4
];
value
=
scopedVars
[
var1
||
var2
||
var3
];
if
(
value
)
{
if
(
value
)
{
return
this
.
formatValue
(
value
.
value
,
format
,
variable
);
return
this
.
formatValue
(
value
.
value
,
format
,
variable
);
}
}
...
@@ -215,15 +221,15 @@ export class TemplateSrv {
...
@@ -215,15 +221,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
,
g4
)
=>
{
return
target
.
replace
(
this
.
regex
,
(
match
,
var1
,
var2
,
fmt2
,
var3
)
=>
{
if
(
scopedVars
)
{
if
(
scopedVars
)
{
var
option
=
scopedVars
[
g1
||
g2
||
g4
];
var
option
=
scopedVars
[
var1
||
var2
||
var3
];
if
(
option
)
{
if
(
option
)
{
return
option
.
text
;
return
option
.
text
;
}
}
}
}
variable
=
this
.
index
[
g1
||
g2
||
g4
];
variable
=
this
.
index
[
var1
||
var2
||
var3
];
if
(
!
variable
)
{
if
(
!
variable
)
{
return
match
;
return
match
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment