diff --git a/internal/web/actions/default/clusters/cluster/createNode.go b/internal/web/actions/default/clusters/cluster/createNode.go index f8b04a8e..84b26db4 100644 --- a/internal/web/actions/default/clusters/cluster/createNode.go +++ b/internal/web/actions/default/clusters/cluster/createNode.go @@ -30,6 +30,11 @@ func (this *CreateNodeAction) Init() { func (this *CreateNodeAction) RunGet(params struct { ClusterId int64 }) { + if params.ClusterId <= 0 { + this.RedirectURL("/clusters") + return + } + var leftMenuItems = []maps.Map{ { "name": "单个创建", diff --git a/internal/web/actions/default/clusters/createNode.go b/internal/web/actions/default/clusters/createNode.go new file mode 100644 index 00000000..a791803d --- /dev/null +++ b/internal/web/actions/default/clusters/createNode.go @@ -0,0 +1,52 @@ +// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn . + +package clusters + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/types" +) + +type CreateNodeAction struct { + actionutils.ParentAction +} + +func (this *CreateNodeAction) Init() { + this.Nav("", "cluster", "createNode") +} + +func (this *CreateNodeAction) RunGet(params struct{}) { + // 集群总数 + totalClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClusters(this.AdminContext(), &pb.CountAllEnabledNodeClustersRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["totalNodeClusters"] = totalClustersResp.Count + + // 节点总数 + totalNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodes(this.AdminContext(), &pb.CountAllEnabledNodesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["totalNodes"] = totalNodesResp.Count + + // 如果只有一个默认集群,那么直接跳转到集群 + clustersResp, err := this.RPC().NodeClusterRPC().ListEnabledNodeClusters(this.AdminContext(), &pb.ListEnabledNodeClustersRequest{ + Offset: 0, + Size: 2, + Keyword: "", + }) + if err != nil { + this.ErrorPage(err) + return + } + if len(clustersResp.NodeClusters) == 1 { + this.RedirectURL("/clusters/cluster/createNode?clusterId=" + types.String(clustersResp.NodeClusters[0].Id)) + return + } + + this.Show() +} diff --git a/internal/web/actions/default/clusters/init.go b/internal/web/actions/default/clusters/init.go index 81b86011..078900ec 100644 --- a/internal/web/actions/default/clusters/init.go +++ b/internal/web/actions/default/clusters/init.go @@ -16,6 +16,7 @@ func init() { Prefix("/clusters"). Get("", new(IndexAction)). GetPost("/create", new(CreateAction)). + GetPost("/createNode", new(CreateNodeAction)). Post("/pin", new(PinAction)). Get("/nodes", new(NodesAction)). diff --git a/web/views/@default/clusters/@menu.html b/web/views/@default/clusters/@menu.html index d70f75e1..166665d0 100644 --- a/web/views/@default/clusters/@menu.html +++ b/web/views/@default/clusters/@menu.html @@ -2,5 +2,6 @@ 集群 ({{totalNodeClusters}}) 节点 ({{totalNodes}}) | - [创建集群] + [创建集群] + [创建节点] diff --git a/web/views/@default/clusters/createNode.html b/web/views/@default/clusters/createNode.html new file mode 100644 index 00000000..48e08267 --- /dev/null +++ b/web/views/@default/clusters/createNode.html @@ -0,0 +1,14 @@ +{$layout} +{$template "menu"} + +
+
+ + + + + +
选择所属集群 *
+ + +
\ No newline at end of file diff --git a/web/views/@default/clusters/createNode.js b/web/views/@default/clusters/createNode.js new file mode 100644 index 00000000..1b4e7d7f --- /dev/null +++ b/web/views/@default/clusters/createNode.js @@ -0,0 +1,13 @@ +Tea.context(function () { + this.clusterId = 0 + + this.changeCluster = function(clusterId) { + this.clusterId = clusterId + } + + this.goNext = function () { + if (this.clusterId > 0) { + window.location = "/clusters/cluster/createNode?clusterId=" + this.clusterId + } + } +}) \ No newline at end of file