allow app menu items to be selectivly pinned to the left nav menu
This commit is contained in:
+10
-8
@@ -18,10 +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,
|
||||
Module: a.Module,
|
||||
JsonData: make(map[string]interface{}),
|
||||
Type: a.Type,
|
||||
Enabled: a.Enabled,
|
||||
PinNavLinks: a.PinNavLinks,
|
||||
Module: a.Module,
|
||||
JsonData: make(map[string]interface{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +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,
|
||||
Module: def.Module,
|
||||
JsonData: b.JsonData,
|
||||
Type: b.Type,
|
||||
Enabled: b.Enabled,
|
||||
PinNavLinks: b.PinNavLinks,
|
||||
Module: def.Module,
|
||||
JsonData: b.JsonData,
|
||||
})
|
||||
seenApps[b.Type] = true
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package dtos
|
||||
|
||||
type AppPlugin struct {
|
||||
Type string `json:"type"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Module string `json:"module"`
|
||||
JsonData map[string]interface{} `json:"jsonData"`
|
||||
Type string `json:"type"`
|
||||
Enabled bool `json:"enabled"`
|
||||
PinNavLinks bool `json:"pin_nav_links"`
|
||||
Module string `json:"module"`
|
||||
JsonData map[string]interface{} `json:"jsonData"`
|
||||
}
|
||||
|
||||
+23
-20
@@ -69,28 +69,31 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
|
||||
for _, css := range plugin.Css {
|
||||
data.PluginCss = append(data.PluginCss, &dtos.PluginCss{Light: css.Light, Dark: css.Dark})
|
||||
}
|
||||
for _, item := range plugin.MainNavLinks {
|
||||
// only show menu items for the specified roles.
|
||||
var validRoles []m.RoleType
|
||||
if string(item.ReqRole) == "" || item.ReqRole == m.ROLE_VIEWER {
|
||||
validRoles = []m.RoleType{m.ROLE_ADMIN, m.ROLE_EDITOR, m.ROLE_VIEWER}
|
||||
} else if item.ReqRole == m.ROLE_EDITOR {
|
||||
validRoles = []m.RoleType{m.ROLE_ADMIN, m.ROLE_EDITOR}
|
||||
} else if item.ReqRole == m.ROLE_ADMIN {
|
||||
validRoles = []m.RoleType{m.ROLE_ADMIN}
|
||||
}
|
||||
ok := true
|
||||
if len(validRoles) > 0 {
|
||||
ok = false
|
||||
for _, role := range validRoles {
|
||||
if role == c.OrgRole {
|
||||
ok = true
|
||||
break
|
||||
|
||||
if plugin.PinNavLinks {
|
||||
for _, item := range plugin.MainNavLinks {
|
||||
// only show menu items for the specified roles.
|
||||
var validRoles []m.RoleType
|
||||
if string(item.ReqRole) == "" || item.ReqRole == m.ROLE_VIEWER {
|
||||
validRoles = []m.RoleType{m.ROLE_ADMIN, m.ROLE_EDITOR, m.ROLE_VIEWER}
|
||||
} else if item.ReqRole == m.ROLE_EDITOR {
|
||||
validRoles = []m.RoleType{m.ROLE_ADMIN, m.ROLE_EDITOR}
|
||||
} else if item.ReqRole == m.ROLE_ADMIN {
|
||||
validRoles = []m.RoleType{m.ROLE_ADMIN}
|
||||
}
|
||||
ok := true
|
||||
if len(validRoles) > 0 {
|
||||
ok = false
|
||||
for _, role := range validRoles {
|
||||
if role == c.OrgRole {
|
||||
ok = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{Text: item.Text, Href: item.Href, Icon: item.Icon})
|
||||
if ok {
|
||||
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{Text: item.Text, Href: item.Href, Icon: item.Icon})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user