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
8f5a7f17
Commit
8f5a7f17
authored
Mar 01, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(templating): more work on context specific varaiable formats, #2918
parent
f3ad71d7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
174 deletions
+40
-174
public/app/features/templating/templateSrv.js
+14
-10
public/app/features/templating/templateValuesSrv.js
+6
-46
public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts
+1
-1
public/test/specs/templateSrv-specs.js
+9
-30
public/test/specs/templateValuesSrv-specs.js
+10
-87
No files found.
public/app/features/templating/templateSrv.js
View file @
8f5a7f17
...
...
@@ -25,10 +25,13 @@ function (angular, _) {
this
.
updateTemplateData
=
function
()
{
this
.
_values
=
{};
_
.
each
(
this
.
variables
,
function
(
variable
)
{
if
(
!
variable
.
current
||
!
variable
.
current
.
isNone
&&
!
variable
.
current
.
value
)
{
return
;
}
this
.
_values
[
variable
.
name
]
=
variable
.
current
.
value
;
},
this
);
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
;
}
};
function
regexEscape
(
value
)
{
...
...
@@ -42,6 +45,10 @@ function (angular, _) {
this
.
formatValue
=
function
(
value
,
format
)
{
switch
(
format
)
{
case
"regex"
:
{
if
(
typeof
value
===
'string'
)
{
return
regexEscape
(
value
);
}
var
escapedValues
=
_
.
map
(
value
,
regexEscape
);
return
'('
+
escapedValues
.
join
(
'|'
)
+
')'
;
}
...
...
@@ -115,13 +122,12 @@ function (angular, _) {
return
match
;
}
systemValue
=
self
.
_grafanaVariables
[
value
];
systemValue
=
self
.
_grafanaVariables
[
value
.
value
];
if
(
systemValue
)
{
return
self
.
formatValue
(
systemValue
);
}
var
res
=
self
.
formatValue
(
value
,
format
);
console
.
log
(
'replace: '
+
value
,
res
);
var
res
=
self
.
formatValue
(
value
.
value
,
format
);
return
res
;
});
};
...
...
@@ -130,7 +136,6 @@ function (angular, _) {
if
(
!
target
)
{
return
target
;
}
var
value
;
var
text
;
this
.
_regex
.
lastIndex
=
0
;
return
target
.
replace
(
this
.
_regex
,
function
(
match
,
g1
,
g2
)
{
...
...
@@ -140,10 +145,9 @@ function (angular, _) {
}
value
=
self
.
_values
[
g1
||
g2
];
text
=
self
.
_texts
[
g1
||
g2
];
if
(
!
value
)
{
return
match
;
}
return
self
.
_grafanaVariables
[
value
]
||
text
;
return
self
.
_grafanaVariables
[
value
.
value
]
||
value
.
text
;
});
};
...
...
public/app/features/templating/templateValuesSrv.js
View file @
8f5a7f17
...
...
@@ -225,58 +225,18 @@ function (angular, _, kbn) {
return
_
.
map
(
_
.
keys
(
options
).
sort
(),
function
(
key
)
{
var
option
=
{
text
:
key
,
value
:
key
};
// // check if values need to be regex escaped
// if (self.shouldRegexEscape(variable)) {
// option.value = self.regexEscape(option.value);
// }
return
option
;
});
};
// this.shouldRegexEscape = function(variable) {
// return (variable.includeAll || variable.multi) && variable.allFormat.indexOf('regex') !== -1;
// };
//
this
.
addAllOption
=
function
(
variable
)
{
// var allValue = '';
// switch(variable.allFormat) {
// case 'wildcard': {
// allValue = '*';
// break;
// }
// case 'regex wildcard': {
// allValue = '.*';
// break;
// }
// case 'lucene': {
// var quotedValues = _.map(variable.options, function(val) {
// return '\\\"' + val.text + '\\\"';
// });
// allValue = '(' + quotedValues.join(' OR ') + ')';
// break;
// }
// case 'regex values': {
// allValue = '(' + _.map(variable.options, function(option) {
// return self.regexEscape(option.text);
// }).join('|') + ')';
// break;
// }
// case 'pipe': {
// allValue = _.pluck(variable.options, 'text').join('|');
// break;
// }
// default: {
// allValue = '{';
// allValue += _.pluck(variable.options, 'text').join(',');
// allValue += '}';
// }
// }
//
if
(
variable
.
allValue
)
{
variable
.
options
.
unshift
({
text
:
'All'
,
value
:
variable
.
allValue
,
isAll
:
true
});
return
;
}
var
value
=
_
.
pluck
(
variable
.
options
,
'text'
);
variable
.
options
.
unshift
({
text
:
'All'
,
value
:
value
});
variable
.
options
.
unshift
({
text
:
'All'
,
value
:
value
,
isAll
:
true
});
};
});
...
...
public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts
View file @
8f5a7f17
...
...
@@ -33,7 +33,7 @@ describe('ElasticDatasource', function() {
var
requestOptions
;
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({});
return
ctx
.
$q
.
when
({
data
:
{}
});
};
ctx
.
ds
.
testDatasource
();
...
...
public/test/specs/templateSrv-specs.js
View file @
8f5a7f17
...
...
@@ -66,7 +66,7 @@ define([
});
});
describe
.
only
(
'lucene format'
,
function
()
{
describe
(
'lucene format'
,
function
()
{
it
(
'should properly escape $test with lucene escape sequences'
,
function
()
{
_templateSrv
.
init
([{
name
:
'test'
,
current
:
{
value
:
'value/4'
}}]);
var
target
=
_templateSrv
.
replace
(
'this:$test'
,
{},
'lucene'
);
...
...
@@ -74,49 +74,29 @@ define([
});
});
describe
(
'
render
variable to string values'
,
function
()
{
describe
(
'
format
variable to string values'
,
function
()
{
it
(
'single value should return value'
,
function
()
{
var
result
=
_templateSrv
.
renderVariableValue
({
current
:
{
value
:
'test'
}}
);
var
result
=
_templateSrv
.
formatValue
(
'test'
);
expect
(
result
).
to
.
be
(
'test'
);
});
it
(
'multi value and glob format should render glob string'
,
function
()
{
var
result
=
_templateSrv
.
renderVariableValue
({
multiFormat
:
'glob'
,
current
:
{
value
:
[
'test'
,
'test2'
],
}
});
var
result
=
_templateSrv
.
formatValue
([
'test'
,
'test2'
],
'glob'
);
expect
(
result
).
to
.
be
(
'{test,test2}'
);
});
it
(
'multi value and lucene should render as lucene expr'
,
function
()
{
var
result
=
_templateSrv
.
renderVariableValue
({
multiFormat
:
'lucene'
,
current
:
{
value
:
[
'test'
,
'test2'
],
}
});
expect
(
result
).
to
.
be
(
'(
\\\
"test
\\\
" OR
\\\
"test2
\\\
")'
);
var
result
=
_templateSrv
.
formatValue
([
'test'
,
'test2'
],
'lucene'
);
expect
(
result
).
to
.
be
(
'("test" OR "test2")'
);
});
it
(
'multi value and regex format should render regex string'
,
function
()
{
var
result
=
_templateSrv
.
renderVariableValue
({
multiFormat
:
'regex values'
,
current
:
{
value
:
[
'test'
,
'test2'
],
}
});
expect
(
result
).
to
.
be
(
'(test|test2)'
);
var
result
=
_templateSrv
.
formatValue
([
'test.'
,
'test2'
],
'regex'
);
expect
(
result
).
to
.
be
(
'(test
\\
.|test2)'
);
});
it
(
'multi value and pipe should render pipe string'
,
function
()
{
var
result
=
_templateSrv
.
renderVariableValue
({
multiFormat
:
'pipe'
,
current
:
{
value
:
[
'test'
,
'test2'
],
}
});
var
result
=
_templateSrv
.
formatValue
([
'test'
,
'test2'
],
'pipe'
);
expect
(
result
).
to
.
be
(
'test|test2'
);
});
...
...
@@ -223,7 +203,6 @@ define([
});
});
});
});
public/test/specs/templateValuesSrv-specs.js
View file @
8f5a7f17
...
...
@@ -247,7 +247,7 @@ define([
});
});
describeUpdateVariable
(
'regex pattern remove duplicates'
,
function
(
scenario
)
{
describeUpdateVariable
(
'regex pattern remove duplicates'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
};
scenario
.
variable
.
regex
=
'backend_01'
;
...
...
@@ -259,107 +259,30 @@ define([
});
});
describeUpdateVariable
(
'with include All
glob syntax
'
,
function
(
scenario
)
{
describeUpdateVariable
(
'with include All'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
allFormat
:
'glob'
};
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
};
scenario
.
queryResult
=
[{
text
:
'backend1'
},
{
text
:
'backend2'
},
{
text
:
'backend3'
}];
});
it
(
'should add All Glob option'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'{backend1,backend2,backend3}'
);
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
);
});
});
describeUpdateVariable
(
'with include all
wildcard
'
,
function
(
scenario
)
{
describeUpdateVariable
(
'with include all
and custom value
'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
all
Format
:
'wildcard
'
};
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
all
Value
:
'*
'
};
scenario
.
queryResult
=
[{
text
:
'backend1'
},
{
text
:
'backend2'
},
{
text
:
'backend3'
}];
});
it
(
'should add All
wildcard option
'
,
function
()
{
it
(
'should add All
option with custom value
'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'*'
);
});
});
describeUpdateVariable
(
'with include all wildcard'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
allFormat
:
'regex wildcard'
};
scenario
.
queryResult
=
[{
text
:
'backend1'
},
{
text
:
'backend2'
},
{
text
:
'backend3'
}];
});
it
(
'should add All wildcard option'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'.*'
);
});
});
describeUpdateVariable
(
'with include all regex values'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
allFormat
:
'wildcard'
};
scenario
.
queryResult
=
[{
text
:
'backend1'
},
{
text
:
'backend2'
},
{
text
:
'backend3'
}];
});
it
(
'should add All wildcard option'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'*'
);
});
});
describeUpdateVariable
(
'with include all glob no values'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
allFormat
:
'glob'
};
scenario
.
queryResult
=
[];
});
it
(
'should add empty glob'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'{}'
);
});
});
describeUpdateVariable
(
'with include all lucene and values'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
allFormat
:
'lucene'
};
scenario
.
queryResult
=
[{
text
:
'backend1'
},
{
text
:
'backend2'
}];
});
it
(
'should add lucene glob'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'(
\\\
"backend1
\\\
" OR
\\\
"backend2
\\\
")'
);
});
});
describeUpdateVariable
(
'with include all regex all values'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
allFormat
:
'regex values'
};
scenario
.
queryResult
=
[{
text
:
'backend1'
},
{
text
:
'backend2'
},
{
text
:
'backend3'
}];
});
it
(
'should add empty glob'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'(backend1|backend2|backend3)'
);
});
});
describeUpdateVariable
(
'with include all regex values and values require escaping'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
allFormat
:
'regex values'
};
scenario
.
queryResult
=
[{
text
:
'/root'
},
{
text
:
'/var'
},
{
text
:
'/lib'
}];
});
it
(
'should regex escape options'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'(
\\
/lib|
\\
/root|
\\
/var)'
);
expect
(
scenario
.
variable
.
options
[
1
].
value
).
to
.
be
(
'
\\
/lib'
);
expect
(
scenario
.
variable
.
options
[
1
].
text
).
to
.
be
(
'/lib'
);
});
});
describeUpdateVariable
(
'with include all pipe all values'
,
function
(
scenario
)
{
scenario
.
setup
(
function
()
{
scenario
.
variable
=
{
type
:
'query'
,
query
:
'apps.*'
,
name
:
'test'
,
includeAll
:
true
,
allFormat
:
'pipe'
};
scenario
.
queryResult
=
[{
text
:
'backend1'
},
{
text
:
'backend2'
},
{
text
:
'backend3'
}];
});
it
(
'should add pipe delimited string'
,
function
()
{
expect
(
scenario
.
variable
.
options
[
0
].
value
).
to
.
be
(
'backend1|backend2|backend3'
);
});
});
});
});
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