1.4.5.2
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"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 {
|
||||
RouteId int64
|
||||
}) {
|
||||
routeResp, err := this.RPC().NSRouteRPC().FindNSRoute(this.UserContext(), &pb.FindNSRouteRequest{NsRouteId: params.RouteId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var route = routeResp.NsRoute
|
||||
if route == nil {
|
||||
this.NotFound("nsRoute", params.RouteId)
|
||||
return
|
||||
}
|
||||
|
||||
var rangeMaps = []maps.Map{}
|
||||
if len(route.RangesJSON) > 0 {
|
||||
err = json.Unmarshal(route.RangesJSON, &rangeMaps)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["route"] = maps.Map{
|
||||
"id": route.Id,
|
||||
"name": route.Name,
|
||||
"isOn": route.IsOn,
|
||||
"ranges": rangeMaps,
|
||||
}
|
||||
|
||||
// 范围类型
|
||||
this.Data["rangeTypes"] = dnsconfigs.AllNSRouteRangeTypes()
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
RouteId int64
|
||||
Name string
|
||||
RangesJSON []byte
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSRoute_LogUpdateNSRoute, params.RouteId)
|
||||
|
||||
params.Must.Field("name", params.Name).
|
||||
Require("请输入线路名称")
|
||||
|
||||
ranges, err := dnsconfigs.InitNSRangesFromJSON(params.RangesJSON)
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
if len(ranges) == 0 {
|
||||
this.Fail("请添加线路范围")
|
||||
}
|
||||
|
||||
_, err = this.RPC().NSRouteRPC().UpdateNSRoute(this.UserContext(), &pb.UpdateNSRouteRequest{
|
||||
NsRouteId: params.RouteId,
|
||||
Name: params.Name,
|
||||
RangesJSON: params.RangesJSON,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user