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
d2437d3c
Commit
d2437d3c
authored
Aug 10, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: ad-hoc filters now works with data source variables, fixes #8052
parent
43fa852c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
15 deletions
+44
-15
public/app/features/templating/specs/template_srv_specs.ts
+25
-0
public/app/features/templating/templateSrv.js
+19
-13
public/app/features/templating/variable_srv.ts
+0
-2
No files found.
public/app/features/templating/specs/template_srv_specs.ts
View file @
d2437d3c
...
...
@@ -51,6 +51,31 @@ describe('templateSrv', function() {
});
});
describe
(
'getAdhocFilters'
,
function
()
{
beforeEach
(
function
()
{
initTemplateSrv
([
{
type
:
'datasource'
,
name
:
'ds'
,
current
:
{
value
:
'logstash'
,
text
:
'logstash'
}},
{
type
:
'adhoc'
,
name
:
'test'
,
datasource
:
'oogle'
,
filters
:
[
1
]},
{
type
:
'adhoc'
,
name
:
'test2'
,
datasource
:
'$ds'
,
filters
:
[
2
]},
]);
});
it
(
'should return filters if datasourceName match'
,
function
()
{
var
filters
=
_templateSrv
.
getAdhocFilters
(
'oogle'
);
expect
(
filters
).
to
.
eql
([
1
]);
});
it
(
'should return empty array if datasourceName does not match'
,
function
()
{
var
filters
=
_templateSrv
.
getAdhocFilters
(
'oogleasdasd'
);
expect
(
filters
).
to
.
eql
([]);
});
it
(
'should return filters when datasourceName match via data source variable'
,
function
()
{
var
filters
=
_templateSrv
.
getAdhocFilters
(
'logstash'
);
expect
(
filters
).
to
.
eql
([
2
]);
});
});
describe
(
'replace can pass multi / all format'
,
function
()
{
beforeEach
(
function
()
{
initTemplateSrv
([{
type
:
'query'
,
name
:
'test'
,
current
:
{
value
:
[
'value1'
,
'value2'
]
}}]);
...
...
public/app/features/templating/templateSrv.js
View file @
d2437d3c
...
...
@@ -15,7 +15,6 @@ function (angular, _, kbn) {
this
.
_index
=
{};
this
.
_texts
=
{};
this
.
_grafanaVariables
=
{};
this
.
_adhocVariables
=
{};
// default built ins
this
.
_builtIns
=
{};
...
...
@@ -30,24 +29,16 @@ function (angular, _, kbn) {
this
.
updateTemplateData
=
function
()
{
this
.
_index
=
{};
this
.
_filters
=
{};
this
.
_adhocVariables
=
{};
for
(
var
i
=
0
;
i
<
this
.
variables
.
length
;
i
++
)
{
var
variable
=
this
.
variables
[
i
];
// add adhoc filters to it's own index
if
(
variable
.
type
===
'adhoc'
)
{
this
.
_adhocVariables
[
variable
.
datasource
]
=
variable
;
continue
;
}
if
(
!
variable
.
current
||
!
variable
.
current
.
isNone
&&
!
variable
.
current
.
value
)
{
continue
;
}
this
.
_index
[
variable
.
name
]
=
variable
;
}
};
this
.
variableInitialized
=
function
(
variable
)
{
...
...
@@ -55,11 +46,26 @@ function (angular, _, kbn) {
};
this
.
getAdhocFilters
=
function
(
datasourceName
)
{
var
variable
=
this
.
_adhocVariables
[
datasourceName
];
if
(
variable
)
{
return
variable
.
filters
||
[];
var
filters
=
[];
for
(
var
i
=
0
;
i
<
this
.
variables
.
length
;
i
++
)
{
var
variable
=
this
.
variables
[
i
];
if
(
variable
.
type
!==
'adhoc'
)
{
continue
;
}
if
(
variable
.
datasource
===
datasourceName
)
{
filters
=
filters
.
concat
(
variable
.
filters
);
}
if
(
variable
.
datasource
.
indexOf
(
'$'
)
===
0
)
{
if
(
this
.
replace
(
variable
.
datasource
)
===
datasourceName
)
{
filters
=
filters
.
concat
(
variable
.
filters
);
}
}
}
return
[];
return
filters
;
};
function
luceneEscape
(
value
)
{
...
...
public/app/features/templating/variable_srv.ts
View file @
d2437d3c
...
...
@@ -247,8 +247,6 @@ export class VariableSrv {
}
filter
.
operator
=
options
.
operator
;
variable
.
setFilters
(
filters
);
this
.
variableUpdated
(
variable
,
true
);
}
...
...
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