3
0

Add support for expr & action persistence on layouts

This commit is contained in:
Tomaž Jerman
2023-03-20 16:44:16 +01:00
committed by Jože Fortun
parent c264bf7bcd
commit 19133a4cb3
2 changed files with 20 additions and 38 deletions
-31
View File
@@ -151,11 +151,6 @@ func (svc pageLayout) search(ctx context.Context, filter types.PageLayoutFilter)
return err
}
set.Walk(func(p *types.PageLayout) error {
preparePageLayoutConfig(svc.pageLayoutSettings, p)
return nil
})
// i18n
tag := locale.GetAcceptLanguageFromContext(ctx)
set.Walk(func(p *types.PageLayout) error {
@@ -224,8 +219,6 @@ func (svc pageLayout) Create(ctx context.Context, new *types.PageLayout) (*types
// return
// }
preparePageLayoutConfig(svc.pageLayoutSettings, new)
if err = label.Create(ctx, s, new); err != nil {
return
}
@@ -331,8 +324,6 @@ func (svc pageLayout) updater(ctx context.Context, s store.Storer, ns *types.Nam
// return
// }
preparePageLayoutConfig(svc.pageLayoutSettings, res)
if changes&pageLayoutLabelsChanged > 0 {
if err = label.Update(ctx, s, res); err != nil {
return
@@ -368,8 +359,6 @@ func (svc pageLayout) lookup(ctx context.Context, namespaceID uint64, lookup fun
return err
}
preparePageLayoutConfig(svc.pageLayoutSettings, p)
p.DecodeTranslations(svc.locale.Locale().ResourceTranslations(locale.GetAcceptLanguageFromContext(ctx), p.ResourceTranslation()))
aProps.setPageLayout(p)
@@ -539,24 +528,6 @@ func (svc pageLayout) handleUndelete(ctx context.Context, ns *types.Namespace, m
return pageLayoutChanged, nil
}
func preparePageLayoutConfig(ss *pageLayoutSettings, p *types.PageLayout) {
if p.ModuleID == 0 {
p.Config.Buttons = nil
return
}
p.Config.Buttons = &types.PageLayoutButtonConfig{}
if ss == nil {
return
}
p.Config.Buttons.New.Enabled = !ss.hideNew
p.Config.Buttons.Edit.Enabled = !ss.hideEdit
p.Config.Buttons.Submit.Enabled = !ss.hideSubmit
p.Config.Buttons.Delete.Enabled = !ss.hideDelete
p.Config.Buttons.Clone.Enabled = !ss.hideClone
p.Config.Buttons.Back.Enabled = !ss.hideBack
}
func (svc *pageLayout) UpdateConfig(ss *systemTypes.AppSettings) {
a := ss.Compose.UI.RecordToolbar
@@ -602,8 +573,6 @@ func loadPageLayout(ctx context.Context, s store.ComposePageLayouts, namespaceID
return nil, PageLayoutErrNotFound()
}
preparePageLayoutConfig(nil, res)
return
}
+20 -7
View File
@@ -63,7 +63,24 @@ type (
}
PageLayoutConfig struct {
Buttons *PageLayoutButtonConfig `json:"buttons,omitempty"`
Visibility PageLayoutVisibility `json:"visibility"`
Actions []PageLayoutAction `json:"actions"`
}
PageLayoutVisibility struct {
Expression string
Roles []string
}
PageLayoutAction struct {
ActionID uint64 `json:"actionID,string"`
Placement string
Meta any
// Kind and Params specify the action's behavior and the parameters it
// can use for execution
Kind string
Params any
}
PageLayoutFilter struct {
@@ -108,12 +125,8 @@ func (set PageLayoutSet) FindByHandle(handle string) *PageLayout {
return nil
}
func (bb *PageLayoutConfig) Scan(src any) error { return sql.ParseJSON(src, bb) }
func (bb PageLayoutConfig) Value() (driver.Value, error) {
// We're not saving button config to the DB; no need for it
bb.Buttons = nil
return json.Marshal(bb)
}
func (bb *PageLayoutConfig) Scan(src any) error { return sql.ParseJSON(src, bb) }
func (bb PageLayoutConfig) Value() (driver.Value, error) { return json.Marshal(bb) }
func (vv *PageLayoutMeta) Scan(src any) error { return sql.ParseJSON(src, vv) }
func (vv *PageLayoutMeta) Value() (driver.Value, error) { return json.Marshal(vv) }