Skip to content

Commit 189ba73

Browse files
authored
feat: Support custom display of the global menu (#8023)
1 parent 50979f6 commit 189ba73

File tree

29 files changed

+187
-241
lines changed

29 files changed

+187
-241
lines changed

core/app/dto/setting.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type SettingInfo struct {
3333
AppStoreLastModified string `json:"appStoreLastModified"`
3434
AppStoreSyncStatus string `json:"appStoreSyncStatus"`
3535

36-
XpackHideMenu string `json:"xpackHideMenu"`
36+
HideMenu string `json:"hideMenu"`
3737
NoAuthSetting string `json:"noAuthSetting"`
3838

3939
ProxyUrl string `json:"proxyUrl"`
@@ -179,13 +179,14 @@ type Clean struct {
179179
Size uint64 `json:"size"`
180180
}
181181

182-
type XpackHideMenu struct {
183-
ID string `json:"id"`
184-
Label string `json:"label"`
185-
IsCheck bool `json:"isCheck"`
186-
Title string `json:"title"`
187-
Path string `json:"path,omitempty"`
188-
Children []XpackHideMenu `json:"children,omitempty"`
182+
type ShowMenu struct {
183+
ID string `json:"id"`
184+
Label string `json:"label"`
185+
Disabled bool `json:"disabled"`
186+
IsShow bool `json:"isShow"`
187+
Title string `json:"title"`
188+
Path string `json:"path,omitempty"`
189+
Children []ShowMenu `json:"children,omitempty"`
189190
}
190191

191192
type ApiInterfaceConfig struct {

core/app/service/setting.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ func (u *SettingService) Update(key, value string) error {
9797
_ = settingRepo.Create("AppStoreLastModified", value)
9898
return nil
9999
}
100+
case "HideMenu":
101+
var menus []dto.ShowMenu
102+
if err := json.Unmarshal([]byte(value), &menus); err != nil {
103+
return err
104+
}
105+
for i := 0; i < len(menus); i++ {
106+
if menus[i].Label == "Home-Menu" || menus[i].Label == "App-Menu" || menus[i].Label == "Setting-Menu" {
107+
menus[i].IsShow = true
108+
}
109+
}
110+
menuItem, err := json.Marshal(&menus)
111+
if err != nil {
112+
return err
113+
}
114+
value = string(menuItem)
100115
}
101116

102117
if err := settingRepo.Update(key, value); err != nil {

core/init/migration/helper/menu.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package helper
2+
3+
import (
4+
"encoding/json"
5+
6+
"github.com/1Panel-dev/1Panel/core/app/dto"
7+
)
8+
9+
func LoadMenus() string {
10+
item := []dto.ShowMenu{
11+
{ID: "1", Disabled: true, Title: "menu.home", IsShow: true, Label: "Home-Menu", Path: "/"},
12+
{ID: "2", Disabled: true, Title: "menu.apps", IsShow: true, Label: "App-Menu", Path: "/apps/all"},
13+
{ID: "3", Disabled: false, Title: "menu.website", IsShow: true, Label: "Website-Menu", Path: "/websites",
14+
Children: []dto.ShowMenu{
15+
{ID: "31", Disabled: false, Title: "menu.website", IsShow: true, Label: "Website", Path: "/websites"},
16+
{ID: "32", Disabled: false, Title: "menu.ssl", IsShow: true, Label: "SSL", Path: "/websites/ssl"},
17+
{ID: "33", Disabled: false, Title: "menu.runtime", IsShow: true, Label: "PHP", Path: "/websites/runtimes/php"},
18+
}},
19+
{ID: "4", Disabled: false, Title: "menu.aiTools", IsShow: true, Label: "AI-Menu", Path: "/ai/model",
20+
Children: []dto.ShowMenu{
21+
{ID: "41", Disabled: false, Title: "aiTools.model.model", IsShow: true, Label: "OllamaModel", Path: "/ai/model"},
22+
{ID: "42", Disabled: false, Title: "aiTools.gpu.gpu", IsShow: true, Label: "GPU", Path: "/ai/gpu"},
23+
}},
24+
{ID: "5", Disabled: false, Title: "menu.database", IsShow: true, Label: "Database-Menu", Path: "/databases"},
25+
{ID: "6", Disabled: false, Title: "menu.container", IsShow: true, Label: "Container-Menu", Path: "/containers"},
26+
{ID: "7", Disabled: false, Title: "menu.system", IsShow: true, Label: "System-Menu", Path: "/hosts/files",
27+
Children: []dto.ShowMenu{
28+
{ID: "71", Disabled: false, Title: "menu.files", IsShow: true, Label: "File", Path: "/hosts/files"},
29+
{ID: "72", Disabled: false, Title: "menu.monitor", IsShow: true, Label: "Monitorx", Path: "/hosts/monitor/monitor"},
30+
{ID: "74", Disabled: false, Title: "menu.firewall", IsShow: true, Label: "FirewallPort", Path: "/hosts/firewall/port"},
31+
{ID: "75", Disabled: false, Title: "menu.supervisor", IsShow: true, Label: "Process", Path: "/hosts/process/process"},
32+
{ID: "76", Disabled: false, Title: "menu.ssh", IsShow: true, Label: "SSH", Path: "/hosts/ssh/ssh"},
33+
}},
34+
{ID: "8", Disabled: false, Title: "menu.terminal", IsShow: true, Label: "Terminal-Menu", Path: "/hosts/terminal"},
35+
{ID: "9", Disabled: false, Title: "menu.toolbox", IsShow: true, Label: "Toolbox-Menu", Path: "/toolbox"},
36+
{ID: "10", Disabled: false, Title: "menu.cronjob", IsShow: true, Label: "Cronjob-Menu", Path: "/cronjobs"},
37+
{ID: "11", Disabled: false, Title: "xpack.menu", IsShow: true, Label: "Xpack-Menu",
38+
Children: []dto.ShowMenu{
39+
{ID: "112", Disabled: false, Title: "xpack.waf.name", IsShow: true, Label: "Dashboard", Path: "/xpack/waf/dashboard"},
40+
{ID: "111", Disabled: false, Title: "xpack.node.nodeManagement", IsShow: true, Label: "Node", Path: "/xpack/node"},
41+
{ID: "113", Disabled: false, Title: "xpack.monitor.name", IsShow: true, Label: "MonitorDashboard", Path: "/xpack/monitor/dashboard"},
42+
{ID: "114", Disabled: false, Title: "xpack.tamper.tamper", IsShow: true, Label: "Tamper", Path: "/xpack/tamper"},
43+
{ID: "116", Disabled: false, Title: "xpack.alert.alert", IsShow: true, Label: "XAlertDashboard", Path: "/xpack/alert/dashboard"},
44+
{ID: "115", Disabled: false, Title: "xpack.setting.setting", IsShow: true, Label: "XSetting", Path: "/xpack/setting"},
45+
}},
46+
{ID: "12", Disabled: false, Title: "menu.logs", IsShow: true, Label: "Log-Menu", Path: "/logs"},
47+
{ID: "13", Disabled: true, Title: "menu.settings", IsShow: true, Label: "Setting-Menu", Path: "/settings"},
48+
}
49+
menu, _ := json.Marshal(item)
50+
return string(menu)
51+
}

core/init/migration/migrate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func Init() {
2121
migrations.UpdateSettingStatus,
2222
migrations.RemoveLocalBackup,
2323
migrations.AddMFAInterval,
24+
migrations.UpdateXpackHideMemu,
2425
})
2526
if err := m.Migrate(); err != nil {
2627
global.LOG.Error(err)

core/init/migration/migrations/init.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/1Panel-dev/1Panel/core/app/model"
99
"github.com/1Panel-dev/1Panel/core/constant"
1010
"github.com/1Panel-dev/1Panel/core/global"
11+
"github.com/1Panel-dev/1Panel/core/init/migration/helper"
1112
"github.com/1Panel-dev/1Panel/core/utils/common"
1213
"github.com/1Panel-dev/1Panel/core/utils/encrypt"
1314
"github.com/go-gormigrate/gormigrate/v2"
@@ -307,3 +308,13 @@ var AddMFAInterval = &gormigrate.Migration{
307308
return nil
308309
},
309310
}
311+
312+
var UpdateXpackHideMemu = &gormigrate.Migration{
313+
ID: "20250227-update-xpack-hide-menu",
314+
Migrate: func(tx *gorm.DB) error {
315+
if err := tx.Model(&model.Setting{}).Where("key = ?", "XpackHideMenu").Updates(map[string]interface{}{"key": "HideMenu", "value": helper.LoadMenus()}).Error; err != nil {
316+
return err
317+
}
318+
return nil
319+
},
320+
}

frontend/src/api/interface/setting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export namespace Setting {
4848
weChatVars: string;
4949
dingVars: string;
5050
snapshotIgnore: string;
51-
xpackHideMenu: string;
51+
hideMenu: string;
5252
noAuthSetting: string;
5353

5454
proxyUrl: string;
@@ -191,7 +191,7 @@ export namespace Setting {
191191
key: string;
192192
name: string;
193193
size: number;
194-
isCheck: boolean;
194+
isShow: boolean;
195195
isDisable: boolean;
196196

197197
path: string;

frontend/src/lang/modules/en.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,9 +1829,8 @@ const message = {
18291829

18301830
license: 'License',
18311831
bindNode: 'Bind Node',
1832-
advancedMenuHide: 'Advanced Menu Hide',
1833-
showMainAdvancedMenu:
1834-
'If only one menu is retained, only the main advanced menu will be displayed in the sidebar',
1832+
menuSetting: 'Menu Settings',
1833+
menuSettingHelper: 'If only 1 menu is kept, the sidebar will directly display that menu.',
18351834
showAll: 'Show All',
18361835
hideALL: 'Hide All',
18371836
ifShow: 'Whether to Show',

frontend/src/lang/modules/ja.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,9 +1694,8 @@ const message = {
16941694

16951695
license: 'ライセンス',
16961696
bindNode: 'ノードをバインド',
1697-
advancedMenuHide: '高度なメニューを非表示にします',
1698-
showMainAdvancedMenu:
1699-
'メニューが1つしか保持されていない場合、メインの詳細メニューのみがサイドバーに表示されます',
1697+
menuSetting: 'メニュー設定',
1698+
menuSettingHelper: '1つのメニューだけを保持する場合、サイドバーにはそのメニューが直接表示されます。',
17001699
showAll: 'すべてを表示します',
17011700
hideALL: 'すべてを隠します',
17021701
ifShow: '表示するかどうか',

frontend/src/lang/modules/ko.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,8 +1667,8 @@ const message = {
16671667

16681668
license: '라이선스',
16691669
bindNode: '노드 바인딩',
1670-
advancedMenuHide: '고급 메뉴 숨기기',
1671-
showMainAdvancedMenu: '하나의 메뉴만 유지하면 사이드바에 주 고급 메뉴만 표시됩니다.',
1670+
menuSetting: '메뉴 설정',
1671+
menuSettingHelper: '메뉴를 1개만 유지하면 사이드바에 해당 메뉴가 직접 표시됩니다.',
16721672
showAll: '모두 표시',
16731673
hideALL: '모두 숨기기',
16741674
ifShow: '표시 여부',

frontend/src/lang/modules/ms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,8 +1751,8 @@ const message = {
17511751

17521752
license: 'Lesen',
17531753
bindNode: 'Ikatan Nod',
1754-
advancedMenuHide: 'Sembunyikan menu lanjutan',
1755-
showMainAdvancedMenu: 'Jika hanya satu menu dikekalkan, hanya menu lanjutan utama akan dipaparkan di bar sisi',
1754+
menuSetting: 'Tetapan Menu',
1755+
menuSettingHelper: 'Jika hanya 1 menu yang disimpan, bar sisi akan langsung menampilkan menu tersebut.',
17561756
showAll: 'Papar Semua',
17571757
hideALL: 'Sembunyikan Semua',
17581758
ifShow: 'Sama ada untuk Dipaparkan',

0 commit comments

Comments
 (0)