Our pure JavaScript Scheduler component


Post by markusmo »

Hi
I am using the new assignment model.

What I am trying to achieve is assinging resources to events at runtime.
For that I am calling the EventStores own
schedule.eventStore.assignEventToResource(event,resource)

And then I see visually in my scheduler, that resources do have this event assigned.
But somehow, when I call
schedule.eventStore.getAssignmentsForEvent(event)
it returns an empty array.

In conclusion:
At initialization time I do have events which return an array of assignments when I call the above mentioned function.
At runtime when I assign events to resources, these events do not have an array of assignments at all, despite being displayed correctly in my scheduler... I am a bit confused, in what I do wrong.

Post by pmiklashevich »

Hello,

Thanks for the feedback. Yes, the docs looks a bit confusing. getAssignmentsForEvent/getAssignmentsForResource work only if assignment store is defined. Otherwise it just returns an empty array. For example, our MultiAssign demo has assignment store, so you can open it and run in console line by line:
event = scheduler.eventStore.first
resource = scheduler.resourceStore.getById('r3')
scheduler.eventStore.isEventAssignedToResource(event, resource)
// false
scheduler.eventStore.getAssignmentsForEvent(event).length
// 3

scheduler.eventStore.assignEventToResource(event, resource)
scheduler.eventStore.isEventAssignedToResource(event, resource)
// true
scheduler.eventStore.getAssignmentsForEvent(event).length
// 4
Cheers,
Pavel

Pavlo Miklashevych
Sr. Frontend Developer


Post by markusmo »

Hi
I had a look at my implementation:
My scheduler object does have an assignment store.
Calling
scheduler.eventStore.assignEventToResource(event, resource)
does add an entry to the assignment store.
But corresponding event does not have an "assignments" property, only the corresponding resource "assignments" property gets updated.

Post by pmiklashevich »

Hello,

Could you please provide a runnable test case we can look at? Please take one of our shipped examples as a base and change it a bit until it starts working like yours. Then zip it up and upload here.

Thanks,
Pavel

Pavlo Miklashevych
Sr. Frontend Developer


Post by markusmo »

Hi
I implemented and example.
There is a Button "more" at the top. Clicking it adds more events.
Then by clicking the events context menu you can see a fourth item "Alert Assignments".
Newly added events are titled "Task without assignment" and there you can see, what I mean.
These new events return "undefined" other ones return an array of objects.
Attachments
multi_example.7z
(3.68 MiB) Downloaded 150 times

Post by pmiklashevich »

Hello,

Thanks for the report! I've created a ticket to check it: https://app.assembla.com/spaces/bryntum/tickets/8482

For now please refrain from using beginBatch/endBatch when you create new events, and since add method accepts an array, your handler might look like this:
let button = new Button({
    appendTo : 'more_events',
    text     : 'More',
    onClick() {
        const tasks = JSON.parse(JSON.stringify(events));
        const assignments = tasks.map(task => {
            task.id = task.id + 10;
            task.startDate = new Date(2017, 0, 1, 10);
            task.endDate = new Date(2017, 0, 1, 12);
            task.name = 'Task without assignment ' + task.id;

            return {
                resourceId : 'r1',
                eventId    : task.id
            };
        });

        scheduler.eventStore.add(tasks);
        scheduler.assignmentStore.add(assignments);

        scheduler.eventStore.commit();
    }
});
Best,
Pavel

Pavlo Miklashevych
Sr. Frontend Developer


Post by markusmo »

Thanks for the reply
This helps alot :-)

Post Reply