fix: 解决重复创建编排导致来源显示错误的问题 (#1558)

pull/1563/head
ssongliu 2023-07-06 14:26:22 +08:00 committed by GitHub
parent 7e9a09c960
commit 1fcc345a7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 8 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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',

View File

@ -595,6 +595,7 @@ const message = {
createComposeTemplate: '',
description: '',
content: '',
contentEmpty: '',
containerNumber: '',
down: '',
up: '',

View File

@ -595,6 +595,7 @@ const message = {
createComposeTemplate: '',
description: '',
content: '',
contentEmpty: '',
containerNumber: '',
down: '',
up: '',

View File

@ -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(() => {

View File

@ -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();