mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-09 00:20:26 +08:00
实现在服务中使用分组
This commit is contained in:
@@ -1,31 +0,0 @@
|
|||||||
package groups
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OptionsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *OptionsAction) RunPost(params struct {
|
|
||||||
ClusterId int64
|
|
||||||
}) {
|
|
||||||
groupsResp, err := this.RPC().NodeGroupRPC().FindAllEnabledNodeGroupsWithClusterId(this.AdminContext(), &pb.FindAllEnabledNodeGroupsWithClusterIdRequest{ClusterId: params.ClusterId})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
groupMaps := []maps.Map{}
|
|
||||||
for _, group := range groupsResp.Groups {
|
|
||||||
groupMaps = append(groupMaps, maps.Map{
|
|
||||||
"id": group.Id,
|
|
||||||
"name": group.Name,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.Data["groups"] = groupMaps
|
|
||||||
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -42,7 +42,6 @@ func init() {
|
|||||||
GetPost("/groups/updatePopup", new(groups.UpdatePopupAction)).
|
GetPost("/groups/updatePopup", new(groups.UpdatePopupAction)).
|
||||||
Post("/groups/delete", new(groups.DeleteAction)).
|
Post("/groups/delete", new(groups.DeleteAction)).
|
||||||
Post("/groups/sort", new(groups.SortAction)).
|
Post("/groups/sort", new(groups.SortAction)).
|
||||||
Post("/groups/options", new(groups.OptionsAction)).
|
|
||||||
GetPost("/groups/selectPopup", new(groups.SelectPopupAction)).
|
GetPost("/groups/selectPopup", new(groups.SelectPopupAction)).
|
||||||
|
|
||||||
EndAll()
|
EndAll()
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ func init() {
|
|||||||
Get("", new(IndexAction)).
|
Get("", new(IndexAction)).
|
||||||
GetPost("/createPopup", new(CreatePopupAction)).
|
GetPost("/createPopup", new(CreatePopupAction)).
|
||||||
GetPost("/updatePopup", new(UpdatePopupAction)).
|
GetPost("/updatePopup", new(UpdatePopupAction)).
|
||||||
Post("/options", new(OptionsAction)).
|
|
||||||
GetPost("/selectPopup", new(SelectPopupAction)).
|
GetPost("/selectPopup", new(SelectPopupAction)).
|
||||||
Post("/delete", new(DeleteAction)).
|
Post("/delete", new(DeleteAction)).
|
||||||
Post("/sort", new(SortAction)).
|
Post("/sort", new(SortAction)).
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
package groups
|
|
||||||
|
|
||||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
||||||
|
|
||||||
type OptionsAction struct {
|
|
||||||
actionutils.ParentAction
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *OptionsAction) RunPost(params struct{}) {
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
package groups
|
package groups
|
||||||
|
|
||||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
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/lists"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type SelectPopupAction struct {
|
type SelectPopupAction struct {
|
||||||
actionutils.ParentAction
|
actionutils.ParentAction
|
||||||
@@ -10,6 +18,61 @@ func (this *SelectPopupAction) Init() {
|
|||||||
this.Nav("", "", "")
|
this.Nav("", "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *SelectPopupAction) RunGet(params struct{}) {
|
func (this *SelectPopupAction) RunGet(params struct {
|
||||||
|
SelectedGroupIds string
|
||||||
|
}) {
|
||||||
|
groupsResp, err := this.RPC().ServerGroupRPC().FindAllEnabledServerGroups(this.AdminContext(), &pb.FindAllEnabledServerGroupsRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedGroupIds := []int64{}
|
||||||
|
if len(params.SelectedGroupIds) > 0 {
|
||||||
|
for _, v := range strings.Split(params.SelectedGroupIds, ",") {
|
||||||
|
selectedGroupIds = append(selectedGroupIds, types.Int64(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
groupMaps := []maps.Map{}
|
||||||
|
for _, group := range groupsResp.Groups {
|
||||||
|
// 已经选过的就跳过
|
||||||
|
if lists.ContainsInt64(selectedGroupIds, group.Id) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
groupMaps = append(groupMaps, maps.Map{
|
||||||
|
"id": group.Id,
|
||||||
|
"name": group.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["groups"] = groupMaps
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *SelectPopupAction) RunPost(params struct {
|
||||||
|
GroupId int64
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
}) {
|
||||||
|
if params.GroupId <= 0 {
|
||||||
|
this.Fail("请选择要使用的分组")
|
||||||
|
}
|
||||||
|
|
||||||
|
groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroup(this.AdminContext(), &pb.FindEnabledServerGroupRequest{GroupId: params.GroupId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
group := groupResp.Group
|
||||||
|
if group == nil {
|
||||||
|
this.NotFound("serverGroup", params.GroupId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["group"] = maps.Map{
|
||||||
|
"id": group.Id,
|
||||||
|
"name": group.Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
|
GroupIds []int64
|
||||||
|
|
||||||
ServerType string
|
ServerType string
|
||||||
Addresses string
|
Addresses string
|
||||||
@@ -259,6 +260,7 @@ func (this *CreateAction) RunPost(params struct {
|
|||||||
ExcludeNodesJSON: excludeNodesJSON,
|
ExcludeNodesJSON: excludeNodesJSON,
|
||||||
WebId: webId,
|
WebId: webId,
|
||||||
ReverseProxyJSON: reverseProxyRefJSON,
|
ReverseProxyJSON: reverseProxyRefJSON,
|
||||||
|
GroupIds: params.GroupIds,
|
||||||
}
|
}
|
||||||
if httpConfig != nil {
|
if httpConfig != nil {
|
||||||
data, err := json.Marshal(httpConfig)
|
data, err := json.Marshal(httpConfig)
|
||||||
|
|||||||
@@ -95,6 +95,17 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分组
|
||||||
|
groupMaps := []maps.Map{}
|
||||||
|
if len(server.Groups) > 0 {
|
||||||
|
for _, group := range server.Groups {
|
||||||
|
groupMaps = append(groupMaps, maps.Map{
|
||||||
|
"id": group.Id,
|
||||||
|
"name": group.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
serverMaps = append(serverMaps, maps.Map{
|
serverMaps = append(serverMaps, maps.Map{
|
||||||
"id": server.Id,
|
"id": server.Id,
|
||||||
"isOn": server.IsOn,
|
"isOn": server.IsOn,
|
||||||
@@ -105,6 +116,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
},
|
},
|
||||||
"ports": portMaps,
|
"ports": portMaps,
|
||||||
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),
|
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),
|
||||||
|
"groups": groupMaps,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.Data["servers"] = serverMaps
|
this.Data["servers"] = serverMaps
|
||||||
|
|||||||
@@ -57,6 +57,17 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
clusterId = server.Cluster.Id
|
clusterId = server.Cluster.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分组
|
||||||
|
groupMaps := []maps.Map{}
|
||||||
|
if len(server.Groups) > 0 {
|
||||||
|
for _, group := range server.Groups {
|
||||||
|
groupMaps = append(groupMaps, maps.Map{
|
||||||
|
"id": group.Id,
|
||||||
|
"name": group.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.Data["server"] = maps.Map{
|
this.Data["server"] = maps.Map{
|
||||||
"id": server.Id,
|
"id": server.Id,
|
||||||
"clusterId": clusterId,
|
"clusterId": clusterId,
|
||||||
@@ -64,6 +75,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
"name": server.Name,
|
"name": server.Name,
|
||||||
"description": server.Description,
|
"description": server.Description,
|
||||||
"isOn": server.IsOn,
|
"isOn": server.IsOn,
|
||||||
|
"groups": groupMaps,
|
||||||
}
|
}
|
||||||
|
|
||||||
serverType := serverconfigs.FindServerType(server.Type)
|
serverType := serverconfigs.FindServerType(server.Type)
|
||||||
@@ -84,6 +96,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
ClusterId int64
|
ClusterId int64
|
||||||
|
GroupIds []int64
|
||||||
IsOn bool
|
IsOn bool
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
@@ -102,6 +115,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
ClusterId: params.ClusterId,
|
ClusterId: params.ClusterId,
|
||||||
IsOn: params.IsOn,
|
IsOn: params.IsOn,
|
||||||
|
GroupIds: params.GroupIds,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -1,20 +1,8 @@
|
|||||||
Vue.component("node-group-selector", {
|
Vue.component("node-group-selector", {
|
||||||
props: ["v-cluster-id", "v-group"],
|
props: ["v-cluster-id", "v-group"],
|
||||||
mounted: function () {
|
|
||||||
let that = this
|
|
||||||
Tea.action("/clusters/cluster/groups/options")
|
|
||||||
.post()
|
|
||||||
.params({
|
|
||||||
clusterId: this.vClusterId
|
|
||||||
})
|
|
||||||
.success(function (resp) {
|
|
||||||
|
|
||||||
})
|
|
||||||
},
|
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
groups: [],
|
selectedGroup: this.vGroup
|
||||||
selectedGroup: this.vGroup,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
53
web/public/js/components/server/server-group-selector.js
Normal file
53
web/public/js/components/server/server-group-selector.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
Vue.component("server-group-selector", {
|
||||||
|
props: ["v-groups"],
|
||||||
|
data: function () {
|
||||||
|
let groups = this.vGroups
|
||||||
|
if (groups == null) {
|
||||||
|
groups = []
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
groups: groups
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
selectGroup: function () {
|
||||||
|
let that = this
|
||||||
|
let groupIds = this.groups.map(function (v) {
|
||||||
|
return v.id.toString()
|
||||||
|
}).join(",")
|
||||||
|
teaweb.popup("/servers/components/groups/selectPopup?selectedGroupIds=" + groupIds, {
|
||||||
|
callback: function (resp) {
|
||||||
|
that.groups.push(resp.data.group)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
addGroup: function () {
|
||||||
|
let that = this
|
||||||
|
teaweb.popup("/servers/components/groups/createPopup", {
|
||||||
|
callback: function (resp) {
|
||||||
|
that.groups.push(resp.data.group)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
removeGroup: function (index) {
|
||||||
|
this.groups.$remove(index)
|
||||||
|
},
|
||||||
|
groupIds: function () {
|
||||||
|
return this.groups.map(function (v) {
|
||||||
|
return v.id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
template: `<div>
|
||||||
|
<div v-if="groups.length > 0">
|
||||||
|
<div class="ui label tiny" v-if="groups.length > 0" v-for="(group, index) in groups">
|
||||||
|
<input type="hidden" name="groupIds" :value="group.id"/>
|
||||||
|
{{group.name}} <a href="" title="删除" @click.prevent="removeGroup(index)"><i class="icon remove"></i></a>
|
||||||
|
</div>
|
||||||
|
<div class="ui divider"></div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<a href="" @click.prevent="selectGroup()">[选择分组]</a> <a href="" @click.prevent="addGroup()">[添加分组]</a>
|
||||||
|
</div>
|
||||||
|
</div>`
|
||||||
|
})
|
||||||
@@ -82,6 +82,13 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>选择分组</td>
|
||||||
|
<td>
|
||||||
|
<server-group-selector></server-group-selector>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2"><more-options-indicator></more-options-indicator></td>
|
<td colspan="2"><more-options-indicator></more-options-indicator></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>服务名称</th>
|
<th>服务名称</th>
|
||||||
|
<th>所属分组</th>
|
||||||
<th>服务类型</th>
|
<th>服务类型</th>
|
||||||
<th>部署集群</th>
|
<th>部署集群</th>
|
||||||
<th>端口</th>
|
<th>端口</th>
|
||||||
@@ -16,6 +17,14 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tr v-for="server in servers">
|
<tr v-for="server in servers">
|
||||||
<td>{{server.name}}</td>
|
<td>{{server.name}}</td>
|
||||||
|
<td>
|
||||||
|
<div v-if="server.groups.length > 0">
|
||||||
|
<div v-for="group in server.groups">
|
||||||
|
<span class="ui label tiny" style="margin-bottom:0.5em">{{group.name}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span class="disabled" v-else>-</span>
|
||||||
|
</td>
|
||||||
<td>{{server.serverTypeName}}</td>
|
<td>{{server.serverTypeName}}</td>
|
||||||
<td>{{server.cluster.name}}</td>
|
<td>{{server.cluster.name}}</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -26,6 +26,12 @@
|
|||||||
{{typeName}}
|
{{typeName}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>选择分组</td>
|
||||||
|
<td>
|
||||||
|
<server-group-selector :v-groups="server.groups"></server-group-selector>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2"><more-options-indicator></more-options-indicator></td>
|
<td colspan="2"><more-options-indicator></more-options-indicator></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user