From 5b68332b9aa2ce15310b3ebb13d431aa2c44acc0 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 27 Apr 2023 10:24:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20compose=20=E9=AA=8C=E8=AF=81=E3=80=81?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=8C=89=E9=92=AE=E5=90=88=E5=B9=B6=20(#806)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/container_compose.go | 10 +--- backend/app/service/docker.go | 8 +-- frontend/src/lang/modules/en.ts | 10 ++-- frontend/src/lang/modules/zh.ts | 10 ++-- .../views/container/compose/create/index.vue | 57 ++++++------------- 5 files changed, 33 insertions(+), 62 deletions(-) diff --git a/backend/app/service/container_compose.go b/backend/app/service/container_compose.go index 4cf67376c..44476756d 100644 --- a/backend/app/service/container_compose.go +++ b/backend/app/service/container_compose.go @@ -213,15 +213,7 @@ func (u *ContainerService) ComposeUpdate(req dto.ComposeUpdate) error { } func (u *ContainerService) loadPath(req *dto.ComposeCreate) error { - if req.From == "template" { - template, err := composeRepo.Get(commonRepo.WithByID(req.Template)) - if err != nil { - return err - } - req.From = "edit" - req.File = template.Content - } - if req.From == "edit" { + if req.From == "template" || req.From == "edit" { dir := fmt.Sprintf("%s/docker/compose/%s", constant.DataDir, req.Name) if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) { if err = os.MkdirAll(dir, os.ModePerm); err != nil { diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index d9b562e5d..55efbffa5 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -40,10 +40,10 @@ type daemonJsonItem struct { func (u *DockerService) LoadDockerStatus() string { status := constant.StatusRunning - // stdout, err := cmd.Exec("systemctl is-active docker") - // if string(stdout) != "active\n" || err != nil { - // status = constant.Stopped - // } + stdout, err := cmd.Exec("systemctl is-active docker") + if string(stdout) != "active\n" || err != nil { + status = constant.Stopped + } return status } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 2872ca7d7..93b2f61c6 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -545,12 +545,11 @@ const message = { compose: 'Compose', fromChangeHelper: 'Switching the source will clear the current edited content. Do you want to continue?', - composeHelper: - 'The current content has passed the format verification. Please click Submit to complete the creation', composePathHelper: 'Config file save path: {0}', apps: 'Apps', local: 'Local', createCompose: 'Create compose', + template: 'Template', composeTemplate: 'Compose template', createComposeTemplate: 'Create compose template', description: 'Description', @@ -994,7 +993,7 @@ const message = { update: 'update', upgrade: 'upgrade', versioneSelect: 'Please select a version', - operatorHelper: 'Operation {0} will be performed on the selected application, continue? ', + operatorHelper: 'Operation {0} will be performed on the selected application, Do you want to continue? ', checkInstalledWarn: '{0} is not detected, please enter the app store and click to install!', gotoInstalled: 'Go to install', search: 'Search', @@ -1023,7 +1022,7 @@ const message = { updatePrompt: 'The current application is the latest version', installPrompt: 'No apps installed yet', updateHelper: 'Updating parameters may cause the application to fail to start, please operate with caution', - updateWarn: 'Update parameters need to rebuild the application, continue? ', + updateWarn: 'Update parameters need to rebuild the application, Do you want to continue? ', busPort: 'Service Port', }, website: { @@ -1161,7 +1160,8 @@ const message = { HTTPAlso: 'HTTP can be accessed directly', sslConfig: 'SSL options', disbaleHTTTPS: 'Disable HTTPS', - disbaleHTTTPSHelper: 'Disabling HTTPS will delete the certificate related configuration, whether to continue', + disbaleHTTTPSHelper: + 'Disabling HTTPS will delete the certificate related configuration, Do you want to continue?', SSLHelper: 'Note: Do not use SSL certificates for illegal websites \n If HTTPS access cannot be used after opening, please check whether the security group has correctly released port 443', SSLConfig: 'Certificate Settings', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 99091c50f..e1a383c9b 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -80,8 +80,8 @@ const message = { Rollbacking: '快照回滚中,请稍候...', }, msg: { - delete: '删除 操作不可回滚,是否继续', - clean: '清空 操作不可回滚,是否继续', + delete: '删除 操作不可回滚,是否继续?', + clean: '清空 操作不可回滚,是否继续?', deleteTitle: '删除', deleteSuccess: '删除成功', loginSuccess: '登录成功', @@ -562,11 +562,11 @@ const message = { compose: '编排', fromChangeHelper: '切换来源将清空当前已编辑内容,是否继续?', - composeHelper: '当前内容已通过格式验证,请点击确认完成创建', composePathHelper: '配置文件保存路径: {0}', apps: '应用商店', local: '本地', createCompose: '创建编排', + template: '模版', composeTemplate: '编排模版', createComposeTemplate: '创建编排模版', description: '描述', @@ -935,7 +935,7 @@ const message = { mfaHelper2: '使用手机应用扫描以下二维码,获取 6 位验证码', mfaHelper3: '输入手机应用上的 6 位数字', sslDisable: '禁用', - sslDisableHelper: '禁用 https 服务,需要重启面板才能生效,是否继续!', + sslDisableHelper: '禁用 https 服务,需要重启面板才能生效,是否继续?', monitor: '监控', enableMonitor: '监控状态', @@ -1166,7 +1166,7 @@ const message = { HTTPAlso: 'HTTP可直接访问', sslConfig: 'SSL 选项', disbaleHTTTPS: '禁用 HTTPS', - disbaleHTTTPSHelper: '禁用 HTTPS会删除证书相关配置,是否继续', + disbaleHTTTPSHelper: '禁用 HTTPS会删除证书相关配置,是否继续?', SSLHelper: '注意:请勿将SSL证书用于非法网站 \n 如开启后无法使用HTTPS访问,请检查安全组是否正确放行443端口', SSLConfig: '证书设置', SSLProConfig: 'SSL 协议设置', diff --git a/frontend/src/views/container/compose/create/index.vue b/frontend/src/views/container/compose/create/index.vue index 92953659b..422b32b60 100644 --- a/frontend/src/views/container/compose/create/index.vue +++ b/frontend/src/views/container/compose/create/index.vue @@ -34,7 +34,9 @@ - + {{ $t('container.composePathHelper', [composeFile]) }} @@ -44,6 +46,7 @@ + {{ $t('commons.button.cancel') }} - - {{ $t('commons.button.verify') }} - - + {{ $t('commons.button.confirm') }} @@ -128,7 +126,6 @@ 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 { MsgSuccess } from '@/utils/message'; const loading = ref(); @@ -145,13 +142,10 @@ const logInfo = ref(); const drawerVisiable = ref(false); const templateOptions = ref(); -const buttonDisabled = ref(false); const baseDir = ref(); const composeFile = ref(); -const hasChecked = ref(); - let timer: NodeJS.Timer | null = null; const form = reactive({ @@ -178,7 +172,6 @@ const acceptParams = (): void => { form.from = 'edit'; form.path = ''; form.file = ''; - hasChecked.value = false; logInfo.value = ''; loadTemplates(); loadPath(); @@ -186,7 +179,6 @@ const acceptParams = (): void => { const emit = defineEmits<{ (e: 'search'): void }>(); const changeTemplate = () => { - hasChecked.value = false; for (const item of templateOptions.value) { if (form.template === item.id) { form.file = item.content; @@ -203,14 +195,11 @@ const changeFrom = () => { type: 'info', }) .then(() => { - hasChecked.value = false; - if (form.from === 'template') { - if (!form.template && templateOptions.value && templateOptions.value.length !== 0) { - form.template = templateOptions.value[0].id; - } - changeTemplate(); + if (oldFrom.value === 'template') { + form.template = null; + form.file = ''; } - if (form.from === 'edit') { + if (oldFrom.value === 'edit') { form.file = ''; } oldFrom.value = form.from; @@ -243,18 +232,21 @@ const changePath = async () => { type FormInstance = InstanceType; const formRef = ref(); -const onTest = async (formEl: FormInstance | undefined) => { +const onSubmit = async (formEl: FormInstance | undefined) => { if (!formEl) return; formEl.validate(async (valid) => { if (!valid) return; loading.value = true; logInfo.value = ''; await testCompose(form) - .then((res) => { + .then(async (res) => { loading.value = false; if (res.data) { - MsgSuccess(i18n.global.t('container.composeHelper')); - hasChecked.value = true; + onCreating.value = true; + mode.value = 'log'; + const res = await upCompose(form); + logInfo.value = ''; + loadLogs(res.data); } }) .catch(() => { @@ -263,19 +255,6 @@ const onTest = async (formEl: FormInstance | undefined) => { }); }; -const onSubmit = async (formEl: FormInstance | undefined) => { - if (!formEl) return; - formEl.validate(async (valid) => { - if (!valid) return; - onCreating.value = true; - mode.value = 'log'; - const res = await upCompose(form); - logInfo.value = ''; - buttonDisabled.value = true; - loadLogs(res.data); - }); -}; - const loadLogs = async (path: string) => { timer = setInterval(async () => { const res = await LoadFile({ path: path }); @@ -294,14 +273,12 @@ const loadLogs = async (path: string) => { onCreating.value = false; clearInterval(Number(timer)); timer = null; - buttonDisabled.value = false; } }, 1000 * 3); }; const loadDir = async (path: string) => { form.path = path; - hasChecked.value = false; }; onBeforeUnmount(() => { @@ -313,3 +290,5 @@ defineExpose({ acceptParams, }); + +