8000 listing: add WrapTable && presets: cfTime Disabled by molon · Pull Request #543 · qor5/admin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

listing: add WrapTable && presets: cfTime Disabled #543

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
Sep 3, 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
12 changes: 10 additions & 2 deletions docs/docsrc/examples/examples_presets/detailing_inline_edit.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package examples_presets

import (
"database/sql/driver"
"encoding/json"
"fmt"
"log"

"database/sql/driver"
"github.com/qor5/admin/v3/media"
"github.com/qor5/admin/v3/presets"
"github.com/qor5/admin/v3/presets/gorm2op"
Expand Down Expand Up @@ -263,6 +263,13 @@ func PresetsDetailNestedMany(b *presets.Builder, db *gorm.DB) (
return columns, nil
}
})
// You can also wrap the table if you need
ccmb2.Listing().WrapTable(func(in presets.TableProcessor) presets.TableProcessor {
return func(evCtx *web.EventContext, table *vx.DataTableBuilder) (*vx.DataTableBuilder, error) {
table.Hover(false)
return in(evCtx, table)
}
})

dp.Field("CreditCards2").Use(ccmb2)
return
Expand Down Expand Up @@ -297,7 +304,8 @@ func (creditCard *creditCards) Scan(data interface{}) (err error) {
func PresetsDetailListSection(b *presets.Builder, db *gorm.DB) (cust *presets.ModelBuilder,
cl *presets.ListingBuilder,
ce *presets.EditingBuilder,
dp *presets.DetailingBuilder) {
dp *presets.DetailingBuilder,
) {
err := db.AutoMigrate(&UserCreditCard{})
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion docs/docsrc/examples/examples_presets/detailing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ - 10000 175,7 +175,7 @@ func TestPresetsDetailNestedMany(t *testing.T) {
"&id=12").
BuildEventFuncRequest()
},
ExpectPortalUpdate0ContainsInOrder: []string{"Felix 1"},
ExpectPortalUpdate0ContainsInOrder: []string{"Felix 1", ":hover='true'", "95550012", ":hover='false'", "95550012"},
},
}

Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,6 @@ github.com/qor5/web v1.3.2 h1:zw796YJeDLe8vRwGR1cM+uS1ZuSkPutchBEXv2GgOhI=
github.com/qor5/web v1.3.2/go.mod h1:LszskQJbFQDJwOeZC6j6afOiHxxyjrzz8B3zuBwfgKQ=
github.com/qor5/web/v3 v3.0.7 h1:1+Ezbl+1m9oZ4S1kcFKybyi6at6qxoY7eJqjb3JETQQ=
github.com/qor5/web/v3 v3.0.7/go.mod h1:32vdHHcZb2JimlcaclW9hLUyimdXjrllZDHTh3rl6d0=
github.com/qor5/x/v3 v3.0.8 h1:orSn34zBSBlAvumWyvmPxjXb8blJ2qGKHZy+8x4Y0gQ=
github.com/qor5/x/v3 v3.0.8/go.mod h1:a+cSXd5UjIOgzhhpvfDxDUdjmKLKeDLeoubcQ9dkxtE=
github.com/qor5/x/v3 v3.0.9-0.20240830065723-63a1ee683f35 h1:S0PNHelYvywRb1gnytDIeU6ICHcpXGK2CYTHSk1HiIY=
github.com/qor5/x/v3 v3.0.9-0.20240830065723-63a1ee683f35/go.mod h1:a+cSXd5UjIOgzhhpvfDxDUdjmKLKeDLeoubcQ9dkxtE=
github.com/qor5/x/v3 v3.0.9-0.20240830095515-24fddd1fdf8f h1:tUAw2vElX+1hHdrzIu+P3H9+BAGnDbXBqI3gPgGNznE=
github.com/qor5/x/v3 v3.0.9-0.20240830095515-24fddd1fdf8f/go.mod h1:a+cSXd5UjIOgzhhpvfDxDUdjmKLKeDLeoubcQ9dkxtE=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
Expand Down
19 changes: 10 additions & 9 deletions presets/field_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@
}).
DialogWidth(640).
ClearText(msgr.Clear).
OkText(msgr.OK)
OkText(msgr.OK).
Disabled(field.Disabled)

