refactor(apps): more WIP work on apps

This commit is contained in:
Torkel Ödegaard
2015-12-22 11:37:44 +01:00
parent eacc46da6d
commit ad94f99d57
16 changed files with 92 additions and 99 deletions
+10 -10
View File
@@ -18,11 +18,11 @@ func GetAppPlugins(c *middleware.Context) Response {
installedAppsMap := make(map[string]*dtos.AppPlugin)
for t, a := range plugins.Apps {
installedAppsMap[t] = &dtos.AppPlugin{
Type: a.Type,
Enabled: a.Enabled,
PinNavLinks: a.PinNavLinks,
Module: a.Module,
JsonData: make(map[string]interface{}),
Type: a.Type,
Enabled: a.Enabled,
Pinned: a.Pinned,
Module: a.Module,
JsonData: make(map[string]interface{}),
}
}
@@ -32,11 +32,11 @@ func GetAppPlugins(c *middleware.Context) Response {
for _, b := range query.Result {
if def, ok := installedAppsMap[b.Type]; ok {
result = append(result, &dtos.AppPlugin{
Type: b.Type,
Enabled: b.Enabled,
PinNavLinks: b.PinNavLinks,
Module: def.Module,
JsonData: b.JsonData,
Type: b.Type,
Enabled: b.Enabled,
Pinned: b.Pinned,
Module: def.Module,
JsonData: b.JsonData,
})
seenApps[b.Type] = true
}
+1 -1
View File
@@ -125,7 +125,7 @@ func GetDataSourcePlugins(c *middleware.Context) {
}
enabledPlugins := plugins.GetEnabledPlugins(orgApps.Result)
for key, value := range enabledPlugins.DataSourcePlugins {
for key, value := range enabledPlugins.DataSources {
if !value.BuiltIn {
dsList[key] = value
}
+5 -5
View File
@@ -1,9 +1,9 @@
package dtos
type AppPlugin struct {
Type string `json:"type"`
Enabled bool `json:"enabled"`
PinNavLinks bool `json:"pin_nav_links"`
Module string `json:"module"`
JsonData map[string]interface{} `json:"jsonData"`
Type string `json:"type"`
Enabled bool `json:"enabled"`
Pinned bool `json:"pinned"`
Module string `json:"module"`
JsonData map[string]interface{} `json:"jsonData"`
}
+3 -2
View File
@@ -34,6 +34,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
if err != nil {
return nil, err
}
enabledPlugins := plugins.GetEnabledPlugins(orgApps.Result)
for _, ds := range orgDataSources {
@@ -49,7 +50,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
"url": url,
}
meta, exists := enabledPlugins.DataSourcePlugins[ds.Type]
meta, exists := enabledPlugins.DataSources[ds.Type]
if !exists {
log.Error(3, "Could not find plugin definition for data source: %v", ds.Type)
continue
@@ -117,7 +118,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
}
panels := map[string]interface{}{}
for _, panel := range enabledPlugins.PanelPlugins {
for _, panel := range enabledPlugins.Panels {
panels[panel.Type] = map[string]interface{}{
"module": panel.Module,
"name": panel.Name,
+2 -2
View File
@@ -52,7 +52,7 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
Text: "Dashboards",
Icon: "fa fa-fw fa-th-large",
Href: "/",
Url: "/",
})
orgApps := m.GetAppPluginsQuery{OrgId: c.OrgId}
@@ -73,7 +73,7 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
}
if plugin.Pinned && plugin.Page != nil {
if c.userHasRole(plugin.Page.reqRole) {
if c.HasUserRole(plugin.Page.ReqRole) {
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
Text: plugin.Page.Text,
Url: plugin.Page.Url,
+3 -3
View File
@@ -30,9 +30,9 @@ func newMacaron() *macaron.Macaron {
}
for _, route := range plugins.StaticRoutes {
pluginRoute := path.Join("/public/plugins/", route.Url)
log.Info("Plugin: Adding static route %s -> %s", pluginRoute, route.Path)
mapStatic(m, route.Path, "", pluginRoute)
pluginRoute := path.Join("/public/plugins/", route.UrlFragment)
log.Info("Plugin: Adding static route %s -> %s", pluginRoute, route.Dir)
mapStatic(m, route.Dir, "", pluginRoute)
}
mapStatic(m, setting.StaticRootPath, "", "public")
+1 -1
View File
@@ -254,6 +254,6 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) {
ctx.JSON(status, resp)
}
func (ctx *Context) hasUserRole(role m.RoleType) bool {
func (ctx *Context) HasUserRole(role m.RoleType) bool {
return ctx.OrgRole.Includes(role)
}
+1 -1
View File
@@ -44,7 +44,7 @@ type ApiPluginRoute struct {
type AppPluginPage struct {
Text string `json:"text"`
Icon string `json:"icon"`
Href string `json:"url"`
Url string `json:"url"`
ReqRole models.RoleType `json:"reqRole"`
}
@@ -4,7 +4,7 @@ import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
func addAppPluginMigration(mg *Migrator) {
var appPluginV1 = Table{
var appPluginV2 = Table{
Name: "app_plugin",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
@@ -20,8 +20,9 @@ func addAppPluginMigration(mg *Migrator) {
{Cols: []string{"org_id", "type"}, Type: UniqueIndex},
},
}
mg.AddMigration("create app_plugin table v1", NewAddTableMigration(appPluginV1))
mg.AddMigration("create app_plugin table v2", NewAddTableMigration(appPluginV2))
//------- indexes ------------------
addTableIndicesMigrations(mg, "v1", appPluginV1)
addTableIndicesMigrations(mg, "v2", appPluginV2)
}