mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(plugins): finished app navigation enhancements, closes #4434
This commit is contained in:
parent
7f79024e6a
commit
10df9dc8c3
@ -3,17 +3,18 @@ package dtos
|
|||||||
import "github.com/grafana/grafana/pkg/plugins"
|
import "github.com/grafana/grafana/pkg/plugins"
|
||||||
|
|
||||||
type PluginSetting struct {
|
type PluginSetting struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
Pinned bool `json:"pinned"`
|
Pinned bool `json:"pinned"`
|
||||||
Module string `json:"module"`
|
Module string `json:"module"`
|
||||||
BaseUrl string `json:"baseUrl"`
|
BaseUrl string `json:"baseUrl"`
|
||||||
Info *plugins.PluginInfo `json:"info"`
|
Info *plugins.PluginInfo `json:"info"`
|
||||||
Includes []*plugins.PluginInclude `json:"includes"`
|
Includes []*plugins.PluginInclude `json:"includes"`
|
||||||
Dependencies *plugins.PluginDependencies `json:"dependencies"`
|
Dependencies *plugins.PluginDependencies `json:"dependencies"`
|
||||||
JsonData map[string]interface{} `json:"jsonData"`
|
JsonData map[string]interface{} `json:"jsonData"`
|
||||||
|
DefaultNavUrl string `json:"defaultNavUrl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PluginListItem struct {
|
type PluginListItem struct {
|
||||||
|
@ -90,7 +90,7 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
|
|||||||
if plugin.Pinned {
|
if plugin.Pinned {
|
||||||
appLink := &dtos.NavLink{
|
appLink := &dtos.NavLink{
|
||||||
Text: plugin.Name,
|
Text: plugin.Name,
|
||||||
Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/edit",
|
Url: plugin.DefaultNavUrl,
|
||||||
Img: plugin.Info.Logos.Small,
|
Img: plugin.Info.Logos.Small,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,9 +100,6 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
|
|||||||
Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/page/" + include.Slug,
|
Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/page/" + include.Slug,
|
||||||
Text: include.Name,
|
Text: include.Name,
|
||||||
}
|
}
|
||||||
if include.DefaultNav {
|
|
||||||
appLink.Url = link.Url
|
|
||||||
}
|
|
||||||
appLink.Children = append(appLink.Children, link)
|
appLink.Children = append(appLink.Children, link)
|
||||||
}
|
}
|
||||||
if include.Type == "dashboard" && include.AddToNav {
|
if include.Type == "dashboard" && include.AddToNav {
|
||||||
@ -110,16 +107,13 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
|
|||||||
Url: setting.AppSubUrl + "/dashboard/db/" + include.Slug,
|
Url: setting.AppSubUrl + "/dashboard/db/" + include.Slug,
|
||||||
Text: include.Name,
|
Text: include.Name,
|
||||||
}
|
}
|
||||||
if include.DefaultNav {
|
|
||||||
appLink.Url = link.Url
|
|
||||||
}
|
|
||||||
appLink.Children = append(appLink.Children, link)
|
appLink.Children = append(appLink.Children, link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.OrgRole == m.ROLE_ADMIN {
|
if c.OrgRole == m.ROLE_ADMIN {
|
||||||
appLink.Children = append(appLink.Children, &dtos.NavLink{Divider: true})
|
appLink.Children = append(appLink.Children, &dtos.NavLink{Divider: true})
|
||||||
appLink.Children = append(appLink.Children, &dtos.NavLink{Text: "Config", Icon: "fa fa-cog", Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/edit"})
|
appLink.Children = append(appLink.Children, &dtos.NavLink{Text: "Plugin Config", Icon: "fa fa-cog", Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/edit"})
|
||||||
}
|
}
|
||||||
|
|
||||||
data.MainNavLinks = append(data.MainNavLinks, appLink)
|
data.MainNavLinks = append(data.MainNavLinks, appLink)
|
||||||
@ -132,10 +126,10 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
|
|||||||
Icon: "fa fa-fw fa-cogs",
|
Icon: "fa fa-fw fa-cogs",
|
||||||
Url: setting.AppSubUrl + "/admin",
|
Url: setting.AppSubUrl + "/admin",
|
||||||
Children: []*dtos.NavLink{
|
Children: []*dtos.NavLink{
|
||||||
{Text: "Global Users", Icon: "fa fa-fw fa-cogs", Url: setting.AppSubUrl + "/admin/users"},
|
{Text: "Global Users", Url: setting.AppSubUrl + "/admin/users"},
|
||||||
{Text: "Global Orgs", Icon: "fa fa-fw fa-cogs", Url: setting.AppSubUrl + "/admin/orgs"},
|
{Text: "Global Orgs", Url: setting.AppSubUrl + "/admin/orgs"},
|
||||||
{Text: "Server Settings", Icon: "fa fa-fw fa-cogs", Url: setting.AppSubUrl + "/admin/settings"},
|
{Text: "Server Settings", Url: setting.AppSubUrl + "/admin/settings"},
|
||||||
{Text: "Server Stats", Icon: "fa-fw fa-cogs", Url: setting.AppSubUrl + "/admin/stats"},
|
{Text: "Server Stats", Url: setting.AppSubUrl + "/admin/stats"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -72,14 +72,15 @@ func GetPluginSettingById(c *middleware.Context) Response {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
dto := &dtos.PluginSetting{
|
dto := &dtos.PluginSetting{
|
||||||
Type: def.Type,
|
Type: def.Type,
|
||||||
Id: def.Id,
|
Id: def.Id,
|
||||||
Name: def.Name,
|
Name: def.Name,
|
||||||
Info: &def.Info,
|
Info: &def.Info,
|
||||||
Dependencies: &def.Dependencies,
|
Dependencies: &def.Dependencies,
|
||||||
Includes: def.Includes,
|
Includes: def.Includes,
|
||||||
BaseUrl: def.BaseUrl,
|
BaseUrl: def.BaseUrl,
|
||||||
Module: def.Module,
|
Module: def.Module,
|
||||||
|
DefaultNavUrl: def.DefaultNavUrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
query := m.GetPluginSettingByIdQuery{PluginId: pluginId, OrgId: c.OrgId}
|
query := m.GetPluginSettingByIdQuery{PluginId: pluginId, OrgId: c.OrgId}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gosimple/slug"
|
"github.com/gosimple/slug"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AppPluginCss struct {
|
type AppPluginCss struct {
|
||||||
@ -75,10 +76,18 @@ func (app *AppPlugin) initApp() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.DefaultNavUrl = setting.AppSubUrl + "/plugins/" + app.Id + "/edit"
|
||||||
|
|
||||||
// slugify pages
|
// slugify pages
|
||||||
for _, page := range app.Includes {
|
for _, include := range app.Includes {
|
||||||
if page.Slug == "" {
|
if include.Slug == "" {
|
||||||
page.Slug = slug.Make(page.Name)
|
include.Slug = slug.Make(include.Name)
|
||||||
|
}
|
||||||
|
if include.Type == "page" && include.DefaultNav {
|
||||||
|
app.DefaultNavUrl = setting.AppSubUrl + "/plugins/" + app.Id + "/page/" + include.Slug
|
||||||
|
}
|
||||||
|
if include.Type == "dashboard" && include.DefaultNav {
|
||||||
|
app.DefaultNavUrl = setting.AppSubUrl + "/dashboard/db/" + include.Slug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ type PluginBase struct {
|
|||||||
|
|
||||||
IncludedInAppId string `json:"-"`
|
IncludedInAppId string `json:"-"`
|
||||||
PluginDir string `json:"-"`
|
PluginDir string `json:"-"`
|
||||||
|
DefaultNavUrl string `json:"-"`
|
||||||
|
|
||||||
// cache for readme file contents
|
// cache for readme file contents
|
||||||
Readme []byte `json:"-"`
|
Readme []byte `json:"-"`
|
||||||
@ -80,7 +81,7 @@ type PluginInclude struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Component string `json:"component"`
|
Component string `json:"component"`
|
||||||
Role models.RoleType `json:"role"`
|
Role models.RoleType `json:"role"`
|
||||||
AddToNav bool `json:"AddToNav"`
|
AddToNav bool `json:"addToNav"`
|
||||||
DefaultNav bool `json:"defaultNav"`
|
DefaultNav bool `json:"defaultNav"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<navbar icon="icon-gf icon-gf-apps" title="{{ctrl.appModel.name}}" title-url="plugins/{{ctrl.pluginId}}/edit">
|
<navbar icon="icon-gf icon-gf-apps" title="{{ctrl.appModel.name}}" title-url="{{ctrl.appModel.defaultNavUrl}}">
|
||||||
</navbar>
|
</navbar>
|
||||||
|
|
||||||
<div class="page-container" >
|
<div class="page-container" >
|
||||||
|
@ -15,6 +15,7 @@ export class AppPageCtrl {
|
|||||||
this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
|
this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
|
||||||
this.appModel = app;
|
this.appModel = app;
|
||||||
this.page = _.findWhere(app.includes, {slug: this.$routeParams.slug});
|
this.page = _.findWhere(app.includes, {slug: this.$routeParams.slug});
|
||||||
|
|
||||||
if (!this.page) {
|
if (!this.page) {
|
||||||
this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
|
this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user