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
fa73b1ce
Commit
fa73b1ce
authored
Mar 01, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(templating): changed how the All templating value works
parent
f4b97979
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
19 deletions
+68
-19
public/app/features/templating/templateSrv.js
+30
-14
public/app/features/templating/templateValuesSrv.js
+2
-3
public/test/specs/templateSrv-specs.js
+35
-0
public/test/specs/templateValuesSrv-specs.js
+1
-2
No files found.
public/app/features/templating/templateSrv.js
View file @
fa73b1ce
...
...
@@ -13,7 +13,7 @@ function (angular, _) {
var
self
=
this
;
this
.
_regex
=
/
\$(\w
+
)
|
\[\[([\s\S]
+
?)\]\]
/g
;
this
.
_
values
=
{};
this
.
_
index
=
{};
this
.
_texts
=
{};
this
.
_grafanaVariables
=
{};
...
...
@@ -23,14 +23,14 @@ function (angular, _) {
};
this
.
updateTemplateData
=
function
()
{
this
.
_
values
=
{};
this
.
_
index
=
{};
for
(
var
i
=
0
;
i
<
this
.
variables
.
length
;
i
++
)
{
var
variable
=
this
.
variables
[
i
];
if
(
!
variable
.
current
||
!
variable
.
current
.
isNone
&&
!
variable
.
current
.
value
)
{
continue
;
}
this
.
_
values
[
variable
.
name
]
=
variable
.
current
;
this
.
_
index
[
variable
.
name
]
=
variable
;
}
};
...
...
@@ -80,7 +80,7 @@ function (angular, _) {
this
.
variableExists
=
function
(
expression
)
{
this
.
_regex
.
lastIndex
=
0
;
var
match
=
this
.
_regex
.
exec
(
expression
);
return
match
&&
(
self
.
_
values
[
match
[
1
]
||
match
[
2
]]
!==
void
0
);
return
match
&&
(
self
.
_
index
[
match
[
1
]
||
match
[
2
]]
!==
void
0
);
};
this
.
containsVariable
=
function
(
str
,
variableName
)
{
...
...
@@ -96,17 +96,24 @@ function (angular, _) {
str
=
_
.
escape
(
str
);
this
.
_regex
.
lastIndex
=
0
;
return
str
.
replace
(
this
.
_regex
,
function
(
match
,
g1
,
g2
)
{
if
(
self
.
_
values
[
g1
||
g2
])
{
if
(
self
.
_
index
[
g1
||
g2
])
{
return
'<span class="template-variable">'
+
match
+
'</span>'
;
}
return
match
;
});
};
this
.
getAllValue
=
function
(
variable
)
{
if
(
variable
.
allValue
)
{
return
variable
.
allValue
;
}
return
_
.
pluck
(
variable
.
options
,
'value'
);
};
this
.
replace
=
function
(
target
,
scopedVars
,
format
)
{
if
(
!
target
)
{
return
target
;
}
var
va
lue
,
systemV
alue
;
var
va
riable
,
systemValue
,
v
alue
;
this
.
_regex
.
lastIndex
=
0
;
return
target
.
replace
(
this
.
_regex
,
function
(
match
,
g1
,
g2
)
{
...
...
@@ -117,25 +124,34 @@ function (angular, _) {
}
}
va
lue
=
self
.
_values
[
g1
||
g2
];
if
(
!
va
lu
e
)
{
va
riable
=
self
.
_index
[
g1
||
g2
];
if
(
!
va
riabl
e
)
{
return
match
;
}
systemValue
=
self
.
_grafanaVariables
[
va
lue
.
value
];
systemValue
=
self
.
_grafanaVariables
[
va
riable
.
current
.
value
];
if
(
systemValue
)
{
return
self
.
formatValue
(
systemValue
);
}
var
res
=
self
.
formatValue
(
value
.
value
,
format
);
value
=
variable
.
current
.
value
;
if
(
self
.
isAllValue
(
value
))
{
value
=
self
.
getAllValue
(
variable
);
}
var
res
=
self
.
formatValue
(
value
,
format
);
return
res
;
});
};
this
.
isAllValue
=
function
(
value
)
{
return
value
===
'$__all'
||
Array
.
isArray
(
value
)
&&
value
[
0
]
===
'$__all'
;
};
this
.
replaceWithText
=
function
(
target
,
scopedVars
)
{
if
(
!
target
)
{
return
target
;
}
var
va
lu
e
;
var
va
riabl
e
;
this
.
_regex
.
lastIndex
=
0
;
return
target
.
replace
(
this
.
_regex
,
function
(
match
,
g1
,
g2
)
{
...
...
@@ -144,10 +160,10 @@ function (angular, _) {
if
(
option
)
{
return
option
.
text
;
}
}
va
lue
=
self
.
_values
[
g1
||
g2
];
if
(
!
va
lu
e
)
{
return
match
;
}
va
riable
=
self
.
_index
[
g1
||
g2
];
if
(
!
va
riabl
e
)
{
return
match
;
}
return
self
.
_grafanaVariables
[
va
lue
.
value
]
||
value
.
text
;
return
self
.
_grafanaVariables
[
va
riable
.
current
.
value
]
||
variable
.
current
.
text
;
});
};
...
...
public/app/features/templating/templateValuesSrv.js
View file @
fa73b1ce
...
...
@@ -231,12 +231,11 @@ function (angular, _, kbn) {
this
.
addAllOption
=
function
(
variable
)
{
if
(
variable
.
allValue
)
{
variable
.
options
.
unshift
({
text
:
'All'
,
value
:
variable
.
allValue
,
isAll
:
true
});
variable
.
options
.
unshift
({
text
:
'All'
,
value
:
variable
.
allValue
});
return
;
}
var
value
=
_
.
pluck
(
variable
.
options
,
'text'
);
variable
.
options
.
unshift
({
text
:
'All'
,
value
:
value
,
isAll
:
true
});
variable
.
options
.
unshift
({
text
:
'All'
,
value
:
"$__all"
});
};
});
...
...
public/test/specs/templateSrv-specs.js
View file @
fa73b1ce
...
...
@@ -66,6 +66,41 @@ define([
});
});
describe
(
'variable with all option'
,
function
()
{
beforeEach
(
function
()
{
_templateSrv
.
init
([{
name
:
'test'
,
current
:
{
value
:
'$__all'
},
options
:
[
{
value
:
'value1'
},
{
value
:
'value2'
}
]
}]);
});
it
(
'should replace $test with formatted all value'
,
function
()
{
var
target
=
_templateSrv
.
replace
(
'this.$test.filters'
,
{},
'glob'
);
expect
(
target
).
to
.
be
(
'this.{value1,value2}.filters'
);
});
});
describe
(
'variable with all option and custom value'
,
function
()
{
beforeEach
(
function
()
{
_templateSrv
.
init
([{
name
:
'test'
,
current
:
{
value
:
'$__all'
},
allValue
:
'*'
,
options
:
[
{
value
:
'value1'
},
{
value
:
'value2'
}
]
}]);
});
it
(
'should replace $test with formatted all value'
,
function
()
{
var
target
=
_templateSrv
.
replace
(
'this.$test.filters'
,
{},
'glob'
);
expect
(
target
).
to
.
be
(
'this.*.filters'
);
});
});
describe
(
'lucene format'
,
function
()
{
it
(
'should properly escape $test with lucene escape sequences'
,
function
()
{
_templateSrv
.
init
([{
name
:
'test'
,
current
:
{
value
:
'value/4'
}}]);
...
...
public/test/specs/templateValuesSrv-specs.js
View file @
fa73b1ce
...
...
@@ -267,8 +267,7 @@ define([
it
(
'should add All option'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
text
).
to
.
be
(
'All'
);
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
eql
([
'backend1'
,
'backend2'
,
'backend3'
]);
expect
(
scenario
.
variable
.
options
[
0
].
isAll
).
to
.
be
(
true
);
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'$__all'
);
});
});
...
...
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