3
0

Change page layout name to title, codegen config tweaks

This commit is contained in:
Tomaž Jerman 2023-03-27 16:38:46 +02:00 committed by Jože Fortun
parent 8437728af1
commit 9d37d8c949
9 changed files with 89 additions and 17 deletions

View File

@ -61,6 +61,8 @@ page: {
meta: {
goType: "*types.PageMeta"
dal: { type: "JSON", defaultEmptyObject: true }
omitSetter: true
omitGetter: true
}
config: {
goType: "types.PageConfig"

View File

@ -42,6 +42,8 @@ pageLayout: {
meta: {
goType: "*types.PageLayoutMeta"
dal: { type: "JSON", defaultEmptyObject: true }
omitSetter: true
omitGetter: true
}
primary: {
@ -52,10 +54,14 @@ pageLayout: {
config: {
goType: "types.PageLayoutConfig"
dal: { type: "JSON", defaultEmptyObject: true }
omitSetter: true
omitGetter: true
}
blocks: {
goType: "types.PageBlocks"
dal: { type: "JSON", defaultEmptyObject: true }
omitSetter: true
omitGetter: true
}
owned_by: schema.AttributeUserRef
@ -90,6 +96,10 @@ pageLayout: {
byNilState: ["deleted"]
}
envoy: {
omit: true
}
rbac: {
operations: {
// @todo not sure how RBAC should work here
@ -109,8 +119,8 @@ pageLayout: {
extended: true
keys: {
name: {
path: ["meta", "name"]
title: {
path: ["meta", "title"]
}
description: {
path: ["meta", "description"]

View File

@ -287,7 +287,7 @@ func (svc resourceTranslationsManager) PageLayout(ctx context.Context, namespace
var k types.LocaleKey
for _, tag := range svc.locale.Tags() {
k = types.LocaleKeyPageLayoutMetaName
k = types.LocaleKeyPageLayoutMetaTitle
out = append(out, &locale.ResourceTranslation{
Resource: res.ResourceTranslation(),
Lang: tag.String(),

View File

@ -504,8 +504,8 @@ func (svc pageLayout) handleUpdate(ctx context.Context, upd *types.PageLayout) p
}
}
if res.Meta != nil && res.Meta.Name != upd.Meta.Name {
res.Meta.Name = upd.Meta.Name
if res.Meta != nil && res.Meta.Title != upd.Meta.Title {
res.Meta.Title = upd.Meta.Title
changes |= pageLayoutChanged
}

View File

@ -331,6 +331,66 @@ func (r *Page) SetValue(name string, pos uint, value any) (err error) {
return nil
}
func (r PageLayout) GetID() uint64 { return r.ID }
func (r *PageLayout) GetValue(name string, pos uint) (any, error) {
switch name {
case "createdAt", "CreatedAt":
return r.CreatedAt, nil
case "deletedAt", "DeletedAt":
return r.DeletedAt, nil
case "handle", "Handle":
return r.Handle, nil
case "id", "ID":
return r.ID, nil
case "namespaceID", "NamespaceID":
return r.NamespaceID, nil
case "ownedBy", "OwnedBy":
return r.OwnedBy, nil
case "pageID", "PageID":
return r.PageID, nil
case "parentID", "ParentID":
return r.ParentID, nil
case "primary", "Primary":
return r.Primary, nil
case "updatedAt", "UpdatedAt":
return r.UpdatedAt, nil
case "weight", "Weight":
return r.Weight, nil
}
return nil, nil
}
func (r *PageLayout) SetValue(name string, pos uint, value any) (err error) {
switch name {
case "createdAt", "CreatedAt":
return cast2.Time(value, &r.CreatedAt)
case "deletedAt", "DeletedAt":
return cast2.TimePtr(value, &r.DeletedAt)
case "handle", "Handle":
return cast2.String(value, &r.Handle)
case "id", "ID":
return cast2.Uint64(value, &r.ID)
case "namespaceID", "NamespaceID":
return cast2.Uint64(value, &r.NamespaceID)
case "ownedBy", "OwnedBy":
return cast2.Uint64(value, &r.OwnedBy)
case "pageID", "PageID":
return cast2.Uint64(value, &r.PageID)
case "parentID", "ParentID":
return cast2.Uint64(value, &r.ParentID)
case "primary", "Primary":
return cast2.Bool(value, &r.Primary)
case "updatedAt", "UpdatedAt":
return cast2.TimePtr(value, &r.UpdatedAt)
case "weight", "Weight":
return cast2.Int(value, &r.Weight)
}
return nil
}
func (r Record) GetID() uint64 { return r.ID }
func (r *Record) GetValue(name string, pos uint) (any, error) {

View File

@ -60,7 +60,7 @@ var (
LocaleKeyPagePageBlockBlockIDDescription = LocaleKey{Path: "pageBlock.{{blockID}}.description"}
LocaleKeyPagePageBlockBlockIDButtonButtonIDLabel = LocaleKey{Path: "pageBlock.{{blockID}}.button.{{buttonID}}.label"}
LocaleKeyPagePageBlockBlockIDContentBody = LocaleKey{Path: "pageBlock.{{blockID}}.content.body"}
LocaleKeyPageLayoutMetaName = LocaleKey{Path: "meta.name"}
LocaleKeyPageLayoutMetaTitle = LocaleKey{Path: "meta.title"}
LocaleKeyPageLayoutMetaDescription = LocaleKey{Path: "meta.description"}
LocaleKeyPageLayoutConfigActionsActionIDLabel = LocaleKey{Path: "config.actions.{{actionID}}.label"}
)
@ -395,8 +395,8 @@ func PageLayoutResourceTranslationTpl() string {
func (r *PageLayout) DecodeTranslations(tt locale.ResourceTranslationIndex) {
var aux *locale.ResourceTranslation
if aux = tt.FindByKey(LocaleKeyPageLayoutMetaName.Path); aux != nil {
r.Meta.Name = aux.Msg
if aux = tt.FindByKey(LocaleKeyPageLayoutMetaTitle.Path); aux != nil {
r.Meta.Title = aux.Msg
}
if aux = tt.FindByKey(LocaleKeyPageLayoutMetaDescription.Path); aux != nil {
@ -411,8 +411,8 @@ func (r *PageLayout) EncodeTranslations() (out locale.ResourceTranslationSet) {
out = append(out, &locale.ResourceTranslation{
Resource: r.ResourceTranslation(),
Key: LocaleKeyPageLayoutMetaName.Path,
Msg: locale.SanitizeMessage(r.Meta.Name),
Key: LocaleKeyPageLayoutMetaTitle.Path,
Msg: locale.SanitizeMessage(r.Meta.Title),
})
out = append(out, &locale.ResourceTranslation{

View File

@ -42,7 +42,7 @@ type (
// Warning: value of this field is now handled via resource-translation facility
// struct field is kept for the convenience for now since it allows us
// easy encoding/decoding of the outgoing/incoming values
Name string `json:"name"`
Title string `json:"title"`
// Warning: value of this field is now handled via resource-translation facility
// struct field is kept for the convenience for now since it allows us

View File

@ -37,7 +37,7 @@ func NewComposePageLayout(pg *types.PageLayout, nsRef, modRef, parentRef *Ref) *
r.SetResourceType(types.PageLayoutResourceType)
r.Res = pg
r.AddIdentifier(identifiers(pg.Handle, pg.Meta.Name, pg.ID)...)
r.AddIdentifier(identifiers(pg.Handle, pg.Meta.Title, pg.ID)...)
r.RefNs = r.addRef(nsRef)
if modRef != nil {

View File

@ -20,12 +20,12 @@ func (h helper) clearPageLayouts() {
h.noError(store.TruncateComposePageLayouts(context.Background(), service.DefaultStore))
}
func (h helper) repoMakePageLayout(ns *types.Namespace, pg *types.Page, name string) *types.PageLayout {
func (h helper) repoMakePageLayout(ns *types.Namespace, pg *types.Page, title string) *types.PageLayout {
res := &types.PageLayout{
ID: id.Next(),
CreatedAt: time.Now(),
Meta: &types.PageLayoutMeta{
Name: name,
Title: title,
},
NamespaceID: ns.ID,
PageID: pg.ID,
@ -56,7 +56,7 @@ func TestPageLayoutRead(t *testing.T) {
Expect(t).
Status(http.StatusOK).
Assert(helpers.AssertNoErrors).
Assert(jsonpath.Equal(`$.response.meta.name`, ly.Meta.Name)).
Assert(jsonpath.Equal(`$.response.meta.name`, ly.Meta.Title)).
Assert(jsonpath.Equal(`$.response.pageLayoutID`, fmt.Sprintf("%d", ly.ID))).
End()
}
@ -132,7 +132,7 @@ func TestPageLayoutCreate(t *testing.T) {
res := h.lookupPageLayoutByID(rsp.Response.ID)
h.a.NotNil(res)
h.a.Equal("some-page-layout", res.Meta.Name)
h.a.Equal("some-page-layout", res.Meta.Title)
}
func TestPageLayoutUpdateForbidden(t *testing.T) {
@ -178,7 +178,7 @@ func TestPageLayoutUpdate(t *testing.T) {
ly = h.lookupPageLayoutByID(ly.ID)
h.a.NotNil(ly)
h.a.Equal("changed-name", ly.Meta.Name)
h.a.Equal("changed-name", ly.Meta.Title)
}
func TestPageLayoutDeleteForbidden(t *testing.T) {