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
db99b865
Unverified
Commit
db99b865
authored
Jan 22, 2019
by
Torkel Ödegaard
Committed by
GitHub
Jan 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12765 from cxcv/master
added percentencode formatting option
parents
75e3d900
bde4b76c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
0 deletions
+22
-0
docs/sources/reference/templating.md
+1
-0
public/app/features/templating/specs/template_srv.test.ts
+5
-0
public/app/features/templating/template_srv.ts
+16
-0
No files found.
docs/sources/reference/templating.md
View file @
db99b865
...
@@ -52,6 +52,7 @@ Filter Option | Example | Raw | Interpolated | Description
...
@@ -52,6 +52,7 @@ Filter Option | Example | Raw | Interpolated | Description
`csv`
| ${servers:csv} |
`'test1', 'test2'`
|
`test1,test2`
| Formats multi-value variable as a comma-separated string
`csv`
| ${servers:csv} |
`'test1', 'test2'`
|
`test1,test2`
| Formats multi-value variable as a comma-separated string
`distributed`
| ${servers:distributed} |
`'test1', 'test2'`
|
`test1,servers=test2`
| Formats multi-value variable in custom format for OpenTSDB.
`distributed`
| ${servers:distributed} |
`'test1', 'test2'`
|
`test1,servers=test2`
| Formats multi-value variable in custom format for OpenTSDB.
`lucene`
| ${servers:lucene} |
`'test', 'test2'`
|
`("test" OR "test2")`
| Formats multi-value variable as a lucene expression.
`lucene`
| ${servers:lucene} |
`'test', 'test2'`
|
`("test" OR "test2")`
| Formats multi-value variable as a lucene expression.
`percentencode`
| ${servers:percentencode} |
`'foo()bar BAZ', 'test2'`
|
`{foo%28%29bar%20BAZ%2Ctest2}`
| Formats multi-value variable into a glob, percent-encoded.
Test the formatting options on the
[
Grafana Play site
](
http://play.grafana.org/d/cJtIfcWiz/template-variable-formatting-options?orgId=1
)
.
Test the formatting options on the
[
Grafana Play site
](
http://play.grafana.org/d/cJtIfcWiz/template-variable-formatting-options?orgId=1
)
.
...
...
public/app/features/templating/specs/template_srv.test.ts
View file @
db99b865
...
@@ -275,6 +275,11 @@ describe('templateSrv', () => {
...
@@ -275,6 +275,11 @@ describe('templateSrv', () => {
expect
(
result
).
toBe
(
'test,test2'
);
expect
(
result
).
toBe
(
'test,test2'
);
});
});
it
(
'multi value and percentencode format should render percent-encoded string'
,
()
=>
{
const
result
=
_templateSrv
.
formatValue
([
'foo()bar BAZ'
,
'test2'
],
'percentencode'
);
expect
(
result
).
toBe
(
'%7Bfoo%28%29bar%20BAZ%2Ctest2%7D'
);
});
it
(
'slash should be properly escaped in regex format'
,
()
=>
{
it
(
'slash should be properly escaped in regex format'
,
()
=>
{
const
result
=
_templateSrv
.
formatValue
(
'Gi3/14'
,
'regex'
);
const
result
=
_templateSrv
.
formatValue
(
'Gi3/14'
,
'regex'
);
expect
(
result
).
toBe
(
'Gi3
\\
/14'
);
expect
(
result
).
toBe
(
'Gi3
\\
/14'
);
...
...
public/app/features/templating/template_srv.ts
View file @
db99b865
...
@@ -77,6 +77,15 @@ export class TemplateSrv {
...
@@ -77,6 +77,15 @@ export class TemplateSrv {
return
'('
+
quotedValues
.
join
(
' OR '
)
+
')'
;
return
'('
+
quotedValues
.
join
(
' OR '
)
+
')'
;
}
}
// encode string according to RFC 3986; in contrast to encodeURIComponent()
// also the sub-delims "!", "'", "(", ")" and "*" are encoded;
// unicode handling uses UTF-8 as in ECMA-262.
encodeURIComponentStrict
(
str
)
{
return
encodeURIComponent
(
str
).
replace
(
/
[
!'()*
]
/g
,
(
c
)
=>
{
return
'%'
+
c
.
charCodeAt
(
0
).
toString
(
16
).
toUpperCase
();
});
}
formatValue
(
value
,
format
,
variable
)
{
formatValue
(
value
,
format
,
variable
)
{
// for some scopedVars there is no variable
// for some scopedVars there is no variable
variable
=
variable
||
{};
variable
=
variable
||
{};
...
@@ -118,6 +127,13 @@ export class TemplateSrv {
...
@@ -118,6 +127,13 @@ export class TemplateSrv {
}
}
return
value
;
return
value
;
}
}
case
'percentencode'
:
{
// like glob, but url escaped
if
(
_
.
isArray
(
value
))
{
return
this
.
encodeURIComponentStrict
(
'{'
+
value
.
join
(
','
)
+
'}'
);
}
return
this
.
encodeURIComponentStrict
(
value
);
}
default
:
{
default
:
{
if
(
_
.
isArray
(
value
))
{
if
(
_
.
isArray
(
value
))
{
return
'{'
+
value
.
join
(
','
)
+
'}'
;
return
'{'
+
value
.
join
(
','
)
+
'}'
;
...
...
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