Files
EdgeAdmin/internal/web/actions/default/clusters/regions/updatePopup.go

72 lines
1.6 KiB
Go
Raw Normal View History

2020-12-10 15:02:55 +08:00
package regions
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2023-06-30 18:08:30 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
2020-12-10 15:02:55 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type UpdatePopupAction struct {
actionutils.ParentAction
}
func (this *UpdatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdatePopupAction) RunGet(params struct {
RegionId int64
}) {
regionResp, err := this.RPC().NodeRegionRPC().FindEnabledNodeRegion(this.AdminContext(), &pb.FindEnabledNodeRegionRequest{NodeRegionId: params.RegionId})
if err != nil {
this.ErrorPage(err)
return
}
region := regionResp.NodeRegion
if region == nil {
this.NotFound("nodeRegion", params.RegionId)
return
}
this.Data["region"] = maps.Map{
2020-12-10 22:21:26 +08:00
"id": region.Id,
"isOn": region.IsOn,
"name": region.Name,
"description": region.Description,
2020-12-10 15:02:55 +08:00
}
this.Show()
}
func (this *UpdatePopupAction) RunPost(params struct {
RegionId int64
2020-12-10 22:21:26 +08:00
Name string
Description string
IsOn bool
2020-12-10 15:02:55 +08:00
Must *actions.Must
CSRF *actionutils.CSRF
}) {
2023-06-30 18:08:30 +08:00
defer this.CreateLogInfo(codes.NodeRegion_LogUpdateNodeRegion, params.RegionId)
2020-12-10 15:02:55 +08:00
params.Must.
Field("name", params.Name).
Require("请输入区域名称")
_, err := this.RPC().NodeRegionRPC().UpdateNodeRegion(this.AdminContext(), &pb.UpdateNodeRegionRequest{
NodeRegionId: params.RegionId,
Name: params.Name,
2020-12-10 22:21:26 +08:00
Description: params.Description,
2020-12-10 15:02:55 +08:00
IsOn: params.IsOn,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}