Skip to content

Commit

Permalink
fix(admin): fixed API PopUpWithForm
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Jun 1, 2020
1 parent 2109ee3 commit a81cee3
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 25 deletions.
5 changes: 2 additions & 3 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/GoAdminGroup/go-admin/modules/logger"
"github.com/GoAdminGroup/go-admin/modules/menu"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/template"
"github.com/GoAdminGroup/go-admin/template/types"
Expand All @@ -36,7 +35,7 @@ type WebFrameWork interface {

// Content add the panel html response of the given callback function to
// the web framework context which is the first parameter.
Content(ctx interface{}, fn types.GetPanelFn, fn2 admin.AddOperationFn, navButtons ...types.Button)
Content(ctx interface{}, fn types.GetPanelFn, fn2 context.NodeProcessor, navButtons ...types.Button)

// User get the auth user model from the given web framework context.
User(ctx interface{}) (models.UserModel, bool)
Expand Down Expand Up @@ -123,7 +122,7 @@ func (base *BaseAdapter) GetUse(app interface{}, plugin []plugins.Plugin, wf Web

// GetContent is a helper function of adapter.Content
func (base *BaseAdapter) GetContent(ctx interface{}, getPanelFn types.GetPanelFn, wf WebFrameWork,
navButtons types.Buttons, fn admin.AddOperationFn) {
navButtons types.Buttons, fn context.NodeProcessor) {

var (
newBase = wf.SetContext(ctx)
Expand Down
3 changes: 1 addition & 2 deletions adapter/beego/beego.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
"github.com/GoAdminGroup/go-admin/template/types"
Expand Down Expand Up @@ -49,7 +48,7 @@ func (bee *Beego) DisableLog() { panic("not implement") }
func (bee *Beego) Static(prefix, path string) { panic("not implement") }

// Content implements the method Adapter.Content.
func (bee *Beego) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn admin.AddOperationFn, navButtons ...types.Button) {
func (bee *Beego) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn gctx.NodeProcessor, navButtons ...types.Button) {
bee.GetContent(ctx, getPanelFn, bee, navButtons, fn)
}

Expand Down
3 changes: 1 addition & 2 deletions adapter/buffalo/buffalo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
"github.com/GoAdminGroup/go-admin/template/types"
Expand Down Expand Up @@ -49,7 +48,7 @@ func (bu *Buffalo) DisableLog() { panic("not implement") }
func (bu *Buffalo) Static(prefix, path string) { panic("not implement") }

// Content implements the method Adapter.Content.
func (bu *Buffalo) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn admin.AddOperationFn, btns ...types.Button) {
func (bu *Buffalo) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn context.NodeProcessor, btns ...types.Button) {
bu.GetContent(ctx, getPanelFn, bu, btns, fn)
}

Expand Down
3 changes: 1 addition & 2 deletions adapter/chi/chi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/GoAdminGroup/go-admin/engine"
cfg "github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
"github.com/GoAdminGroup/go-admin/template/types"
Expand Down Expand Up @@ -49,7 +48,7 @@ func (ch *Chi) DisableLog() { panic("not implement") }
func (ch *Chi) Static(prefix, path string) { panic("not implement") }

// Content implements the method Adapter.Content.
func (ch *Chi) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn admin.AddOperationFn, btns ...types.Button) {
func (ch *Chi) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn context.NodeProcessor, btns ...types.Button) {
ch.GetContent(ctx, getPanelFn, ch, btns, fn)
}

Expand Down
3 changes: 1 addition & 2 deletions adapter/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
"github.com/GoAdminGroup/go-admin/template/types"
Expand Down Expand Up @@ -48,7 +47,7 @@ func (e *Echo) DisableLog() { panic("not implement") }
func (e *Echo) Static(prefix, path string) { panic("not implement") }

// Content implements the method Adapter.Content.
func (e *Echo) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn admin.AddOperationFn, btns ...types.Button) {
func (e *Echo) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn context.NodeProcessor, btns ...types.Button) {
e.GetContent(ctx, getPanelFn, e, btns, fn)
}

Expand Down
3 changes: 1 addition & 2 deletions adapter/fasthttp/fasthttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
"github.com/GoAdminGroup/go-admin/template/types"
Expand Down Expand Up @@ -50,7 +49,7 @@ func (fast *Fasthttp) DisableLog() { panic("not implement") }
func (fast *Fasthttp) Static(prefix, path string) { panic("not implement") }

// Content implements the method Adapter.Content.
func (fast *Fasthttp) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn admin.AddOperationFn, btns ...types.Button) {
func (fast *Fasthttp) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn context.NodeProcessor, btns ...types.Button) {
fast.GetContent(ctx, getPanelFn, fast, btns, fn)
}

Expand Down
3 changes: 1 addition & 2 deletions adapter/gf/gf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
"github.com/GoAdminGroup/go-admin/template/types"
Expand Down Expand Up @@ -49,7 +48,7 @@ func (gf *Gf) DisableLog() { panic("not implement") }
func (gf *Gf) Static(prefix, path string) { panic("not implement") }

