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
4ef79d25
Commit
4ef79d25
authored
Feb 28, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(templating): initial work on rethink of value formating
parent
62d703fd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
28 deletions
+50
-28
public/app/features/dashboard/partials/shareModal.html
+15
-14
public/app/features/templating/templateSrv.js
+19
-14
public/test/specs/templateSrv-specs.js
+16
-0
No files found.
public/app/features/dashboard/partials/shareModal.html
View file @
4ef79d25
...
...
@@ -136,22 +136,23 @@
<
button
class
=
"btn btn-inverse btn-large"
data
-
clipboard
-
text
=
"{{snapshotUrl}}"
clipboard
-
button
><
i
class
=
"fa fa-clipboard"
><
/i> Copy Link</
button
>
<
/div
>
<
/div
>
<
/div
>
<
div
ng
-
if
=
"step === 1"
class
=
"gf-form-buttons-row"
>
<
button
class
=
"btn btn-success btn-large"
ng
-
click
=
"createSnapshot()"
ng
-
disabled
=
"loading"
>
<
i
class
=
"fa fa-save"
><
/i
>
Local
Snapshot
<
/button
>
<
button
class
=
"btn btn-primary btn-large"
ng
-
if
=
"externalEnabled"
ng
-
click
=
"createSnapshot(true)"
ng
-
disabled
=
"loading"
>
<
i
class
=
"fa fa-cloud-upload"
><
/i
>
{{
sharingButtonText
}}
<
/button
>
<
/div
>
<
div
class
=
"pull-right"
ng
-
if
=
"step === 2"
style
=
"padding: 5px"
>
Did
you
make
a
mistake
?
<
a
class
=
"pointer"
ng
-
click
=
"deleteSnapshot()"
target
=
"_blank"
>
delete
snapshot
.
<
/a
>
<
/div
>
<
div
ng
-
if
=
"step === 1"
class
=
"gf-form-buttons-row"
>
<
button
class
=
"btn btn-success btn-large"
ng
-
click
=
"createSnapshot()"
ng
-
disabled
=
"loading"
>
<
i
class
=
"fa fa-save"
><
/i
>
Local
Snapshot
<
/button
>
<
button
class
=
"btn btn-primary btn-large"
ng
-
if
=
"externalEnabled"
ng
-
click
=
"createSnapshot(true)"
ng
-
disabled
=
"loading"
>
<
i
class
=
"fa fa-cloud-upload"
><
/i
>
{{
sharingButtonText
}}
<
/button
>
<
/div
>
<
div
class
=
"pull-right"
ng
-
if
=
"step === 2"
style
=
"padding: 5px"
>
Did
you
make
a
mistake
?
<
a
class
=
"pointer"
ng
-
click
=
"deleteSnapshot()"
target
=
"_blank"
>
delete
snapshot
.
<
/a
>
<
/div
>
<
/div
>
<
/div
>
</script>
public/app/features/templating/templateSrv.js
View file @
4ef79d25
...
...
@@ -24,22 +24,18 @@ function (angular, _) {
this
.
updateTemplateData
=
function
()
{
this
.
_values
=
{};
this
.
_texts
=
{};
_
.
each
(
this
.
variables
,
function
(
variable
)
{
if
(
!
variable
.
current
||
!
variable
.
current
.
isNone
&&
!
variable
.
current
.
value
)
{
return
;
}
this
.
_values
[
variable
.
name
]
=
this
.
renderVariableValue
(
variable
);
this
.
_texts
[
variable
.
name
]
=
variable
.
current
.
text
;
},
this
);
if
(
!
variable
.
current
||
!
variable
.
current
.
isNone
&&
!
variable
.
current
.
value
)
{
return
;
}
this
.
_values
[
variable
.
name
]
=
variable
.
current
.
value
;
},
this
);
};
this
.
renderVariableValue
=
function
(
variable
)
{
var
value
=
variable
.
current
.
value
;
this
.
formatValue
=
function
(
value
,
format
)
{
if
(
_
.
isString
(
value
))
{
return
value
;
}
else
{
switch
(
variable
.
multiF
ormat
)
{
switch
(
f
ormat
)
{
case
"regex values"
:
{
return
'('
+
value
.
join
(
'|'
)
+
')'
;
}
...
...
@@ -89,22 +85,31 @@ function (angular, _) {
});
};
this
.
replace
=
function
(
target
,
scopedVars
)
{
this
.
replace
=
function
(
target
,
scopedVars
,
format
)
{
if
(
!
target
)
{
return
target
;
}
var
value
;
var
value
,
systemValue
;
this
.
_regex
.
lastIndex
=
0
;
return
target
.
replace
(
this
.
_regex
,
function
(
match
,
g1
,
g2
)
{
if
(
scopedVars
)
{
value
=
scopedVars
[
g1
||
g2
];
if
(
value
)
{
return
value
.
value
;
}
if
(
value
)
{
return
self
.
formatValue
(
value
.
value
);
}
}
value
=
self
.
_values
[
g1
||
g2
];
if
(
!
value
)
{
return
match
;
}
if
(
!
value
)
{
return
match
;
}
systemValue
=
self
.
_grafanaVariables
[
value
];
if
(
systemValue
)
{
return
self
.
formatValue
(
systemValue
);
}
return
self
.
_grafanaVariables
[
value
]
||
value
;
return
self
.
formatValue
(
value
,
format
)
;
});
};
...
...
public/test/specs/templateSrv-specs.js
View file @
4ef79d25
...
...
@@ -45,6 +45,22 @@ define([
});
});
describe
.
only
(
'replace can pass multi / all format'
,
function
()
{
beforeEach
(
function
()
{
_templateSrv
.
init
([{
name
:
'test'
,
current
:
{
value
:
[
'value1'
,
'value2'
]
}}]);
});
it
(
'should replace $test with globbed value'
,
function
()
{
var
target
=
_templateSrv
.
replace
(
'this.$test.filters'
,
{},
'glob'
);
expect
(
target
).
to
.
be
(
'this.{value1,value2}.filters'
);
});
it
(
'should replace $test with piped value'
,
function
()
{
var
target
=
_templateSrv
.
replace
(
'this=$test'
,
{},
'pipe'
);
expect
(
target
).
to
.
be
(
'this=value1|value2'
);
});
});
describe
(
'render variable to string values'
,
function
()
{
it
(
'single value should return value'
,
function
()
{
var
result
=
_templateSrv
.
renderVariableValue
({
current
:
{
value
:
'test'
}});
...
...
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