github.com/kotovmak/go-admin@v1.1.1/modules/ui/ui.go (about) 1 package ui 2 3 import ( 4 "github.com/kotovmak/go-admin/modules/config" 5 "github.com/kotovmak/go-admin/modules/language" 6 "github.com/kotovmak/go-admin/modules/service" 7 "github.com/kotovmak/go-admin/template/icon" 8 "github.com/kotovmak/go-admin/template/types" 9 "github.com/kotovmak/go-admin/template/types/action" 10 ) 11 12 type Service struct { 13 NavButtons *types.Buttons 14 } 15 16 const ServiceKey = "ui" 17 18 func (s *Service) Name() string { 19 return "ui" 20 } 21 22 func GetService(srv service.List) *Service { 23 if v, ok := srv.Get("ui").(*Service); ok { 24 return v 25 } 26 panic("wrong service") 27 } 28 29 func NewService(btns *types.Buttons) *Service { 30 return &Service{ 31 NavButtons: btns, 32 } 33 } 34 35 func (s *Service) UpdateButtons() { 36 37 } 38 39 func (s *Service) RemoveOrShowSiteNavButton(remove bool) { 40 if remove { 41 *s.NavButtons = (*s.NavButtons).RemoveSiteNavButton() 42 } else { 43 *s.NavButtons = (*s.NavButtons).AddNavButton(icon.Gear, types.NavBtnSiteName, 44 action.JumpInNewTab(config.Url("/info/site/edit"), 45 language.GetWithScope("site setting", "config"))) 46 } 47 } 48 49 func (s *Service) RemoveOrShowInfoNavButton(remove bool) { 50 if remove { 51 *s.NavButtons = (*s.NavButtons).RemoveInfoNavButton() 52 } else { 53 *s.NavButtons = (*s.NavButtons).AddNavButton(icon.Info, types.NavBtnInfoName, 54 action.JumpInNewTab(config.Url("/application/info"), 55 language.GetWithScope("system info", "system"))) 56 } 57 58 } 59 60 func (s *Service) RemoveOrShowToolNavButton(remove bool) { 61 if remove { 62 *s.NavButtons = (*s.NavButtons).RemoveToolNavButton() 63 } else { 64 *s.NavButtons = (*s.NavButtons).AddNavButton(icon.Wrench, types.NavBtnToolName, 65 action.JumpInNewTab(config.Url("/info/generate/new"), 66 language.GetWithScope("tool", "tool"))) 67 } 68 69 } 70 71 func (s *Service) RemoveOrShowPlugNavButton(remove bool) { 72 if remove { 73 *s.NavButtons = (*s.NavButtons).RemovePlugNavButton() 74 } else { 75 *s.NavButtons = (*s.NavButtons).AddNavButton(icon.Plug, types.NavBtnToolName, 76 action.JumpInNewTab(config.Url("/plugin"), 77 language.GetWithScope("plugin", "plugin"))) 78 } 79 80 }