allow app menu items to be selectivly pinned to the left nav menu

This commit is contained in:
woodsaj
2015-12-18 15:10:52 +08:00
parent 48cf56b69a
commit 3d15ee6d74
10 changed files with 73 additions and 54 deletions
+10 -8
View File
@@ -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
}
+5 -4
View File
@@ -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
View File
@@ -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})
}
}
}
}