diff --git a/internal/web/actions/default/clusters/cluster/createBatch.go b/internal/web/actions/default/clusters/cluster/createBatch.go index 9839bd56..6055d325 100644 --- a/internal/web/actions/default/clusters/cluster/createBatch.go +++ b/internal/web/actions/default/clusters/cluster/createBatch.go @@ -44,6 +44,7 @@ func (this *CreateBatchAction) RunGet(params struct { func (this *CreateBatchAction) RunPost(params struct { ClusterId int64 GroupId int64 + RegionId int64 IpList string Must *actions.Must @@ -79,6 +80,7 @@ func (this *CreateBatchAction) RunPost(params struct { Name: ip, ClusterId: params.ClusterId, GroupId: params.GroupId, + RegionId: params.RegionId, Login: nil, }) if err != nil { diff --git a/internal/web/actions/default/clusters/cluster/createNode.go b/internal/web/actions/default/clusters/cluster/createNode.go index e5a479eb..36341283 100644 --- a/internal/web/actions/default/clusters/cluster/createNode.go +++ b/internal/web/actions/default/clusters/cluster/createNode.go @@ -72,6 +72,7 @@ func (this *CreateNodeAction) RunPost(params struct { IpAddressesJSON []byte ClusterId int64 GroupId int64 + RegionId int64 GrantId int64 SshHost string SshPort int @@ -120,6 +121,7 @@ func (this *CreateNodeAction) RunPost(params struct { Name: params.Name, ClusterId: params.ClusterId, GroupId: params.GroupId, + RegionId: params.RegionId, Login: loginInfo, DnsDomainId: params.DnsDomainId, DnsRoutes: dnsRouteCodes, diff --git a/internal/web/actions/default/clusters/cluster/index.go b/internal/web/actions/default/clusters/cluster/index.go index 2d4d8cee..f73918d9 100644 --- a/internal/web/actions/default/clusters/cluster/index.go +++ b/internal/web/actions/default/clusters/cluster/index.go @@ -25,11 +25,13 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ClusterId int64 GroupId int64 + RegionId int64 InstalledState int ActiveState int Keyword string }) { this.Data["groupId"] = params.GroupId + this.Data["regionId"] = params.RegionId this.Data["installState"] = params.InstalledState this.Data["activeState"] = params.ActiveState this.Data["keyword"] = params.Keyword @@ -37,6 +39,7 @@ func (this *IndexAction) RunGet(params struct { countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ ClusterId: params.ClusterId, GroupId: params.GroupId, + RegionId: params.RegionId, InstallState: types.Int32(params.InstalledState), ActiveState: types.Int32(params.ActiveState), Keyword: params.Keyword, @@ -54,6 +57,7 @@ func (this *IndexAction) RunGet(params struct { Size: page.Size, ClusterId: params.ClusterId, GroupId: params.GroupId, + RegionId: params.RegionId, InstallState: types.Int32(params.InstalledState), ActiveState: types.Int32(params.ActiveState), Keyword: params.Keyword, @@ -89,6 +93,7 @@ func (this *IndexAction) RunGet(params struct { }) } + // 分组 var groupMap maps.Map = nil if node.Group != nil { groupMap = maps.Map{ @@ -97,6 +102,15 @@ func (this *IndexAction) RunGet(params struct { } } + // 区域 + var regionMap maps.Map = nil + if node.Region != nil { + regionMap = maps.Map{ + "id": node.Region.Id, + "name": node.Region.Name, + } + } + // DNS dnsRouteNames := []string{} for _, route := range node.DnsRoutes { @@ -131,6 +145,7 @@ func (this *IndexAction) RunGet(params struct { "isSynced": isSynced, "ipAddresses": ipAddresses, "group": groupMap, + "region": regionMap, "dnsRouteNames": dnsRouteNames, }) } @@ -164,5 +179,20 @@ func (this *IndexAction) RunGet(params struct { } this.Data["groups"] = groupMaps + // 所有区域 + regionsResp, err := this.RPC().NodeRegionRPC().FindAllEnabledAndOnNodeRegions(this.AdminContext(), &pb.FindAllEnabledAndOnNodeRegionsRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + regionMaps := []maps.Map{} + for _, region := range regionsResp.NodeRegions { + regionMaps = append(regionMaps, maps.Map{ + "id": region.Id, + "name": region.Name, + }) + } + this.Data["regions"] = regionMaps + this.Show() } diff --git a/internal/web/actions/default/clusters/cluster/node/node.go b/internal/web/actions/default/clusters/cluster/node/node.go index 47710446..4f58ef93 100644 --- a/internal/web/actions/default/clusters/cluster/node/node.go +++ b/internal/web/actions/default/clusters/cluster/node/node.go @@ -137,6 +137,7 @@ func (this *NodeAction) RunGet(params struct { status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃 } + // 分组 var groupMap maps.Map = nil if node.Group != nil { groupMap = maps.Map{ @@ -145,6 +146,15 @@ func (this *NodeAction) RunGet(params struct { } } + // 区域 + var regionMap maps.Map = nil + if node.Region != nil { + regionMap = maps.Map{ + "id": node.Region.Id, + "name": node.Region.Name, + } + } + this.Data["node"] = maps.Map{ "id": node.Id, "name": node.Name, @@ -169,7 +179,8 @@ func (this *NodeAction) RunGet(params struct { "connectionCount": status.ConnectionCount, }, - "group": groupMap, + "group": groupMap, + "region": regionMap, } this.Show() diff --git a/internal/web/actions/default/clusters/cluster/node/update.go b/internal/web/actions/default/clusters/cluster/node/update.go index 16131274..9a7975a8 100644 --- a/internal/web/actions/default/clusters/cluster/node/update.go +++ b/internal/web/actions/default/clusters/cluster/node/update.go @@ -138,6 +138,7 @@ func (this *UpdateAction) RunGet(params struct { } } + // 分组 var groupMap maps.Map = nil if node.Group != nil { groupMap = maps.Map{ @@ -146,6 +147,15 @@ func (this *UpdateAction) RunGet(params struct { } } + // 区域 + var regionMap maps.Map = nil + if node.Region != nil { + regionMap = maps.Map{ + "id": node.Region.Id, + "name": node.Region.Name, + } + } + this.Data["node"] = maps.Map{ "id": node.Id, "name": node.Name, @@ -155,6 +165,7 @@ func (this *UpdateAction) RunGet(params struct { "maxCPU": node.MaxCPU, "isOn": node.IsOn, "group": groupMap, + "region": regionMap, } // 所有集群 @@ -182,6 +193,7 @@ func (this *UpdateAction) RunPost(params struct { LoginId int64 NodeId int64 GroupId int64 + RegionId int64 Name string IPAddressesJSON []byte `alias:"ipAddressesJSON"` ClusterId int64 @@ -237,6 +249,7 @@ func (this *UpdateAction) RunPost(params struct { _, err := this.RPC().NodeRPC().UpdateNode(this.AdminContext(), &pb.UpdateNodeRequest{ NodeId: params.NodeId, GroupId: params.GroupId, + RegionId: params.RegionId, Name: params.Name, ClusterId: params.ClusterId, Login: loginInfo, diff --git a/internal/web/actions/default/clusters/regions/createPopup.go b/internal/web/actions/default/clusters/regions/createPopup.go index 17402900..616eef76 100644 --- a/internal/web/actions/default/clusters/regions/createPopup.go +++ b/internal/web/actions/default/clusters/regions/createPopup.go @@ -4,6 +4,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" ) type CreatePopupAction struct { @@ -34,6 +35,11 @@ func (this *CreatePopupAction) RunPost(params struct { return } + this.Data["region"] = maps.Map{ + "id": createResp.NodeRegionId, + "name": params.Name, + } + // 日志 defer this.CreateLogInfo("创建节点区域 %d", createResp.NodeRegionId) diff --git a/internal/web/actions/default/clusters/regions/init.go b/internal/web/actions/default/clusters/regions/init.go index c0d9ae19..3408aad4 100644 --- a/internal/web/actions/default/clusters/regions/init.go +++ b/internal/web/actions/default/clusters/regions/init.go @@ -18,6 +18,7 @@ func init() { GetPost("/updatePopup", new(UpdatePopupAction)). Post("/delete", new(DeleteAction)). Post("/sort", new(SortAction)). + GetPost("/selectPopup", new(SelectPopupAction)). EndAll() }) } diff --git a/internal/web/actions/default/clusters/regions/selectPopup.go b/internal/web/actions/default/clusters/regions/selectPopup.go new file mode 100644 index 00000000..6838d3e8 --- /dev/null +++ b/internal/web/actions/default/clusters/regions/selectPopup.go @@ -0,0 +1,60 @@ +package regions + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" +) + +type SelectPopupAction struct { + actionutils.ParentAction +} + +func (this *SelectPopupAction) Init() { + this.Nav("", "", "") +} + +func (this *SelectPopupAction) RunGet(params struct{}) { + regionsResp, err := this.RPC().NodeRegionRPC().FindAllEnabledAndOnNodeRegions(this.AdminContext(), &pb.FindAllEnabledAndOnNodeRegionsRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + + regionMaps := []maps.Map{} + for _, region := range regionsResp.NodeRegions { + regionMaps = append(regionMaps, maps.Map{ + "id": region.Id, + "name": region.Name, + }) + } + this.Data["regions"] = regionMaps + + this.Show() +} + +func (this *SelectPopupAction) RunPost(params struct { + RegionId int64 + + Must *actions.Must + CSRF *actionutils.CSRF +}) { + regionResp, err := this.RPC().NodeRegionRPC().FindEnabledNodeRegion(this.AdminContext(), &pb.FindEnabledNodeRegionRequest{NodeRegionId: params.RegionId}) + if err != nil { + this.ErrorPage(err) + return + } + region := regionResp.NodeRegion + if region == nil { + this.NotFound("nodeRegion", params.RegionId) + return + } + + this.Data["region"] = maps.Map{ + "id": region.Id, + "name": region.Name, + } + + this.Success() +} diff --git a/web/public/js/components/node/node-group-selector.js b/web/public/js/components/node/node-group-selector.js index 82473834..7fe3d1a3 100644 --- a/web/public/js/components/node/node-group-selector.js +++ b/web/public/js/components/node/node-group-selector.js @@ -27,7 +27,7 @@ Vue.component("node-group-selector", { } }, template: `
-
+
{{selectedGroup.name}}  
diff --git a/web/public/js/components/node/node-region-selector.js b/web/public/js/components/node/node-region-selector.js new file mode 100644 index 00000000..e38866bc --- /dev/null +++ b/web/public/js/components/node/node-region-selector.js @@ -0,0 +1,38 @@ +Vue.component("node-region-selector", { + props: ["v-region"], + data: function () { + return { + selectedRegion: this.vRegion + } + }, + methods: { + selectRegion: function () { + let that = this + teaweb.popup("/clusters/regions/selectPopup?clusterId=" + this.vClusterId, { + callback: function (resp) { + that.selectedRegion = resp.data.region + } + }) + }, + addRegion: function () { + let that = this + teaweb.popup("/clusters/regions/createPopup?clusterId=" + this.vClusterId, { + callback: function (resp) { + that.selectedRegion = resp.data.region + } + }) + }, + removeRegion: function () { + this.selectedRegion = null + } + }, + template: `
+
+ + {{selectedRegion.name}}   +
+
+ [选择区域]   [添加区域] +
+
` +}) \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/createBatch.html b/web/views/@default/clusters/cluster/createBatch.html index c0795559..a4fea875 100644 --- a/web/views/@default/clusters/cluster/createBatch.html +++ b/web/views/@default/clusters/cluster/createBatch.html @@ -14,6 +14,12 @@

每行一个节点IP。

+ + 所属区域 + + + + 所属分组 diff --git a/web/views/@default/clusters/cluster/createNode.html b/web/views/@default/clusters/cluster/createNode.html index 800c1f29..5b173daf 100644 --- a/web/views/@default/clusters/cluster/createNode.html +++ b/web/views/@default/clusters/cluster/createNode.html @@ -27,6 +27,12 @@

可用线路是根据集群设置的域名获取的,注意DNS服务商可能对这些线路有所限制。

+ + 所属区域 + + + + 所属分组 diff --git a/web/views/@default/clusters/cluster/groups/selectPopup.html b/web/views/@default/clusters/cluster/groups/selectPopup.html index 3913af62..ce4fec0a 100644 --- a/web/views/@default/clusters/cluster/groups/selectPopup.html +++ b/web/views/@default/clusters/cluster/groups/selectPopup.html @@ -9,7 +9,7 @@ 选择分组
- {{group.name}} + {{group.name}}

点击可已选中要使用的分组。

diff --git a/web/views/@default/clusters/cluster/index.html b/web/views/@default/clusters/cluster/index.html index f22e0429..3fd0f235 100644 --- a/web/views/@default/clusters/cluster/index.html +++ b/web/views/@default/clusters/cluster/index.html @@ -5,31 +5,28 @@
-
- 所属分组: -
+
+ +
-
- 安装状态: -
-
- 在线状态: -
@@ -48,10 +45,10 @@ - - - + + + @@ -62,10 +59,13 @@ - + + + + + diff --git a/web/views/@default/clusters/cluster/node/update.html b/web/views/@default/clusters/cluster/node/update.html index 47cc80a4..60c3b4c0 100644 --- a/web/views/@default/clusters/cluster/node/update.html +++ b/web/views/@default/clusters/cluster/node/update.html @@ -35,6 +35,12 @@ + + + +
ID 节点名称所属分组IP所属区域所属分组IP DNS线路 CPU 内存
{{node.id}} {{node.name}} + {{node.region.name}} + - + - {{node.group.name}} + {{node.group.name}} - diff --git a/web/views/@default/clusters/cluster/node/node.html b/web/views/@default/clusters/cluster/node/node.html index 319012c7..070be23b 100644 --- a/web/views/@default/clusters/cluster/node/node.html +++ b/web/views/@default/clusters/cluster/node/node.html @@ -35,10 +35,17 @@ {{route.name}}
所属区域 + {{node.region.name}} + 没有设置区域。 +
所属分组 - {{node.group.name}} + {{node.group.name}} 没有设置分组。
所属区域 + +
所属分组 diff --git a/web/views/@default/clusters/regions/selectPopup.html b/web/views/@default/clusters/regions/selectPopup.html new file mode 100644 index 00000000..546dfeda --- /dev/null +++ b/web/views/@default/clusters/regions/selectPopup.html @@ -0,0 +1,23 @@ +{$layout "layout_popup"} + +

选择分组

+ + + + + + + + + +
选择区域 +
+ {{region.name}} +

点击可已选中要使用的区域。

+
+
+

暂时还没有可以使用的区域。

+
+
+ 确定 + \ No newline at end of file diff --git a/web/views/@default/clusters/regions/selectPopup.js b/web/views/@default/clusters/regions/selectPopup.js new file mode 100644 index 00000000..4aebc192 --- /dev/null +++ b/web/views/@default/clusters/regions/selectPopup.js @@ -0,0 +1,8 @@ +Tea.context(function () { + this.success = NotifyPopup + this.regionId = 0 + + this.selectRegion = function (region) { + this.regionId = region.id + } +}) \ No newline at end of file