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
430bcf19
Commit
430bcf19
authored
May 19, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(export): templetize annotations and template vars, #5084
parent
cac723da
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
9 deletions
+49
-9
public/app/features/dashboard/export/exporter.ts
+26
-6
public/app/features/dashboard/specs/exporter_specs.ts
+23
-3
No files found.
public/app/features/dashboard/export/exporter.ts
View file @
430bcf19
...
@@ -22,12 +22,10 @@ export class DashboardExporter {
...
@@ -22,12 +22,10 @@ export class DashboardExporter {
var
datasources
=
{};
var
datasources
=
{};
var
promises
=
[];
var
promises
=
[];
for
(
let
row
of
dash
.
rows
)
{
var
templateizeDatasourceUsage
=
obj
=>
{
_
.
each
(
row
.
panels
,
(
panel
)
=>
{
promises
.
push
(
this
.
datasourceSrv
.
get
(
obj
.
datasource
).
then
(
ds
=>
{
if
(
panel
.
datasource
!==
undefined
)
{
promises
.
push
(
this
.
datasourceSrv
.
get
(
panel
.
datasource
).
then
(
ds
=>
{
var
refName
=
'DS_'
+
ds
.
name
.
replace
(
' '
,
'_'
).
toUpperCase
();
var
refName
=
'DS_'
+
ds
.
name
.
replace
(
' '
,
'_'
).
toUpperCase
();
datasources
[
panel
.
datasource
]
=
{
datasources
[
obj
.
datasource
]
=
{
name
:
refName
,
name
:
refName
,
label
:
ds
.
name
,
label
:
ds
.
name
,
description
:
''
,
description
:
''
,
...
@@ -35,7 +33,7 @@ export class DashboardExporter {
...
@@ -35,7 +33,7 @@ export class DashboardExporter {
pluginId
:
ds
.
meta
.
id
,
pluginId
:
ds
.
meta
.
id
,
pluginName
:
ds
.
meta
.
name
,
pluginName
:
ds
.
meta
.
name
,
};
};
panel
.
datasource
=
'${'
+
refName
+
'}'
;
obj
.
datasource
=
'${'
+
refName
+
'}'
;
requires
[
'datasource'
+
ds
.
meta
.
id
]
=
{
requires
[
'datasource'
+
ds
.
meta
.
id
]
=
{
type
:
'datasource'
,
type
:
'datasource'
,
...
@@ -44,6 +42,13 @@ export class DashboardExporter {
...
@@ -44,6 +42,13 @@ export class DashboardExporter {
version
:
ds
.
meta
.
info
.
version
||
"1.0.0"
,
version
:
ds
.
meta
.
info
.
version
||
"1.0.0"
,
};
};
}));
}));
};
// check up panel data sources
for
(
let
row
of
dash
.
rows
)
{
_
.
each
(
row
.
panels
,
(
panel
)
=>
{
if
(
panel
.
datasource
!==
undefined
)
{
templateizeDatasourceUsage
(
panel
);
}
}
var
panelDef
=
config
.
panels
[
panel
.
type
];
var
panelDef
=
config
.
panels
[
panel
.
type
];
...
@@ -58,6 +63,21 @@ export class DashboardExporter {
...
@@ -58,6 +63,21 @@ export class DashboardExporter {
});
});
}
}
// templatize template vars
for
(
let
variable
of
dash
.
templating
.
list
)
{
if
(
variable
.
type
===
'query'
)
{
templateizeDatasourceUsage
(
variable
);
variable
.
options
=
[];
variable
.
current
=
{};
variable
.
refresh
=
1
;
}
}
// templatize annotations vars
for
(
let
annotationDef
of
dash
.
annotations
.
list
)
{
templateizeDatasourceUsage
(
annotationDef
);
}
return
Promise
.
all
(
promises
).
then
(()
=>
{
return
Promise
.
all
(
promises
).
then
(()
=>
{
_
.
each
(
datasources
,
(
value
,
key
)
=>
{
_
.
each
(
datasources
,
(
value
,
key
)
=>
{
inputs
.
push
(
value
);
inputs
.
push
(
value
);
...
...
public/app/features/dashboard/specs/exporter_specs.ts
View file @
430bcf19
...
@@ -10,12 +10,21 @@ describe.only('given dashboard with repeated panels', function() {
...
@@ -10,12 +10,21 @@ describe.only('given dashboard with repeated panels', function() {
beforeEach
(
done
=>
{
beforeEach
(
done
=>
{
dash
=
{
dash
=
{
rows
:
[],
rows
:
[],
templating
:
{
list
:
[]
}
templating
:
{
list
:
[]
},
annotations
:
{
list
:
[]
},
};
};
dash
.
templating
.
list
.
push
({
dash
.
templating
.
list
.
push
({
name
:
'apps'
,
name
:
'apps'
,
current
:
{},
type
:
'query'
,
options
:
[]
datasource
:
'gfdb'
,
current
:
{
value
:
'Asd'
,
text
:
'Asd'
},
options
:
[{
value
:
'Asd'
,
text
:
'Asd'
}]
});
dash
.
annotations
.
list
.
push
({
name
:
'logs'
,
datasource
:
'gfdb'
,
});
});
dash
.
rows
.
push
({
dash
.
rows
.
push
({
...
@@ -63,6 +72,17 @@ describe.only('given dashboard with repeated panels', function() {
...
@@ -63,6 +72,17 @@ describe.only('given dashboard with repeated panels', function() {
expect
(
panel
.
datasource
).
to
.
be
(
"${DS_GFDB}"
);
expect
(
panel
.
datasource
).
to
.
be
(
"${DS_GFDB}"
);
});
});
it
(
'should replace datasource in variable query'
,
function
()
{
expect
(
exported
.
templating
.
list
[
0
].
datasource
).
to
.
be
(
"${DS_GFDB}"
);
expect
(
exported
.
templating
.
list
[
0
].
options
.
length
).
to
.
be
(
0
);
expect
(
exported
.
templating
.
list
[
0
].
current
.
value
).
to
.
be
(
undefined
);
expect
(
exported
.
templating
.
list
[
0
].
current
.
text
).
to
.
be
(
undefined
);
});
it
(
'should replace datasource in annotation query'
,
function
()
{
expect
(
exported
.
annotations
.
list
[
0
].
datasource
).
to
.
be
(
"${DS_GFDB}"
);
});
it
(
'should add datasource as input'
,
function
()
{
it
(
'should add datasource as input'
,
function
()
{
expect
(
exported
.
__inputs
[
0
].
name
).
to
.
be
(
"DS_GFDB"
);
expect
(
exported
.
__inputs
[
0
].
name
).
to
.
be
(
"DS_GFDB"
);
expect
(
exported
.
__inputs
[
0
].
pluginId
).
to
.
be
(
"testdb"
);
expect
(
exported
.
__inputs
[
0
].
pluginId
).
to
.
be
(
"testdb"
);
...
...
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