123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package admin
- import (
- "net/http"
- "github.com/qor5/admin/pagebuilder"
- "github.com/qor5/admin/pagebuilder/example"
- "github.com/qor5/admin/presets"
- "github.com/qor5/admin/presets/gorm2op"
- "github.com/qor5/admin/utils"
- "github.com/qor5/ui/vuetify"
- "github.com/qor5/web"
- "github.com/qor5/x/perm"
- h "github.com/theplant/htmlgo"
- "golang.org/x/text/language"
- )
- const (
- PublishDir = "./publish"
- )
- type Config struct {
- pb *presets.Builder
- pageBuilder *pagebuilder.Builder
- }
- func InitApp() *http.ServeMux {
- c := newPB()
- mux := SetupRouter(c)
- return mux
- }
- func newPB() Config {
- db := ConnectDB()
- b := presets.New().VuetifyOptions(`
- {
- icons: {
- iconfont: 'md', // 'mdi' || 'mdiSvg' || 'md' || 'fa' || 'fa4'
- },
- theme: {
- themes: {
- light: {
- primary: "#ed6f2d",
- secondary: "#009688",
- accent: "#ff5722",
- error: "#f44336",
- warning: "#ff9800",
- info: "#8bc34a",
- success: "#4caf50"
- },
- },
- },
- }
- `)
- b.URIPrefix("/admin").DataOperator(gorm2op.DataOperator(db)).
- BrandFunc(func(ctx *web.EventContext) h.HTMLComponent {
- logo := `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAESElEQVR4Xu1aS1LbQBDVSLYhq8AJsE8A3MAs+KyCfQNYJlSq7BMEToCphGQZOEHEjs8C5wTxDeKcIMoqhXGkdLsk12ikkWakMR7wTBULrPl0v3790aiJteCDLLj+lgHAMGDBEXgSF2g2myvVarUug7XjON719fVQZk2RuTMDAJWu1WodQsg+CIbKrxQRENa4QRBc3t7eugXXZy6bCQB7e3tNEPprqLgquXs3NzddVZtF+ygHAJSvg/I/Slg8S0cXQGirBEE5ALu7u99AwBYj5AD+l/VndJkNFkgAt63SHZQCEFL/nlLeA4EPywicAugAWLCpigXCAG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/Wl1tQTqXL0C0HYcd4T6SzTBgApWJqtJkBQCNjzEUUw4C5wK7RoQvPgP92SnFu7MAGXwAAAABJRU5ErkJggg==`
- return vuetify.VContainer(
- h.Img(logo).Attr("width", "120"),
- ).Class("ma-n4")
- }).
- HomePageFunc(func(ctx *web.EventContext) (r web.PageResponse, err error) {
- r.Body = vuetify.VContainer(
- h.H1("Home"),
- h.P().Text("Change your home page here"))
- return
- })
- b.Permission(
- perm.New().Policies(
- perm.PolicyFor(perm.Anybody).WhoAre(perm.Allowed).ToDo(presets.PermCreate, presets.PermUpdate, presets.PermDelete, presets.PermGet, presets.PermList).On("*"),
- perm.PolicyFor(perm.Anybody).WhoAre(perm.Denied).ToDo(presets.PermCreate, presets.PermUpdate, presets.PermDelete).On("*:activity_logs:*"),
- ),
- )
- utils.Configure(b)
- //ab := activity.New(b, db).SetCreatorContextKey(login.UserKey)
- //l10nBuilder := l10n.New()
- pageBuilder := example.ConfigPageBuilder(db, "/admin/page_builder", ``, b.I18n())
- //pm := pageBuilder.Configure(b, db, l10nBuilder, ab, nil, nil)
- //tm := pageBuilder.ConfigTemplate(b, db)
- //cm := pageBuilder.ConfigCategory(b, db, nil)
- //ab.RegisterModels(pm, tm, cm)
- b.I18n().
- SupportLanguages(language.English, language.SimplifiedChinese).
- RegisterForModule(language.English, I18nExampleKey, Messages_en_US).
- RegisterForModule(language.SimplifiedChinese, I18nExampleKey, Messages_zh_CN).
- RegisterForModule(language.SimplifiedChinese, presets.ModelsI18nModuleKey, Messages_zh_CN_ModelsI18nModuleKey).
- GetSupportLanguagesFromRequestFunc(func(r *http.Request) []language.Tag {
- return b.I18n().GetSupportLanguages()
- })
- b.MenuOrder(
- b.MenuGroup("Page Builder").SubItems("pages", "page_templates", "page_categories").Icon("web"),
- "shared_containers",
- )
- initWebsiteData(db)
- return Config{
- pb: b,
- pageBuilder: pageBuilder,
- }
- }
|