// Content implements the method Adapter.Content.
func (gf *Gf) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn admin.AddOperationFn, btns ...types.Button) {
func (gf *Gf) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn context.NodeProcessor, btns ...types.Button) {
gf.GetContent(ctx, getPanelFn, gf, btns, fn)
}

Expand Down
3 changes: 1 addition & 2 deletions adapter/gin/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
"github.com/GoAdminGroup/go-admin/template/types"
Expand Down Expand Up @@ -44,7 +43,7 @@ func (gins *Gin) Use(app interface{}, plugs []plugins.Plugin) error {
}

// Content implements the method Adapter.Content.
func (gins *Gin) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn admin.AddOperationFn, btns ...types.Button) {
func (gins *Gin) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn context.NodeProcessor, btns ...types.Button) {
gins.GetContent(ctx, getPanelFn, gins, btns, fn)
}

Expand Down
3 changes: 1 addition & 2 deletions adapter/gorilla/gorilla.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/constant"
"github.com/GoAdminGroup/go-admin/template/types"
Expand Down Expand Up @@ -49,7 +48,7 @@ func (g *Gorilla) DisableLog() { panic("not implement") }
func (g *Gorilla) Static(prefix, path string) { panic("not implement") }

// Content implements the method Adapter.Content.
func (g *Gorilla) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn admin.AddOperationFn, btns ...types.Button) {
func (g *Gorilla) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn context.NodeProcessor, btns ...types.Button) {
g.GetContent(ctx, getPanelFn, g, btns, fn)
}

Expand Down
3 changes: 1 addition & 2 deletions adapter/iris/iris.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"errors"
"github.com/GoAdminGroup/go-admin/adapter"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/admin/models"
"github.com/GoAdminGroup/go-admin/template/types"
"github.com/kataras/iris/v12"
Expand Down Expand Up @@ -49,7 +48,7 @@ func (is *Iris) DisableLog() { panic("not implement") }
func (is *Iris) Static(prefix, path string) { panic("not implement") }

// Content implements the method Adapter.Content.
func (is *Iris) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn admin.AddOperationFn, btns ...types.Button) {
func (is *Iris) Content(ctx interface{}, getPanelFn types.GetPanelFn, fn context.NodeProcessor, btns ...types.Button) {
is.GetContent(ctx, getPanelFn, is, btns, fn)
}

Expand Down
2 changes: 2 additions & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (r Router) GetURL(value ...string) string {
return u
}

type NodeProcessor func(...Node)

type Node struct {
Path string
Method string
Expand Down
7 changes: 4 additions & 3 deletions plugins/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/guard"
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table"
"github.com/GoAdminGroup/go-admin/template/types"
"github.com/GoAdminGroup/go-admin/template/types/action"
_ "github.com/GoAdminGroup/go-admin/template/types/display"
)

Expand Down Expand Up @@ -52,6 +53,8 @@ func (admin *Admin) InitPlugin(services service.List) {
admin.handler.AddNavButton(admin.UI.NavButtons)

table.SetServices(services)

action.InitOperationHandlerSetter(admin.GetAddOperationFn())
}

// NewAdmin return the global Admin plugin.
Expand All @@ -63,9 +66,7 @@ func NewAdmin(tableCfg ...table.GeneratorList) *Admin {
}
}

type AddOperationFn func(nodes ...context.Node)

func (admin *Admin) GetAddOperationFn() AddOperationFn {
func (admin *Admin) GetAddOperationFn() context.NodeProcessor {
return admin.handler.AddOperation
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// something like init the database and set the config and register
// the routes. The Plugin must implement the three methods.
type Plugin interface {
GetHandler() context.HandlerMap
GetHandler() context.HandlerMap // 返回路由和控制器方法
InitPlugin(services service.List)
Name() string
Prefix() string
Expand Down
8 changes: 8 additions & 0 deletions template/types/action/popup.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ type PopUpData struct {

type GetForm func(panel *types.FormPanel) *types.FormPanel

var operationHandlerSetter context.NodeProcessor

func InitOperationHandlerSetter(p context.NodeProcessor) {
operationHandlerSetter = p
}

func PopUpWithForm(data PopUpData, fn GetForm, url string) *PopUpAction {
if data.Id == "" {
panic("wrong popup action parameter, empty id")
Expand All @@ -149,6 +155,8 @@ func PopUpWithForm(data PopUpData, fn GetForm, url string) *PopUpAction {
SetContent(btn1 + btn2).GetContent()
panel := fn(types.NewFormPanel())

operationHandlerSetter(panel.Callbacks...)

fields, tabFields, tabHeaders := panel.GetNewFormFields()

return true, "ok", template2.Default().Box().
Expand Down

0 comments on commit a81cee3

Please sign in to comment.