1.4.5.2
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package browser
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
DataId string
|
||||
}) {
|
||||
browserResp, err := this.RPC().FormalClientBrowserRPC().FindFormalClientBrowserWithDataId(this.AdminContext(), &pb.FindFormalClientBrowserWithDataIdRequest{DataId: params.DataId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var browser = browserResp.FormalClientBrowser
|
||||
if browser == nil {
|
||||
this.NotFound("formalClientBrowser", 0)
|
||||
return
|
||||
}
|
||||
if browser.Codes == nil {
|
||||
browser.Codes = []string{}
|
||||
}
|
||||
this.Data["browser"] = maps.Map{
|
||||
"id": browser.Id,
|
||||
"name": browser.Name,
|
||||
"codes": browser.Codes,
|
||||
"dataId": browser.DataId,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
BrowserId int64
|
||||
Name string
|
||||
Codes []string
|
||||
DataId string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.ClientBrowser_LogUpdateClientBrowser, params.BrowserId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入浏览器名称").
|
||||
Field("dataId", params.DataId).
|
||||
Require("请输入数据ID")
|
||||
|
||||
if len(params.Codes) == 0 {
|
||||
params.Codes = []string{params.Name}
|
||||
}
|
||||
|
||||
// 检查dataId
|
||||
browserResp, err := this.RPC().FormalClientBrowserRPC().FindFormalClientBrowserWithDataId(this.AdminContext(), &pb.FindFormalClientBrowserWithDataIdRequest{DataId: params.DataId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if browserResp.FormalClientBrowser != nil && browserResp.FormalClientBrowser.Id != params.BrowserId {
|
||||
this.Fail("该数据ID已经被 '" + browserResp.FormalClientBrowser.Name + "'所使用,请换一个")
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().FormalClientBrowserRPC().UpdateFormalClientBrowser(this.AdminContext(), &pb.UpdateFormalClientBrowserRequest{
|
||||
FormalClientBrowserId: params.BrowserId,
|
||||
Name: params.Name,
|
||||
Codes: params.Codes,
|
||||
DataId: params.DataId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user