From 1fcc345a7a319306566b86df543c4f0a7bb07d45 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 6 Jul 2023 14:26:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=BC=96=E6=8E=92=E5=AF=BC=E8=87=B4=E6=9D=A5?= =?UTF-8?q?=E6=BA=90=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#1558)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/repo/compose_template.go | 11 +++++++++++ backend/app/service/container_compose.go | 6 +++++- frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/tw.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + .../views/container/compose/create/index.vue | 17 ++++++++++++++--- .../views/container/compose/detail/index.vue | 16 ++++++++++++---- 7 files changed, 45 insertions(+), 8 deletions(-) diff --git a/backend/app/repo/compose_template.go b/backend/app/repo/compose_template.go index 934b1bc34..4259e2fb5 100644 --- a/backend/app/repo/compose_template.go +++ b/backend/app/repo/compose_template.go @@ -15,6 +15,7 @@ type IComposeTemplateRepo interface { Update(id uint, vars map[string]interface{}) error Delete(opts ...DBOption) error + GetRecord(opts ...DBOption) (model.Compose, error) CreateRecord(compose *model.Compose) error DeleteRecord(opts ...DBOption) error ListRecord() ([]model.Compose, error) @@ -72,6 +73,16 @@ func (u *ComposeTemplateRepo) Delete(opts ...DBOption) error { return db.Delete(&model.ComposeTemplate{}).Error } +func (u *ComposeTemplateRepo) GetRecord(opts ...DBOption) (model.Compose, error) { + var compose model.Compose + db := global.DB + for _, opt := range opts { + db = opt(db) + } + err := db.First(&compose).Error + return compose, err +} + func (u *ComposeTemplateRepo) ListRecord() ([]model.Compose, error) { var composes []model.Compose if err := global.DB.Find(&composes).Error; err != nil { diff --git a/backend/app/service/container_compose.go b/backend/app/service/container_compose.go index b40469d63..52275a952 100644 --- a/backend/app/service/container_compose.go +++ b/backend/app/service/container_compose.go @@ -92,7 +92,7 @@ func (u *ContainerService) PageCompose(req dto.SearchWithPage) (int64, interface } } for _, item := range composeCreatedByLocal { - if err := composeRepo.DeleteRecord(commonRepo.WithByName(item.Name)); err != nil { + if err := composeRepo.DeleteRecord(commonRepo.WithByID(item.ID)); err != nil { global.LOG.Error(err) } } @@ -127,6 +127,10 @@ func (u *ContainerService) PageCompose(req dto.SearchWithPage) (int64, interface } func (u *ContainerService) TestCompose(req dto.ComposeCreate) (bool, error) { + composeItem, _ := composeRepo.GetRecord(commonRepo.WithByName(req.Name)) + if composeItem.ID != 0 { + return false, constant.ErrRecordExist + } if err := u.loadPath(&req); err != nil { return false, err } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 48c4b59d2..fc7165082 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -609,6 +609,7 @@ const message = { createComposeTemplate: 'Create compose template', description: 'Description', content: 'Content', + contentEmpty: 'Compose content cannot be empty, please enter and try again!', containerNumber: 'Container number', down: 'Down', up: 'Up', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 9d9d05969..2755073c6 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -595,6 +595,7 @@ const message = { createComposeTemplate: '創建編排模版', description: '描述', content: '內容', + contentEmpty: '編排內容不能為空,請輸入後重試!', containerNumber: '容器數量', down: '刪除', up: '啟動', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 5c0d5071e..2110a6de7 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -595,6 +595,7 @@ const message = { createComposeTemplate: '创建编排模版', description: '描述', content: '内容', + contentEmpty: '编排内容不能为空,请输入后重试!', containerNumber: '容器数量', down: '删除', up: '启动', diff --git a/frontend/src/views/container/compose/create/index.vue b/frontend/src/views/container/compose/create/index.vue index 4a196ea91..3a2411b2c 100644 --- a/frontend/src/views/container/compose/create/index.vue +++ b/frontend/src/views/container/compose/create/index.vue @@ -126,6 +126,7 @@ import { listComposeTemplate, testCompose, upCompose } from '@/api/modules/conta import { loadBaseDir } from '@/api/modules/setting'; import { LoadFile } from '@/api/modules/files'; import { formatImageStdout } from '@/utils/docker'; +import { MsgError } from '@/utils/message'; const loading = ref(); @@ -238,6 +239,10 @@ const onSubmit = async (formEl: FormInstance | undefined) => { if (!formEl) return; formEl.validate(async (valid) => { if (!valid) return; + if ((form.from === 'edit' || form.from === 'template') && form.file.length === 0) { + MsgError(i18n.global.t('container.contentEmpty')); + return; + } loading.value = true; logInfo.value = ''; await testCompose(form) @@ -246,9 +251,15 @@ const onSubmit = async (formEl: FormInstance | undefined) => { if (res.data) { onCreating.value = true; mode.value = 'log'; - const res = await upCompose(form); - logInfo.value = ''; - loadLogs(res.data); + await upCompose(form) + .then((res) => { + logInfo.value = ''; + loadLogs(res.data); + }) + .catch(() => { + loading.value = false; + onCreating.value = false; + }); } }) .catch(() => { diff --git a/frontend/src/views/container/compose/detail/index.vue b/frontend/src/views/container/compose/detail/index.vue index 118d58bec..257c96549 100644 --- a/frontend/src/views/container/compose/detail/index.vue +++ b/frontend/src/views/container/compose/detail/index.vue @@ -163,11 +163,19 @@ const search = async () => { page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, filters: filterItem, + orderBy: 'created_at', + order: 'null', }; - await searchContainer(params).then((res) => { - data.value = res.data.items || []; - paginationConfig.total = res.data.total; - }); + loading.value = true; + await searchContainer(params) + .then((res) => { + loading.value = false; + data.value = res.data.items || []; + paginationConfig.total = res.data.total; + }) + .catch(() => { + loading.value = false; + }); }; const detailInfo = ref();