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
2de439bd
Commit
2de439bd
authored
Mar 11, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(plugins): progress on dashboard installs , #4298
parent
60adcede
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
154 additions
and
38 deletions
+154
-38
pkg/api/api.go
+10
-4
pkg/api/dtos/plugins.go
+6
-0
pkg/api/plugins.go
+31
-0
pkg/models/plugin_settings.go
+0
-0
pkg/plugins/dashboard_installer.go
+56
-0
pkg/plugins/dashboards.go
+25
-11
pkg/plugins/models.go
+1
-1
public/app/features/dashboard/import_list/import_list.ts
+21
-18
public/app/features/datasources/edit_ctrl.ts
+2
-2
public/app/features/plugins/edit_ctrl.ts
+1
-1
public/app/features/plugins/list_ctrl.ts
+1
-1
No files found.
pkg/api/api.go
View file @
2de439bd
...
...
@@ -126,10 +126,6 @@ func Register(r *macaron.Macaron) {
r
.
Post
(
"/invites"
,
quota
(
"user"
),
bind
(
dtos
.
AddInviteForm
{}),
wrap
(
AddOrgInvite
))
r
.
Patch
(
"/invites/:code/revoke"
,
wrap
(
RevokeInvite
))
// apps
r
.
Get
(
"/plugins"
,
wrap
(
GetPluginList
))
r
.
Get
(
"/plugins/:pluginId/settings"
,
wrap
(
GetPluginSettingById
))
r
.
Post
(
"/plugins/:pluginId/settings"
,
bind
(
m
.
UpdatePluginSettingCmd
{}),
wrap
(
UpdatePluginSetting
))
},
reqOrgAdmin
)
// create new org
...
...
@@ -177,6 +173,16 @@ func Register(r *macaron.Macaron) {
r
.
Get
(
"/"
,
wrap
(
GetDataSourceByName
))
},
reqOrgAdmin
)
r
.
Group
(
"/plugins"
,
func
()
{
r
.
Get
(
"/"
,
wrap
(
GetPluginList
))
r
.
Get
(
"/dashboards/:pluginId"
,
wrap
(
GetPluginDashboards
))
r
.
Post
(
"/dashboards/install"
,
bind
(
dtos
.
InstallPluginDashboardCmd
{}),
wrap
(
InstallPluginDashboard
))
r
.
Get
(
"/:pluginId/settings"
,
wrap
(
GetPluginSettingById
))
r
.
Post
(
"/:pluginId/settings"
,
bind
(
m
.
UpdatePluginSettingCmd
{}),
wrap
(
UpdatePluginSetting
))
},
reqOrgAdmin
)
r
.
Get
(
"/frontend/settings/"
,
GetFrontendSettings
)
r
.
Any
(
"/datasources/proxy/:id/*"
,
reqSignedIn
,
ProxyDataSourceRequest
)
r
.
Any
(
"/datasources/proxy/:id"
,
reqSignedIn
,
ProxyDataSourceRequest
)
...
...
pkg/api/dtos/plugins.go
View file @
2de439bd
...
...
@@ -25,3 +25,9 @@ type PluginListItem struct {
Pinned
bool
`json:"pinned"`
Info
*
plugins
.
PluginInfo
`json:"info"`
}
type
InstallPluginDashboardCmd
struct
{
PluginId
string
`json:"pluginId"`
Path
string
`json:"path"`
Inputs
map
[
string
]
interface
{}
`json:"inputs"`
}
pkg/api/plugin
_setting
.go
→
pkg/api/plugin
s
.go
View file @
2de439bd
...
...
@@ -107,3 +107,34 @@ func UpdatePluginSetting(c *middleware.Context, cmd m.UpdatePluginSettingCmd) Re
return
ApiSuccess
(
"Plugin settings updated"
)
}
func
GetPluginDashboards
(
c
*
middleware
.
Context
)
Response
{
pluginId
:=
c
.
Params
(
":pluginId"
)
if
list
,
err
:=
plugins
.
GetPluginDashboards
(
c
.
OrgId
,
pluginId
);
err
!=
nil
{
if
notfound
,
ok
:=
err
.
(
plugins
.
PluginNotFoundError
);
ok
{
return
ApiError
(
404
,
notfound
.
Error
(),
nil
)
}
return
ApiError
(
500
,
"Failed to get plugin dashboards"
,
err
)
}
else
{
return
Json
(
200
,
list
)
}
}
func
InstallPluginDashboard
(
c
*
middleware
.
Context
,
apiCmd
dtos
.
InstallPluginDashboardCmd
)
Response
{
cmd
:=
plugins
.
InstallPluginDashboardCommand
{
OrgId
:
c
.
OrgId
,
UserId
:
c
.
UserId
,
PluginId
:
apiCmd
.
PluginId
,
Path
:
apiCmd
.
Path
,
Inputs
:
apiCmd
.
Inputs
,
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to install dashboard"
,
err
)
}
return
Json
(
200
,
cmd
.
Result
)
}
pkg/models/plugin_setting.go
→
pkg/models/plugin_setting
s
.go
View file @
2de439bd
File moved
pkg/plugins/dashboard_installer.go
0 → 100644
View file @
2de439bd
package
plugins
import
(
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
)
type
InstallPluginDashboardCommand
struct
{
Path
string
`json:"string"`
Inputs
map
[
string
]
interface
{}
`json:"inputs"`
OrgId
int64
`json:"-"`
UserId
int64
`json:"-"`
PluginId
string
`json:"-"`
Result
*
PluginDashboardInfoDTO
}
func
init
()
{
bus
.
AddHandler
(
"plugins"
,
InstallPluginDashboard
)
}
func
InstallPluginDashboard
(
cmd
*
InstallPluginDashboardCommand
)
error
{
plugin
,
exists
:=
Plugins
[
cmd
.
PluginId
]
if
!
exists
{
return
PluginNotFoundError
{
cmd
.
PluginId
}
}
var
dashboard
*
m
.
Dashboard
var
err
error
if
dashboard
,
err
=
loadPluginDashboard
(
plugin
,
cmd
.
Path
);
err
!=
nil
{
return
err
}
saveCmd
:=
m
.
SaveDashboardCommand
{
Dashboard
:
dashboard
.
Data
,
OrgId
:
cmd
.
OrgId
,
UserId
:
cmd
.
UserId
,
}
if
err
:=
bus
.
Dispatch
(
&
saveCmd
);
err
!=
nil
{
return
err
}
cmd
.
Result
=
&
PluginDashboardInfoDTO
{
PluginId
:
cmd
.
PluginId
,
Title
:
dashboard
.
Title
,
Path
:
cmd
.
Path
,
Revision
:
dashboard
.
GetString
(
"revision"
,
"1.0"
),
InstalledURI
:
"db/"
+
saveCmd
.
Result
.
Slug
,
InstalledRevision
:
dashboard
.
GetString
(
"revision"
,
"1.0"
),
}
return
nil
}
pkg/plugins/dashboards.go
View file @
2de439bd
...
...
@@ -10,25 +10,27 @@ import (
)
type
PluginDashboardInfoDTO
struct
{
Title
string
InstalledURI
string
InstalledRevision
string
Revision
string
Description
string
PluginId
string
`json:"pluginId"`
Title
string
`json:"title"`
InstalledURI
string
`json:"installedURI"`
InstalledRevision
string
`json:"installedRevision"`
Revision
string
`json:"revision"`
Description
string
`json:"description"`
Path
string
`json:"path"`
}
func
GetPluginDashboards
(
orgId
int64
,
pluginId
string
)
([]
*
PluginDashboardInfoDTO
,
error
)
{
plugin
,
exists
:=
Plugins
[
pluginId
]
if
!
exists
{
return
nil
,
&
PluginNotFoundError
{
pluginId
}
return
nil
,
PluginNotFoundError
{
pluginId
}
}
result
:=
make
([]
*
PluginDashboardInfoDTO
,
0
)
for
_
,
include
:=
range
plugin
.
Includes
{
if
include
.
Type
==
PluginTypeDashboard
{
if
dashInfo
,
err
:=
getDashboardImportStatus
(
orgId
,
plugin
,
include
);
err
!=
nil
{
if
dashInfo
,
err
:=
getDashboardImportStatus
(
orgId
,
plugin
,
include
.
Path
);
err
!=
nil
{
return
nil
,
err
}
else
{
result
=
append
(
result
,
dashInfo
)
...
...
@@ -39,10 +41,9 @@ func GetPluginDashboards(orgId int64, pluginId string) ([]*PluginDashboardInfoDT
return
result
,
nil
}
func
getDashboardImportStatus
(
orgId
int64
,
plugin
*
PluginBase
,
dashInclude
*
PluginInclude
)
(
*
PluginDashboardInfoDTO
,
error
)
{
res
:=
&
PluginDashboardInfoDTO
{}
func
loadPluginDashboard
(
plugin
*
PluginBase
,
path
string
)
(
*
m
.
Dashboard
,
error
)
{
dashboardFilePath
:=
filepath
.
Join
(
plugin
.
PluginDir
,
dashInclude
.
P
ath
)
dashboardFilePath
:=
filepath
.
Join
(
plugin
.
PluginDir
,
p
ath
)
reader
,
err
:=
os
.
Open
(
dashboardFilePath
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -57,8 +58,21 @@ func getDashboardImportStatus(orgId int64, plugin *PluginBase, dashInclude *Plug
return
nil
,
err
}
dashboard
:=
m
.
NewDashboardFromJson
(
data
)
return
m
.
NewDashboardFromJson
(
data
),
nil
}
func
getDashboardImportStatus
(
orgId
int64
,
plugin
*
PluginBase
,
path
string
)
(
*
PluginDashboardInfoDTO
,
error
)
{
res
:=
&
PluginDashboardInfoDTO
{}
var
dashboard
*
m
.
Dashboard
var
err
error
if
dashboard
,
err
=
loadPluginDashboard
(
plugin
,
path
);
err
!=
nil
{
return
nil
,
err
}
res
.
Path
=
path
res
.
PluginId
=
plugin
.
Id
res
.
Title
=
dashboard
.
Title
res
.
Revision
=
dashboard
.
GetString
(
"revision"
,
"1.0"
)
...
...
pkg/plugins/models.go
View file @
2de439bd
...
...
@@ -21,7 +21,7 @@ type PluginNotFoundError struct {
PluginId
string
}
func
(
e
*
PluginNotFoundError
)
Error
()
string
{
func
(
e
PluginNotFoundError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"Plugin with id %s not found"
,
e
.
PluginId
)
}
...
...
public/app/features/dashboard/import_list/import_list.ts
View file @
2de439bd
...
...
@@ -11,29 +11,26 @@ export class DashImportListCtrl {
dashboards
:
any
[];
plugin
:
any
;
constructor
(
private
$http
)
{
constructor
(
private
$http
,
private
backendSrv
,
private
$rootScope
)
{
this
.
dashboards
=
[];
this
.
plugin
.
includes
.
filter
(
val
=>
val
.
type
===
'dashboard'
)
.
forEach
(
this
.
getDashbordImportStatus
.
bind
(
this
));
}
getDashbordImportStatus
(
dash
)
{
var
dashUrl
=
this
.
plugin
.
baseUrl
+
'/'
+
dash
.
path
;
this
.
$http
.
get
(
dashUrl
).
then
(
res
=>
{
this
.
load
(
res
.
data
);
backendSrv
.
get
(
`/api/plugins/dashboards/
${
this
.
plugin
.
id
}
`
).
then
(
dashboards
=>
{
this
.
dashboards
=
dashboards
;
});
}
load
(
json
)
{
var
model
=
angular
.
fromJson
(
json
);
console
.
log
(
model
);
}
import
(
dash
)
{
var
installCmd
=
{
pluginId
:
this
.
plugin
.
id
,
path
:
dash
.
path
,
inputs
:
{}
};
this
.
backendSrv
.
post
(
`/api/plugins/dashboards/install`
,
installCmd
).
then
(
res
=>
{
console
.
log
(
res
);
});
}
}
var
template
=
`
...
...
@@ -45,11 +42,17 @@ var template = `
<i class="icon-gf icon-gf-dashboard"></i>
</td>
<td>
{{dash.name}}</span>
{{dash.title}}
</td>
<td>
{{dash.revision}}
</td>
<td>
{{dash.installedRevision}}
</td>
<td class="width-2">
<button class="btn btn-secondary" ng-click="ctrl.import(dash)">Install</button>
</td
</td
>
</tr>
</tbody>
</table>
...
...
public/app/features/datasources/edit_ctrl.ts
View file @
2de439bd
...
...
@@ -54,7 +54,7 @@ export class DataSourceEditCtrl {
return
this
.
$q
.
when
(
null
);
}
return
this
.
backendSrv
.
get
(
'/api/
org/
plugins'
,
{
enabled
:
1
,
type
:
'datasource'
}).
then
(
plugins
=>
{
return
this
.
backendSrv
.
get
(
'/api/plugins'
,
{
enabled
:
1
,
type
:
'datasource'
}).
then
(
plugins
=>
{
datasourceTypes
=
plugins
;
this
.
types
=
plugins
;
});
...
...
@@ -70,7 +70,7 @@ export class DataSourceEditCtrl {
typeChanged
()
{
this
.
hasDashboards
=
false
;
return
this
.
backendSrv
.
get
(
'/api/
org/
plugins/'
+
this
.
current
.
type
+
'/settings'
).
then
(
pluginInfo
=>
{
return
this
.
backendSrv
.
get
(
'/api/plugins/'
+
this
.
current
.
type
+
'/settings'
).
then
(
pluginInfo
=>
{
this
.
datasourceMeta
=
pluginInfo
;
this
.
hasDashboards
=
_
.
findWhere
(
pluginInfo
.
includes
,
{
type
:
'dashboard'
});
});
...
...
public/app/features/plugins/edit_ctrl.ts
View file @
2de439bd
...
...
@@ -22,7 +22,7 @@ export class PluginEditCtrl {
}
init
()
{
return
this
.
backendSrv
.
get
(
`/api/
org/
plugins/
${
this
.
pluginId
}
/settings`
).
then
(
result
=>
{
return
this
.
backendSrv
.
get
(
`/api/plugins/
${
this
.
pluginId
}
/settings`
).
then
(
result
=>
{
this
.
model
=
result
;
this
.
pluginIcon
=
this
.
getPluginIcon
(
this
.
model
.
type
);
...
...
public/app/features/plugins/list_ctrl.ts
View file @
2de439bd
...
...
@@ -8,7 +8,7 @@ export class PluginListCtrl {
/** @ngInject */
constructor
(
private
backendSrv
:
any
)
{
this
.
backendSrv
.
get
(
'api/
org/plugins'
).
then
(
plugins
=>
{
this
.
backendSrv
.
get
(
'api/
plugins'
,
{
embedded
:
0
}
).
then
(
plugins
=>
{
this
.
plugins
=
plugins
;
});
}
...
...
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