2020-07-22 22:19:39 +08:00
|
|
|
package nodes
|
|
|
|
|
|
2020-07-29 19:34:54 +08:00
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
)
|
2020-07-22 22:19:39 +08:00
|
|
|
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
2020-07-29 19:34:54 +08:00
|
|
|
this.Nav("", "node", "index")
|
2020-07-22 22:19:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunGet(params struct{}) {
|
2020-07-29 19:34:54 +08:00
|
|
|
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodes(this.AdminContext(), &pb.CountAllEnabledNodesRequest{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page := this.NewPage(countResp.Count)
|
|
|
|
|
this.Data["page"] = page.AsHTML()
|
|
|
|
|
|
|
|
|
|
nodesResp, err := this.RPC().NodeRPC().ListEnabledNodes(this.AdminContext(), &pb.ListEnabledNodesRequest{
|
|
|
|
|
Offset: page.Offset,
|
|
|
|
|
Size: page.Size,
|
|
|
|
|
})
|
|
|
|
|
nodeMaps := []maps.Map{}
|
|
|
|
|
for _, node := range nodesResp.Nodes {
|
|
|
|
|
nodeMaps = append(nodeMaps, maps.Map{
|
|
|
|
|
"id": node.Id,
|
|
|
|
|
"name": node.Name,
|
|
|
|
|
"cluster": maps.Map{
|
|
|
|
|
"id": node.Cluster.Id,
|
|
|
|
|
"name": node.Cluster.Name,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["nodes"] = nodeMaps
|
|
|
|
|
|
2020-07-22 22:19:39 +08:00
|
|
|
this.Show()
|
|
|
|
|
}
|