Files
waf-platform/EdgeAdmin/internal/web/actions/default/settings/client-browsers/index.go

60 lines
1.4 KiB
Go

// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package clientbrowsers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct {
Keyword string
}) {
this.Data["keyword"] = params.Keyword
countResp, err := this.RPC().FormalClientBrowserRPC().CountFormalClientBrowsers(this.AdminContext(), &pb.CountFormalClientBrowsersRequest{
Keyword: params.Keyword,
})
if err != nil {
this.ErrorPage(err)
return
}
var page = this.NewPage(countResp.Count)
this.Data["page"] = page.AsHTML()
browsersResp, err := this.RPC().FormalClientBrowserRPC().ListFormalClientBrowsers(this.AdminContext(), &pb.ListFormalClientBrowsersRequest{
Keyword: params.Keyword,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var browserMaps = []maps.Map{}
for _, browser := range browsersResp.FormalClientBrowsers {
var codes = browser.Codes
if codes == nil {
codes = []string{}
}
browserMaps = append(browserMaps, maps.Map{
"id": browser.Id,
"name": browser.Name,
"codes": codes,
"dataId": browser.DataId,
})
}
this.Data["browsers"] = browserMaps
this.Show()
}