From a81cee33148d58f3e47e7043e1ae540526a24f93 Mon Sep 17 00:00:00 2001 From: cg33 Date: Mon, 1 Jun 2020 15:32:06 +0800 Subject: [PATCH] fix(admin): fixed API PopUpWithForm --- adapter/adapter.go | 5 ++--- adapter/beego/beego.go | 3 +-- adapter/buffalo/buffalo.go | 3 +-- adapter/chi/chi.go | 3 +-- adapter/echo/echo.go | 3 +-- adapter/fasthttp/fasthttp.go | 3 +-- adapter/gf/gf.go | 3 +-- adapter/gin/gin.go | 3 +-- adapter/gorilla/gorilla.go | 3 +-- adapter/iris/iris.go | 3 +-- context/context.go | 2 ++ plugins/admin/admin.go | 7 ++++--- plugins/plugins.go | 2 +- template/types/action/popup.go | 8 ++++++++ 14 files changed, 26 insertions(+), 25 deletions(-) diff --git a/adapter/adapter.go b/adapter/adapter.go index b5f4a04e3..081e2eb20 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -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" @@ -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) @@ -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) diff --git a/adapter/beego/beego.go b/adapter/beego/beego.go index 7a0c2021f..a4ed30a27 100644 --- a/adapter/beego/beego.go +++ b/adapter/beego/beego.go @@ -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" @@ -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) } diff --git a/adapter/buffalo/buffalo.go b/adapter/buffalo/buffalo.go index 06c76289e..36aab7d6e 100644 --- a/adapter/buffalo/buffalo.go +++ b/adapter/buffalo/buffalo.go @@ -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" @@ -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) } diff --git a/adapter/chi/chi.go b/adapter/chi/chi.go index 2c37d6358..ad1c6531c 100644 --- a/adapter/chi/chi.go +++ b/adapter/chi/chi.go @@ -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" @@ -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) } diff --git a/adapter/echo/echo.go b/adapter/echo/echo.go index 9d0af0299..fd9103b77 100644 --- a/adapter/echo/echo.go +++ b/adapter/echo/echo.go @@ -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" @@ -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) } diff --git a/adapter/fasthttp/fasthttp.go b/adapter/fasthttp/fasthttp.go index b724a2194..dad05dd31 100644 --- a/adapter/fasthttp/fasthttp.go +++ b/adapter/fasthttp/fasthttp.go @@ -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" @@ -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) } diff --git a/adapter/gf/gf.go b/adapter/gf/gf.go index 679b984b1..ccfb13642 100644 --- a/adapter/gf/gf.go +++ b/adapter/gf/gf.go @@ -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" @@ -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) } diff --git a/adapter/gin/gin.go b/adapter/gin/gin.go index 51e8cbbc2..ff11432b8 100644 --- a/adapter/gin/gin.go +++ b/adapter/gin/gin.go @@ -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" @@ -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) } diff --git a/adapter/gorilla/gorilla.go b/adapter/gorilla/gorilla.go index 84220fe17..8915bfba4 100644 --- a/adapter/gorilla/gorilla.go +++ b/adapter/gorilla/gorilla.go @@ -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" @@ -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) } diff --git a/adapter/iris/iris.go b/adapter/iris/iris.go index d726d8a9e..def17a8f7 100644 --- a/adapter/iris/iris.go +++ b/adapter/iris/iris.go @@ -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" @@ -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) } diff --git a/context/context.go b/context/context.go index e83ade66b..e95dea725 100644 --- a/context/context.go +++ b/context/context.go @@ -69,6 +69,8 @@ func (r Router) GetURL(value ...string) string { return u } +type NodeProcessor func(...Node) + type Node struct { Path string Method string diff --git a/plugins/admin/admin.go b/plugins/admin/admin.go index aac529030..176e940bc 100644 --- a/plugins/admin/admin.go +++ b/plugins/admin/admin.go @@ -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" ) @@ -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. @@ -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 } diff --git a/plugins/plugins.go b/plugins/plugins.go index 70b070b16..bf4bd84b3 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -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 diff --git a/template/types/action/popup.go b/template/types/action/popup.go index 2ee01f495..adc0c48a8 100644 --- a/template/types/action/popup.go +++ b/template/types/action/popup.go @@ -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") @@ -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().