feat: Set overview as default menu for multi-node management (#11588)

This commit is contained in:
ssongliu
2026-01-07 22:06:13 +08:00
committed by GitHub
parent cc23444776
commit eb3d613e3d
3 changed files with 45 additions and 2 deletions
+3 -2
View File
@@ -3,10 +3,11 @@ package helper
import (
"encoding/json"
"fmt"
"strings"
"github.com/1Panel-dev/1Panel/core/app/dto"
"github.com/1Panel-dev/1Panel/core/app/model"
"gorm.io/gorm"
"strings"
)
func LoadMenus() string {
@@ -43,7 +44,7 @@ func LoadMenus() string {
Children: []dto.ShowMenu{
{ID: "118", Disabled: false, Title: "xpack.app.app", IsShow: true, Label: "XApp", Path: "/xpack/app", Sort: 100},
{ID: "112", Disabled: false, Title: "xpack.waf.name", IsShow: true, Label: "Dashboard", Path: "/xpack/waf/dashboard", Sort: 200},
{ID: "111", Disabled: false, Title: "xpack.node.nodeManagement", IsShow: true, Label: "Node", Path: "/xpack/node", Sort: 300},
{ID: "111", Disabled: false, Title: "xpack.node.nodeManagement", IsShow: true, Label: "NodeDashboard", Path: "/xpack/node/dashboard", Sort: 300},
{ID: "119", Disabled: false, Title: "xpack.upage", IsShow: true, Label: "Upage", Path: "/xpack/upage", Sort: 400},
{ID: "113", Disabled: false, Title: "xpack.monitor.name", IsShow: true, Label: "MonitorDashboard", Path: "/xpack/monitor/dashboard", Sort: 500},
{ID: "114", Disabled: false, Title: "xpack.tamper.tamper", IsShow: true, Label: "Tamper", Path: "/xpack/tamper", Sort: 600},
+1
View File
@@ -26,6 +26,7 @@ func Init() {
migrations.AddUpgradeBackupCopies,
migrations.AddScriptSync,
migrations.UpdateXpackHideMenuSort,
migrations.AdjustXpackNode,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
+41
View File
@@ -602,3 +602,44 @@ var UpdateXpackHideMenuSort = &gormigrate.Migration{
return tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Update("value", string(updatedJSON)).Error
},
}
var AdjustXpackNode = &gormigrate.Migration{
ID: "20260108-adjust-xpack-node",
Migrate: func(tx *gorm.DB) error {
var menuJSON string
if err := tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Pluck("value", &menuJSON).Error; err != nil {
return err
}
if menuJSON == "" {
menuJSON = helper.LoadMenus()
}
var menus []dto.ShowMenu
if err := json.Unmarshal([]byte(menuJSON), &menus); err != nil {
return tx.Model(&model.Setting{}).
Where("key = ?", "HideMenu").
Update("value", helper.LoadMenus()).Error
}
for i := 0; i < len(menus); i++ {
if menus[i].Label != "Xpack-Menu" {
continue
}
for j := 0; j < len(menus[i].Children); j++ {
if menus[i].Children[j].Label == "Node" {
menus[i].Children[j].Label = "NodeDashboard"
menus[i].Children[j].Path = "/xpack/node/dashboard"
break
}
}
}
updatedJSON, err := json.Marshal(menus)
if err != nil {
return tx.Model(&model.Setting{}).
Where("key = ?", "HideMenu").
Update("value", helper.LoadMenus()).Error
}
return tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Update("value", string(updatedJSON)).Error
},
}