Tweak page layout sub types and JSON encoding
This commit is contained in:
committed by
Jože Fortun
parent
fb1d6b601d
commit
e18049f933
@@ -73,7 +73,7 @@ pageLayout: {
|
||||
omitGetter: true
|
||||
}
|
||||
blocks: {
|
||||
goType: "types.PageBlocks"
|
||||
goType: "types.PageLayoutBlocks"
|
||||
dal: { type: "JSON", defaultEmptyObject: true }
|
||||
omitSetter: true
|
||||
omitGetter: true
|
||||
|
||||
@@ -24,10 +24,10 @@ type (
|
||||
|
||||
Weight int `json:"weight"`
|
||||
|
||||
Meta PageLayoutMeta `json:"meta"`
|
||||
Meta PageLayoutMeta `json:"meta,omitempty"`
|
||||
|
||||
Config PageLayoutConfig `json:"config"`
|
||||
Blocks PageBlocks `json:"blocks"`
|
||||
Blocks PageLayoutBlocks `json:"blocks,omitempty"`
|
||||
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
|
||||
@@ -38,6 +38,14 @@ type (
|
||||
DeletedAt *time.Time `json:"deletedAt,omitempty"`
|
||||
}
|
||||
|
||||
PageLayoutBlocks []PageLayoutBlock
|
||||
|
||||
PageLayoutBlock struct {
|
||||
BlockID uint64 `json:"blockID,string,omitempty"`
|
||||
XYWH [4]int `json:"xywh"` // x,y,w,h
|
||||
Meta map[string]any `json:"meta,omitempty"`
|
||||
}
|
||||
|
||||
PageLayoutMeta struct {
|
||||
// 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
|
||||
@@ -48,6 +56,8 @@ type (
|
||||
// struct field is kept for the convenience for now since it allows us
|
||||
// easy encoding/decoding of the outgoing/incoming values
|
||||
Description string `json:"description"`
|
||||
|
||||
Style map[string]any `json:"style,omitempty"`
|
||||
}
|
||||
|
||||
PageLayoutButton struct {
|
||||
@@ -71,25 +81,20 @@ type (
|
||||
PageLayoutConfig struct {
|
||||
Visibility PageLayoutVisibility `json:"visibility"`
|
||||
|
||||
Buttons *PageLayoutButtonConfig `json:"buttons"`
|
||||
Actions []PageLayoutAction `json:"actions"`
|
||||
Buttons PageLayoutButtonConfig `json:"buttons"`
|
||||
Actions []PageLayoutAction `json:"actions,omitempty"`
|
||||
}
|
||||
|
||||
PageLayoutVisibility struct {
|
||||
Expression string `json:"expression"`
|
||||
Roles []string `json:"roles"`
|
||||
Roles []string `json:"roles,omitempty"`
|
||||
}
|
||||
|
||||
PageLayoutAction struct {
|
||||
ActionID uint64 `json:"actionID,string"`
|
||||
Placement string `json:"placement"`
|
||||
Meta any `json:"meta"`
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// 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
|
||||
Label string `json:"label"`
|
||||
ActionID uint64 `json:"actionID,string"`
|
||||
Placement string `json:"placement"`
|
||||
Meta PageLayoutActionMeta `json:"meta"`
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// Kind and Params specify the action's behavior and the parameters it
|
||||
// can use for execution
|
||||
@@ -97,6 +102,13 @@ type (
|
||||
Params any `json:"params"`
|
||||
}
|
||||
|
||||
PageLayoutActionMeta struct {
|
||||
// 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
|
||||
Label string `json:"label"`
|
||||
}
|
||||
|
||||
PageLayoutFilter struct {
|
||||
PageLayoutID []uint64 `json:"pageLayoutID,string"`
|
||||
NamespaceID uint64 `json:"namespaceID,string"`
|
||||
@@ -184,3 +196,6 @@ func (bb PageLayoutConfig) Value() (driver.Value, error) { return json.Marshal(b
|
||||
|
||||
func (vv *PageLayoutMeta) Scan(src any) error { return sql.ParseJSON(src, &vv) }
|
||||
func (vv PageLayoutMeta) Value() (driver.Value, error) { return json.Marshal(vv) }
|
||||
|
||||
func (bb *PageLayoutBlocks) Scan(src any) error { return sql.ParseJSON(src, bb) }
|
||||
func (bb PageLayoutBlocks) Value() (driver.Value, error) { return json.Marshal(bb) }
|
||||
|
||||
@@ -48,81 +48,6 @@ func NewComposePageLayout(pg *types.PageLayout, nsRef, modRef, parentRef *Ref) *
|
||||
r.RefParent = r.addRef(parentRef).Constraint(r.RefNs)
|
||||
}
|
||||
|
||||
var ref *Ref
|
||||
for i, b := range pg.Blocks {
|
||||
switch b.Kind {
|
||||
case "RecordList":
|
||||
ref = r.pbRecordList(b.Options)
|
||||
if ref != nil {
|
||||
r.addRef(ref)
|
||||
r.BlockRefs[i] = append(r.BlockRefs[i], ref)
|
||||
r.ModRefs = append(r.ModRefs, ref)
|
||||
}
|
||||
|
||||
case "Automation":
|
||||
bb, _ := b.Options["buttons"].([]interface{})
|
||||
for _, b := range bb {
|
||||
button, _ := b.(map[string]interface{})
|
||||
ref = r.pbAutomation(button)
|
||||
if ref != nil {
|
||||
r.addRef(ref)
|
||||
r.BlockRefs[i] = append(r.BlockRefs[i], ref)
|
||||
r.WfRefs = append(r.WfRefs, ref)
|
||||
}
|
||||
}
|
||||
|
||||
case "RecordOrganizer":
|
||||
ref = r.pbRecordList(b.Options)
|
||||
if ref != nil {
|
||||
r.addRef(ref)
|
||||
r.BlockRefs[i] = append(r.BlockRefs[i], ref)
|
||||
r.ModRefs = append(r.ModRefs, ref)
|
||||
}
|
||||
|
||||
case "Chart":
|
||||
ref = r.pbChart(b.Options)
|
||||
if ref != nil {
|
||||
r.addRef(ref)
|
||||
r.BlockRefs[i] = append(r.BlockRefs[i], ref)
|
||||
r.RefCharts = append(r.RefCharts, ref)
|
||||
}
|
||||
|
||||
case "Calendar":
|
||||
ff, _ := b.Options["feeds"].([]interface{})
|
||||
for _, f := range ff {
|
||||
feed, _ := f.(map[string]interface{})
|
||||
fOpts, _ := (feed["options"]).(map[string]interface{})
|
||||
|
||||
ref = r.pbCalendar(fOpts)
|
||||
if ref != nil {
|
||||
r.addRef(ref)
|
||||
r.BlockRefs[i] = append(r.BlockRefs[i], ref)
|
||||
r.ModRefs = append(r.ModRefs, ref)
|
||||
}
|
||||
}
|
||||
|
||||
case "Metric":
|
||||
mm, _ := b.Options["metrics"].([]interface{})
|
||||
for _, m := range mm {
|
||||
mops, _ := m.(map[string]interface{})
|
||||
ref = r.pbMetric(mops)
|
||||
if ref != nil {
|
||||
r.addRef(ref)
|
||||
r.BlockRefs[i] = append(r.BlockRefs[i], ref)
|
||||
r.ModRefs = append(r.ModRefs, ref)
|
||||
}
|
||||
}
|
||||
|
||||
case "Comment":
|
||||
ref = r.pbComment(b.Options)
|
||||
if ref != nil {
|
||||
r.addRef(ref.Constraint(r.RefNs))
|
||||
r.BlockRefs[i] = append(r.BlockRefs[i], ref)
|
||||
r.ModRefs = append(r.ModRefs, ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initial timestamps
|
||||
r.SetTimestamps(MakeTimestampsCUDA(&pg.CreatedAt, pg.UpdatedAt, pg.DeletedAt, nil))
|
||||
|
||||
@@ -156,44 +81,6 @@ func (r *ComposePageLayout) ReRef(old RefSet, new RefSet) {
|
||||
}
|
||||
|
||||
func (r *ComposePageLayout) Prune(ref *Ref) {
|
||||
var auxRef *Ref
|
||||
|
||||
outer:
|
||||
for i := len(r.Res.Blocks) - 1; i >= 0; i-- {
|
||||
b := r.Res.Blocks[i]
|
||||
|
||||
switch b.Kind {
|
||||
// Implement the rest when support is needed
|
||||
case "Automation":
|
||||
if b.Options["buttons"] == nil {
|
||||
// In case the block isn't connected to a workflow (placeholder, script)
|
||||
if auxRef == nil {
|
||||
r.removeBlock(i)
|
||||
continue outer
|
||||
}
|
||||
} else {
|
||||
bb, _ := b.Options["buttons"].([]interface{})
|
||||
for _, b := range bb {
|
||||
button, _ := b.(map[string]interface{})
|
||||
auxRef = r.pbAutomation(button)
|
||||
|
||||
// In case the block isn't connected to a workflow (placeholder, script)
|
||||
if auxRef == nil {
|
||||
r.removeBlock(i)
|
||||
continue outer
|
||||
}
|
||||
|
||||
// In case we are removing it
|
||||
if auxRef.equals(ref) {
|
||||
r.ReplaceRef(ref, nil)
|
||||
r.WfRefs = r.WfRefs.replaceRef(ref, nil)
|
||||
r.removeBlock(i)
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ComposePageLayout) SysID() uint64 {
|
||||
|
||||
@@ -141,7 +141,7 @@ func migratePageChunk(ctx context.Context, s store.Storer, translations systemTy
|
||||
for _, b := range p.Blocks {
|
||||
b.XYWH = adjustBlockScale(b.XYWH, 12, 48)
|
||||
|
||||
ly.Blocks = append(ly.Blocks, types.PageBlock{
|
||||
ly.Blocks = append(ly.Blocks, types.PageLayoutBlock{
|
||||
BlockID: b.BlockID,
|
||||
XYWH: b.XYWH,
|
||||
})
|
||||
@@ -166,14 +166,14 @@ func migratePageChunk(ctx context.Context, s store.Storer, translations systemTy
|
||||
return
|
||||
}
|
||||
|
||||
func extractPageButtons(p *types.Page) (out *types.PageLayoutButtonConfig) {
|
||||
func extractPageButtons(p *types.Page) (out types.PageLayoutButtonConfig) {
|
||||
ss := service.CurrentSettings.Compose.UI.RecordToolbar
|
||||
|
||||
if p.ModuleID == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
out = &types.PageLayoutButtonConfig{}
|
||||
out = types.PageLayoutButtonConfig{}
|
||||
out.New.Enabled = !ss.HideNew
|
||||
out.Edit.Enabled = !ss.HideEdit
|
||||
out.Submit.Enabled = !ss.HideSubmit
|
||||
|
||||
+1
-1
@@ -315,7 +315,7 @@ type (
|
||||
Meta composeType.PageLayoutMeta `db:"meta"`
|
||||
Primary bool `db:"primary"`
|
||||
Config composeType.PageLayoutConfig `db:"config"`
|
||||
Blocks composeType.PageBlocks `db:"blocks"`
|
||||
Blocks composeType.PageLayoutBlocks `db:"blocks"`
|
||||
OwnedBy uint64 `db:"owned_by"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt *time.Time `db:"updated_at"`
|
||||
|
||||
Reference in New Issue
Block a user