阶段性提交

This commit is contained in:
GoEdgeLab
2020-09-06 16:19:34 +08:00
parent 2ba46b9162
commit 124cbd3302
185 changed files with 5306 additions and 1832 deletions

View File

@@ -0,0 +1,50 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
)
type CreateAction struct {
actionutils.ParentAction
}
func (this *CreateAction) Init() {
this.Nav("", "node", "create")
}
func (this *CreateAction) RunGet(params struct{}) {
this.Show()
}
func (this *CreateAction) RunPost(params struct {
Name string
Host string
Port int
Description string
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入API节点").
Field("host", params.Host).
Require("请输入主机地址").
Field("port", params.Port).
Gt(0, "端口不能小于1").
Lte(65535, "端口不能大于65535")
_, err := this.RPC().APINodeRPC().CreateAPINode(this.AdminContext(), &pb.CreateAPINodeRequest{
Name: params.Name,
Description: params.Description,
Host: params.Host,
Port: int32(params.Port),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,73 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"net/http"
"strconv"
)
type Helper struct {
}
func NewHelper() *Helper {
return &Helper{}
}
func (this *Helper) BeforeAction(action *actions.ActionObject) (goNext bool) {
if action.Request.Method != http.MethodGet {
return true
}
action.Data["teaMenu"] = "api"
nodeId := action.ParamInt64("nodeId")
nodeIdString := strconv.FormatInt(nodeId, 10)
// 节点信息
rpcClient, err := rpc.SharedRPC()
if err != nil {
logs.Error(err)
return
}
nodeResp, err := rpcClient.APINodeRPC().FindEnabledAPINode(rpcClient.Context(action.Context.GetInt64("adminId")), &pb.FindEnabledAPINodeRequest{NodeId: nodeId})
if err != nil {
action.WriteString(err.Error())
return
}
if nodeResp.Node == nil {
action.WriteString("node not found")
return
}
node := nodeResp.Node
// 顶部Tab栏
selectedTabbar, _ := action.Data["mainTab"]
tabbar := actionutils.NewTabbar()
tabbar.Add("当前节点:"+node.Name, "", "/api", "left long alternate arrow", false)
tabbar.Add("设置", "", "/api/node/settings?nodeId="+nodeIdString, "setting", selectedTabbar == "setting")
actionutils.SetTabbar(action, tabbar)
// 左侧菜单栏
secondMenuItem := action.Data.GetString("secondMenuItem")
switch selectedTabbar {
case "setting":
action.Data["leftMenuItems"] = this.createSettingMenu(nodeIdString, secondMenuItem)
}
return true
}
// 设置相关菜单
func (this *Helper) createSettingMenu(nodeIdString string, selectedItem string) (items []maps.Map) {
items = append(items, maps.Map{
"name": "基础设置",
"url": "/api/node/settings?nodeId=" + nodeIdString,
"isActive": selectedItem == "basic",
})
return
}

View File

@@ -0,0 +1,20 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Prefix("/api/node").
// 节点相关
GetPost("/settings", new(SettingsAction)).
EndAll()
})
}

View File

@@ -0,0 +1,78 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type SettingsAction struct {
actionutils.ParentAction
}
func (this *SettingsAction) Init() {
this.Nav("", "setting", "")
this.SecondMenu("basic")
}
func (this *SettingsAction) RunGet(params struct {
NodeId int64
}) {
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{
NodeId: params.NodeId,
})
if err != nil {
this.ErrorPage(err)
return
}
node := nodeResp.Node
if node == nil {
this.WriteString("要操作的节点不存在")
return
}
this.Data["node"] = maps.Map{
"id": node.Id,
"name": node.Name,
"description": node.Description,
"host": node.Host,
"port": node.Port,
}
this.Show()
}
// 保存基础设置
func (this *SettingsAction) RunPost(params struct {
NodeId int64
Name string
Host string
Port int
Description string
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入API节点").
Field("host", params.Host).
Require("请输入主机地址").
Field("port", params.Port).
Gt(0, "端口不能小于1").
Lte(65535, "端口不能大于65535")
_, err := this.RPC().APINodeRPC().UpdateAPINode(this.AdminContext(), &pb.UpdateAPINodeRequest{
NodeId: params.NodeId,
Name: params.Name,
Description: params.Description,
Host: params.Host,
Port: int32(params.Port),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}