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
bf72b26c
Commit
bf72b26c
authored
Mar 11, 2019
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring of multi-value datasource PR #15812
parent
a8486806
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
27 deletions
+9
-27
public/app/features/panel/metrics_panel_ctrl.ts
+1
-20
public/app/features/plugins/datasource_srv.ts
+8
-7
No files found.
public/app/features/panel/metrics_panel_ctrl.ts
View file @
bf72b26c
...
...
@@ -79,28 +79,9 @@ class MetricsPanelCtrl extends PanelCtrl {
delete
this
.
error
;
this
.
loading
=
true
;
// set "mydatasource" to whatever the panel has defined
let
mydatasource
=
this
.
panel
.
datasource
;
let
datasourceVarName
=
''
;
// look for data source variables
for
(
let
i
=
0
;
i
<
this
.
templateSrv
.
variables
.
length
;
i
++
)
{
const
variable
=
this
.
templateSrv
.
variables
[
i
];
if
(
variable
.
type
!==
'datasource'
)
{
continue
;
}
datasourceVarName
=
variable
.
name
;
}
// if a data source variable was found, use its value
if
(
datasourceVarName
!==
''
&&
this
.
panel
.
scopedVars
&&
this
.
panel
.
scopedVars
[
datasourceVarName
])
{
mydatasource
=
this
.
panel
.
scopedVars
[
datasourceVarName
].
value
;
}
// load datasource service
this
.
datasourceSrv
.
get
(
mydatasource
)
.
get
(
this
.
panel
.
datasource
,
this
.
panel
.
scopedVars
)
.
then
(
this
.
updateTimeRange
.
bind
(
this
))
.
then
(
this
.
issueQueries
.
bind
(
this
))
.
then
(
this
.
handleQueryResult
.
bind
(
this
))
...
...
public/app/features/plugins/datasource_srv.ts
View file @
bf72b26c
...
...
@@ -7,7 +7,7 @@ import config from 'app/core/config';
import
{
importPluginModule
}
from
'./plugin_loader'
;
// Types
import
{
DataSourceApi
,
DataSourceSelectItem
}
from
'@grafana/ui/src/types'
;
import
{
DataSourceApi
,
DataSourceSelectItem
,
ScopedVars
}
from
'@grafana/ui/src/types'
;
export
class
DatasourceSrv
{
datasources
:
{
[
name
:
string
]:
DataSourceApi
};
...
...
@@ -21,12 +21,17 @@ export class DatasourceSrv {
this
.
datasources
=
{};
}
get
(
name
?:
string
):
Promise
<
DataSourceApi
>
{
get
(
name
?:
string
,
scopedVars
?:
ScopedVars
):
Promise
<
DataSourceApi
>
{
if
(
!
name
)
{
return
this
.
get
(
config
.
defaultDatasource
);
}
name
=
this
.
templateSrv
.
replace
(
name
);
name
=
this
.
templateSrv
.
replace
(
name
,
scopedVars
,
(
value
,
variable
)
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
[
0
];
}
return
value
;
});
if
(
name
===
'default'
)
{
return
this
.
get
(
config
.
defaultDatasource
);
...
...
@@ -40,10 +45,6 @@ export class DatasourceSrv {
}
loadDatasource
(
name
:
string
):
Promise
<
DataSourceApi
>
{
// if there are multiple datasources provided, just use the first one
const
re
=
/{
([^
,}
]
+
)
.*/
;
name
=
name
.
replace
(
re
,
'$1'
);
const
dsConfig
=
config
.
datasources
[
name
];
if
(
!
dsConfig
)
{
return
this
.
$q
.
reject
({
message
:
'Datasource named '
+
name
+
' was not found'
});
...
...
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