8000 listing title func by molon · Pull Request #334 · qor5/admin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

listing title func #334

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 5 commits into from
Jul 22, 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
6 changes: 1 addition & 5 deletions activity/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ func (ab *Builder) defaultLogModelInstall(b *presets.Builder, mb *presets.ModelB
})

lb.NewButtonFunc(func(ctx *web.EventContext) h.HTMLComponent { return nil })

// TODO: should be able to delete log ?
lb.RowMenu().RowMenuItem("Delete").ComponentFunc(func(obj any, id string, ctx *web.EventContext) h.HTMLComponent {
return nil
})
lb.RowMenu().Empty()

lb.Field("CreatedAt").Label(Messages_en_US.ModelCreatedAt).ComponentFunc(
func(obj any, field *presets.FieldContext, ctx *web.EventContext) h.HTMLComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func EnsureVersionListDisplay(selected string, dislayModels []*examples_admin.Wi
"active_filter_tab", "f_named_versions", "f_select_id", selected, "Named Versions",
"</v-tabs>",
// Ensure columns display
"<tr>", "<th>Version</th>", "<th>State</th>", "<th>Start at</th>", "<th>End at</th>", "<th>Notes</th>", "<th>Option</th>", "</tr>",
"<tr>", "<th>Version</th>", "<th>Status</th>", "<th>Start at</th>", "<th>End at</th>", "<th>Notes</th>", "<th>Option</th>", "</tr>",
),
// Ensure list content display
testflow.WrapEvent(func(t *testing.T, w *httptest.ResponseRecorder, r *http.Request, e multipartestutils.TestEventResponse) {
Expand Down
23 changes: 22 additions & 1 deletion example/admin/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,14 @@ type Messages_ModelsI18nModuleKey struct {
PagesLocale string
PagesNotes string
PagesDraftCount string
PagesPath string
PagesOnline string
PagesVersion string
PagesVersions string
PagesStartAt string
PagesEndAt string
PagesOption string
PagesLive string

Page string
PagesStatus string
Expand Down Expand Up @@ -338,10 +345,17 @@ var Messages_zh_CN_ModelsI18nModuleKey = &Messages_ModelsI18nModuleKey{
PagesLocale: "地区",
PagesNotes: "备注",
PagesDraftCount: "草稿数",
PagesPath: "路径",
PagesOnline: "在线",
PagesVersion: "版本",
PagesVersions: "版本",
PagesStartAt: "开始时间",
PagesEndAt: "结束时间",
PagesOption: "选项",
PagesLive: "发布状态",

Page: "Page",
PagesStatus: "PagesStatus",
PagesStatus: "状态",
PagesSchedule: "PagesSchedule",
PagesCategoryID: "PagesCategoryID",
PagesTemplateSelection: "PagesTemplateSelection",
Expand Down Expand Up @@ -481,7 +495,14 @@ var Messages_ja_JP_ModelsI18nModuleKey = &Messages_ModelsI18nModuleKey{
PagesLocale: "ローカル",
PagesNotes: "ノート",
PagesDraftCount: "カウント下書き",
PagesPath: "パス",
PagesOnline: "オンライン",
PagesVersion: "バージョン",
PagesVersions: "バージョン",
PagesStartAt: "開始日時",
PagesEndAt: "終了日時",
PagesOption: "オプション",
PagesLive: "ライブ",

Page: "ページ",
PagesStatus: "状態",
Expand Down
11 changes: 7 additions & 4 deletions pagebuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,12 @@ func (b *Builder) configTemplateAndPage(pb *presets.Builder, r *ModelBuilder) {

func (b *Builder) defaultPageInstall(pb *presets.Builder, pm *presets.ModelBuilder) (err error) {
db := b.db
lb := pm.Listing("ID", "Title", publish.ListingFieldLive, "Path")

listingFields := []string{"ID", "Title", publish.ListingFieldLive, "Path"}
if b.ab != nil {
listingFields = append(listingFields, activity.ListFieldNotes)
}
lb := pm.Listing(listingFields...)
lb.Field("Path").ComponentFunc(func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) h.HTMLComponent {
page := obj.(*Page)
category, err := page.GetCategory(db)
Expand All @@ -433,15 +438,13 @@ func (b *Builder) defaultPageInstall(pb *presets.Builder, pm *presets.ModelBuild
}
return h.Td(h.Text(page.getAccessUrl(page.getPublishUrl(b.l10n.GetLocalePath(page.LocaleCode), category.Path))))
})

detailList := []interface{}{"Title", PageBuilderPreviewCard, "Page"}
if b.seoBuilder != nil {
detailList = append(detailList, seo.SeoDetailFieldName)
}

dp := pm.Detailing(detailList...)
if b.ab != nil {
detailList = append(detailList, activity.ListFieldNotes)
}
dp.Field("Title").ComponentFunc(func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) h.HTMLComponent {
var versionBadge *VChipBuilder
if v, ok := obj.(PrimarySlugInterface); ok {
Expand Down
33 changes: 24 additions & 9 deletions presets/listing_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

// title is the title of the listing page.
// its default value is "Listing ${modelName}".
title string
title string
titleFunc func(evCtx *web.EventContext) (string, error)

// perPage is the number of records per page.
// if request query param "per_page" is set, it will be set to that value.
Expand Down Expand Up @@ -121,6 +122,11 @@
return b
}

func (b *ListingBuilder) TitleFunc(f func(evCtx *web.EventContext) (string, error)) (r *ListingBuilder) {
b.titleFunc = f
return b
}

func (b *ListingBuilder) KeywordSearchOff(v bool) (r *ListingBuilder) {
b.keywordSearchOff = v
return b
Expand Down Expand Up @@ -213,10 +219,9 @@
return r, perm.PermissionDenied
}

msgr := MustGetMessages(evCtx.R)
title := b.title
if title == "" {
title = msgr.ListingObjectTitle(i18n.T(evCtx.R, ModelsI18nModuleKey, b.mb.label))
title, err := b.getTitle(evCtx)
if err != nil {
return r, err

Check warning on line 224 in presets/listing_builder.go

View check run for this annotation

Codecov / codecov/patch

presets/listing_builder.go#L224

Added line #L224 was not covered by tests
}
r.PageTitle = title

Expand All @@ -239,16 +244,26 @@
return
}

func (b *ListingBuilder) getTitle(evCtx *web.EventContext) (string, error) {
if b.titleFunc != nil {
return b.titleFunc(evCtx)
}
title := b.title
if title == "" {
title = MustGetMessages(evCtx.R).ListingObjectTitle(i18n.T(evCtx.R, ModelsI18nModuleKey, b.mb.label))
}
return title, nil
}

func (b *ListingBuilder) openListingDialog(evCtx *web.EventContext) (r web.EventResponse, err error) {
if b.mb.Info().Verifier().Do(PermList).WithReq(evCtx.R).IsAllowed() != nil {
err = perm.PermissionDenied
return
}

msgr := MustGetMessages(evCtx.R)
title := b.title
if title == "" {
title = msgr.ListingObjectTitle(i18n.T(evCtx.R, ModelsI18nModuleKey, b.mb.label))
title, err := b.getTitle(evCtx)
if err != nil {
return r, err

Check warning on line 266 in presets/listing_builder.go

View check run for this annotation

Codecov / codecov/patch

presets/listing_builder.go#L266

Added line #L266 was not covered by tests
}

evCtx.WithContextValue(ctxInDialog, true)
Expand Down
8 changes: 3 additions & 5 deletions presets/nested_many.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"github.com/jinzhu/inflection"
"github.com/pkg/errors"
"github.com/qor5/web/v3"
"github.com/qor5/x/v3/i18n"
"github.com/qor5/x/v3/perm"
. "github.com/qor5/x/v3/ui/vuetify"
"github.com/sunfmin/reflectutils"
Expand Down Expand Up @@ -108,10 +107,9 @@
return
}

msgr := MustGetMessages(evCtx.R)
title := b.title
if title == "" {
title = msgr.ListingObjectTitle(i18n.T(evCtx.R, ModelsI18nModuleKey, b.mb.label))
title, err := b.getTitle(evCtx)
if err != nil {
return r, err

Check warning on line 112 in presets/nested_many.go

View check run for this annotation

Codecov / codecov/patch

presets/nested_many.go#L112

Added line #L112 was not covered by tests
}
evCtx.WithContextValue(ctxInDialog, true)

Expand Down
24 changes: 15 additions & 9 deletions publish/version_compo.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,18 @@ func configureVersionListDialog(db *gorm.DB, pb *Builder, b *presets.Builder, pm

listingHref := mb.Info().ListingHref()
registerEventFuncsForVersion(mb, db)
listingFields := []string{"Version", "State", "StartAt", "EndAt", "Option"}
listingFields := []string{"Version", "Status", "StartAt", "EndAt", "Option"}
if pb.ab != nil {
defer func() { pb.ab.RegisterModel(mb) }()
listingFields = []string{"Version", "State", "StartAt", "EndAt", activity.ListFieldNotes, "Option"}
listingFields = []string{"Version", "Status", "StartAt", "EndAt", activity.ListFieldNotes, "Option"}
}

// TODO: i18n
lb := mb.Listing(listingFields...).
DialogWidth("900").
Title("Version List").
DialogWidth("900px").
TitleFunc(func(evCtx *web.EventContext) (string, error) {
msgr := i18n.MustGetModuleMessages(evCtx.R, I18nPublishKey, Messages_en_US).(*Messages)
return msgr.VersionsList, nil
}).
SearchColumns("version", "version_name").
PerPage(10).
WrapSearchFunc(func(in presets.SearchFunc) presets.SearchFunc {
Expand Down Expand Up @@ -317,7 +319,7 @@ func configureVersionListDialog(db *gorm.DB, pb *Builder, b *presets.Builder, pm
),
)
})
lb.Field("State").ComponentFunc(StatusListFunc())
lb.Field("Status").ComponentFunc(StatusListFunc())
lb.Field("StartAt").ComponentFunc(func(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) h.HTMLComponent {
p := obj.(ScheduleInterface)

Expand Down Expand Up @@ -367,6 +369,8 @@ func configureVersionListDialog(db *gorm.DB, pb *Builder, b *presets.Builder, pm
lb.NewButtonFunc(func(ctx *web.EventContext) h.HTMLComponent { return nil })
lb.DisableModelListeners(true)
lb.FooterAction("Cancel").ButtonCompFunc(func(evCtx *web.EventContext) h.HTMLComponent {
utilsMsgr := i18n.MustGetModuleMessages(evCtx.R, utils.I18nUtilsKey, utils.Messages_en_US).(*utils.Messages)

ctx := evCtx.R.Context()
c := presets.ListingCompoFromContext(ctx)
filter := MustFilterQuery(c)
Expand All @@ -384,13 +388,15 @@ func configureVersionListDialog(db *gorm.DB, pb *Builder, b *presets.Builder, pm
`, selected, filter.Encode(), filterKeySelected))).Go(),
),
),
v.VBtn("Cancel").Variant(v.VariantElevated).Attr("@click", "vars.presetsListingDialog=false"),
v.VBtn(utilsMsgr.Cancel).Variant(v.VariantElevated).Attr("@click", "vars.presetsListingDialog=false"),
)
})
lb.FooterAction("Save").ButtonCompFunc(func(ctx *web.EventContext) h.HTMLComponent {
lb.FooterAction("OK").ButtonCompFunc(func(ctx *web.EventContext) h.HTMLComponent {
utilsMsgr := i18n.MustGetModuleMessages(ctx.R, utils.I18nUtilsKey, utils.Messages_en_US).(*utils.Messages)

compo := presets.ListingCompoFromEventContext(ctx)
selected := MustFilterQuery(compo).Get(filterKeySelected)
return v.VBtn("Save").Disabled(selected == "").Variant(v.VariantElevated).Color(v.ColorSecondary).Attr("@click",
return v.VBtn(utilsMsgr.OK).Disabled(selected == "").Variant(v.VariantElevated).Color(v.ColorSecondary).Attr("@click",
fmt.Sprintf(`%s;%s;`,
presets.CloseListingDialogVarScript,
web.Emit(NotifVersionSelected(mb), PayloadVersionSelected{Slug: selected}),
Expand Down
Loading
0