// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . package packages import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" "strings" ) type UpdatePopupAction struct { actionutils.ParentAction } func (this *UpdatePopupAction) Init() { this.Nav("", "", "") } func (this *UpdatePopupAction) RunGet(params struct { PackageId int64 }) { packageResp, err := this.RPC().TrafficPackageRPC().FindTrafficPackage(this.AdminContext(), &pb.FindTrafficPackageRequest{TrafficPackageId: params.PackageId}) if err != nil { this.ErrorPage(err) return } var p = packageResp.TrafficPackage if p == nil { this.NotFound("trafficPackage", params.PackageId) return } this.Data["package"] = maps.Map{ "id": p.Id, "size": p.Size, "unit": strings.ToUpper(p.Unit), "isOn": p.IsOn, } this.Show() } func (this *UpdatePopupAction) RunPost(params struct { PackageId int64 IsOn bool Must *actions.Must CSRF *actionutils.CSRF }) { defer this.CreateLogInfo(codes.TrafficPackage_LogUpdateTrafficPackage, params.PackageId) _, err := this.RPC().TrafficPackageRPC().UpdateTrafficPackage(this.AdminContext(), &pb.UpdateTrafficPackageRequest{ TrafficPackageId: params.PackageId, IsOn: params.IsOn, }) if err != nil { this.ErrorPage(err) return } this.Success() }