8000 fix PageLayout by zhangshanwen · Pull Request #277 · qor5/admin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix PageLayout #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions docs/docsrc/examples/examples_admin/page_builder_with_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,23 @@
b.Use(puBuilder)

pb := pagebuilder.New(b.GetURIPrefix()+"/page_builder", db, b.I18n()).
Publisher(puBuilder)
Publisher(puBuilder).WrapPageLayout(func(v pagebuilder.PageLayoutFunc) pagebuilder.PageLayoutFunc {
return func(body HTMLComponent, input *pagebuilder.PageLayoutInput, ctx *web.EventContext) HTMLComponent {
input.FreeStyleCss = append(input.FreeStyleCss, `.test-div { width: 200px;background-color:#E1E1E1; }`)
input.FreeStyleTopJs = append(input.FreeStyleTopJs, `console.log("free style")`)
input.Footer = Components(
Style(`.test-div1 { width: 300px;background-color:blue; }`),
Style(`.test-div2 { width: 400px;background-color:red; }`),
Script("console.log('in footer')"),
)
return v(body, input, ctx)
}
})

header := pb.RegisterContainer("MyContent").Group("Navigation").
RenderFunc(func(obj interface{}, input *pagebuilder.RenderInput, ctx *web.EventContext) HTMLComponent {
c := obj.(*MyContent)
return Div().Text(c.Text).Style("height:200px")
return Div().Text(c.Text).Class("test-div")
}).Cover("https://qor5.com/img/qor-logo.png")

ed := header.Model(&MyContent{}).Editing("Text", "Color")
Expand All @@ -183,7 +194,7 @@
pb.RegisterModelContainer("CampaignContent", campaignModelBuilder).Group("Campaign").
RenderFunc(func(obj interface{}, input *pagebuilder.RenderInput, ctx *web.EventContext) HTMLComponent {
c := obj.(*CampaignContent)
return Div(Text(c.Title)).Style("height:200px")
return Div(Text(c.Title)).Class("test-div1")

Check warning on line 197 in docs/docsrc/examples/examples_admin/page_builder_with_campaign.go

View check run for this annotation

Codecov / codecov/patch

docs/docsrc/examples/examples_admin/page_builder_with_campaign.go#L197

Added line #L197 was not covered by tests
}).Model(&CampaignContent{}).Editing("Title", "Banner")

campaignModelBuilder.Use(pb)
Expand All @@ -202,7 +213,7 @@
pb.RegisterModelContainer("ProductContent", productModelBuilder).Group("CampaignProduct").
RenderFunc(func(obj interface{}, input *pagebuilder.RenderInput, ctx *web.EventContext) HTMLComponent {
c := obj.(*ProductContent)
return Div(Text(c.Name)).Style("height:200px")
return Div(Text(c.Name)).Class("test-div2")

Check warning on line 216 in docs/docsrc/examples/examples_admin/page_builder_with_campaign.go

View check run for this annotation

Codecov / codecov/patch

docs/docsrc/examples/examples_admin/page_builder_with_campaign.go#L216

Added line #L216 was not covered by tests
}).Model(&ProductContent{}).Editing("Name")

productModelBuilder.Use(pb)
Expand Down
7 changes: 6 additions & 1 deletion pagebuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ create unique index if not exists uidx_page_builder_demo_containers_model_name_l
r.templateInstall = r.defaultTemplateInstall
r.categoryInstall = r.defaultCategoryInstall
r.pageInstall = r.defaultPageInstall
r.pageLayoutFunc = defaultPageLayoutFunc

r.ps = presets.New().
BrandTitle("Page Builder").
Expand Down Expand Up @@ -184,6 +185,11 @@ func (b *Builder) PageLayout(v PageLayoutFunc) (r *Builder) {
return b
}

func (b *Builder) WrapPageLayout(warp func(v PageLayoutFunc) PageLayoutFunc) (r *Builder) {
b.pageLayoutFunc = warp(b.pageLayoutFunc)
return b
}

func (b *Builder) SubPageTitle(v SubPageTitleFunc) (r *Builder) {
b.subPageTitleFunc = v
return b
Expand Down Expand Up @@ -288,7 +294,6 @@ func (b *Builder) ModelInstall(pb *presets.Builder, mb *presets.ModelBuilder) (e
b.configEditor(r)
b.configPublish(r)
b.configDetail(r)
b.pageLayoutFunc = DefaultPageLayoutFunc
return nil
}

Expand Down
1 change: 0 additions & 1 deletion pagebuilder/example/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func ConfigPageBuilder(db *gorm.DB, prefix, style string, i18nB *i18n.Builder) *
pb.GetPresetsBuilder().ExtraAsset("/redactor.js", "text/javascript", richeditor.JSComponentsPack())
pb.GetPresetsBuilder().ExtraAsset("/redactor.css", "text/css", richeditor.CSSComponentsPack())

pb.PageLayout(pagebuilder.DefaultPageLayoutFunc)
fSys, _ := fs.Sub(containerImages, "assets/images")
imagePrefix := "/assets/images"
pb.Images(http.StripPrefix(path.Join(prefix, imagePrefix), http.FileServer(http.FS(fSys))), imagePrefix)
Expand Down
2 changes: 1 addition & 1 deletion pagebuilder/page_layout.go
66DF
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
h "github.com/theplant/htmlgo"
)

func DefaultPageLayoutFunc(body h.HTMLComponent, input *PageLayoutInput, ctx *web.EventContext) h.HTMLComponent {
func defaultPageLayoutFunc(body h.HTMLComponent, input *PageLayoutInput, ctx *web.EventContext) h.HTMLComponent {
var freeStyleCss h.HTMLComponent
if len(input.FreeStyleCss) > 0 {
freeStyleCss = h.Style(strings.Join(input.FreeStyleCss, "\n"))
Expand Down
Loading
0