mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-11-17 14:18:46 +08:00
fix: Modify the planned task script display (#8569)
This commit is contained in:
parent
2b0e932ca5
commit
099ca7ff6c
9 changed files with 51 additions and 23 deletions
|
|
@ -44,12 +44,7 @@ func (b *BaseApi) SearchContainer(c *gin.Context) {
|
|||
// @Security Timestamp
|
||||
// @Router /containers/list [post]
|
||||
func (b *BaseApi) ListContainer(c *gin.Context) {
|
||||
list, err := containerService.List()
|
||||
if err != nil {
|
||||
helper.InternalServer(c, err)
|
||||
return
|
||||
}
|
||||
helper.SuccessWithData(c, list)
|
||||
helper.SuccessWithData(c, containerService.List())
|
||||
}
|
||||
|
||||
// @Tags Container
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ func (s *SettingRepo) Get(opts ...DBOption) (model.Setting, error) {
|
|||
func (s *SettingRepo) GetValueByKey(key string) (string, error) {
|
||||
var setting model.Setting
|
||||
if err := global.DB.Model(&model.Setting{}).Where("key = ?", key).First(&setting).Error; err != nil {
|
||||
global.LOG.Errorf("load %s from db setting failed, err: %v", key, err)
|
||||
return "", err
|
||||
}
|
||||
return setting.Value, nil
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ type ContainerService struct{}
|
|||
|
||||
type IContainerService interface {
|
||||
Page(req dto.PageContainer) (int64, interface{}, error)
|
||||
List() ([]string, error)
|
||||
List() []string
|
||||
LoadStatus() (dto.ContainerStatus, error)
|
||||
PageNetwork(req dto.SearchWithPage) (int64, interface{}, error)
|
||||
ListNetwork() ([]dto.Options, error)
|
||||
|
|
@ -219,15 +219,17 @@ func (u *ContainerService) Page(req dto.PageContainer) (int64, interface{}, erro
|
|||
return int64(total), backDatas, nil
|
||||
}
|
||||
|
||||
func (u *ContainerService) List() ([]string, error) {
|
||||
func (u *ContainerService) List() []string {
|
||||
client, err := docker.NewDockerClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
global.LOG.Errorf("load docker client for contianer list failed, err: %v", err)
|
||||
return nil
|
||||
}
|
||||
defer client.Close()
|
||||
containers, err := client.ContainerList(context.Background(), container.ListOptions{All: true})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
global.LOG.Errorf("load contianer list failed, err: %v", err)
|
||||
return nil
|
||||
}
|
||||
var datas []string
|
||||
for _, container := range containers {
|
||||
|
|
@ -238,7 +240,7 @@ func (u *ContainerService) List() ([]string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
return datas, nil
|
||||
return datas
|
||||
}
|
||||
|
||||
func (u *ContainerService) LoadStatus() (dto.ContainerStatus, error) {
|
||||
|
|
|
|||
|
|
@ -103,13 +103,17 @@ func (u *CronjobService) LoadScriptOptions() []dto.ScriptOptions {
|
|||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
lang, _ := settingRepo.GetValueByKey("Language")
|
||||
if len(lang) == 0 {
|
||||
lang = "en"
|
||||
}
|
||||
var options []dto.ScriptOptions
|
||||
for _, script := range scripts {
|
||||
var item dto.ScriptOptions
|
||||
item.ID = script.ID
|
||||
var translations = make(map[string]string)
|
||||
_ = json.Unmarshal([]byte(script.Name), &translations)
|
||||
if name, ok := translations["en"]; ok {
|
||||
if name, ok := translations[lang]; ok {
|
||||
item.Name = strings.ReplaceAll(name, " ", "_")
|
||||
} else {
|
||||
item.Name = strings.ReplaceAll(script.Name, " ", "_")
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ func InitAgentDB() {
|
|||
migrations.UpdateWebsiteAcmeAccount,
|
||||
migrations.UpdateAppInstall,
|
||||
migrations.AddMcpServer,
|
||||
migrations.InitLanguageSetting,
|
||||
})
|
||||
if err := m.Migrate(); err != nil {
|
||||
global.LOG.Error(err)
|
||||
|
|
|
|||
|
|
@ -374,3 +374,25 @@ var AddMcpServer = &gormigrate.Migration{
|
|||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var InitLanguageSetting = &gormigrate.Migration{
|
||||
ID: "20240722-init-language-setting",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
var langSetting model.Setting
|
||||
_ = tx.Where("key = ?", "Language").First(&langSetting)
|
||||
if langSetting.ID == 0 {
|
||||
if err := tx.Create(&model.Setting{Key: "Language", Value: "zh"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var systemIPSetting model.Setting
|
||||
_ = tx.Where("key = ?", "SystemIP").First(&systemIPSetting)
|
||||
if systemIPSetting.ID == 0 {
|
||||
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export namespace Cronjob {
|
|||
inContainer: boolean;
|
||||
containerName: string;
|
||||
user: string;
|
||||
scriptID: number;
|
||||
appID: string;
|
||||
website: string;
|
||||
exclusionRules: string;
|
||||
|
|
@ -58,6 +59,7 @@ export namespace Cronjob {
|
|||
specs: Array<string>;
|
||||
specObjs: Array<SpecObj>;
|
||||
|
||||
scriptID: number;
|
||||
appID: string;
|
||||
website: string;
|
||||
exclusionRules: string;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export const loadCronjobInfo = (id: number) => {
|
|||
};
|
||||
|
||||
export const loadScriptOptions = () => {
|
||||
return http.get<Cronjob.ScriptOptions>(`/cronjobs/script/options`);
|
||||
return http.get<Array<Cronjob.ScriptOptions>>(`/cronjobs/script/options`);
|
||||
};
|
||||
|
||||
export const getRecordLog = (id: number) => {
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@
|
|||
</el-form-item>
|
||||
</LayoutCol>
|
||||
<LayoutCol v-if="form.type === 'directory'">
|
||||
<el-form-item :label="$t('cronjob.backupContent')">
|
||||
<el-form-item :label="$t('commons.button.backup')">
|
||||
<el-radio-group v-model="form.isDir" class="w-full">
|
||||
<el-radio :value="true">{{ $t('file.dir') }}</el-radio>
|
||||
<el-radio :value="false">{{ $t('menu.files') }}</el-radio>
|
||||
|
|
@ -440,7 +440,7 @@
|
|||
</el-col>
|
||||
|
||||
<LayoutCol v-if="isDir() && form.isDir">
|
||||
<el-form-item prop="sourceDir">
|
||||
<el-form-item :label="$t('cronjob.backupContent')" prop="sourceDir">
|
||||
<el-input v-model="form.sourceDir">
|
||||
<template #prepend>
|
||||
<FileList @choose="loadDir" :dir="true" :path="form.sourceDir" />
|
||||
|
|
@ -449,13 +449,13 @@
|
|||
</el-form-item>
|
||||
</LayoutCol>
|
||||
<LayoutCol v-if="isDir() && !form.isDir">
|
||||
<el-input class="mb-5">
|
||||
<template #prepend>
|
||||
<FileList @choose="loadFile" :dir="false" />
|
||||
</template>
|
||||
</el-input>
|
||||
<el-form-item prop="files">
|
||||
<div style="width: 100%">
|
||||
<el-form-item :label="$t('cronjob.backupContent')" prop="files">
|
||||
<el-input>
|
||||
<template #prepend>
|
||||
<FileList @choose="loadFile" :dir="false" />
|
||||
</template>
|
||||
</el-input>
|
||||
<div class="w-full">
|
||||
<ComplexTable :show-header="false" :data="form.files" v-if="form.files">
|
||||
<el-table-column prop="val" />
|
||||
<el-table-column width="60">
|
||||
|
|
@ -698,6 +698,8 @@ const form = reactive<Cronjob.CronjobInfo>({
|
|||
inContainer: false,
|
||||
containerName: '',
|
||||
user: '',
|
||||
|
||||
scriptID: null,
|
||||
appID: '',
|
||||
website: '',
|
||||
exclusionRules: '',
|
||||
|
|
@ -766,6 +768,7 @@ const search = async () => {
|
|||
form.executor !== 'python3';
|
||||
}
|
||||
|
||||
form.scriptID = res.data.scriptID;
|
||||
form.appID = res.data.appID;
|
||||
form.website = res.data.website;
|
||||
form.exclusionRules = res.data.exclusionRules;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue