1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

feat: 修改可升级判断

This commit is contained in:
zhengkunwang223 2022-11-22 14:22:25 +08:00 committed by zhengkunwang223
parent 74d45a391a
commit bdfad5e710
7 changed files with 93 additions and 43 deletions

View File

@ -47,10 +47,11 @@ type CheckInstalled struct {
type AppInstalled struct { type AppInstalled struct {
model.AppInstall model.AppInstall
Total int `json:"total"` Total int `json:"total"`
Ready int `json:"ready"` Ready int `json:"ready"`
AppName string `json:"appName"` AppName string `json:"appName"`
Icon string `json:"icon"` Icon string `json:"icon"`
CanUpdate bool `json:"canUpdate"`
} }
type AppInstalledRequest struct { type AppInstalledRequest struct {

View File

@ -7,17 +7,17 @@ import (
type AppInstall struct { type AppInstall struct {
BaseModel BaseModel
Name string `json:"name" gorm:"type:varchar(64);not null"` Name string `json:"name" gorm:"type:varchar(64);not null"`
AppId uint `json:"appId" gorm:"type:integer;not null"` AppId uint `json:"appId" gorm:"type:integer;not null"`
AppDetailId uint `json:"appDetailId" gorm:"type:integer;not null"` AppDetailId uint `json:"appDetailId" gorm:"type:integer;not null"`
Version string `json:"version" gorm:"type:varchar(64);not null"` Version string `json:"version" gorm:"type:varchar(64);not null"`
Param string `json:"param" gorm:"type:longtext;"` Param string `json:"param" gorm:"type:longtext;"`
Env string `json:"env" gorm:"type:longtext;"` Env string `json:"env" gorm:"type:longtext;"`
DockerCompose string `json:"dockerCompose" gorm:"type:longtext;"` DockerCompose string `json:"dockerCompose" gorm:"type:longtext;"`
Status string `json:"status" gorm:"type:varchar(256);not null"` Status string `json:"status" gorm:"type:varchar(256);not null"`
Description string `json:"description" gorm:"type:varchar(256);"` Description string `json:"description" gorm:"type:varchar(256);"`
Message string `json:"message" gorm:"type:longtext;"` Message string `json:"message" gorm:"type:longtext;"`
CanUpdate bool `json:"canUpdate"` //CanUpdate bool `json:"canUpdate"`
ContainerName string `json:"containerName" gorm:"type:varchar(256);not null"` ContainerName string `json:"containerName" gorm:"type:varchar(256);not null"`
ServiceName string `json:"serviceName" gorm:"type:varchar(256);not null"` ServiceName string `json:"serviceName" gorm:"type:varchar(256);not null"`
HttpPort int `json:"httpPort" gorm:"type:integer;not null"` HttpPort int `json:"httpPort" gorm:"type:integer;not null"`

View File

@ -524,9 +524,9 @@ func syncCanUpdate() {
if err := appDetailRepo.BatchUpdateBy(map[string]interface{}{"last_version": lastVersion}, commonRepo.WithIdsIn(updateDetailIds)); err != nil { if err := appDetailRepo.BatchUpdateBy(map[string]interface{}{"last_version": lastVersion}, commonRepo.WithIdsIn(updateDetailIds)); err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error()) global.LOG.Errorf("sync update app error: %s", err.Error())
} }
if err := appInstallRepo.BatchUpdateBy(map[string]interface{}{"can_update": 1}, appInstallRepo.WithDetailIdsIn(updateDetailIds)); err != nil { //if err := appInstallRepo.BatchUpdateBy(map[string]interface{}{"can_update": 1}, appInstallRepo.WithDetailIdsIn(updateDetailIds)); err != nil {
global.LOG.Errorf("sync update app error: %s", err.Error()) // global.LOG.Errorf("sync update app error: %s", err.Error())
} //}
} }
} }

View File

@ -24,16 +24,14 @@ type AppInstallService struct {
} }
func (a AppInstallService) Page(req dto.AppInstalledRequest) (int64, []dto.AppInstalled, error) { func (a AppInstallService) Page(req dto.AppInstalledRequest) (int64, []dto.AppInstalled, error) {
total, installed, err := appInstallRepo.Page(req.Page, req.PageSize) total, installs, err := appInstallRepo.Page(req.Page, req.PageSize)
if err != nil { if err != nil {
return 0, nil, err return 0, nil, err
} }
var installDTOs []dto.AppInstalled
for _, in := range installed { installDTOs, err := handleInstalled(installs)
installDto := dto.AppInstalled{ if err != nil {
AppInstall: in, return 0, nil, err
}
installDTOs = append(installDTOs, installDto)
} }
return total, installDTOs, nil return total, installDTOs, nil
@ -74,15 +72,7 @@ func (a AppInstallService) Search(req dto.AppInstalledRequest) ([]dto.AppInstall
} }
} }
var installDTOs []dto.AppInstalled return handleInstalled(installs)
for _, in := range installs {
installDto := dto.AppInstalled{
AppInstall: in,
}
installDTOs = append(installDTOs, installDto)
}
return installDTOs, nil
} }
func (a AppInstallService) Operate(req dto.AppInstallOperate) error { func (a AppInstallService) Operate(req dto.AppInstallOperate) error {

View File

@ -211,18 +211,18 @@ func updateInstall(installId uint, detailId uint) error {
if err != nil { if err != nil {
return err return err
} }
oldDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(install.AppDetailId)) //oldDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(install.AppDetailId))
if err != nil { //if err != nil {
return err // return err
} //}
detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(detailId)) detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(detailId))
if err != nil { if err != nil {
return err return err
} }
if oldDetail.LastVersion == detail.Version { //if oldDetail.LastVersion == detail.Version {
install.CanUpdate = false // install.CanUpdate = false
} //}
if install.Version == detail.Version { if install.Version == detail.Version {
return errors.New("two version is same") return errors.New("two version is same")
} }
@ -556,3 +556,38 @@ func getAppFromOss() error {
}() }()
return nil return nil
} }
func handleInstalled(installed []model.AppInstall) ([]dto.AppInstalled, error) {
var res []dto.AppInstalled
for _, installed := range installed {
installDTO := dto.AppInstalled{
AppInstall: installed,
}
app, err := appRepo.GetFirst(commonRepo.WithByID(installed.AppId))
if err != nil {
return nil, err
}
details, err := appDetailRepo.GetBy(appDetailRepo.WithAppId(app.ID))
if err != nil {
return nil, err
}
var versions []string
for _, detail := range details {
versions = append(versions, detail.Version)
}
versions = common.GetSortedVersions(versions)
lastVersion := versions[0]
if common.IsCrossVersion(installed.Version, lastVersion) {
installDTO.CanUpdate = app.CrossVersionUpdate
} else {
installDTO.CanUpdate = common.CompareVersion(lastVersion, installed.Version)
}
res = append(res, installDTO)
}
return res, nil
}

View File

@ -686,6 +686,7 @@ export default {
restoreWarn: '回滚操作会重启应用,并替换数据,此操作不可回滚,是否继续?', restoreWarn: '回滚操作会重启应用,并替换数据,此操作不可回滚,是否继续?',
update: '升级', update: '升级',
versioneSelect: '请选择版本', versioneSelect: '请选择版本',
operatorHelper: '将对选中应用进行 {0} 操作是否继续',
}, },
website: { website: {
primaryDomain: '主域名', primaryDomain: '主域名',

View File

@ -97,7 +97,7 @@ import { onMounted, onUnmounted, reactive, ref } from 'vue';
import ComplexTable from '@/components/complex-table/index.vue'; import ComplexTable from '@/components/complex-table/index.vue';
import { dateFromat } from '@/utils/util'; import { dateFromat } from '@/utils/util';
import i18n from '@/lang'; import i18n from '@/lang';
import { ElMessage } from 'element-plus'; import { ElMessage, ElMessageBox } from 'element-plus';
import Backups from './backups.vue'; import Backups from './backups.vue';
import { App } from '@/api/interface/app'; import { App } from '@/api/interface/app';
@ -154,7 +154,7 @@ const openOperate = (row: any, op: string) => {
open.value = true; open.value = true;
}); });
} else { } else {
open.value = true; onOperate(op);
} }
}; };
@ -175,6 +175,29 @@ const handleClose = () => {
open.value = false; open.value = false;
}; };
const onOperate = async (operation: string) => {
ElMessageBox.confirm(
i18n.global.t('app.operatorHelper', [i18n.global.t('app.' + operation)]),
i18n.global.t('app.' + operation),
{
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',
},
).then(() => {
open.value = false;
loading.value = true;
InstalledOp(operateReq)
.then(() => {
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
search();
})
.finally(() => {
loading.value = false;
});
});
};
const getMsg = (op: string) => { const getMsg = (op: string) => {
let tip = ''; let tip = '';
switch (op) { switch (op) {