Our pure JavaScript Scheduler component


Post by probo »

alex.l wrote: Mon May 09, 2022 9:19 am

Hi probo,

I don't see you removed load/sync URLs from crudManager as Johan adviced and use AjaxStore together with crudManager load calls, so this is one of potential problems.
You used custom field names (resource_id) so please post Resource model code as well (I mean ProductionUnit).
It will be great if you just zip and attach a runnable test case with JSON examples you used for it. We need to reproduce the problem to help you with that. For now it just works in case we update resources using our examples.

Thank you!

So i've prepared a new testcase. Alex, i will send you the zip file for this issue. Also i want to point out that it doesn't make a difference if you use syncDataOnLoad or not, i left it in for this example. I've adjusted my project settings as follows:

project: {
    resourceModelClass: ProductionUnit,
    assignmentStore: {
        syncDataOnLoad: true
    },
    eventStore: {
        fields: [
            'sourceData',
            'type',
            'type_id'
        ],
        syncDataOnLoad: true
    },
    resourceStore: {
        syncDataOnLoad: true
    },
    transport: {
        load: {
            url: '/print-planning/plannable-items',
        },
        sync: {
            url: '/print-planning/plannable-items/sync',
        },
    },
    validateResponse: true,
    autoSync: true
},

Here is my combo field

{
    type: 'combo',
    displayField: 'name',
    valueField: 'id',
    store: new Store({
        data: [
            {
                id: 3,
                name: 'Sublimation'
            },
            {
                id: 5,
                name: 'Sheet'
            },
            {
                id: 8,
                name: 'Wood'
            }
        ]
    }),
    listeners: {
        change(data) {
            const scheduler = this.parent.parent;
            const project = scheduler.project;

        project.transport.load.url = '/data/machine-' + data.value + '.json';
        project.load();
    }
}
},

What we want to achieve, is when you switch to another resource using the combo box that it loads the assignments, events and resources from the json files. It loads the resources but not the events.

STR:

  1. Select Sheet as your first selection (events are visible)
  2. Select Sublimation as your second choice
  3. Select Wood as your third choice
  4. Select Sheet again as your option

Actual result: Events are not visible anymore
Expected results: Events are visible

Kind regards,
probo


Post by alex.l »

Hi probo,

Thank you for clarifications. Now it's clear what happened.
Lets say, your first dataset has resources with id: 1 and id: 2, and events that assigned on it. So assignmentStore has records with resourceId: 1 and resourceId: 2.
After that you load new data - resources with id: 3 and id: 4. It's new dataset. Project will validate assignments and check if a reference on AssignmentModel instance that stored in EventModel is valid or not (isntance with resourceId : 1). It fact, it will not be not valid (nothing in resource store with that id), attached instance will be destroyed and record from assignment store will be removed accordingly. This is by design. New created resources after second load even with same ids has nothing related to old resources with these ids, we can't count on that ids are not just reused for new instances.

So, in that case you have to add assignments again.

All the best,
Alex


Post Reply