From 0a9fc267140e01c08e7d90c3033be8b2813bbf3c Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 5 Sep 2023 17:32:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=B9=E5=99=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E6=98=BE=E7=A4=BA=E4=BC=98=E5=8C=96=20(#2188?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #2181 --- backend/app/service/container.go | 63 ++++++++++++++++--- frontend/src/lang/modules/en.ts | 4 +- frontend/src/lang/modules/tw.ts | 4 +- frontend/src/lang/modules/zh.ts | 4 +- .../src/views/container/container/index.vue | 59 +++++++++-------- frontend/src/views/database/mysql/index.vue | 2 +- .../src/views/database/mysql/remote/index.vue | 2 +- .../views/host/firewall/ip/operate/index.vue | 2 +- 8 files changed, 92 insertions(+), 48 deletions(-) diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 40dea952e..f2ff47108 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -147,14 +147,7 @@ func (u *ContainerService) Page(req dto.PageContainer) (int64, interface{}, erro IsFromApp = true } - var ports []string - for _, port := range item.Ports { - itemPortStr := fmt.Sprintf("%v/%s", port.PrivatePort, port.Type) - if port.PublicPort != 0 { - itemPortStr = fmt.Sprintf("%v->%v/%s", port.PublicPort, port.PrivatePort, port.Type) - } - ports = append(ports, itemPortStr) - } + ports := simplifyPort(item.Ports) backDatas[i] = dto.ContainerInfo{ ContainerID: item.ID, CreateTime: time.Unix(item.Created, 0).Format("2006-01-02 15:04:05"), @@ -937,3 +930,57 @@ func loadVolumeBinds(binds []string) []dto.VolumeHelper { } return datas } + +func simplifyPort(ports []types.Port) []string { + var datas []string + if len(ports) == 0 { + return datas + } + if len(ports) == 1 { + itemPortStr := fmt.Sprintf("%v/%s", ports[0].PrivatePort, ports[0].Type) + if ports[0].PublicPort != 0 { + itemPortStr = fmt.Sprintf("%v->%v/%s", ports[0].PublicPort, ports[0].PrivatePort, ports[0].Type) + } + datas = append(datas, itemPortStr) + return datas + } + + sort.Slice(ports, func(i, j int) bool { + return ports[i].PrivatePort < ports[j].PrivatePort + }) + start := ports[0] + + for i := 1; i < len(ports); i++ { + if ports[i].PrivatePort != ports[i-1].PrivatePort+1 || ports[i].IP != ports[i-1].IP || ports[i].PublicPort != ports[i-1].PublicPort+1 || ports[i].Type != ports[i-1].Type { + if ports[i-1].PrivatePort == start.PrivatePort { + itemPortStr := fmt.Sprintf("%s:%v/%s", start.IP, start.PrivatePort, start.Type) + if start.PublicPort != 0 { + itemPortStr = fmt.Sprintf("%s:%v->%v/%s", start.IP, start.PublicPort, start.PrivatePort, start.Type) + } + datas = append(datas, itemPortStr) + } else { + itemPortStr := fmt.Sprintf("%s:%v-%v/%s", start.IP, start.PrivatePort, ports[i-1].PrivatePort, start.Type) + if start.PublicPort != 0 { + itemPortStr = fmt.Sprintf("%s:%v-%v->%v-%v/%s", start.IP, start.PublicPort, ports[i-1].PublicPort, start.PrivatePort, ports[i-1].PrivatePort, start.Type) + } + datas = append(datas, itemPortStr) + } + start = ports[i] + } else if i == len(ports)-1 { + if ports[i].PrivatePort == start.PrivatePort { + itemPortStr := fmt.Sprintf("%s:%v/%s", start.IP, start.PrivatePort, start.Type) + if start.PublicPort != 0 { + itemPortStr = fmt.Sprintf("%s:%v->%v/%s", start.IP, start.PublicPort, start.PrivatePort, start.Type) + } + datas = append(datas, itemPortStr) + } else { + itemPortStr := fmt.Sprintf("%s:%v-%v/%s", start.IP, start.PrivatePort, ports[i].PrivatePort, start.Type) + if start.PublicPort != 0 { + itemPortStr = fmt.Sprintf("%s:%v-%v->%v-%v/%s", start.IP, start.PublicPort, ports[i].PublicPort, start.PrivatePort, ports[i].PrivatePort, start.Type) + } + datas = append(datas, itemPortStr) + } + } + } + return datas +} diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index f060b5227..2354c4958 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -78,7 +78,6 @@ const message = { interval: 'Interval', user: 'User', title: 'Title', - network: 'Network', port: 'Port', protocol: 'Protocol', tableSetting: 'Table setting', @@ -515,6 +514,7 @@ const message = { 'Clearing logs requires restarting the container, and this operation cannot be rolled back. Do you want to continue?', newName: 'New name', source: 'Resource rate', + ip: 'IP address', cpuShare: 'CPU Share', cpuShareHelper: 'The default CPU share for a container is 1024, which can be increased to give the container more CPU time.', @@ -532,7 +532,7 @@ const message = { targetImage: 'Target image', targetImageHelper: 'Please enter the target image version', appHelper: - 'This container is sourced from the application store. Upgrading it may cause the service to be unavailable. Do you want to continue?', + 'This container is sourced from the application store. Upgrading it may cause the service to be unavailable.', forcePull: 'forced image pull ', forcePullHelper: 'Ignore existing images on the server and pull again.', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index d371af1a1..8b1abced4 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -78,7 +78,6 @@ const message = { interval: '耗時', user: '用戶', title: '標題', - network: '網絡', port: '端口', protocol: '協議', tableSetting: '列表設置', @@ -501,6 +500,7 @@ const message = { cleanLogHelper: '清空日誌需要重啟容器,該操作無法回滾,是否繼續?', newName: '新名稱', source: '資源使用率', + ip: 'IP 地址', cpuShare: 'CPU 權重', cpuShareHelper: '容器默認份額為 1024 個 CPU,增大可使當前容器獲得更多的 CPU 時間', @@ -515,7 +515,7 @@ const message = { oldImage: '當前鏡像', targetImage: '目標鏡像', targetImageHelper: '請輸入目標鏡像版本', - appHelper: '該容器來源於應用商店,升級可能導致該服務不可用,是否繼續?', + appHelper: '該容器來源於應用商店,升級可能導致該服務不可用', forcePull: '強製拉取鏡像', forcePullHelper: '忽略服務器已存在的鏡像,重新拉取一次', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index ff185975e..8b6b272bd 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -78,7 +78,6 @@ const message = { interval: '耗时', user: '用户', title: '标题', - network: '网络', port: '端口', protocol: '协议', tableSetting: '列表设置', @@ -501,6 +500,7 @@ const message = { cleanLogHelper: '清空日志需要重启容器,该操作无法回滚,是否继续?', newName: '新名称', source: '资源使用率', + ip: 'IP 地址', cpuShare: 'CPU 权重', cpuShareHelper: '容器默认份额为 1024 个 CPU,增大可使当前容器获得更多的 CPU 时间', @@ -515,7 +515,7 @@ const message = { oldImage: '当前镜像', targetImage: '目标镜像', targetImageHelper: '请输入目标镜像版本', - appHelper: '该容器来源于应用商店,升级可能导致该服务不可用,是否继续?', + appHelper: '该容器来源于应用商店,升级可能导致该服务不可用', forcePull: '强制拉取镜像', forcePullHelper: '忽略服务器已存在的镜像,重新拉取一次', diff --git a/frontend/src/views/container/container/index.vue b/frontend/src/views/container/container/index.vue index 4fbde0957..3f126db5b 100644 --- a/frontend/src/views/container/container/index.vue +++ b/frontend/src/views/container/container/index.vue @@ -83,12 +83,12 @@ min-width="80" prop="imageName" /> - + - + - +