Check warning on line 219 in presets/field_defaults.go

View check run for this annotation

Codecov / codecov/patch

presets/field_defaults.go#L218-L219

Added lines #L218 - L219 were not covered by tests
}

func cfTimeSetter(obj interface{}, field *FieldContext, ctx *web.EventContext) (err error) {
Expand All @@ -234,14 +235,14 @@
return h.Div(
h.Span(field.Label).Class("text-subtitle-2 text-high-emphasis section-filed-label mb-1 d-sm-inline-block"),
VTextField().
Density(DensityComfortable).
Class("section-field").
Type("text").
Variant(FieldVariantOutlined).
BgColor(ColorBackground).
Attr(web.VField(field.FormKey, fmt.Sprint(reflectutils.MustGet(obj, field.Name)))...).
ErrorMessages(field.Errors...).
Disabled(field.Disabled),
Density(DensityComfortable).
Class("section-field").
Type("text").
Variant(FieldVariantOutlined).
BgColor(ColorBackground).
Attr(web.VField(field.FormKey, fmt.Sprint(reflectutils.MustGet(obj, field.Name)))...).
ErrorMessages(field.Errors...).
Disabled(field.Disabled),
).Class("section-field-wrap")
}

Expand Down
13 changes: 13 additions & 0 deletions presets/listing_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ColumnsProcessor func(evCtx *web.EventContext, columns []*Column) ([]*Column, error)
CellProcessor func(evCtx *web.EventContext, cell h.MutableAttrHTMLComponent, id string, obj any) (h.MutableAttrHTMLComponent, error)
RowProcessor func(evCtx *web.EventContext, row h.MutableAttrHTMLComponent, id string, obj any) (h.MutableAttrHTMLComponent, error)
TableProcessor func(evCtx *web.EventContext, table *vx.DataTableBuilder) (*vx.DataTableBuilder, error)
)

type OrderableField struct {
Expand All @@ -48,6 +49,7 @@
cellWrapperFunc vx.CellWrapperFunc
cellProcessor CellProcessor
rowProcessor RowProcessor
tableProcessor TableProcessor
Searcher SearchFunc
searchColumns []string
titleFunc func(evCtx *web.EventContext, style ListingStyle, defaultTitle string) (title string, titleCompo h.HTMLComponent, err error)
Expand Down Expand Up @@ -140,6 +142,17 @@
return b
}

func (b *ListingBuilder) WrapTable(w func(in TableProcessor) TableProcessor) (r *ListingBuilder) {
if b.tableProcessor == nil {
b.tableProcessor = w(func(evCtx *web.EventContext, table *vx.DataTableBuilder) (*vx.DataTableBuilder, error) {
return table, nil
})
} else {
b.tableProcessor = w(b.tableProcessor)

Check warning on line 151 in presets/listing_builder.go

View check run for this annotation

Codecov / codecov/patch

presets/listing_builder.go#L150-L151

Added lines #L150 - L151 were not covered by tests
}
return b
}

func (b *ListingBuilder) DisablePagination(v bool) (r *ListingBuilder) {
b.disablePagination = v
return b
Expand Down
7 changes: 7 additions & 0 deletions presets/listing_compo.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,13 @@
dataTable.Column(col.Name).Title(col.Label).CellComponentFunc(c.lb.cellComponentFunc(f))
}

if c.lb.tableProcessor != nil {
dataTable, err = c.lb.tableProcessor(evCtx, dataTable)
if err != nil {
panic(err)

Check warning on line 589 in presets/listing_compo.go

View check run for this annotation

Codecov / codecov/patch

presets/listing_compo.go#L589

Added line #L589 was not covered by tests
}
}

var dataTableAdditions h.HTMLComponent
if totalCount <= 0 {
dataTableAdditions = h.Div().Class("mt-10 text-center grey--text text--darken-2").Children(
Expand Down
Loading
0