menu_group.go 739 B

1234567891011121314151617181920212223242526272829303132333435
  1. package presets
  2. type MenuGroupBuilder struct {
  3. name string
  4. icon string
  5. // item can be Slug name, model name
  6. // the underlying logic is using Slug name,
  7. // so if the Slug name is customized, item must be the Slug name
  8. subMenuItems []string
  9. }
  10. func (b *MenuGroupBuilder) Icon(v string) (r *MenuGroupBuilder) {
  11. b.icon = v
  12. return b
  13. }
  14. func (b *MenuGroupBuilder) SubItems(ss ...string) (r *MenuGroupBuilder) {
  15. b.subMenuItems = ss
  16. return b
  17. }
  18. type MenuGroups struct {
  19. menuGroups []*MenuGroupBuilder
  20. }
  21. func (g *MenuGroups) MenuGroup(name string) (r *MenuGroupBuilder) {
  22. for _, mg := range g.menuGroups {
  23. if mg.name == name {
  24. return mg
  25. }
  26. }
  27. r = &MenuGroupBuilder{name: name}
  28. g.menuGroups = append(g.menuGroups, r)
  29. return
  30. }