Hello.
I need to achieve following case:
1) I am doing drag & drop and using beforeEventDropFinalize event.
2) I have async logic to check I can do it or no.
3) After checking I am receiving new Gantt data from API and I need to replace resource data.
I need to replace:
- dependencies
- events
- assignments
- resource info
ResourceId is not changing, but all other fields can be changed.
Resource from ResourcesStore cannot be removed, because I need to left him in same place, same zoom, same scroll etc - it need to be 'silent', but with tasks refresh on UI.
I implemented my custom data changer, where I am comparing resources/tasks/dependencies and removing all which are associated with resource.
Like this:
private refreshDependencies(refreshedDependencies: any[], refreshedTasks: any[]): void {
const dependenciesToRemove: any[] = [];
this.schedulerInstance.dependencyStore.forEach(
(x: any) => {
const taskFrom = refreshedTasks.find(y => y.id === x.from);
const taskTo = refreshedTasks.find(y => y.id === x.to);
if (taskFrom != null || taskTo != null) {
dependenciesToRemove.push(x);
}
});
dependenciesToRemove.forEach((x: any) => this.schedulerInstance.dependencyStore.remove(x));
this.schedulerInstance.dependencyStore.commit();
this.schedulerInstance.dependencyStore.add(refreshedDependencies);
}
I replaced my models with 'any'.
My solution looks to work, but not fully after upgrade SchedulerPro to 4.1.3
After first drag & drop is ok, but after click of any event from this resource, I can see error in console:
error-handler.service.ts:104 TypeError: Cannot read property 'event' of undefined
at gantt.module.js:141246
at Array.map (<anonymous>)
at EventDrag.getMinimalDragData (gantt.module.js:141246)
at EventDrag.onBeforeDragStart (gantt.module.js:134135)
at DragHelper.trigger (gantt.module.js:5805)
at DragHelper.callPreventable (gantt.module.js:5648)
at DragHelper.internalMove (gantt.module.js:37167)
at DragHelper.onMouseMove (gantt.module.js:37234)
at HTMLDocument.handler (gantt.module.js:36314)
at ZoneDelegate.invokeTask (zone-evergreen.js:406)
And this is fragment form gantt.module.js:
const eventRecords = [...new Set(assignmentRecords.map(assignment => assignment.event))]; <--- line error
return {
eventRecord,
resourceRecord,
assignmentRecord,
eventRecords,
assignmentRecords
};
}
I am sure that you predicted this behavior and there is simple way exist to achievie this refreshing.
Greetings & waiting for help:)