diff --git a/compose/page.cue b/compose/page.cue index 3f96cbc28..bff0af7a2 100644 --- a/compose/page.cue +++ b/compose/page.cue @@ -58,6 +58,30 @@ page: schema.#Resource & { keys: { title: {} description: {} + recordToolbarButtonNewLabel: { + path: ["recordToolbar", "new", "label"] + customHandler: true + } + recordToolbarButtonEditLabel: { + path: ["recordToolbar", "edit", "label"] + customHandler: true + } + recordToolbarButtonSubmitLabel: { + path: ["recordToolbar", "submit", "label"] + customHandler: true + } + recordToolbarButtonDeleteLabel: { + path: ["recordToolbar", "delete", "label"] + customHandler: true + } + recordToolbarButtonCloneLabel: { + path: ["recordToolbar", "clone", "label"] + customHandler: true + } + recordToolbarButtonBackLabel: { + path: ["recordToolbar", "back", "label"] + customHandler: true + } blockTitle: { path: ["pageBlock", {part: "blockID", var: true}, "title"] customHandler: true diff --git a/compose/service/locale.go b/compose/service/locale.go index b60e723ec..360684e18 100644 --- a/compose/service/locale.go +++ b/compose/service/locale.go @@ -180,6 +180,51 @@ func (svc resourceTranslationsManager) pageExtended(ctx context.Context, res *ty ) for _, tag := range svc.locale.Tags() { + // Button translations + if res.Config.Buttons != nil { + out = append(out, &locale.ResourceTranslation{ + Resource: res.ResourceTranslation(), + Lang: tag.String(), + Key: types.LocaleKeyPageRecordToolbarNewLabel.Path, + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), types.LocaleKeyPageRecordToolbarNewLabel.Path), + }) + + out = append(out, &locale.ResourceTranslation{ + Resource: res.ResourceTranslation(), + Lang: tag.String(), + Key: types.LocaleKeyPageRecordToolbarEditLabel.Path, + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), types.LocaleKeyPageRecordToolbarEditLabel.Path), + }) + + out = append(out, &locale.ResourceTranslation{ + Resource: res.ResourceTranslation(), + Lang: tag.String(), + Key: types.LocaleKeyPageRecordToolbarSubmitLabel.Path, + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), types.LocaleKeyPageRecordToolbarSubmitLabel.Path), + }) + + out = append(out, &locale.ResourceTranslation{ + Resource: res.ResourceTranslation(), + Lang: tag.String(), + Key: types.LocaleKeyPageRecordToolbarDeleteLabel.Path, + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), types.LocaleKeyPageRecordToolbarDeleteLabel.Path), + }) + + out = append(out, &locale.ResourceTranslation{ + Resource: res.ResourceTranslation(), + Lang: tag.String(), + Key: types.LocaleKeyPageRecordToolbarCloneLabel.Path, + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), types.LocaleKeyPageRecordToolbarCloneLabel.Path), + }) + + out = append(out, &locale.ResourceTranslation{ + Resource: res.ResourceTranslation(), + Lang: tag.String(), + Key: types.LocaleKeyPageRecordToolbarBackLabel.Path, + Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), types.LocaleKeyPageRecordToolbarBackLabel.Path), + }) + } + for i, block := range res.Blocks { pbContentID := locale.ContentID(block.BlockID, i) rpl := strings.NewReplacer( diff --git a/compose/types/locale.gen.go b/compose/types/locale.gen.go index 51e9e09c2..f50861c39 100644 --- a/compose/types/locale.gen.go +++ b/compose/types/locale.gen.go @@ -45,6 +45,12 @@ var ( LocaleKeyNamespaceMetaDescription = LocaleKey{Path: "meta.description"} LocaleKeyPageTitle = LocaleKey{Path: "title"} LocaleKeyPageDescription = LocaleKey{Path: "description"} + LocaleKeyPageRecordToolbarNewLabel = LocaleKey{Path: "recordToolbar.new.label"} + LocaleKeyPageRecordToolbarEditLabel = LocaleKey{Path: "recordToolbar.edit.label"} + LocaleKeyPageRecordToolbarSubmitLabel = LocaleKey{Path: "recordToolbar.submit.label"} + LocaleKeyPageRecordToolbarDeleteLabel = LocaleKey{Path: "recordToolbar.delete.label"} + LocaleKeyPageRecordToolbarCloneLabel = LocaleKey{Path: "recordToolbar.clone.label"} + LocaleKeyPageRecordToolbarBackLabel = LocaleKey{Path: "recordToolbar.back.label"} LocaleKeyPagePageBlockBlockIDTitle = LocaleKey{Path: "pageBlock.{{blockID}}.title"} LocaleKeyPagePageBlockBlockIDDescription = LocaleKey{Path: "pageBlock.{{blockID}}.description"} LocaleKeyPagePageBlockBlockIDButtonButtonIDLabel = LocaleKey{Path: "pageBlock.{{blockID}}.button.{{buttonID}}.label"} diff --git a/compose/types/page.go b/compose/types/page.go index acc7c5918..33bc88bf4 100644 --- a/compose/types/page.go +++ b/compose/types/page.go @@ -75,12 +75,28 @@ type ( Variants map[string]string `json:"variants,omitempty"` } + PageButton struct { + Label string `json:"label"` + Enabled bool `json:"enabled"` + } + + PageButtonConfig struct { + New PageButton `json:"new"` + Edit PageButton `json:"edit"` + Submit PageButton `json:"submit"` + Delete PageButton `json:"delete"` + Clone PageButton `json:"clone"` + Back PageButton `json:"back"` + } + PageConfig struct { // How page is presented in the navigation NavItem struct { Icon *PageConfigIcon `json:"icon,omitempty"` } `json:"navItem"` + Buttons *PageButtonConfig `json:"buttons,omitempty"` + //// Example how page-config structure can evolve in the future //Views []struct { // // what kind of output is this view intended for (screen, mobile...?) @@ -166,6 +182,28 @@ func (m Page) Clone() *Page { func (p *Page) decodeTranslations(tt locale.ResourceTranslationIndex) { var aux *locale.ResourceTranslation + // Buttons here + if p.Config.Buttons != nil { + if aux = tt.FindByKey(LocaleKeyPageRecordToolbarNewLabel.Path); aux != nil { + p.Config.Buttons.New.Label = aux.Msg + } + if aux = tt.FindByKey(LocaleKeyPageRecordToolbarEditLabel.Path); aux != nil { + p.Config.Buttons.Edit.Label = aux.Msg + } + if aux = tt.FindByKey(LocaleKeyPageRecordToolbarSubmitLabel.Path); aux != nil { + p.Config.Buttons.Submit.Label = aux.Msg + } + if aux = tt.FindByKey(LocaleKeyPageRecordToolbarDeleteLabel.Path); aux != nil { + p.Config.Buttons.Delete.Label = aux.Msg + } + if aux = tt.FindByKey(LocaleKeyPageRecordToolbarCloneLabel.Path); aux != nil { + p.Config.Buttons.Clone.Label = aux.Msg + } + if aux = tt.FindByKey(LocaleKeyPageRecordToolbarBackLabel.Path); aux != nil { + p.Config.Buttons.Back.Label = aux.Msg + } + } + for i, block := range p.Blocks { blockID := locale.ContentID(block.BlockID, i) rpl := strings.NewReplacer( @@ -213,7 +251,10 @@ func (p *Page) decodeTranslations(tt locale.ResourceTranslationIndex) { } func (p *Page) encodeTranslations() (out locale.ResourceTranslationSet) { - out = make(locale.ResourceTranslationSet, 0, 3) + out = make(locale.ResourceTranslationSet, 0, 12) + + // Button translations don't need to happen here as we don't do anything with buttons at the moment + // @todo when we add custom buttons this should change // Page blocks for i, block := range p.Blocks { @@ -386,5 +427,8 @@ func (bb *PageConfig) Scan(value interface{}) error { } func (bb PageConfig) Value() (driver.Value, error) { + // We're not saving button config to the DB; no need for it + bb.Buttons = nil + return json.Marshal(bb) }