Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions agent/app/api/v2/compose_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ func (b *BaseApi) CreateComposeTemplate(c *gin.Context) {
helper.Success(c)
}

// @Tags Container Compose-template
// @Summary Bacth compose template
// @Accept json
// @Param request body dto.ComposeTemplateBatch true "request"
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /containers/template/batch [post]
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"批量导入编排模版","formatEN":"batch import compose templates"}
func (b *BaseApi) BatchComposeTemplate(c *gin.Context) {
var req dto.ComposeTemplateBatch
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}

if err := composeTemplateService.Batch(req); err != nil {
helper.InternalServer(c, err)
return
}
helper.Success(c)
}

// @Tags Container Compose-template
// @Summary Page compose templates
// @Accept json
Expand Down
4 changes: 4 additions & 0 deletions agent/app/dto/compose_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ type ComposeTemplateCreate struct {
Content string `json:"content"`
}

type ComposeTemplateBatch struct {
Templates []ComposeTemplateCreate `json:"templates" validate:"required"`
}

type ComposeTemplateUpdate struct {
ID uint `json:"id"`
Description string `json:"description"`
Expand Down
20 changes: 19 additions & 1 deletion agent/app/service/compose_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"github.com/1Panel-dev/1Panel/agent/app/dto"
"github.com/1Panel-dev/1Panel/agent/app/model"
"github.com/1Panel-dev/1Panel/agent/app/repo"
"github.com/1Panel-dev/1Panel/agent/buserr"
"github.com/jinzhu/copier"
Expand All @@ -12,8 +13,9 @@ type ComposeTemplateService struct{}
type IComposeTemplateService interface {
List() ([]dto.ComposeTemplateInfo, error)
SearchWithPage(search dto.SearchWithPage) (int64, interface{}, error)
Create(composeDto dto.ComposeTemplateCreate) error
Create(req dto.ComposeTemplateCreate) error
Update(id uint, upMap map[string]interface{}) error
Batch(req dto.ComposeTemplateBatch) error
Delete(ids []uint) error
}

Expand Down Expand Up @@ -64,6 +66,22 @@ func (u *ComposeTemplateService) Create(composeDto dto.ComposeTemplateCreate) er
return nil
}

func (u *ComposeTemplateService) Batch(req dto.ComposeTemplateBatch) error {
for _, item := range req.Templates {
template, _ := composeRepo.Get(repo.WithByName(item.Name))
if template.ID == 0 {
if err := composeRepo.Create(&model.ComposeTemplate{Name: item.Name, Content: item.Content, Description: item.Description}); err != nil {
return err
}
} else {
if err := composeRepo.Update(template.ID, map[string]interface{}{"content": item.Content, "description": item.Description}); err != nil {
return err
}
}
}
return nil
}

