[#6122] fixed model->record and model->collection events sync

This commit is contained in:
Gani Georgiev
2024-12-16 14:49:24 +02:00
parent e34c25858c
commit cb3936a499
4 changed files with 310 additions and 29 deletions

View File

@@ -173,8 +173,8 @@ type ModelEvent struct {
}
type ModelErrorEvent struct {
ModelEvent
Error error
ModelEvent
}
// -------------------------------------------------------------------
@@ -196,8 +196,8 @@ type RecordEvent struct {
}
type RecordErrorEvent struct {
RecordEvent
Error error
RecordEvent
}
func syncModelEventWithRecordEvent(me *ModelEvent, re *RecordEvent) {
@@ -216,6 +216,12 @@ func syncModelEventWithRecordEvent(me *ModelEvent, re *RecordEvent) {
// }
}
func syncRecordEventWithModelEvent(re *RecordEvent, me *ModelEvent) {
re.App = me.App
re.Context = me.Context
re.Type = me.Type
}
func newRecordEventFromModelEvent(me *ModelEvent) (*RecordEvent, bool) {
record, ok := me.Model.(*Record)
if !ok {
@@ -253,6 +259,11 @@ func syncModelErrorEventWithRecordErrorEvent(me *ModelErrorEvent, re *RecordErro
me.Error = re.Error
}
func syncRecordErrorEventWithModelErrorEvent(re *RecordErrorEvent, me *ModelErrorEvent) {
syncRecordEventWithModelEvent(&re.RecordEvent, &me.ModelEvent)
me.Error = re.Error
}
// -------------------------------------------------------------------
// Collection events data
// -------------------------------------------------------------------
@@ -272,8 +283,8 @@ type CollectionEvent struct {
}
type CollectionErrorEvent struct {
CollectionEvent
Error error
CollectionEvent
}
func syncModelEventWithCollectionEvent(me *ModelEvent, ce *CollectionEvent) {
@@ -283,6 +294,15 @@ func syncModelEventWithCollectionEvent(me *ModelEvent, ce *CollectionEvent) {
me.Model = ce.Collection
}
func syncCollectionEventWithModelEvent(ce *CollectionEvent, me *ModelEvent) {
ce.App = me.App
ce.Context = me.Context
ce.Type = me.Type
if c, ok := me.Model.(*Collection); ok {
ce.Collection = c
}
}
func newCollectionEventFromModelEvent(me *ModelEvent) (*CollectionEvent, bool) {
record, ok := me.Model.(*Collection)
if !ok {
@@ -316,6 +336,11 @@ func syncModelErrorEventWithCollectionErrorEvent(me *ModelErrorEvent, ce *Collec
me.Error = ce.Error
}
func syncCollectionErrorEventWithModelErrorEvent(ce *CollectionErrorEvent, me *ModelErrorEvent) {
syncCollectionEventWithModelEvent(&ce.CollectionEvent, &me.ModelEvent)
me.Error = ce.Error
}
// -------------------------------------------------------------------
// File API events data
// -------------------------------------------------------------------