Our pure JavaScript Scheduler component


Post by Globox21126 »

How to configure stm to work with adding multiple events in the for loop. As below, I start a batch for each of the stores, multi add works as it should, because events are added at once. When I run undo, unfortunately only the last one is removed. Did I do something wrong with the configuration?

Multiadd:

              if (date) {
                let _date : Date = date;
                                eventStore.beginBatch(); 
                assignmentStore.beginBatch(); 
                resourceStore.beginBatch(); 
                for(let i = 0; i < this.multiselectPayload.length; i++){
                  let event = new EventModel(this.multiselectPayload[i]);
                  event.setStartDate(_date, true);
                  let createdEvent = scheduler.eventStore.add(event);
                  let result : EventModel  = scheduler.eventStore.find(x=>x.id === createdEvent[0].id) as 
                  EventModel;     
assignmentStore.assignEventToResource(event, context.resource); await eventStore.project.commitAsync(); await assignmentStore.project.commitAsync();
await resourceStore.project.commitAsync();
_date = result.endDate as Date;
} eventStore.endBatch(); assignmentStore.endBatch(); resourceStore.endBatch(); let differenceArray = this.sessionServiceEvents.filter(x => !this.multiselectPayload.includes(x)); this.sessionService.eventsToAddOnMultiselectArray.next([]); this.sessionService.events.next(differenceArray); }

State Tracking Manager Service:

export class StateTrackingService {

constructor(public sessionService: SessionService) {}

//private variables
undo: number;
redo: number;

public stmConfig = new StateTrackingManager({
    autoRecord : true,
    listeners  : {
        'recordingstop' : () => {
           this.sessionService.sessionUndo.next((this.stmConfig.position - 1).toString());
           this.sessionService.sessionRedo.next((this.stmConfig.queue.length - (this.stmConfig.position)).toString());
        },
        'restoringstop' : () => {
            this.sessionService.sessionUndo.next((this.stmConfig.position - 1).toString());
            this.sessionService.sessionRedo.next((this.stmConfig.queue.length - (this.stmConfig.position)).toString());
        }
    },
});

public setStateRecorder(resourceStore: SchedulerResourceStore, eventStore: SchedulerEventStore, assignmentStore: SchedulerAssignmentStore) {
    
    //properties
    this.stmConfig.autoRecord = this.stmConfig.autoRecord;
    this.stmConfig.disabled = this.stmConfig.disabled;

    //stores to record
    this.stmConfig.addStore(resourceStore);
    this.stmConfig.addStore(eventStore);
    this.stmConfig.addStore(assignmentStore);

    //enabling 
    this.stmConfig.enable();
}

}

Initialization of STM service in main component:

    this.dragAndDropService.getDragFunction(this.scheduler, this.myDrag, this.assignmentStore, this.eventStore, this.resourceStore);


Post by alex.l »

Try to disable autoRecord before do your loops. and call startTransaction before and stopTransaction after all (end set autoRecord back).
https://bryntum.com/docs/scheduler/#Core/data/stm/StateTrackingManager#config-autoRecord
https://bryntum.com/docs/scheduler/#Core/data/stm/StateTrackingManager#function-startTransaction
https://bryntum.com/docs/scheduler/#Core/data/stm/StateTrackingManager#function-stopTransaction

Small remarks.

                  let createdEvent = scheduler.eventStore.add(event);
                  let result : EventModel  = scheduler.eventStore.find(x=>x.id === createdEvent[0].id) as 
                  EventModel; 

createdEvent[0] === result

And I am not sure about use case, but looks like all you need is dependencies https://bryntum.com/docs/scheduler/#Scheduler/feature/Dependencies to have tasks scheduled one by one with no need in calculations of every endDate
https://bryntum.com/docs/scheduler/#Scheduler/model/DependencyModel
https://bryntum.com/examples/scheduler/dependencies/

All the best,
Alex


Post by Globox21126 »

Thank you!

Now it works.
About your remark, I add many tasks that do not necessarily have to be related in time. Therefore, I cannot use the dependency. But thanks :)


Post Reply