func (u *ComposeTemplateService) Delete(ids []uint) error {
if len(ids) == 1 {
compose, _ := composeRepo.Get(repo.WithByID(ids[0]))
Expand Down
1 change: 1 addition & 0 deletions agent/router/ro_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (s *ContainerRouter) InitRouter(Router *gin.RouterGroup) {
baRouter.GET("/template", baseApi.ListComposeTemplate)
baRouter.POST("/template/search", baseApi.SearchComposeTemplate)
baRouter.POST("/template/update", baseApi.UpdateComposeTemplate)
baRouter.POST("/template/batch", baseApi.BatchComposeTemplate)
baRouter.POST("/template", baseApi.CreateComposeTemplate)
baRouter.POST("/template/del", baseApi.DeleteComposeTemplate)

Expand Down
6 changes: 0 additions & 6 deletions frontend/src/api/interface/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,25 +318,19 @@ export namespace Container {

export interface TemplateCreate {
name: string;
from: string;
description: string;
path: string;
content: string;
}
export interface TemplateUpdate {
id: number;
from: string;
description: string;
path: string;
content: string;
}
export interface TemplateInfo {
id: number;
createdAt: Date;
name: string;
from: string;
description: string;
path: string;
content: string;
}

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/api/modules/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ export const deleteComposeTemplate = (params: { ids: number[] }) => {
export const createComposeTemplate = (params: Container.TemplateCreate) => {
return http.post(`/containers/template`, params);
};
export const batchComposeTemplate = (templates: Array<Container.TemplateCreate>) => {
return http.post(`/containers/template/batch`, { templates: templates });
};
export const updateComposeTemplate = (params: Container.TemplateUpdate) => {
return http.post(`/containers/template/update`, params);
};
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/status/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const getType = (status: string) => {
case 'healthy':
case 'unused':
case 'executing':
case 'new':
return 'success';
case 'stopped':
case 'exceptional':
Expand All @@ -76,7 +77,10 @@ const getType = (status: string) => {
case 'dead':
case 'removing':
case 'deleted':
case 'conflict':
return 'warning';
case 'duplicate':
return 'info';
default:
return 'primary';
}
Expand Down
17 changes: 7 additions & 10 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ const message = {
installSuccess: 'Install successful',
uninstallSuccess: 'Uninstall successful',
offlineTips: 'Offline version does not support this operation',
errImportFormat: 'Import data or format is abnormal, please check and try again!',
importHelper:
'When importing conflicting or duplicate data, the imported content will be used as the standard to update the original database data.',
errImport: 'File content is abnormal:',
},
login: {
username: 'Username',
Expand Down Expand Up @@ -335,6 +339,9 @@ const message = {
systemrestart: 'Interrupted',
starterr: 'Startup failed',
uperr: 'Startup failed',
new: 'New',
conflict: 'Conflict',
duplicate: 'Duplicate',
},
units: {
second: ' second | second | seconds',
Expand Down Expand Up @@ -1037,8 +1044,6 @@ const message = {
cronjob: {
create: 'Create cron job',
edit: 'Edit cron job',
errImport: 'File content exception:',
errImportFormat: 'The scheduled task data or format is abnormal. Please check and try again!',
importHelper:
'Duplicate scheduled tasks will be automatically skipped during import. Tasks will be set to [Disabled] status by default, and set to [Pending Edit] status when data association is abnormal.',
changeStatus: 'Change status',
Expand Down Expand Up @@ -2886,15 +2891,7 @@ const message = {
forwardHelper2: 'Leave the destination IP blank to forward to the local port.',
forwardHelper3: 'Only support IPv4 port forwarding.',
forwardInboundInterface: 'Forward Inbound Network Interface',
importHelper:
'When importing conflicting or duplicate firewall rules, the imported content will be used as the standard to update the original firewall rules.',
exportHelper: 'About to export {0} firewall rules. Continue?',
new: 'New',
conflict: 'Conflict',
duplicate: 'Duplicate',
errImportFormat: 'Import file format error, please check the JSON file format',
errImport: 'Import failed: ',
selectImportRules: 'Please select rules to import',
importSuccess: 'Successfully imported {0} rules',
importPartialSuccess: 'Import completed: {0} succeeded, {1} failed',
},
Expand Down
18 changes: 7 additions & 11 deletions frontend/src/lang/modules/es-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ const message = {
installSuccess: 'Instalación completada correctamente',
uninstallSuccess: 'Desinstalación completada correctamente',
offlineTips: 'La versión offline no admite esta operación',
errImportFormat: 'Los datos de importación o el formato son anormales, ¡compruebe e inténtelo de nuevo!',
importHelper:
'Al importar datos conflictivos o duplicados, el contenido importado se utilizará como estándar para actualizar los datos originales de la base de datos.',
errImport: 'El contenido del archivo es anormal:',
},
login: {
username: 'Usuario',
Expand Down Expand Up @@ -342,6 +346,9 @@ const message = {
systemrestart: 'Interrumpido',
starterr: 'Error al iniciar',
uperr: 'Error al iniciar',
new: 'Nuevo',
conflict: 'Conflicto',
duplicate: 'Duplicado',
},
units: {
second: ' segundo | segundo | segundos',
Expand Down Expand Up @@ -1036,9 +1043,6 @@ const message = {
cronjob: {
create: 'Crear tarea programada',
edit: 'Editar tarea programada',
errImport: 'Excepción en el contenido del archivo:',
errImportFormat:
'Los datos o el formato de la tarea programada son anormales. ¡Por favor verifique e inténtelo de nuevo!',
importHelper:
'Las tareas programadas duplicadas se omitirán automáticamente durante la importación. Las tareas se establecerán en estado [Deshabilitado] por defecto, y en estado [Pendiente de edición] cuando la asociación de datos sea anormal.',
changeStatus: 'Cambiar estado',
Expand Down Expand Up @@ -2859,15 +2863,7 @@ const message = {
forwardHelper2: 'Deja en blanco la IP de destino para reenviar al puerto local.',
forwardHelper3: 'Solo se admite redirección de puertos IPv4.',
forwardInboundInterface: 'Interfaz de Red de Entrada para Reenvío',
importHelper:
'Al importar reglas de firewall conflictivas o duplicadas, el contenido importado se utilizará como estándar para actualizar las reglas de firewall originales.',
exportHelper: 'A punto de exportar {0} reglas de firewall. ¿Continuar?',
new: 'Nueva',
conflict: 'Conflicto',
duplicate: 'Duplicada',
errImportFormat: 'Error en el formato del archivo importado, comprueba el formato del archivo JSON',
errImport: 'Error al importar: ',
selectImportRules: 'Selecciona las reglas que deseas importar',
importSuccess: 'Se importaron correctamente {0} reglas',
importPartialSuccess: 'Importación completada: {0} correctas, {1} fallidas',
},
Expand Down
17 changes: 7 additions & 10 deletions frontend/src/lang/modules/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ const message = {
resetSuccess: 'リセット成功',
creatingInfo: '作成、この操作は必要ありません',
offlineTips: 'オフライン版はこの操作をサポートしていません',
errImportFormat: 'インポートデータまたはフォーマットが異常です。確認して再試行してください!',
importHelper:
'競合または重複するデータをインポートする場合、インポートされた内容を基準として元のデータベースデータを更新します。',
errImport: 'ファイル内容が異常です:',
},
login: {
username: 'ユーザー名',
Expand Down Expand Up @@ -324,6 +328,9 @@ const message = {
systemrestart: '中断',
starterr: '起動に失敗しました',
uperr: '起動に失敗しました',
new: '新規',
conflict: '競合',
duplicate: '重複',
},
units: {
second: '2番目|2番目|秒',
Expand Down Expand Up @@ -1008,8 +1015,6 @@ const message = {
cronjob: {
create: 'Cronジョブを作成します',
edit: 'Cronジョブを編集します',
errImport: 'ファイル内容異常:',
errImportFormat: 'インポートしたスケジュールタスクのデータまたは形式が異常です。確認して再試行してください!',
importHelper:
'インポート時に同名のスケジュールタスクは自動的にスキップされます。タスクはデフォルトで【無効】状態に設定され、データ関連付け異常時には【編集待ち】状態に設定されます。',
changeStatus: 'ステータスを変更します',
Expand Down Expand Up @@ -2801,15 +2806,7 @@ const message = {
forwardHelper2: '宛先IPを空白のままにして、ローカルポートに転送します。',
forwardHelper3: 'IPv4ポート転送のみをサポートします。',
forwardInboundInterface: '転送入站ネットワークインターフェース',
importHelper:
'競合または重複するファイアウォールルールをインポートする場合、インポートされた内容を基準として元のファイアウォールルールを更新します。',
exportHelper: '{0} 件のファイアウォールルールをエクスポートします。続行しますか?',
new: '新規',
conflict: '競合',
duplicate: '重複',
errImportFormat: 'インポートファイルの形式エラーです。JSON ファイルの形式を確認してください',
errImport: 'インポートに失敗しました: ',
selectImportRules: 'インポートするルールを選択してください',
importSuccess: '{0} 件のルールを正常にインポートしました',
importPartialSuccess: 'インポート完了: {0} 件成功、{1} 件失敗',
},
Expand Down
17 changes: 7 additions & 10 deletions frontend/src/lang/modules/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ const message = {
resetSuccess: '초기화 완료',
creatingInfo: '생성 중입니다. 이 작업이 필요하지 않습니다',
offlineTips: '오프라인 버전은 이 작업을 지원하지 않습니다',
errImportFormat: '가져오기 데이터 또는 형식이 비정상입니다. 확인 후 다시 시도하세요!',
importHelper:
'충돌하거나 중복되는 데이터를 가져올 때 가져온 내용을 기준으로 원래 데이터베이스 데이터를 업데이트합니다.',
errImport: '파일 내용이 비정상입니다:',
},
login: {
username: '사용자 이름',
Expand Down Expand Up @@ -326,6 +330,9 @@ const message = {
systemrestart: '중단됨',
starterr: '시작 실패',
uperr: '실행 실패',
new: '신규',
conflict: '충돌',
duplicate: '중복',
},
units: {
second: '초 | 초 | 초',
Expand Down Expand Up @@ -998,8 +1005,6 @@ const message = {
cronjob: {
create: '크론 작업 생성',
edit: '크론 작업 수정',
errImport: '파일 내용 이상:',
errImportFormat: '가져온 예약 작업 데이터 또는 형식이 이상합니다. 확인 후 다시 시도하십시오!',
importHelper:
'가져오기 시 동일한 이름의 예약 작업은 자동으로 건너뜁니다. 작업은 기본적으로 【비활성화】 상태로 설정되며, 데이터 연동 이상 시 【편집 대기】 상태로 설정됩니다.',
changeStatus: '상태 변경',
Expand Down Expand Up @@ -2752,15 +2757,7 @@ const message = {
forwardHelper2: '대상 IP 를 비워두면 로컬 포트로 전달됩니다.',
forwardHelper3: 'IPv4 포트 전달만 지원됩니다.',
forwardInboundInterface: '포워딩 인바운드 네트워크 인터페이스',
importHelper:
'충돌하거나 중복되는 방화벽 규칙을 가져올 때 가져온 내용을 기준으로 원래 방화벽 규칙을 업데이트합니다.',
exportHelper: '{0}개의 방화벽 규칙을 내보내려고 합니다. 계속하시겠습니까?',
new: '신규',
conflict: '충돌',
duplicate: '중복',
errImportFormat: '가져오기 파일 형식 오류입니다. JSON 파일 형식을 확인하세요',
errImport: '가져오기에 실패했습니다: ',
selectImportRules: '가져올 규칙을 선택하세요',
importSuccess: '{0}개의 규칙을 성공적으로 가져왔습니다',
importPartialSuccess: '가져오기 완료: 성공 {0}건, 실패 {1}건',
},
Expand Down
17 changes: 7 additions & 10 deletions frontend/src/lang/modules/ms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ const message = {
resetSuccess: 'Berjaya ditetapkan semula',
creatingInfo: 'Sedang mencipta, operasi ini tidak diperlukan',
offlineTips: 'Versi luar talian tidak menyokong operasi ini',
errImportFormat: 'Data import atau format adalah tidak normal, sila periksa dan cuba lagi!',
importHelper:
'Apabila mengimport data yang bercanggah atau pendua, kandungan yang diimport akan digunakan sebagai piawai untuk mengemas kini data pangkalan data asal.',
errImport: 'Kandungan fail adalah tidak normal:',
},
login: {
username: 'Nama Pengguna',
Expand Down Expand Up @@ -332,6 +336,9 @@ const message = {
systemrestart: 'Dihentikan',
starterr: 'Permulaan gagal',
uperr: 'Permulaan gagal',
new: 'Baru',
conflict: 'Konflik',
duplicate: 'Pendua',
},
units: {
second: 'saat | saat | saat',
Expand Down Expand Up @@ -1032,8 +1039,6 @@ const message = {
cronjob: {
create: 'Cipta tugas cron',
edit: 'Edit tugas cron',
errImport: 'Kandungan fail tidak normal:',
errImportFormat: 'Data atau format tugas terjadual yang diimport tidak normal. Sila semak dan cuba lagi!',
importHelper:
'Tugas terjadual dengan nama sama akan dilangkau secara automatik semasa import. Tugas akan ditetapkan ke status 【Lumpuh】 secara lalai, dan ditetapkan ke status 【Menunggu Edit】 apabila perkaitan data tidak normal.',
changeStatus: 'Tukar status',
Expand Down Expand Up @@ -2867,15 +2872,7 @@ const message = {
forwardHelper2: 'Biarkan IP sasaran kosong untuk memajukan ke port tempatan.',
forwardHelper3: 'Hanya menyokong pemajuan port IPv4.',
forwardInboundInterface: 'Antara Muka Rangkaian Masukan Penerusan',
importHelper:
'Apabila mengimport peraturan firewall yang bercanggah atau pendua, kandungan yang diimport akan digunakan sebagai piawai untuk mengemas kini peraturan firewall asal.',
exportHelper: 'Akan mengeksport {0} peraturan firewall. Teruskan?',
new: 'Baharu',
conflict: 'Konflik',
duplicate: 'Duplikat',
errImportFormat: 'Ralat format fail import, sila semak format fail JSON',
errImport: 'Import gagal: ',
selectImportRules: 'Sila pilih peraturan untuk diimport',
importSuccess: '{0} peraturan berjaya diimport',
importPartialSuccess: 'Import selesai: {0} berjaya, {1} gagal',
},
Expand Down
Loading
Loading