实现在服务中使用分组

This commit is contained in:
GoEdgeLab
2020-10-29 21:37:48 +08:00
parent 8397c71a21
commit cc9b1adb34
13 changed files with 169 additions and 59 deletions

View File

@@ -16,7 +16,6 @@ func init() {
Get("", new(IndexAction)).
GetPost("/createPopup", new(CreatePopupAction)).
GetPost("/updatePopup", new(UpdatePopupAction)).
Post("/options", new(OptionsAction)).
GetPost("/selectPopup", new(SelectPopupAction)).
Post("/delete", new(DeleteAction)).
Post("/sort", new(SortAction)).

View File

@@ -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()
}

View File

@@ -1,6 +1,14 @@
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 {
actionutils.ParentAction
@@ -10,6 +18,61 @@ func (this *SelectPopupAction) Init() {
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()
}
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()
}