Files
EdgeAdmin/internal/web/actions/default/clusters/grants/index.go

76 lines
2.0 KiB
Go
Raw Normal View History

2020-07-29 19:34:54 +08:00
package grants
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2020-10-25 21:27:28 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
2020-07-29 19:34:54 +08:00
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "grant", "index")
}
2021-05-23 21:12:52 +08:00
func (this *IndexAction) RunGet(params struct {
Keyword string
}) {
this.Data["keyword"] = params.Keyword
countResp, err := this.RPC().NodeGrantRPC().CountAllEnabledNodeGrants(this.AdminContext(), &pb.CountAllEnabledNodeGrantsRequest{
Keyword: params.Keyword,
})
2020-07-29 19:34:54 +08:00
if err != nil {
this.ErrorPage(err)
return
}
page := this.NewPage(countResp.Count)
this.Data["page"] = page.AsHTML()
grantsResp, err := this.RPC().NodeGrantRPC().ListEnabledNodeGrants(this.AdminContext(), &pb.ListEnabledNodeGrantsRequest{
2021-05-23 21:12:52 +08:00
Keyword: params.Keyword,
Offset: page.Offset,
Size: page.Size,
2020-07-29 19:34:54 +08:00
})
if err != nil {
this.ErrorPage(err)
return
}
grantMaps := []maps.Map{}
2021-04-18 21:19:50 +08:00
for _, grant := range grantsResp.NodeGrants {
2020-10-25 21:27:28 +08:00
// 集群数
2021-05-25 17:48:51 +08:00
countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithNodeGrantId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithNodeGrantIdRequest{NodeGrantId: grant.Id})
2020-10-25 21:27:28 +08:00
if err != nil {
this.ErrorPage(err)
return
}
countClusters := countClustersResp.Count
// 节点数
2021-05-25 17:48:51 +08:00
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithNodeGrantId(this.AdminContext(), &pb.CountAllEnabledNodesWithNodeGrantIdRequest{NodeGrantId: grant.Id})
2020-10-25 21:27:28 +08:00
if err != nil {
this.ErrorPage(err)
return
}
countNodes := countNodesResp.Count
2020-07-29 19:34:54 +08:00
grantMaps = append(grantMaps, maps.Map{
"id": grant.Id,
"name": grant.Name,
"method": maps.Map{
"type": grant.Method,
2023-06-28 19:07:42 +08:00
"name": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
2020-07-29 19:34:54 +08:00
},
2021-05-23 21:12:52 +08:00
"username": grant.Username,
2020-10-25 21:27:28 +08:00
"countClusters": countClusters,
"countNodes": countNodes,
2020-07-29 19:34:54 +08:00
})
}
this.Data["grants"] = grantMaps
this.Show()
}