Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions core/app/dto/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type SettingInfo struct {
AppStoreLastModified string `json:"appStoreLastModified"`
AppStoreSyncStatus string `json:"appStoreSyncStatus"`

XpackHideMenu string `json:"xpackHideMenu"`
HideMenu string `json:"hideMenu"`
NoAuthSetting string `json:"noAuthSetting"`

ProxyUrl string `json:"proxyUrl"`
Expand Down Expand Up @@ -179,13 +179,14 @@ type Clean struct {
Size uint64 `json:"size"`
}

type XpackHideMenu struct {
ID string `json:"id"`
Label string `json:"label"`
IsCheck bool `json:"isCheck"`
Title string `json:"title"`
Path string `json:"path,omitempty"`
Children []XpackHideMenu `json:"children,omitempty"`
type ShowMenu struct {
ID string `json:"id"`
Label string `json:"label"`
Disabled bool `json:"disabled"`
IsShow bool `json:"isShow"`
Title string `json:"title"`
Path string `json:"path,omitempty"`
Children []ShowMenu `json:"children,omitempty"`
}

type ApiInterfaceConfig struct {
Expand Down
15 changes: 15 additions & 0 deletions core/app/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ func (u *SettingService) Update(key, value string) error {
_ = settingRepo.Create("AppStoreLastModified", value)
return nil
}
case "HideMenu":
var menus []dto.ShowMenu
if err := json.Unmarshal([]byte(value), &menus); err != nil {
return err
}
for i := 0; i < len(menus); i++ {
if menus[i].Label == "Home-Menu" || menus[i].Label == "App-Menu" || menus[i].Label == "Setting-Menu" {
menus[i].IsShow = true
}
}
menuItem, err := json.Marshal(&menus)
if err != nil {
return err
}
value = string(menuItem)
}

if err := settingRepo.Update(key, value); err != nil {
Expand Down
51 changes: 51 additions & 0 deletions core/init/migration/helper/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package helper

import (
"encoding/json"

"github.com/1Panel-dev/1Panel/core/app/dto"
)

func LoadMenus() string {
item := []dto.ShowMenu{
{ID: "1", Disabled: true, Title: "menu.home", IsShow: true, Label: "Home-Menu", Path: "/"},
{ID: "2", Disabled: true, Title: "menu.apps", IsShow: true, Label: "App-Menu", Path: "/apps/all"},
{ID: "3", Disabled: false, Title: "menu.website", IsShow: true, Label: "Website-Menu", Path: "/websites",
Children: []dto.ShowMenu{
{ID: "31", Disabled: false, Title: "menu.website", IsShow: true, Label: "Website", Path: "/websites"},
{ID: "32", Disabled: false, Title: "menu.ssl", IsShow: true, Label: "SSL", Path: "/websites/ssl"},
{ID: "33", Disabled: false, Title: "menu.runtime", IsShow: true, Label: "PHP", Path: "/websites/runtimes/php"},
}},
{ID: "4", Disabled: false, Title: "menu.aiTools", IsShow: true, Label: "AI-Menu", Path: "/ai/model",
Children: []dto.ShowMenu{
{ID: "41", Disabled: false, Title: "aiTools.model.model", IsShow: true, Label: "OllamaModel", Path: "/ai/model"},
{ID: "42", Disabled: false, Title: "aiTools.gpu.gpu", IsShow: true, Label: "GPU", Path: "/ai/gpu"},
}},
{ID: "5", Disabled: false, Title: "menu.database", IsShow: true, Label: "Database-Menu", Path: "/databases"},
{ID: "6", Disabled: false, Title: "menu.container", IsShow: true, Label: "Container-Menu", Path: "/containers"},
{ID: "7", Disabled: false, Title: "menu.system", IsShow: true, Label: "System-Menu", Path: "/hosts/files",
Children: []dto.ShowMenu{
{ID: "71", Disabled: false, Title: "menu.files", IsShow: true, Label: "File", Path: "/hosts/files"},
{ID: "72", Disabled: false, Title: "menu.monitor", IsShow: true, Label: "Monitorx", Path: "/hosts/monitor/monitor"},
{ID: "74", Disabled: false, Title: "menu.firewall", IsShow: true, Label: "FirewallPort", Path: "/hosts/firewall/port"},
{ID: "75", Disabled: false, Title: "menu.supervisor", IsShow: true, Label: "Process", Path: "/hosts/process/process"},
{ID: "76", Disabled: false, Title: "menu.ssh", IsShow: true, Label: "SSH", Path: "/hosts/ssh/ssh"},
}},
{ID: "8", Disabled: false, Title: "menu.terminal", IsShow: true, Label: "Terminal-Menu", Path: "/hosts/terminal"},
{ID: "9", Disabled: false, Title: "menu.toolbox", IsShow: true, Label: "Toolbox-Menu", Path: "/toolbox"},
{ID: "10", Disabled: false, Title: "menu.cronjob", IsShow: true, Label: "Cronjob-Menu", Path: "/cronjobs"},
{ID: "11", Disabled: false, Title: "xpack.menu", IsShow: true, Label: "Xpack-Menu",
Children: []dto.ShowMenu{
{ID: "112", Disabled: false, Title: "xpack.waf.name", IsShow: true, Label: "Dashboard", Path: "/xpack/waf/dashboard"},
{ID: "111", Disabled: false, Title: "xpack.node.nodeManagement", IsShow: true, Label: "Node", Path: "/xpack/node"},
{ID: "113", Disabled: false, Title: "xpack.monitor.name", IsShow: true, Label: "MonitorDashboard", Path: "/xpack/monitor/dashboard"},
{ID: "114", Disabled: false, Title: "xpack.tamper.tamper", IsShow: true, Label: "Tamper", Path: "/xpack/tamper"},
{ID: "116", Disabled: false, Title: "xpack.alert.alert", IsShow: true, Label: "XAlertDashboard", Path: "/xpack/alert/dashboard"},
{ID: "115", Disabled: false, Title: "xpack.setting.setting", IsShow: true, Label: "XSetting", Path: "/xpack/setting"},
}},
{ID: "12", Disabled: false, Title: "menu.logs", IsShow: true, Label: "Log-Menu", Path: "/logs"},
{ID: "13", Disabled: true, Title: "menu.settings", IsShow: true, Label: "Setting-Menu", Path: "/settings"},
}
menu, _ := json.Marshal(item)
return string(menu)
}
1 change: 1 addition & 0 deletions core/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func Init() {
migrations.UpdateSettingStatus,
migrations.RemoveLocalBackup,
migrations.AddMFAInterval,
migrations.UpdateXpackHideMemu,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
Expand Down
11 changes: 11 additions & 0 deletions core/init/migration/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/1Panel-dev/1Panel/core/app/model"
"github.com/1Panel-dev/1Panel/core/constant"
"github.com/1Panel-dev/1Panel/core/global"
"github.com/1Panel-dev/1Panel/core/init/migration/helper"
"github.com/1Panel-dev/1Panel/core/utils/common"
"github.com/1Panel-dev/1Panel/core/utils/encrypt"
"github.com/go-gormigrate/gormigrate/v2"
Expand Down Expand Up @@ -307,3 +308,13 @@ var AddMFAInterval = &gormigrate.Migration{
return nil
},
}

var UpdateXpackHideMemu = &gormigrate.Migration{
ID: "20250227-update-xpack-hide-menu",
Migrate: func(tx *gorm.DB) error {
if err := tx.Model(&model.Setting{}).Where("key = ?", "XpackHideMenu").Updates(map[string]interface{}{"key": "HideMenu", "value": helper.LoadMenus()}).Error; err != nil {
return err
}
return nil
},
}
4 changes: 2 additions & 2 deletions frontend/src/api/interface/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export namespace Setting {
weChatVars: string;
dingVars: string;
snapshotIgnore: string;
xpackHideMenu: string;
hideMenu: string;
noAuthSetting: string;

proxyUrl: string;
Expand Down Expand Up @@ -191,7 +191,7 @@ export namespace Setting {
key: string;
name: string;
size: number;
isCheck: boolean;
isShow: boolean;
isDisable: boolean;

path: string;
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1829,9 +1829,8 @@ const message = {

license: 'License',
bindNode: 'Bind Node',
advancedMenuHide: 'Advanced Menu Hide',
showMainAdvancedMenu:
'If only one menu is retained, only the main advanced menu will be displayed in the sidebar',
menuSetting: 'Menu Settings',
menuSettingHelper: 'If only 1 menu is kept, the sidebar will directly display that menu.',
showAll: 'Show All',
hideALL: 'Hide All',
ifShow: 'Whether to Show',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1694,9 +1694,8 @@ const message = {

license: 'ライセンス',
bindNode: 'ノードをバインド',
advancedMenuHide: '高度なメニューを非表示にします',
showMainAdvancedMenu:
'メニューが1つしか保持されていない場合、メインの詳細メニューのみがサイドバーに表示されます',
menuSetting: 'メニュー設定',
menuSettingHelper: '1つのメニューだけを保持する場合、サイドバーにはそのメニューが直接表示されます。',
showAll: 'すべてを表示します',
hideALL: 'すべてを隠します',
ifShow: '表示するかどうか',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lang/modules/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1667,8 +1667,8 @@ const message = {

license: '라이선스',
bindNode: '노드 바인딩',
advancedMenuHide: '고급 메뉴 숨기기',
showMainAdvancedMenu: '하나의 메뉴만 유지하면 사이드바에 주 고급 메뉴만 표시됩니다.',
menuSetting: '메뉴 설정',
menuSettingHelper: '메뉴를 1개만 유지하면 사이드바에 해당 메뉴가 직접 표시됩니다.',
showAll: '모두 표시',
hideALL: '모두 숨기기',
ifShow: '표시 여부',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lang/modules/ms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1751,8 +1751,8 @@ const message = {

license: 'Lesen',
bindNode: 'Ikatan Nod',
advancedMenuHide: 'Sembunyikan menu lanjutan',
showMainAdvancedMenu: 'Jika hanya satu menu dikekalkan, hanya menu lanjutan utama akan dipaparkan di bar sisi',
menuSetting: 'Tetapan Menu',
menuSettingHelper: 'Jika hanya 1 menu yang disimpan, bar sisi akan langsung menampilkan menu tersebut.',
showAll: 'Papar Semua',
hideALL: 'Sembunyikan Semua',
ifShow: 'Sama ada untuk Dipaparkan',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1736,9 +1736,8 @@ const message = {

license: 'Licença',
bindNode: 'Vincular Nó',
advancedMenuHide: 'Ocultar menu avançado',
showMainAdvancedMenu:
'Se apenas um menu for mantido, somente o menu avançado principal será exibido na barra lateral',
menuSetting: 'Configurações do Menu',
menuSettingHelper: 'Se apenas 1 menu for mantido, a barra lateral exibirá diretamente esse menu.',
showAll: 'Mostrar Tudo',
hideALL: 'Ocultar Tudo',
ifShow: 'Exibir?',
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/lang/modules/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1735,9 +1735,8 @@ const message = {

license: 'Лицензия',
bindNode: 'Привязать Узел',
advancedMenuHide: 'Скрыть расширенное меню',
showMainAdvancedMenu:
'Если сохранено только одно меню, в боковой панели будет отображаться только основное расширенное меню',
menuSetting: 'Настройки меню',
menuSettingHelper: 'Если оставить только 1 меню, боковая панель будет напрямую отображать это меню.',
showAll: 'Показать все',
hideALL: 'Скрыть все',
ifShow: 'Показывать',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lang/modules/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1697,8 +1697,8 @@ const message = {

license: '許可證',
bindNode: '綁定節點',
advancedMenuHide: '高級功能選單隱藏',
showMainAdvancedMenu: '如果只保留 1 個選單,則側邊欄只會顯示高級功能主選單',
menuSetting: '菜單設定',
menuSettingHelper: '如果只保留 1 個菜單,則側邊欄會直接顯示該菜單。',
showAll: '全部顯示',
hideALL: '全部隱藏',
ifShow: '是否顯示',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1689,8 +1689,8 @@ const message = {

license: '许可证',
bindNode: '绑定节点',
advancedMenuHide: '高级功能菜单隐藏',
showMainAdvancedMenu: '如果只保留 1 个菜单,则侧边栏只会显示高级功能主菜单',
menuSetting: '菜单设置',
menuSettingHelper: '如果只保留 1 个菜单,则侧边栏会直接显示该菜单',
showAll: '全部显示',
hideALL: '全部隐藏',
ifShow: '是否显示',
Expand Down
91 changes: 30 additions & 61 deletions frontend/src/layout/components/Sidebar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ const loadCurrentName = () => {
};

const screenWidth = ref(0);

interface Node {
id: string;
title: string;
path?: string;
label: string;
isCheck: boolean;
children?: Node[];
}
const listeningWindow = () => {
window.onresize = () => {
return (() => {
Expand Down Expand Up @@ -204,68 +195,46 @@ const changeNode = (command: string) => {
}
};

function extractLabels(node: Node, result: string[]): void {
if (node.isCheck) {
result.push(node.label);
}
if (node.children) {
for (const childNode of node.children) {
extractLabels(childNode, result);
function getCheckedLabels(menu: any, showMap: any) {
for (const item of menu) {
if (item.isShow) {
showMap[item.label] = true;
}
if (item.children) {
getCheckedLabels(item.children, showMap);
}
}
}

function getCheckedLabels(json: Node): string[] {
let result: string[] = [];
extractLabels(json, result);
return result;
}

const search = async () => {
let checkedLabels: any[] = [];
const res = await getSettingInfo();
version.value = res.data.systemVersion;
const json: Node = JSON.parse(res.data.xpackHideMenu);
checkedLabels = getCheckedLabels(json);

const menuItem = JSON.parse(res.data.hideMenu);
const showMap = new Map();
getCheckedLabels(menuItem, showMap);
let rstMenuList: RouteRecordRaw[] = [];
menuStore.menuList.forEach((item) => {
let menuItem = JSON.parse(JSON.stringify(item));
let menuChildren: RouteRecordRaw[] = [];
if (menuItem.path === '/xpack') {
if (checkedLabels.length) {
menuItem.children = menuItem.children.filter((child: any) => {
return !(globalStore.isIntl && child.path.includes('/xpack/alert'));
});
menuItem.children.forEach((child: any) => {
for (const str of checkedLabels) {
if (child.name === str) {
child.hidden = false;
}
}
if (child.hidden === false) {
menuChildren.push(child);
if (checkedLabels.length === 2) {
menuItem.meta.title = child.meta.title;
} else {
menuItem.meta.title = 'xpack.menu';
}
}
});
menuItem.meta.hideInSidebar = false;
for (const menu of menuStore.menuList) {
let menuItem = JSON.parse(JSON.stringify(menu));
if (!showMap[menuItem.name]) {
continue;
} else if (menuItem.name === 'Xpack-Menu') {
menuItem.meta.hideInSidebar = false;
}
let itemChildren = [];
for (const item of menuItem.children) {
if (item.name === 'XAlertDashboard' && globalStore.isIntl) {
continue;
}
if (showMap[item.name]) {
itemChildren.push(item);
}
menuItem.children = menuChildren as RouteRecordRaw[];
rstMenuList.push(menuItem);
} else {
menuItem.children.forEach((child: any) => {
if (!child.hidden) {
menuChildren.push(child);
}
});
menuItem.children = menuChildren as RouteRecordRaw[];
rstMenuList.push(menuItem);
}
});
if (itemChildren.length === 1) {
menuItem.meta.title = itemChildren[0].meta.title;
}
menuItem.children = itemChildren;
rstMenuList.push(menuItem);
}
menuStore.menuList = rstMenuList;
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no significant code changes in this snippet that could potentially be optimized or addressed by a reviewer. Please refer to the existing comments on GitHub before suggesting any modifications.

No specific issues were pointed out; therefore, there should not be necessary corrections for your review purpose since you've mentioned an "English" answer format but did not include anything related to translation, localization, etc. This seems like feedback for another part of Stack Overflow. If these snippets belong specifically to your application's project and need further inspection, kindly provide more context so I can assist better.

However, regarding English style and punctuation correction, remember they often vary between programming languages and software applications. For instance, using double quotes around variable names might seem informal to developers from different industries, depending on their culture. It would also be helpful if you explain which parts do not appear coherent or readable according to English conventions! Please share more details.

Expand Down
1 change: 1 addition & 0 deletions frontend/src/routers/modules/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Layout } from '@/routers/constant';
const databaseRouter = {
sort: 4,
path: '/ai',
name: 'AI-Menu',
component: Layout,
redirect: '/ai/model',
meta: {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/routers/modules/app-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Layout } from '@/routers/constant';
const appStoreRouter = {
sort: 2,
path: '/apps',
name: 'App-Menu',
component: Layout,
redirect: '/apps/all',
meta: {
Expand Down
Loading
Loading