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
4356e980
Commit
4356e980
authored
Nov 27, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashfolders: create app folder on dashboard import
parent
07cd1826
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
13 deletions
+101
-13
pkg/plugins/dashboard_importer.go
+25
-0
pkg/plugins/dashboard_importer_test.go
+28
-12
pkg/plugins/dashboards.go
+10
-0
pkg/services/sqlstore/dashboard.go
+1
-1
pkg/services/sqlstore/dashboard_test.go
+37
-0
No files found.
pkg/plugins/dashboard_importer.go
View file @
4356e980
...
...
@@ -49,6 +49,30 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
if
dashboard
,
err
=
loadPluginDashboard
(
cmd
.
PluginId
,
cmd
.
Path
);
err
!=
nil
{
return
err
}
var
plugin
*
PluginBase
if
plugin
,
err
=
getPlugin
(
cmd
.
PluginId
);
err
!=
nil
{
return
err
}
folderDash
:=
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"title"
:
plugin
.
Name
,
})
saveCmd
:=
m
.
SaveDashboardCommand
{
Dashboard
:
folderDash
,
OrgId
:
cmd
.
OrgId
,
UserId
:
cmd
.
UserId
,
PluginId
:
cmd
.
PluginId
,
IsFolder
:
true
,
}
if
err
:=
bus
.
Dispatch
(
&
saveCmd
);
err
!=
nil
{
return
err
}
dashboard
.
FolderId
=
saveCmd
.
Result
.
Id
}
else
{
dashboard
=
m
.
NewDashboardFromJson
(
cmd
.
Dashboard
)
}
...
...
@@ -69,6 +93,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
UserId
:
cmd
.
UserId
,
Overwrite
:
cmd
.
Overwrite
,
PluginId
:
cmd
.
PluginId
,
FolderId
:
dashboard
.
FolderId
,
}
if
err
:=
bus
.
Dispatch
(
&
saveCmd
);
err
!=
nil
{
...
...
pkg/plugins/dashboard_importer_test.go
View file @
4356e980
...
...
@@ -22,10 +22,19 @@ func TestDashboardImport(t *testing.T) {
So
(
err
,
ShouldBeNil
)
folderId
:=
int64
(
1000
)
var
importedDash
*
m
.
Dashboard
var
createdFolder
*
m
.
Dashboard
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
SaveDashboardCommand
)
error
{
importedDash
=
cmd
.
GetDashboardModel
()
cmd
.
Result
=
importedDash
if
cmd
.
IsFolder
{
createdFolder
=
cmd
.
GetDashboardModel
()
createdFolder
.
Id
=
folderId
cmd
.
Result
=
createdFolder
}
else
{
importedDash
=
cmd
.
GetDashboardModel
()
cmd
.
Result
=
importedDash
}
return
nil
})
...
...
@@ -54,21 +63,28 @@ func TestDashboardImport(t *testing.T) {
panel
:=
importedDash
.
Data
.
Get
(
"rows"
)
.
GetIndex
(
0
)
.
Get
(
"panels"
)
.
GetIndex
(
0
)
So
(
panel
.
Get
(
"datasource"
)
.
MustString
(),
ShouldEqual
,
"graphite"
)
So
(
importedDash
.
FolderId
,
ShouldEqual
,
folderId
)
})
Convey
(
"should create app folder"
,
func
()
{
So
(
createdFolder
.
Title
,
ShouldEqual
,
"Test App"
)
So
(
createdFolder
.
Id
,
ShouldEqual
,
folderId
)
})
})
Convey
(
"When evaling dashboard template"
,
t
,
func
()
{
template
,
_
:=
simplejson
.
NewJson
([]
byte
(
`{
"__inputs": [
{
"name": "DS_NAME",
"type": "datasource"
}
],
"test": {
"prop": "${DS_NAME}"
}
}`
))
"__inputs": [
{
"name": "DS_NAME",
"type": "datasource"
}
],
"test": {
"prop": "${DS_NAME}"
}
}`
))
evaluator
:=
&
DashTemplateEvaluator
{
template
:
template
,
...
...
pkg/plugins/dashboards.go
View file @
4356e980
...
...
@@ -108,3 +108,13 @@ func loadPluginDashboard(pluginId, path string) (*m.Dashboard, error) {
return
m
.
NewDashboardFromJson
(
data
),
nil
}
func
getPlugin
(
pluginId
string
)
(
*
PluginBase
,
error
)
{
plugin
,
exists
:=
Plugins
[
pluginId
]
if
!
exists
{
return
nil
,
PluginNotFoundError
{
pluginId
}
}
return
plugin
,
nil
}
pkg/services/sqlstore/dashboard.go
View file @
4356e980
...
...
@@ -340,7 +340,7 @@ func GetDashboards(query *m.GetDashboardsQuery) error {
func
GetDashboardsByPluginId
(
query
*
m
.
GetDashboardsByPluginIdQuery
)
error
{
var
dashboards
=
make
([]
*
m
.
Dashboard
,
0
)
err
:=
x
.
Where
(
"org_id=? AND plugin_id=?"
,
query
.
OrgId
,
query
.
PluginId
)
.
Find
(
&
dashboards
)
err
:=
x
.
Where
(
"org_id=? AND plugin_id=?
AND is_folder=0
"
,
query
.
OrgId
,
query
.
PluginId
)
.
Find
(
&
dashboards
)
query
.
Result
=
dashboards
if
err
!=
nil
{
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
4356e980
...
...
@@ -458,6 +458,25 @@ func TestDashboardDataAccess(t *testing.T) {
})
})
})
Convey
(
"Given a plugin with imported dashboards"
,
func
()
{
pluginId
:=
"test-app"
appFolder
:=
insertTestDashboardForPlugin
(
"app-test"
,
1
,
0
,
true
,
pluginId
)
insertTestDashboardForPlugin
(
"app-dash1"
,
1
,
appFolder
.
Id
,
false
,
pluginId
)
insertTestDashboardForPlugin
(
"app-dash2"
,
1
,
appFolder
.
Id
,
false
,
pluginId
)
Convey
(
"Should return imported dashboard"
,
func
()
{
query
:=
m
.
GetDashboardsByPluginIdQuery
{
PluginId
:
pluginId
,
OrgId
:
1
,
}
err
:=
GetDashboardsByPluginId
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
})
})
})
}
...
...
@@ -479,6 +498,24 @@ func insertTestDashboard(title string, orgId int64, folderId int64, isFolder boo
return
cmd
.
Result
}
func
insertTestDashboardForPlugin
(
title
string
,
orgId
int64
,
folderId
int64
,
isFolder
bool
,
pluginId
string
)
*
m
.
Dashboard
{
cmd
:=
m
.
SaveDashboardCommand
{
OrgId
:
orgId
,
FolderId
:
folderId
,
IsFolder
:
isFolder
,
Dashboard
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"id"
:
nil
,
"title"
:
title
,
}),
PluginId
:
pluginId
,
}
err
:=
SaveDashboard
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
return
cmd
.
Result
}
func
createUser
(
name
string
,
role
string
,
isAdmin
bool
)
m
.
User
{
setting
.
AutoAssignOrg
=
true
setting
.
AutoAssignOrgRole
=
role
...
...
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