3
0

Add missing res. tr. identification logic

This commit is contained in:
Tomaž Jerman
2021-09-29 16:37:27 +02:00
committed by Denis Arh
parent cbb486ef5a
commit 7ea20c489b
5 changed files with 100 additions and 0 deletions

View File

@@ -249,6 +249,13 @@ func (svc module) Create(ctx context.Context, new *types.Module) (*types.Module,
f.CreatedAt = *now()
f.UpdatedAt = nil
f.DeletedAt = nil
// Assure validatorID
for i, v := range f.Expressions.Validators {
v.ValidatorID = uint64(i) + 1
f.Expressions.Validators[i] = v
}
return nil
})
}
@@ -461,6 +468,16 @@ func (svc module) handleUpdate(ctx context.Context, upd *types.Module) moduleUpd
return moduleUnchanged, ModuleErrNotAllowedToUpdate()
}
// Get max validatorID for later use
vvID := make([]uint64, len(res.Fields))
for i, f := range res.Fields {
for _, v := range f.Expressions.Validators {
if vvID[i] < v.ValidatorID {
vvID[i] = v.ValidatorID
}
}
}
if res.Name != upd.Name {
changes |= moduleChanged
res.Name = upd.Name
@@ -495,6 +512,19 @@ func (svc module) handleUpdate(ctx context.Context, upd *types.Module) moduleUpd
res.Fields = upd.Fields
}
// Assure validatorIDs
for i, f := range res.Fields {
for j, v := range f.Expressions.Validators {
if v.ValidatorID == 0 {
vvID[i] += 1
v.ValidatorID = vvID[i]
f.Expressions.Validators[j] = v
changes |= moduleFieldsChanged
}
}
}
if upd.Labels != nil {
if label.Changed(res.Labels, upd.Labels) {
changes |= moduleLabelsChanged

View File

@@ -289,6 +289,11 @@ func (svc page) Create(ctx context.Context, new *types.Page) (*types.Page, error
new.UpdatedAt = nil
new.DeletedAt = nil
// Assure pageblock IDs
for i, b := range new.Blocks {
b.BlockID = uint64(i) + 1
}
if err = store.CreateComposePage(ctx, s, new); err != nil {
return err
}
@@ -346,6 +351,14 @@ func (svc page) updater(ctx context.Context, namespaceID, pageID uint64, action
return err
}
// Get max blockID for later use
blockID := uint64(0)
for _, b := range p.Blocks {
if b.BlockID > blockID {
blockID = b.BlockID
}
}
old = p.Clone()
aProps.setNamespace(ns)
@@ -468,6 +481,14 @@ func (svc page) handleUpdate(ctx context.Context, upd *types.Page) pageUpdateHan
return pageUnchanged, PageErrNotAllowedToUpdate()
}
// Get max blockID for later use
blockID := uint64(0)
for _, b := range res.Blocks {
if b.BlockID > blockID {
blockID = b.BlockID
}
}
if res.ID != upd.ID {
res.ID = upd.ID
changes |= pageChanged
@@ -483,6 +504,17 @@ func (svc page) handleUpdate(ctx context.Context, upd *types.Page) pageUpdateHan
changes |= pageChanged
}
// Assure blockIDs
for i, b := range res.Blocks {
if b.BlockID == 0 {
blockID++
b.BlockID = blockID
res.Blocks[i] = b
changes |= pageChanged
}
}
if res.Title != upd.Title {
res.Title = upd.Title
changes |= pageChanged

View File

@@ -159,6 +159,17 @@ func (n *composeModule) Encode(ctx context.Context, pl *payload) (err error) {
} else {
originalFields = make(types.ModuleFieldSet, 0)
}
// Get max validatorID for later use
vvID := make([]uint64, len(res.Fields))
for i, f := range res.Fields {
for _, v := range f.Expressions.Validators {
if vvID[i] < v.ValidatorID {
vvID[i] = v.ValidatorID
}
}
}
for i, f := range res.Fields {
of := originalFields.FindByName(f.Name)
if of != nil {
@@ -171,6 +182,16 @@ func (n *composeModule) Encode(ctx context.Context, pl *payload) (err error) {
f.DeletedAt = nil
f.CreatedAt = *now()
// Assure validatorIDs
for j, v := range f.Expressions.Validators {
if v.ValidatorID == 0 {
vvID[i] += 1
v.ValidatorID = vvID[i]
f.Expressions.Validators[j] = v
}
}
if f.Options != nil && f.Kind == "Record" {
refMod := f.Options.String("module")
if refMod == "" {

View File

@@ -216,7 +216,23 @@ func (n *composePage) Encode(ctx context.Context, pl *payload) (err error) {
return ""
}
// Get max blockID for later use
blockID := uint64(0)
for _, b := range res.Blocks {
if b.BlockID > blockID {
blockID = b.BlockID
}
}
for i, b := range res.Blocks {
// Assure blockIDs
if b.BlockID == 0 {
blockID++
b.BlockID = blockID
res.Blocks[i] = b
}
switch b.Kind {
case "RecordList":
id := ss(b.Options, "module", "moduleID")

View File

@@ -237,6 +237,7 @@ func (c *composePageBlock) MarshalYAML() (interface{}, error) {
}
return makeMap(
"blockID", c.res.BlockID,
"title", c.res.Title,
"description", c.res.Description,
"options", c.res.Options,