mirror of https://github.com/1Panel-dev/1Panel
fix: 解决重复创建编排导致来源显示错误的问题 (#1558)
parent
7e9a09c960
commit
1fcc345a7a
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -595,6 +595,7 @@ const message = {
|
|||
createComposeTemplate: '創建編排模版',
|
||||
description: '描述',
|
||||
content: '內容',
|
||||
contentEmpty: '編排內容不能為空,請輸入後重試!',
|
||||
containerNumber: '容器數量',
|
||||
down: '刪除',
|
||||
up: '啟動',
|
||||
|
|
|
@ -595,6 +595,7 @@ const message = {
|
|||
createComposeTemplate: '创建编排模版',
|
||||
description: '描述',
|
||||
content: '内容',
|
||||
contentEmpty: '编排内容不能为空,请输入后重试!',
|
||||
containerNumber: '容器数量',
|
||||
down: '删除',
|
||||
up: '启动',
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue