Our pure JavaScript Scheduler component


Post by dpontes »

Hello!

I am trying to perform the assignment of Parent Events into the Scheduler Pro but I am having some issues when trying to move the Parent Event after scheduling it.

Parent Events that were already scheduled can be moved properly.

This is what I am using to perform this scheduling action inside the "onTaskDrop"

// Remove Task from Grid
me.grid.store.remove(task);

// Schedule Parent Event First
this.schedule.scheduleEvent({
	resourceRecord    : context.resource,
	eventRecord       : task,
	startDate         : startDate,
	element: context.element
});
	
const children = [...task.children]; // Clone children, just in case.
// When parentEvent is scheduled, the order or the children will be defined based on "eventSequence"
children.sort((a, b) => {
	if(!a.eventSequence || !b.eventSequence) {
		return 0;
	}
	return a.eventSequence - b.eventSequence;
})
		
let previousChildDuration = 0;

// Schedule each children, passing the correct date offset for each child.
for(const child of children) {
	const dateWithMinutesOffset = startDate.getTime() + previousChildDuration * 60000;
	const adjustedDate = new Date(dateWithMinutesOffset);
	
	this.schedule.scheduleEvent({
		resourceRecord  : context.resource,
		eventRecord     : child,
		startDate       : adjustedDate
	});
	
	previousChildDuration += child.duration;
}

context.finalize();

I did performed some debugging, and I see that the "context.valid" is false for the Event that I am trying to move.

Here is what I found so far to be the reason for "context.valid" to be false:

The "draggedEvent" that is stored inside "eventsToCheck" is getting its "startDate" reverted to its original Date after this line is processed:

await Promise.all([toScheduler.project !== fromScheduler.project ? toScheduler.project.commitAsync() : null, fromScheduler.project.commitAsync()]);
issue-drag-scheduled-event-context-false.png
issue-drag-scheduled-event-context-false.png (60.46 KiB) Viewed 483 times

This will cause the date comparison to assign "false" to the "updated" property, which will later on be used to define "context.valid" to false.

I am trying to debug further and discover the reason why after the commitAsync promise the startDate of draggedEvent is reverting to its original startDate, but no luck on this yet.

Would the way I am trying to perform this Parent Events scheduling missing something that could be causing this issue?

Thank you!

Last edited by dpontes on Wed Mar 22, 2023 3:38 pm, edited 2 times in total.

Post by alex.l »

Hi,

Hard to say since you used custom code for it, we need to run and debug it to see what exactly is going on. Does it work well if you comment your handler?

If possible, please attach runnable application that we could use to reproduce this problem.
Please also provide steps to reproduce and actual/expected results.

Btw, I don't see any onTaskDrop documented in SchedulerPro, only https://bryntum.com/products/schedulerpro/docs/api/Scheduler/feature/EventDrag#event-eventDrop

All the best,
Alex


Post by dpontes »

Hello Alex, I will try to reproduce the issue in one of Bryntum samples and I will provide it.

Sorry I missed this piece of information, the "onTaskDrop" is the function we assign to the "drop" listener of "Drag.js".

Which handler would you referring for commenting and test if works?

The steps to reproduce:

  • The unscheduled Grid has a Unscheduled Parent Event (which has children events)
  • Drag the parent event from the grid to the Scheduler.
  • Try to move the parent event to a different timeline in the scheduler.

Expected results: The Parent Event is moved to the new startDate you just dragged.
Current behavior: The parent event jumps back to its original timeline right away (the video demonstrate this behavior).

I am not sure if this could help at all in identifying the possible issue here.

But here is a diff of 2 events when I try to drag:

The Event 60 is parent event that came from the Unscheduled Grid.
The Event 74 is a parent event that was already scheduled when the app initialized.

If I try to move the Event 60, it doesn't work, jumps back to its original timeline.
If I try to move the Event 74, it works properly.

I highlighted in green the diff I could notice. The one that brought my attention is that the Event 60 has a object assigned to the "unjoinedStore", while the 74 doesn't.

events-diff.png
events-diff.png (141.02 KiB) Viewed 465 times

Post by dpontes »

Hi Alex,

I am trying to replicate the issue using the "drag-from-grid" as the starting point, but I am facing a different issue when trying to drag the event from the Grid:

bryntum-example-error-drag-from-grid.png
bryntum-example-error-drag-from-grid.png (244.75 KiB) Viewed 462 times

This is the modified example I am currently having this issue:

drag-from-grid.zip
(2.04 MiB) Downloaded 30 times

Notice that in "unplanned.json", the first event is a Parent Event.

Also inside "Drag.js", I modified the "onDrop" to perform the scheduling of parent and child events.


Post by dpontes »

In addition to my previous posts, I was just wondering what is the difference between passing "element" or not to the scheduleEvent function?

I did not notice any difference in behavior when I pass it or not

element-param.png
element-param.png (91.51 KiB) Viewed 461 times

Thank you!


Post by alex.l »

The error you see happened because of wrong import here

import { SchedulerEventModel } from '@bryntum/schedulerpro';

export default class Task extends SchedulerEventModel {

SchedulerEventModel is a model for Scheduler, we added Scheduler prefix for all components that have same name but used for simple Scheduler version to avoid problems with importing. For SchedulerPro please import EventModel

import { EventModel } from '@bryntum/schedulerpro';

export default class Task extends EventModel {

After that that error is gone, but your logic with adding child nodes in a loop will produce another one. But the problem there in the code, I guess you just stopped your implementation in a middle because of previous error, so I did nothing with it.

I did not notice any difference in behavior when I pass it or not

If you passed, the element will be re-used and added into timeline. If not, a new one will be added. Not a big difference.

All the best,
Alex


Post by dpontes »

Hi Alex, thank you so much for finding out that issue with the Task. That fixed the issues I was having.

I could reproduce the exact same issue I was having in our project.

Follow a video and the source code.

You will notice in the video that there are currently 2 issues with the parent events that were scheduled:

  • Dragging to a different timespan doesn't work, and the event jump back to its original position
  • If I schedule 2 parent events consecutive, the first Undo works properly, but the second one crash the lib.
issues-with-scheduled-parent-event.mp4
(3.09 MiB) Downloaded 32 times
drag-from-grid.zip
(2.04 MiB) Downloaded 31 times

Appreciate a lot your help on this! :)


Post by alex.l »

Thanks for the test case. I reproduced both problems. That looks like internal problem to me. I opened tickets to investigate it deeply.
Here are links to track the status
https://github.com/bryntum/support/issues/6296
https://github.com/bryntum/support/issues/6297

All the best,
Alex


Post by dpontes »

Hello Alex, thanks for opening the tickets.

I have also detected an issue with the Undo when using the approach of removing from one store and adding to other store.

Can you confirm for me if this is caused maybe because of something I am doing wrong, or maybe this issue could be related with the tickets you already opened?

The issue: When I assign a parent event, if I Undo it and try to assign a different parent event, the action is not performed correctly.

Follow the source code + video:

Thank you!


Post by alex.l »

Hi,

That's the same error as in https://github.com/bryntum/support/issues/6296
I commented the ticket to test this scenario too while fixing that.

Thank you.

All the best,
Alex


Post Reply