管理端全部功能跑通
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type ClusterAction struct {
|
||||
@@ -20,19 +23,75 @@ func (this *ClusterAction) RunGet(params struct {
|
||||
Keyword string
|
||||
}) {
|
||||
httpdnsutils.AddLeftMenu(this.Parent())
|
||||
cluster := pickCluster(params.ClusterId)
|
||||
|
||||
// 构建顶部 tabbar
|
||||
cluster, err := findClusterMap(this.Parent(), params.ClusterId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
httpdnsutils.AddClusterTabbar(this.Parent(), cluster.GetString("name"), params.ClusterId, "node")
|
||||
|
||||
nodes, err := listNodeMaps(this.Parent(), params.ClusterId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
nodes = filterClusterNodes(nodes, params.InstalledState, params.ActiveState, params.Keyword)
|
||||
|
||||
this.Data["clusterId"] = params.ClusterId
|
||||
this.Data["cluster"] = cluster
|
||||
this.Data["installState"] = params.InstalledState
|
||||
this.Data["activeState"] = params.ActiveState
|
||||
this.Data["keyword"] = params.Keyword
|
||||
nodes := mockNodes(params.ClusterId, params.InstalledState, params.ActiveState, params.Keyword)
|
||||
this.Data["nodes"] = nodes
|
||||
this.Data["hasNodes"] = len(nodes) > 0
|
||||
this.Data["page"] = ""
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func filterClusterNodes(nodes []maps.Map, installedState int, activeState int, keyword string) []maps.Map {
|
||||
keyword = strings.ToLower(strings.TrimSpace(keyword))
|
||||
|
||||
result := make([]maps.Map, 0, len(nodes))
|
||||
for _, node := range nodes {
|
||||
isInstalled := node.GetBool("isInstalled")
|
||||
if installedState == 1 && !isInstalled {
|
||||
continue
|
||||
}
|
||||
if installedState == 2 && isInstalled {
|
||||
continue
|
||||
}
|
||||
|
||||
status := node.GetMap("status")
|
||||
isOnline := node.GetBool("isOn") && node.GetBool("isUp") && status.GetBool("isActive")
|
||||
if activeState == 1 && !isOnline {
|
||||
continue
|
||||
}
|
||||
if activeState == 2 && isOnline {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(keyword) > 0 {
|
||||
hit := strings.Contains(strings.ToLower(node.GetString("name")), keyword)
|
||||
if !hit {
|
||||
ipAddresses, ok := node["ipAddresses"].([]maps.Map)
|
||||
if ok {
|
||||
for _, ipAddr := range ipAddresses {
|
||||
if strings.Contains(strings.ToLower(ipAddr.GetString("ip")), keyword) {
|
||||
hit = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !hit {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, node)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user