118 lines
2.8 KiB
Go
118 lines
2.8 KiB
Go
//go:build plus
|
|
|
|
package domains
|
|
|
|
import (
|
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/iwind/TeaGo/maps"
|
|
)
|
|
|
|
type IndexAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *IndexAction) Init() {
|
|
this.Nav("", "", "index")
|
|
}
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
ClusterId int64
|
|
UserId int64
|
|
GroupId int64
|
|
Keyword string
|
|
}) {
|
|
if !teaconst.IsPlus {
|
|
this.RedirectURL("/")
|
|
return
|
|
}
|
|
|
|
this.Data["clusterId"] = params.ClusterId
|
|
this.Data["userId"] = params.UserId
|
|
this.Data["groupId"] = params.GroupId
|
|
this.Data["keyword"] = params.Keyword
|
|
|
|
// 集群数量
|
|
countClustersResp, err := this.RPC().NSClusterRPC().CountAllNSClusters(this.AdminContext(), &pb.CountAllNSClustersRequest{})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
this.Data["countClusters"] = countClustersResp.Count
|
|
|
|
// 分页
|
|
countResp, err := this.RPC().NSDomainRPC().CountAllNSDomains(this.AdminContext(), &pb.CountAllNSDomainsRequest{
|
|
UserId: params.UserId,
|
|
NsDomainGroupId: params.GroupId,
|
|
NsClusterId: params.ClusterId,
|
|
Keyword: params.Keyword,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var page = this.NewPage(countResp.Count)
|
|
this.Data["page"] = page.AsHTML()
|
|
|
|
// 列表
|
|
domainsResp, err := this.RPC().NSDomainRPC().ListNSDomains(this.AdminContext(), &pb.ListNSDomainsRequest{
|
|
UserId: params.UserId,
|
|
NsClusterId: params.ClusterId,
|
|
NsDomainGroupId: params.GroupId,
|
|
Keyword: params.Keyword,
|
|
Offset: page.Offset,
|
|
Size: page.Size,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var domainMaps = []maps.Map{}
|
|
for _, domain := range domainsResp.NsDomains {
|
|
// 集群信息
|
|
var clusterMap maps.Map
|
|
if domain.NsCluster != nil {
|
|
clusterMap = maps.Map{
|
|
"id": domain.NsCluster.Id,
|
|
"name": domain.NsCluster.Name,
|
|
}
|
|
}
|
|
|
|
// 用户信息
|
|
var userMap maps.Map
|
|
if domain.User != nil {
|
|
userMap = maps.Map{
|
|
"id": domain.User.Id,
|
|
"username": domain.User.Username,
|
|
"fullname": domain.User.Fullname,
|
|
}
|
|
}
|
|
|
|
// 分组信息
|
|
var groupMaps = []maps.Map{}
|
|
for _, group := range domain.NsDomainGroups {
|
|
groupMaps = append(groupMaps, maps.Map{
|
|
"id": group.Id,
|
|
"name": group.Name,
|
|
"userId": group.UserId,
|
|
})
|
|
}
|
|
|
|
domainMaps = append(domainMaps, maps.Map{
|
|
"id": domain.Id,
|
|
"name": domain.Name,
|
|
"status": domain.Status,
|
|
"statusName": dnsconfigs.NSDomainStatusName(domain.Status),
|
|
"isOn": domain.IsOn,
|
|
"cluster": clusterMap,
|
|
"user": userMap,
|
|
"groups": groupMaps,
|
|
})
|
|
}
|
|
this.Data["domains"] = domainMaps
|
|
|
|
this.Show()
|
|
}
|