Our powerful JS Calendar component


Post by kevinschweikert »

Hey,

Bryntum Calendar Version: 5.3.5
we have defined custom fields on our eventStore like this:

crudManager: {
                eventStore: {
                    fields: [
                    ...
                        { name: 'playout_tags', dataSource: 'playout_tags' , type: 'array'}
                    ]
                },

we do some validation in the beforeDragMoveEnd callback and are accessing the eventRecord:

listeners: {
                beforeDragMoveEnd: async ({ eventRecord }) => {
                	playout_tags = eventRecord.getData("playout_tags")
                	id = eventRecord.getData("id")
                	return true
                }}

When you drag the event in the calendar for the first time, no problem. The playout_tags are there as expected. If you move the event a second time, the values are null. How can you access the missing data?
And how can you get the ID from the database instead of a generated ID?

Has it anything to do with uncommited changes?
Help would be very appreciated. Thanks in advance!


Post by kevinschweikert »

Nevermind, i found the issue. Our API just sets the playout_tags on load requests but not on sync requests...
But the ID question is still unanswered.


Post by marcio »

Hey kevinschweikert,

Glad that you figure out the issue with the array field.

Regarding the ID questions, yes, you need to commit the changes to the backend, that's why we have configs like https://bryntum.com/products/gantt/docs/api/Core/data/Model#property-isPhantom and https://bryntum.com/products/gantt/docs/api/Scheduler/crud/AbstractCrudManagerMixin#config-phantomIdField

Best regards,
Márcio


Post by kevinschweikert »

Hey marcio,

thanks for the quick reply! The isPhantom property is true in this case.
Could you help me out, how to get the persisted ID of an existing event from the database in the beforeDragMoveEnd function?
I tried using calendar.project.commitAsync() but that didn't change anything.


Post by marcio »

Hey kevinschweikert,

Try to access the id and other properties like this

eventRecord.id
eventRecord.playout_tags

If the data is still incorrect, we would need a test case, you can see more of our guidelines here https://www.bryntum.com/forum/viewtopic.php?f=1&t=772

Best regards,
Márcio


Post by kevinschweikert »

Hey marcio,

the output from eventRecord.id

_generatedModelClass_c34aafad-22c6-4527-8f64-e39e0a56ec67

I expected something like "2" because our database is using integer primary keys. Do you still need a test case?


Post by Animal »

The id in the event will be whatever you sent the id as in the JSON.

If you show us the JSON that you loaded, and show us your Model definition with all fields you defined on it, we can help.


Post by kevinschweikert »

Hey Animal,

sure!

Model definition:

crudManager: {
                eventStore: {
                    fields: [
                        { name: 'type', type: 'string' },
                        { name: 'initial_duration', dataSource: 'initial_duration', type: 'float' },
                        { name: 'durationUnit', dataSource: 'duration_unit' },
                        { name: 'playlist_id', dataSource: 'playlist_id' },
                        { name: 'asset_id', dataSource: 'asset_id' },
                        { name: 'playout_tags', dataSource: 'playout_tags', type: 'array' }
                    ]
                },

Load response:

{
   "events":{
      "rows":[
         {
            "$PhantomId":null,
            "asset_id":null,
            "duration_unit":"second",
            "endDate":"2023-05-25T16:14:00Z",
            "exceptionDates":[
               
], "id":1, "initial_duration":1.2e3, "name":"Event 1", "playlist_id":1, "playout_tags":[ "default" ], "recurrenceRule":null, "resourceId":1, "startDate":"2023-05-25T15:14:00Z", "type":"playlist" } ], "total":1 }, "requestId":16850314486530, "resources":{ "rows":[ .... ], "total":4 }, "success":true }

Sync Request for new item dragged from external source:

{
   "type":"sync",
   "requestId":16850314775152,
   "events":{
      "added":[
         {
            "startDate":"2023-05-25T20:30:00+02:00",
            "endDate":"2023-05-25T20:30:10+02:00",
            "duration":10,
            "duration_unit":"second",
            "cls":"",
            "name":"Image Asset",
            "exceptionDates":[
               
], "resourceId":1, "allDay":false, "type":"asset", "initial_duration":10, "asset_id":"1", "playout_tags":[ "default" ], "$PhantomId":"_generatedModelClass_7953ea4c-0972-429b-a362-f0c441453f13" } ] } }

Sync Response from new item dragged from external source:

{
   "events":{
      "removed":[
         
], "rows":[ { "$PhantomId":"_generatedModelClass_7953ea4c-0972-429b-a362-f0c441453f13", "asset_id":1, "duration_unit":"second", "endDate":"2023-05-25T18:30:10Z", "exceptionDates":[ ], "id":2, "initial_duration":10.0, "name":"Image Asset", "playlist_id":null, "playout_tags":[ "default" ], "recurrenceRule":null, "resourceId":1, "startDate":"2023-05-25T18:30:00Z", "type":"asset" } ] }, "requestId":16850314775152, "success":true }

Sync request from existing event

{
   "type":"sync",
   "requestId":16850314584671,
   "events":{
      "updated":[
         {
            "startDate":"2023-05-25T18:09:00+02:00",
            "endDate":"2023-05-25T19:09:00+02:00",
            "id":1
         }
      ]
   }
}

Sync response from existing event

{
   "events":{
      "removed":[
         
], "rows":[ { "$PhantomId":null, "asset_id":null, "duration_unit":"second", "endDate":"2023-05-25T17:09:00Z", "exceptionDates":[ ], "id":1, "initial_duration":1.2e3, "name":"Event 1", "playlist_id":1, "playout_tags":[ "default" ], "recurrenceRule":null, "resourceId":1, "startDate":"2023-05-25T16:09:00Z", "type":"playlist" } ] }, "requestId":16850314584671, "success":true }

Does that help, or do you need anything else?

Cheers
Kevin


Post by Animal »

See https://bryntum.com/products/calendar/docs/guide/Calendar/data/crud_manager#sync-response-structure

In the return packet, it has to have the phantom id which is to be matched up with.


Post by kevinschweikert »

But how can the API know, what the PhantomID is, when it's not in the request from the client (only, id, startDate and endDate are available in my example). Does the server also have to keep track of the PhantomIDs?
In the sync request with the create event request, there is a PhantomID and we send it right back.


Post Reply