From 19a2af8bfac39094e1c0da6a11f80be5ba4565e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 3 May 2021 11:32:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=92=8C=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=9C=80=E8=BF=91=E5=B8=B8=E7=94=A8=E7=9A=84=E9=9B=86=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/rpc/rpc_client.go | 4 ++++ .../actions/default/clusters/cluster/index.go | 10 ++++++++++ .../clusters/clusterutils/cluster_helper.go | 4 +++- .../web/actions/default/clusters/index.go | 20 ++++++++++++++++++- web/views/@default/clusters/index.html | 6 ++++++ web/views/@default/clusters/index.js | 7 +++++++ 6 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 web/views/@default/clusters/index.js diff --git a/internal/rpc/rpc_client.go b/internal/rpc/rpc_client.go index 9f10808f..e53ea683 100644 --- a/internal/rpc/rpc_client.go +++ b/internal/rpc/rpc_client.go @@ -340,6 +340,10 @@ func (this *RPCClient) AuthorityNodeRPC() pb.AuthorityNodeServiceClient { return pb.NewAuthorityNodeServiceClient(this.pickConn()) } +func (this *RPCClient) LatestItemRPC() pb.LatestItemServiceClient { + return pb.NewLatestItemServiceClient(this.pickConn()) +} + // Context 构造Admin上下文 func (this *RPCClient) Context(adminId int64) context.Context { ctx := context.Background() diff --git a/internal/web/actions/default/clusters/cluster/index.go b/internal/web/actions/default/clusters/cluster/index.go index c35f91a7..909dfeb5 100644 --- a/internal/web/actions/default/clusters/cluster/index.go +++ b/internal/web/actions/default/clusters/cluster/index.go @@ -203,5 +203,15 @@ func (this *IndexAction) RunGet(params struct { } this.Data["regions"] = regionMaps + // 记录最近访问 + _, err = this.RPC().LatestItemRPC().IncreaseLatestItem(this.AdminContext(), &pb.IncreaseLatestItemRequest{ + ItemType: "cluster", + ItemId: params.ClusterId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Show() } diff --git a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go index 957acfec..3332e99b 100644 --- a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go +++ b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go @@ -24,7 +24,7 @@ func NewClusterHelper() *ClusterHelper { return &ClusterHelper{} } -func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) { +func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNext bool) { action := actionPtr.Object() if action.Request.Method != http.MethodGet { return @@ -67,6 +67,8 @@ func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) { action.Data["leftMenuItems"] = this.createSettingMenu(cluster, secondMenuItem) } } + + return true } // 设置菜单 diff --git a/internal/web/actions/default/clusters/index.go b/internal/web/actions/default/clusters/index.go index 0abb182e..6b7a4d75 100644 --- a/internal/web/actions/default/clusters/index.go +++ b/internal/web/actions/default/clusters/index.go @@ -24,9 +24,10 @@ func (this *IndexAction) RunGet(params struct { Keyword string SearchType string }) { + isSearching := len(params.Keyword) > 0 this.Data["keyword"] = params.Keyword this.Data["searchType"] = params.SearchType - this.Data["isSearching"] = len(params.Keyword) > 0 + this.Data["isSearching"] = isSearching // 搜索节点 if params.SearchType == "node" && len(params.Keyword) > 0 { @@ -34,6 +35,23 @@ func (this *IndexAction) RunGet(params struct { return } + // 常用的节点 + latestClusterMaps := []maps.Map{} + if !isSearching { + clustersResp, err := this.RPC().NodeClusterRPC().FindLatestNodeClusters(this.AdminContext(), &pb.FindLatestNodeClustersRequest{Size: 4}) + if err != nil { + this.ErrorPage(err) + return + } + for _, cluster := range clustersResp.NodeClusters { + latestClusterMaps = append(latestClusterMaps, maps.Map{ + "id": cluster.Id, + "name": cluster.Name, + }) + } + } + this.Data["latestClusters"] = latestClusterMaps + // 搜索集群 countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClusters(this.AdminContext(), &pb.CountAllEnabledNodeClustersRequest{ Keyword: params.Keyword, diff --git a/web/views/@default/clusters/index.html b/web/views/@default/clusters/index.html index ff5d7570..a982844e 100644 --- a/web/views/@default/clusters/index.html +++ b/web/views/@default/clusters/index.html @@ -11,8 +11,14 @@
+
+ 常用 +
+
+ 常用集群:{{cluster.name}}   +