Premium support for our pure JavaScript UI components


Post by guillaume.morin »

Hello,

I have a similar case as described here
viewtopic.php?p=111185&hilit=save+load#p111185

I manually call backend to get data and populate scheduler using:

scheduler.project.loadInlineData(remote_data);

The remote data may have inconsistent dates not following constraints, so the scheduler does its magic and reschedule the dependent events.

I'd like this initial scheduling to be saved.
However, after the call to loadInlineData(), scheduler.project.changes is null.

How can I get the initial changes that was applied by the scheduler ?

Last edited by guillaume.morin on Wed Mar 22, 2023 9:49 pm, edited 1 time in total.

Post by Maxim Gorkovsky »

Hello.
Try setting this config to false: https://bryntum.com/products/gantt/docs/api/Gantt/model/ProjectModel#config-silenceInitialCommit
Then changes from the first calculation should be reported as changes


Post by guillaume.morin »

Gave silenceInitialCommit=false a try, but it now returns a lot of false positive changes.
I included an excerpt of the changes object after initial load.
In summary:

  • events.updated contains all events -> It should not return all events, I will need to investigate, I suspect it is because my load request didn't inlcude an endDate but a only a duration ?

  • resources.updated contains all resources -> I don't see why all resources got updated

  • assignments.added contains all assignments -> make no sense, the scheduler didn't add any assignements

  • dependencies.added contains all dependencies -> make no sense, the scheduler didn't add any dependencies

{
    "events": {
        "updated": [
            {
                "segments": null,
                "effort": 48,
                "constraintType": null,
                "constraintDate": null,
                "endDate": "2023-03-03T00:00:00-05:00",
                "calendar": null,
                "id": "WO-23-001_JOB1"
            }, ...
        ]
    },
    "resources": {
        "updated": [
            {
                "calendar": null,
                "id": "Brassage SLOT 1"
            }, ...
        ]
    },
    "assignments": {
        "added": [
            {
                "units": 100,
                "resourceId": "Brassage SLOT 1",
                "eventId": "WO-23-001_JOB1",
                "$PhantomId": "_generatedn_c2a77166-4328-44bc-ad5a-60181ddf3d54"
            }, ...
        ]
    },
    "dependencies": {
        "added": [
            {
                "type": 0,
                "cls": "",
                "fromSide": null,
                "toSide": null,
                "lag": 0,
                "lagUnit": "day",
                "fromEvent": "WO-23-001_JOB1",
                "toEvent": "WO-23-001_JOB2",
                "active": true,
                "$PhantomId": "_generatedn_396005a5-922c-49fa-8bca-304ed5bebd03"
            }, ...
        ]
    }
}

What I'm looking for is simply to get the list of events for which the scheduling engine changed the start date during initial load.
I guess it will be simpler to keep a copy of the orignal data from server do this comparison myself.


Post by mats »

events.updated contains all events -> It should not return all events, I will need to investigate, I suspect it is because my load request didn't inlcude an endDate but a only a duration ?

Yes that's likely it.

Can you please post the raw dataset you load and the raw "changes" object so we can have a look?


Post by guillaume.morin »

Sure thing, see attached.

Attachments
load.json
(65.98 KiB) Downloaded 17 times
changes.json
(50.32 KiB) Downloaded 15 times

Post by guillaume.morin »

FYI, I was able to get the initial changes, without silenceInitialCommit=false, using the following code.
There is really no other change the scheduler can do to my original data, so that will do the job for now.

await this.project.loadInlineData(server_data);

server_data.eventsData.forEach(server_event => {
	let sch_event = this.project.eventStore.getById(server_event.id);
	if (!DateHelper.isEqual(DateHelper.parse(server_event.startDate), sch_event.startDate, "d")) {
		console.log("Initial Schedule change: ", server_event.id, DateHelper.parse(server_event.startDate), sch_event.startDate);
	}
});

Post by marcio »

Hey guillaume.morin,

Glad that you figure it out and thanks for sharing your solution here in the forums. :)

Best regards,
Márcio


Post by guillaume.morin »

Just wanted to share my final solution using dataReady event and posting a sync with the changes.

... and ask another question :-)
I didn't find any doc on isInitialCommit, nor on originalData.
Is it ok to use ?

dataReady(e) {
	if (e.isInitialCommit) 
	{
		let updatedEvents = [];
		scheduler.project.events.forEach(x => {
			if (!DateHelper.isEqual(DateHelper.parse(x.originalData.startDate), x.startDate, "d")) 
			{
				updatedEvents.push({
					"id": x.id,
					"startDate": x.startDate,
					"endDate": x.endDate
				});
			}
		});
		if (updatedEvents.length > 0) 
		{
			scheduler.project.sendRequest({
				type: 'sync',
				data: JSON.stringify({
					requestId: scheduler.project.requestId,
					events : {
						updated : updatedEvents
					}
				})
			});
		}
	}
}


Post by alex.l »

Hi, thank you for the question.

You can use isInitialCommit flag, I already updated docs to make it public, the change will be available in the nearest patch release.
Regarding to originalData, it's private and may not work as you expected. originalData object may not contains not committed changes in a record. I see you found that and used in your logic.
But it's for internal use, better to check project.changes to get updated records.

All the best,
Alex


Post Reply