From 161ccc80399d94a53c43ea52e8538f06c8714ddf Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:14:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=B9=E5=99=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=8A=B6=E6=80=81=E7=AD=9B=E9=80=89=20(#2587?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #2471 --- backend/app/dto/container.go | 1 + backend/app/service/container.go | 11 +++++++++++ cmd/server/docs/docs.go | 16 +++++++++++++++- cmd/server/docs/swagger.json | 16 +++++++++++++++- cmd/server/docs/swagger.yaml | 12 ++++++++++++ frontend/src/api/interface/container.ts | 1 + frontend/src/components/status/index.vue | 5 +++++ frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/tw.ts | 7 ++++--- frontend/src/lang/modules/zh.ts | 8 +++++--- .../src/views/container/container/index.vue | 19 +++++++++++++++++-- sonar-project.properties | 2 ++ 12 files changed, 89 insertions(+), 10 deletions(-) diff --git a/backend/app/dto/container.go b/backend/app/dto/container.go index 59fa11da6..1a6851a88 100644 --- a/backend/app/dto/container.go +++ b/backend/app/dto/container.go @@ -5,6 +5,7 @@ import "time" type PageContainer struct { PageInfo Name string `json:"name"` + State string `json:"state" validate:"required,oneof=all created running paused restarting removing exited dead"` OrderBy string `json:"orderBy"` Order string `json:"order"` Filters string `json:"filters"` diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 2f2070b5e..4ac990a95 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -102,6 +102,17 @@ func (u *ContainerService) Page(req dto.PageContainer) (int64, interface{}, erro } } } + if req.State != "all" { + length, count := len(list), 0 + for count < length { + if list[count].State != req.State { + list = append(list[:count], list[(count+1):]...) + length-- + } else { + count++ + } + } + } switch req.OrderBy { case "name": sort.Slice(list, func(i, j int) bool { diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 16cf66352..87275609c 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -14491,7 +14491,8 @@ const docTemplate = `{ "type": "object", "required": [ "page", - "pageSize" + "pageSize", + "state" ], "properties": { "filters": { @@ -14511,6 +14512,19 @@ const docTemplate = `{ }, "pageSize": { "type": "integer" + }, + "state": { + "type": "string", + "enum": [ + "all", + "created", + "running", + "paused", + "restarting", + "removing", + "exited", + "dead" + ] } } }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 129f84d67..3e9a4b0ca 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -14484,7 +14484,8 @@ "type": "object", "required": [ "page", - "pageSize" + "pageSize", + "state" ], "properties": { "filters": { @@ -14504,6 +14505,19 @@ }, "pageSize": { "type": "integer" + }, + "state": { + "type": "string", + "enum": [ + "all", + "created", + "running", + "paused", + "restarting", + "removing", + "exited", + "dead" + ] } } }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index d9e1427ad..b5cc4e7fc 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -1634,9 +1634,21 @@ definitions: type: integer pageSize: type: integer + state: + enum: + - all + - created + - running + - paused + - restarting + - removing + - exited + - dead + type: string required: - page - pageSize + - state type: object dto.PageInfo: properties: diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index 32b8c92e6..7061aaf92 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -8,6 +8,7 @@ export namespace Container { } export interface ContainerSearch extends ReqPage { name: string; + state: string; filters: string; orderBy: string; order: string; diff --git a/frontend/src/components/status/index.vue b/frontend/src/components/status/index.vue index 631bcde62..da1c2eb47 100644 --- a/frontend/src/components/status/index.vue +++ b/frontend/src/components/status/index.vue @@ -28,6 +28,10 @@ const getType = (status: string) => { case 'stopped': return 'danger'; case 'unhealthy': + case 'paused': + case 'exited': + case 'dead': + case 'removing': return 'warning'; default: return ''; @@ -43,6 +47,7 @@ const loadingStatus = [ 'recreating', 'creating', 'starting', + 'removing', ]; const loadingIcon = (status: string): boolean => { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index f97e5843b..4641f8581 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -212,6 +212,7 @@ const message = { removing: 'Removing', paused: 'Paused', exited: 'Exited', + dead: 'Dead', installing: 'Installing', enabled: 'Enabled', disabled: 'Disabled', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 4cb2ced6c..aeda637f1 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -208,9 +208,10 @@ const message = { restarting: '重啟中', uploading: '上傳中', unhealthy: '異常', - removing: '遷移中', - paused: '暫停', - exited: '停止', + removing: '移除中', + paused: '已暫停', + exited: '已停止', + dead: '已結束', installing: '安裝中', enabled: '已啟用', disabled: '已停止', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index c8e45eae2..9f9e1e6d8 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -208,9 +208,10 @@ const message = { restarting: '重启中', uploading: '上传中', unhealthy: '异常', - removing: '迁移中', - paused: '暂停', - exited: '停止', + removing: '移除中', + paused: '已暂停', + exited: '已停止', + dead: '已结束', installing: '安装中', enabled: '已启用', disabled: '已停止', @@ -485,6 +486,7 @@ const message = { operatorHelper: '将对以下容器进行 {0} 操作,是否继续?', operatorAppHelper: '将对以下容器进行 {0} 操作,其中部分来源于应用商店,该操作可能会影响到该服务的正常使用,是否确认?', + dead: '', start: '启动', stop: '停止', restart: '重启', diff --git a/frontend/src/views/container/container/index.vue b/frontend/src/views/container/container/index.vue index ff9577715..2ba9583e9 100644 --- a/frontend/src/views/container/container/index.vue +++ b/frontend/src/views/container/container/index.vue @@ -55,6 +55,19 @@ +