|
|
|
|
|
|
|
|
|
package engine |
|
|
|
import ( |
|
"bytes" |
|
"encoding/json" |
|
errors2 "errors" |
|
"fmt" |
|
template2 "html/template" |
|
"net/http" |
|
"runtime/debug" |
|
"strings" |
|
"sync" |
|
|
|
"github.com/GoAdminGroup/go-admin/modules/language" |
|
"github.com/GoAdminGroup/go-admin/template/icon" |
|
"github.com/GoAdminGroup/go-admin/template/types/action" |
|
|
|
"github.com/GoAdminGroup/go-admin/adapter" |
|
"github.com/GoAdminGroup/go-admin/context" |
|
"github.com/GoAdminGroup/go-admin/modules/auth" |
|
"github.com/GoAdminGroup/go-admin/modules/config" |
|
"github.com/GoAdminGroup/go-admin/modules/db" |
|
"github.com/GoAdminGroup/go-admin/modules/errors" |
|
"github.com/GoAdminGroup/go-admin/modules/logger" |
|
"github.com/GoAdminGroup/go-admin/modules/menu" |
|
"github.com/GoAdminGroup/go-admin/modules/service" |
|
"github.com/GoAdminGroup/go-admin/modules/system" |
|
"github.com/GoAdminGroup/go-admin/modules/ui" |
|
"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/response" |
|
"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table" |
|
"github.com/GoAdminGroup/go-admin/template" |
|
"github.com/GoAdminGroup/go-admin/template/types" |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
type Engine struct { |
|
PluginList plugins.Plugins |
|
Adapter adapter.WebFrameWork |
|
Services service.List |
|
NavButtons *types.Buttons |
|
config *config.Config |
|
announceLock sync.Once |
|
} |
|
|
|
|
|
func Default() *Engine { |
|
engine = &Engine{ |
|
Adapter: defaultAdapter, |
|
Services: service.GetServices(), |
|
NavButtons: new(types.Buttons), |
|
} |
|
return engine |
|
} |
|
|
|
|
|
func (eng *Engine) Use(router interface{}) error { |
|
if eng.Adapter == nil { |
|
emptyAdapterPanic() |
|
} |
|
|
|
eng.Services.Add(auth.InitCSRFTokenSrv(eng.DefaultConnection())) |
|
eng.initSiteSetting() |
|
eng.initJumpNavButtons() |
|
eng.initPlugins() |
|
|
|
printInitMsg(language.Get("initialize success")) |
|
|
|
return eng.Adapter.Use(router, eng.PluginList) |
|
} |
|
|
|
|
|
func (eng *Engine) AddPlugins(plugs ...plugins.Plugin) *Engine { |
|
|
|
if len(plugs) == 0 { |
|
return eng |
|
} |
|
|
|
for _, plug := range plugs { |
|
eng.PluginList = eng.PluginList.Add(plug) |
|
} |
|
|
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddPluginList(plugs plugins.Plugins) *Engine { |
|
|
|
if len(plugs) == 0 { |
|
return eng |
|
} |
|
|
|
for _, plug := range plugs { |
|
eng.PluginList = eng.PluginList.Add(plug) |
|
} |
|
|
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) FindPluginByName(name string) (plugins.Plugin, bool) { |
|
for _, plug := range eng.PluginList { |
|
if plug.Name() == name { |
|
return plug, true |
|
} |
|
} |
|
return nil, false |
|
} |
|
|
|
|
|
func (eng *Engine) AddAuthService(processor auth.Processor) *Engine { |
|
eng.Services.Add("auth", auth.NewService(processor)) |
|
return eng |
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (eng *Engine) announce() *Engine { |
|
if eng.config.Debug { |
|
eng.announceLock.Do(func() { |
|
fmt.Printf(language.Get("goadmin is now running. \nrunning in \"debug\" mode. switch to \"release\" mode in production.\n\n")) |
|
}) |
|
} |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddConfig(cfg *config.Config) *Engine { |
|
return eng.setConfig(cfg).announce().initDatabase() |
|
} |
|
|
|
|
|
func (eng *Engine) setConfig(cfg *config.Config) *Engine { |
|
eng.config = config.Initialize(cfg) |
|
sysCheck, themeCheck := template.CheckRequirements() |
|
if !sysCheck { |
|
logger.Panicf(language.Get("wrong goadmin version, theme %s required goadmin version are %s"), |
|
eng.config.Theme, strings.Join(template.Default().GetRequirements(), ",")) |
|
} |
|
if !themeCheck { |
|
logger.Panicf(language.Get("wrong theme version, goadmin %s required version of theme %s is %s"), |
|
system.Version(), eng.config.Theme, strings.Join(system.RequireThemeVersion()[eng.config.Theme], ",")) |
|
} |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddConfigFromJSON(path string) *Engine { |
|
cfg := config.ReadFromJson(path) |
|
return eng.setConfig(&cfg).announce().initDatabase() |
|
} |
|
|
|
|
|
func (eng *Engine) AddConfigFromYAML(path string) *Engine { |
|
cfg := config.ReadFromYaml(path) |
|
return eng.setConfig(&cfg).announce().initDatabase() |
|
} |
|
|
|
|
|
func (eng *Engine) AddConfigFromINI(path string) *Engine { |
|
cfg := config.ReadFromINI(path) |
|
return eng.setConfig(&cfg).announce().initDatabase() |
|
} |
|
|
|
|
|
func (eng *Engine) initDatabase() *Engine { |
|
printInitMsg(language.Get("initialize database connections")) |
|
for driver, databaseCfg := range eng.config.Databases.GroupByDriver() { |
|
eng.Services.Add(driver, db.GetConnectionByDriver(driver).InitDB(databaseCfg)) |
|
} |
|
if defaultAdapter == nil { |
|
emptyAdapterPanic() |
|
} |
|
defaultConnection := db.GetConnection(eng.Services) |
|
defaultAdapter.SetConnection(defaultConnection) |
|
eng.Adapter.SetConnection(defaultConnection) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddAdapter(ada adapter.WebFrameWork) *Engine { |
|
eng.Adapter = ada |
|
defaultAdapter = ada |
|
return eng |
|
} |
|
|
|
|
|
var defaultAdapter adapter.WebFrameWork |
|
|
|
var engine *Engine |
|
|
|
|
|
var navButtons = new(types.Buttons) |
|
|
|
func emptyAdapterPanic() { |
|
logger.Panic(language.Get("adapter is nil, import the default adapter or use addadapter method add the adapter")) |
|
} |
|
|
|
|
|
func Register(ada adapter.WebFrameWork) { |
|
if ada == nil { |
|
emptyAdapterPanic() |
|
} |
|
defaultAdapter = ada |
|
} |
|
|
|
|
|
func User(ctx interface{}) (models.UserModel, bool) { |
|
return defaultAdapter.User(ctx) |
|
} |
|
|
|
|
|
func (eng *Engine) User(ctx interface{}) (models.UserModel, bool) { |
|
return eng.Adapter.User(ctx) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
func (eng *Engine) DB(driver string) db.Connection { |
|
return db.GetConnectionFromService(eng.Services.Get(driver)) |
|
} |
|
|
|
|
|
func (eng *Engine) DefaultConnection() db.Connection { |
|
return eng.DB(eng.config.Databases.GetDefault().Driver) |
|
} |
|
|
|
|
|
func (eng *Engine) MysqlConnection() db.Connection { |
|
return db.GetConnectionFromService(eng.Services.Get(db.DriverMysql)) |
|
} |
|
|
|
|
|
func (eng *Engine) MssqlConnection() db.Connection { |
|
return db.GetConnectionFromService(eng.Services.Get(db.DriverMssql)) |
|
} |
|
|
|
|
|
func (eng *Engine) PostgresqlConnection() db.Connection { |
|
return db.GetConnectionFromService(eng.Services.Get(db.DriverPostgresql)) |
|
} |
|
|
|
|
|
func (eng *Engine) SqliteConnection() db.Connection { |
|
return db.GetConnectionFromService(eng.Services.Get(db.DriverSqlite)) |
|
} |
|
|
|
|
|
func (eng *Engine) OceanBaseConnection() db.Connection { |
|
return db.GetConnectionFromService(eng.Services.Get(db.DriverOceanBase)) |
|
} |
|
|
|
type ConnectionSetter func(db.Connection) |
|
|
|
|
|
func (eng *Engine) ResolveConnection(setter ConnectionSetter, driver string) *Engine { |
|
setter(eng.DB(driver)) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) ResolveMysqlConnection(setter ConnectionSetter) *Engine { |
|
eng.ResolveConnection(setter, db.DriverMysql) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) ResolveMssqlConnection(setter ConnectionSetter) *Engine { |
|
eng.ResolveConnection(setter, db.DriverMssql) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) ResolveSqliteConnection(setter ConnectionSetter) *Engine { |
|
eng.ResolveConnection(setter, db.DriverSqlite) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) ResolvePostgresqlConnection(setter ConnectionSetter) *Engine { |
|
eng.ResolveConnection(setter, db.DriverPostgresql) |
|
return eng |
|
} |
|
|
|
type Setter func(*Engine) |
|
|
|
|
|
func (eng *Engine) Clone(e *Engine) *Engine { |
|
e = eng |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) ClonedBySetter(setter Setter) *Engine { |
|
setter(eng) |
|
return eng |
|
} |
|
|
|
func (eng *Engine) deferHandler(conn db.Connection) context.Handler { |
|
return func(ctx *context.Context) { |
|
defer func(ctx *context.Context) { |
|
if user, ok := ctx.UserValue["user"].(models.UserModel); ok { |
|
var input []byte |
|
form := ctx.Request.MultipartForm |
|
if form != nil { |
|
input, _ = json.Marshal((*form).Value) |
|
} |
|
|
|
models.OperationLog().SetConn(conn).New(user.Id, ctx.Path(), ctx.Method(), ctx.LocalIP(), string(input)) |
|
} |
|
|
|
if err := recover(); err != nil { |
|
logger.Error(err) |
|
logger.Error(string(debug.Stack())) |
|
|
|
var ( |
|
errMsg string |
|
ok bool |
|
e error |
|
) |
|
|
|
if errMsg, ok = err.(string); !ok { |
|
if e, ok = err.(error); ok { |
|
errMsg = e.Error() |
|
} |
|
} |
|
|
|
if errMsg == "" { |
|
errMsg = "system error" |
|
} |
|
|
|
if ctx.WantJSON() { |
|
response.Error(ctx, errMsg) |
|
return |
|
} |
|
|
|
eng.errorPanelHTML(ctx, new(bytes.Buffer), errors2.New(errMsg)) |
|
} |
|
}(ctx) |
|
ctx.Next() |
|
} |
|
} |
|
|
|
|
|
func (eng *Engine) wrapWithAuthMiddleware(handler context.Handler) context.Handlers { |
|
conn := db.GetConnection(eng.Services) |
|
return []context.Handler{eng.deferHandler(conn), response.OffLineHandler, auth.Middleware(conn), handler} |
|
} |
|
|
|
|
|
func (eng *Engine) wrap(handler context.Handler) context.Handlers { |
|
conn := db.GetConnection(eng.Services) |
|
return []context.Handler{eng.deferHandler(conn), response.OffLineHandler, handler} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
func (eng *Engine) AddNavButtons(title template2.HTML, icon string, action types.Action) *Engine { |
|
btn := types.GetNavButton(title, icon, action) |
|
*eng.NavButtons = append(*eng.NavButtons, btn) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddNavButtonsRaw(btns ...types.Button) *Engine { |
|
*eng.NavButtons = append(*eng.NavButtons, btns...) |
|
return eng |
|
} |
|
|
|
type navJumpButtonParam struct { |
|
Exist bool |
|
Icon string |
|
BtnName string |
|
URL string |
|
Title string |
|
TitleScore string |
|
} |
|
|
|
func (eng *Engine) addJumpNavButton(param navJumpButtonParam) *Engine { |
|
if param.Exist { |
|
*eng.NavButtons = (*eng.NavButtons).AddNavButton(param.Icon, param.BtnName, |
|
action.JumpInNewTab(config.Url(param.URL), |
|
language.GetWithScope(param.Title, param.TitleScore))) |
|
} |
|
return eng |
|
} |
|
|
|
func printInitMsg(msg string) { |
|
logger.Info(msg) |
|
} |
|
|
|
func (eng *Engine) initJumpNavButtons() { |
|
printInitMsg(language.Get("initialize navigation buttons")) |
|
for _, param := range eng.initNavJumpButtonParams() { |
|
eng.addJumpNavButton(param) |
|
} |
|
navButtons = eng.NavButtons |
|
eng.Services.Add(ui.ServiceKey, ui.NewService(eng.NavButtons)) |
|
} |
|
|
|
func (eng *Engine) initPlugins() { |
|
|
|
printInitMsg(language.Get("initialize plugins")) |
|
|
|
eng.AddPlugins(admin.NewAdmin()).AddPluginList(plugins.Get()) |
|
|
|
var plugGenerators = make(table.GeneratorList) |
|
|
|
for i := range eng.PluginList { |
|
if eng.PluginList[i].Name() != "admin" { |
|
printInitMsg("--> " + eng.PluginList[i].Name()) |
|
eng.PluginList[i].InitPlugin(eng.Services) |
|
if !eng.PluginList[i].GetInfo().SkipInstallation { |
|
eng.AddGenerator("plugin_"+eng.PluginList[i].Name(), eng.PluginList[i].GetSettingPage()) |
|
} |
|
plugGenerators = plugGenerators.Combine(eng.PluginList[i].GetGenerators()) |
|
} |
|
} |
|
adm := eng.AdminPlugin().AddGenerators(plugGenerators) |
|
adm.InitPlugin(eng.Services) |
|
plugins.Add(adm) |
|
} |
|
|
|
func (eng *Engine) initNavJumpButtonParams() []navJumpButtonParam { |
|
return []navJumpButtonParam{ |
|
{ |
|
Exist: !eng.config.HideConfigCenterEntrance, |
|
Icon: icon.Gear, |
|
BtnName: types.NavBtnSiteName, |
|
URL: "/info/site/edit", |
|
Title: "site setting", |
|
TitleScore: "config", |
|
}, { |
|
Exist: !eng.config.HideToolEntrance && eng.config.IsNotProductionEnvironment(), |
|
Icon: icon.Wrench, |
|
BtnName: types.NavBtnToolName, |
|
URL: "/info/generate/new", |
|
Title: "code generate tool", |
|
TitleScore: "tool", |
|
}, { |
|
Exist: !eng.config.HideAppInfoEntrance, |
|
Icon: icon.Info, |
|
BtnName: types.NavBtnInfoName, |
|
URL: "/application/info", |
|
Title: "site info", |
|
TitleScore: "system", |
|
}, { |
|
Exist: !eng.config.HidePluginEntrance, |
|
Icon: icon.Th, |
|
BtnName: types.NavBtnPlugName, |
|
URL: "/plugins", |
|
Title: "plugins", |
|
TitleScore: "plugin", |
|
}, |
|
} |
|
} |
|
|
|
func (eng *Engine) initSiteSetting() { |
|
|
|
printInitMsg(language.Get("initialize configuration")) |
|
|
|
err := eng.config.Update(models.Site(). |
|
SetConn(eng.DefaultConnection()). |
|
Init(eng.config.ToMap()). |
|
AllToMap()) |
|
if err != nil { |
|
logger.Panic(err) |
|
} |
|
eng.Services.Add("config", config.SrvWithConfig(eng.config)) |
|
|
|
errors.Init() |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (eng *Engine) Content(ctx interface{}, panel types.GetPanelFn) { |
|
if eng.Adapter == nil { |
|
emptyAdapterPanic() |
|
} |
|
eng.Adapter.Content(ctx, panel, eng.AdminPlugin().GetAddOperationFn(), *eng.NavButtons...) |
|
} |
|
|
|
|
|
|
|
func Content(ctx interface{}, panel types.GetPanelFn) { |
|
if defaultAdapter == nil { |
|
emptyAdapterPanic() |
|
} |
|
defaultAdapter.Content(ctx, panel, engine.AdminPlugin().GetAddOperationFn(), *navButtons...) |
|
} |
|
|
|
|
|
func (eng *Engine) Data(method, url string, handler context.Handler, noAuth ...bool) { |
|
if len(noAuth) > 0 && noAuth[0] { |
|
eng.Adapter.AddHandler(method, url, eng.wrap(handler)) |
|
} else { |
|
eng.Adapter.AddHandler(method, url, eng.wrapWithAuthMiddleware(handler)) |
|
} |
|
} |
|
|
|
|
|
func (eng *Engine) HTML(method, url string, fn types.GetPanelInfoFn, noAuth ...bool) { |
|
|
|
var handler = func(ctx *context.Context) { |
|
panel, err := fn(ctx) |
|
if err != nil { |
|
panel = template.WarningPanel(ctx, err.Error()) |
|
} |
|
|
|
eng.AdminPlugin().GetAddOperationFn()(panel.Callbacks...) |
|
|
|
var ( |
|
tmpl, tmplName = template.Default(ctx).GetTemplate(ctx.IsPjax()) |
|
|
|
user = auth.Auth(ctx) |
|
buf = new(bytes.Buffer) |
|
) |
|
|
|
hasError := tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(ctx, &types.NewPageParam{ |
|
User: user, |
|
Menu: menu.GetGlobalMenu(user, eng.Adapter.GetConnection(), ctx.Lang()).SetActiveClass(config.URLRemovePrefix(ctx.Path())), |
|
Panel: panel.GetContent(eng.config.IsProductionEnvironment()), |
|
Assets: template.GetComponentAssetImportHTML(ctx), |
|
Buttons: eng.NavButtons.CheckPermission(user), |
|
TmplHeadHTML: template.Default(ctx).GetHeadHTML(), |
|
TmplFootJS: template.Default(ctx).GetFootJS(), |
|
Iframe: ctx.IsIframe(), |
|
})) |
|
|
|
if hasError != nil { |
|
logger.Error(fmt.Sprintf("error: %s adapter content, ", eng.Adapter.Name()), hasError) |
|
} |
|
|
|
ctx.HTMLByte(http.StatusOK, buf.Bytes()) |
|
} |
|
|
|
if len(noAuth) > 0 && noAuth[0] { |
|
eng.Adapter.AddHandler(method, url, eng.wrap(handler)) |
|
} else { |
|
eng.Adapter.AddHandler(method, url, eng.wrapWithAuthMiddleware(handler)) |
|
} |
|
} |
|
|
|
|
|
|
|
func (eng *Engine) HTMLFile(method, url, path string, data map[string]interface{}, noAuth ...bool) { |
|
|
|
var handler = func(ctx *context.Context) { |
|
|
|
cbuf := new(bytes.Buffer) |
|
|
|
t, err := template2.ParseFiles(path) |
|
if err != nil { |
|
eng.errorPanelHTML(ctx, cbuf, err) |
|
return |
|
} else if err := t.Execute(cbuf, data); err != nil { |
|
eng.errorPanelHTML(ctx, cbuf, err) |
|
return |
|
} |
|
|
|
var ( |
|
tmpl, tmplName = template.Default(ctx).GetTemplate(ctx.IsPjax()) |
|
|
|
user = auth.Auth(ctx) |
|
buf = new(bytes.Buffer) |
|
) |
|
|
|
hasError := tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(ctx, &types.NewPageParam{ |
|
User: user, |
|
Menu: menu.GetGlobalMenu(user, eng.Adapter.GetConnection(), ctx.Lang()).SetActiveClass(eng.config.URLRemovePrefix(ctx.Path())), |
|
Panel: types.Panel{ |
|
Content: template.HTML(cbuf.String()), |
|
}, |
|
Assets: template.GetComponentAssetImportHTML(ctx), |
|
Buttons: eng.NavButtons.CheckPermission(user), |
|
TmplHeadHTML: template.Default(ctx).GetHeadHTML(), |
|
TmplFootJS: template.Default(ctx).GetFootJS(), |
|
Iframe: ctx.IsIframe(), |
|
})) |
|
|
|
if hasError != nil { |
|
logger.Error(fmt.Sprintf("error: %s adapter content, ", eng.Adapter.Name()), hasError) |
|
} |
|
|
|
ctx.HTMLByte(http.StatusOK, buf.Bytes()) |
|
} |
|
|
|
if len(noAuth) > 0 && noAuth[0] { |
|
eng.Adapter.AddHandler(method, url, eng.wrap(handler)) |
|
} else { |
|
eng.Adapter.AddHandler(method, url, eng.wrapWithAuthMiddleware(handler)) |
|
} |
|
} |
|
|
|
|
|
|
|
func (eng *Engine) HTMLFiles(method, url string, data map[string]interface{}, files ...string) { |
|
eng.Adapter.AddHandler(method, url, eng.wrapWithAuthMiddleware(eng.htmlFilesHandler(data, files...))) |
|
} |
|
|
|
|
|
|
|
func (eng *Engine) HTMLFilesNoAuth(method, url string, data map[string]interface{}, files ...string) { |
|
eng.Adapter.AddHandler(method, url, eng.wrap(eng.htmlFilesHandler(data, files...))) |
|
} |
|
|
|
|
|
|
|
func (eng *Engine) htmlFilesHandler(data map[string]interface{}, files ...string) context.Handler { |
|
return func(ctx *context.Context) { |
|
|
|
cbuf := new(bytes.Buffer) |
|
|
|
t, err := template2.ParseFiles(files...) |
|
if err != nil { |
|
eng.errorPanelHTML(ctx, cbuf, err) |
|
return |
|
} else if err := t.Execute(cbuf, data); err != nil { |
|
eng.errorPanelHTML(ctx, cbuf, err) |
|
return |
|
} |
|
|
|
var ( |
|
tmpl, tmplName = template.Default(ctx).GetTemplate(ctx.IsPjax()) |
|
|
|
user = auth.Auth(ctx) |
|
buf = new(bytes.Buffer) |
|
) |
|
|
|
hasError := tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(ctx, &types.NewPageParam{ |
|
User: user, |
|
Menu: menu.GetGlobalMenu(user, eng.Adapter.GetConnection(), ctx.Lang()).SetActiveClass(eng.config.URLRemovePrefix(ctx.Path())), |
|
Panel: types.Panel{ |
|
Content: template.HTML(cbuf.String()), |
|
}, |
|
Assets: template.GetComponentAssetImportHTML(ctx), |
|
Buttons: eng.NavButtons.CheckPermission(user), |
|
TmplHeadHTML: template.Default(ctx).GetHeadHTML(), |
|
TmplFootJS: template.Default(ctx).GetFootJS(), |
|
Iframe: ctx.IsIframe(), |
|
})) |
|
|
|
if hasError != nil { |
|
logger.Error(fmt.Sprintf("error: %s adapter content, ", eng.Adapter.Name()), hasError) |
|
} |
|
|
|
ctx.HTMLByte(http.StatusOK, buf.Bytes()) |
|
} |
|
} |
|
|
|
|
|
func (eng *Engine) errorPanelHTML(ctx *context.Context, buf *bytes.Buffer, err error) { |
|
|
|
user := auth.Auth(ctx) |
|
tmpl, tmplName := template.Default(ctx).GetTemplate(ctx.IsPjax()) |
|
|
|
hasError := tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(ctx, &types.NewPageParam{ |
|
User: user, |
|
Menu: menu.GetGlobalMenu(user, eng.Adapter.GetConnection(), ctx.Lang()).SetActiveClass(eng.config.URLRemovePrefix(ctx.Path())), |
|
Panel: template.WarningPanel(ctx, err.Error()).GetContent(eng.config.IsProductionEnvironment()), |
|
Assets: template.GetComponentAssetImportHTML(ctx), |
|
Buttons: (*eng.NavButtons).CheckPermission(user), |
|
TmplHeadHTML: template.Default(ctx).GetHeadHTML(), |
|
TmplFootJS: template.Default(ctx).GetFootJS(), |
|
Iframe: ctx.IsIframe(), |
|
})) |
|
|
|
if hasError != nil { |
|
logger.Error(fmt.Sprintf("error: %s adapter content, ", eng.Adapter.Name()), hasError) |
|
} |
|
|
|
ctx.HTMLByte(http.StatusOK, buf.Bytes()) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
func (eng *Engine) AddGenerators(list ...table.GeneratorList) *Engine { |
|
plug, exist := eng.FindPluginByName("admin") |
|
if exist { |
|
plug.(*admin.Admin).AddGenerators(list...) |
|
return eng |
|
} |
|
eng.PluginList = append(eng.PluginList, admin.NewAdmin(list...)) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AdminPlugin() *admin.Admin { |
|
plug, exist := eng.FindPluginByName("admin") |
|
if exist { |
|
return plug.(*admin.Admin) |
|
} |
|
adm := admin.NewAdmin() |
|
eng.PluginList = append(eng.PluginList, adm) |
|
return adm |
|
} |
|
|
|
|
|
func (eng *Engine) SetCaptcha(captcha map[string]string) *Engine { |
|
eng.AdminPlugin().SetCaptcha(captcha) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) SetCaptchaDriver(driver string) *Engine { |
|
eng.AdminPlugin().SetCaptcha(map[string]string{"driver": driver}) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddGenerator(key string, g table.Generator) *Engine { |
|
eng.AdminPlugin().AddGenerator(key, g) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddGlobalDisplayProcessFn(f types.FieldFilterFn) *Engine { |
|
types.AddGlobalDisplayProcessFn(f) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddDisplayFilterLimit(limit int) *Engine { |
|
types.AddLimit(limit) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddDisplayFilterTrimSpace() *Engine { |
|
types.AddTrimSpace() |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddDisplayFilterSubstr(start int, end int) *Engine { |
|
types.AddSubstr(start, end) |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddDisplayFilterToTitle() *Engine { |
|
types.AddToTitle() |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddDisplayFilterToUpper() *Engine { |
|
types.AddToUpper() |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddDisplayFilterToLower() *Engine { |
|
types.AddToUpper() |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddDisplayFilterXssFilter() *Engine { |
|
types.AddXssFilter() |
|
return eng |
|
} |
|
|
|
|
|
func (eng *Engine) AddDisplayFilterXssJsFilter() *Engine { |
|
types.AddXssJsFilter() |
|
return eng |
|
} |
|
|