mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 22:18:07 +08:00
fix: 解决重复创建编排导致来源显示错误的问题 (#1558)
This commit is contained in:
parent
7e9a09c960
commit
1fcc345a7a
@ -15,6 +15,7 @@ type IComposeTemplateRepo interface {
|
|||||||
Update(id uint, vars map[string]interface{}) error
|
Update(id uint, vars map[string]interface{}) error
|
||||||
Delete(opts ...DBOption) error
|
Delete(opts ...DBOption) error
|
||||||
|
|
||||||
|
GetRecord(opts ...DBOption) (model.Compose, error)
|
||||||
CreateRecord(compose *model.Compose) error
|
CreateRecord(compose *model.Compose) error
|
||||||
DeleteRecord(opts ...DBOption) error
|
DeleteRecord(opts ...DBOption) error
|
||||||
ListRecord() ([]model.Compose, error)
|
ListRecord() ([]model.Compose, error)
|
||||||
@ -72,6 +73,16 @@ func (u *ComposeTemplateRepo) Delete(opts ...DBOption) error {
|
|||||||
return db.Delete(&model.ComposeTemplate{}).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) {
|
func (u *ComposeTemplateRepo) ListRecord() ([]model.Compose, error) {
|
||||||
var composes []model.Compose
|
var composes []model.Compose
|
||||||
if err := global.DB.Find(&composes).Error; err != nil {
|
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 {
|
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)
|
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) {
|
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 {
|
if err := u.loadPath(&req); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -609,6 +609,7 @@ const message = {
|
|||||||
createComposeTemplate: 'Create compose template',
|
createComposeTemplate: 'Create compose template',
|
||||||
description: 'Description',
|
description: 'Description',
|
||||||
content: 'Content',
|
content: 'Content',
|
||||||
|
contentEmpty: 'Compose content cannot be empty, please enter and try again!',
|
||||||
containerNumber: 'Container number',
|
containerNumber: 'Container number',
|
||||||
down: 'Down',
|
down: 'Down',
|
||||||
up: 'Up',
|
up: 'Up',
|
||||||
|
@ -595,6 +595,7 @@ const message = {
|
|||||||
createComposeTemplate: '創建編排模版',
|
createComposeTemplate: '創建編排模版',
|
||||||
description: '描述',
|
description: '描述',
|
||||||
content: '內容',
|
content: '內容',
|
||||||
|
contentEmpty: '編排內容不能為空,請輸入後重試!',
|
||||||
containerNumber: '容器數量',
|
containerNumber: '容器數量',
|
||||||
down: '刪除',
|
down: '刪除',
|
||||||
up: '啟動',
|
up: '啟動',
|
||||||
|
@ -595,6 +595,7 @@ const message = {
|
|||||||
createComposeTemplate: '创建编排模版',
|
createComposeTemplate: '创建编排模版',
|
||||||
description: '描述',
|
description: '描述',
|
||||||
content: '内容',
|
content: '内容',
|
||||||
|
contentEmpty: '编排内容不能为空,请输入后重试!',
|
||||||
containerNumber: '容器数量',
|
containerNumber: '容器数量',
|
||||||
down: '删除',
|
down: '删除',
|
||||||
up: '启动',
|
up: '启动',
|
||||||
|
@ -126,6 +126,7 @@ import { listComposeTemplate, testCompose, upCompose } from '@/api/modules/conta
|
|||||||
import { loadBaseDir } from '@/api/modules/setting';
|
import { loadBaseDir } from '@/api/modules/setting';
|
||||||
import { LoadFile } from '@/api/modules/files';
|
import { LoadFile } from '@/api/modules/files';
|
||||||
import { formatImageStdout } from '@/utils/docker';
|
import { formatImageStdout } from '@/utils/docker';
|
||||||
|
import { MsgError } from '@/utils/message';
|
||||||
|
|
||||||
const loading = ref();
|
const loading = ref();
|
||||||
|
|
||||||
@ -238,6 +239,10 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
|
|||||||
if (!formEl) return;
|
if (!formEl) return;
|
||||||
formEl.validate(async (valid) => {
|
formEl.validate(async (valid) => {
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
|
if ((form.from === 'edit' || form.from === 'template') && form.file.length === 0) {
|
||||||
|
MsgError(i18n.global.t('container.contentEmpty'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
logInfo.value = '';
|
logInfo.value = '';
|
||||||
await testCompose(form)
|
await testCompose(form)
|
||||||
@ -246,9 +251,15 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
|
|||||||
if (res.data) {
|
if (res.data) {
|
||||||
onCreating.value = true;
|
onCreating.value = true;
|
||||||
mode.value = 'log';
|
mode.value = 'log';
|
||||||
const res = await upCompose(form);
|
await upCompose(form)
|
||||||
|
.then((res) => {
|
||||||
logInfo.value = '';
|
logInfo.value = '';
|
||||||
loadLogs(res.data);
|
loadLogs(res.data);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false;
|
||||||
|
onCreating.value = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
@ -163,10 +163,18 @@ const search = async () => {
|
|||||||
page: paginationConfig.currentPage,
|
page: paginationConfig.currentPage,
|
||||||
pageSize: paginationConfig.pageSize,
|
pageSize: paginationConfig.pageSize,
|
||||||
filters: filterItem,
|
filters: filterItem,
|
||||||
|
orderBy: 'created_at',
|
||||||
|
order: 'null',
|
||||||
};
|
};
|
||||||
await searchContainer(params).then((res) => {
|
loading.value = true;
|
||||||
|
await searchContainer(params)
|
||||||
|
.then((res) => {
|
||||||
|
loading.value = false;
|
||||||
data.value = res.data.items || [];
|
data.value = res.data.items || [];
|
||||||
paginationConfig.total = res.data.total;
|
paginationConfig.total = res.data.total;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user