Our powerful JS Calendar component


Post by tdset »

Hello,

I'm using a configuration similar to the official Calendar Scheduler demo: https://www.bryntum.com/examples/calendar/calendar-scheduler/

Also I'm using an external events editor, open on beforeEventEdit().

I have trouble working with events due to the durationUnit being inconsistent. For instance looking at the event using this listener:

beforeEventEdit({ eventRecord }) {
    console.log(eventRecord);
}

reveals that:

  • durationUnit for an existing event is "day"
  • durationUnit for an event created by clicking and dragging in Timeline view is "day"
  • durationUnit for an event created by clicking and dragging in Day or Week views is "m"
  • durationUnit for an event created by double clicking is "hour"

Is there a reason for this and how should I go about streamlining things?

I tried to use durationMS instead of duration but this doesn't entirely solve the problem since I also use the sync transport mechanism, which doesn't POST the durationMS field.

Also the server side code responding to sync needs to respond with an object containing a "duration" property that can be interpreted in different ways.

The effect is that at any point you can have, say, 3 different events displayed, each of them with a duration expressed in a different unit:

  • in days if the event existed on initial load or if it was created by clicking and dragging in Timeline view
  • in minutes if the event was created by clicking and dragging in Day or Week view
  • in hours if the event was created by double clicking
    which is very inconvenient when using an external editor and the sync mechanism.

Can you recommend an optimal way of approaching this?

Thanks.


Post by tdset »

I managed to (partially) work around this issue by creating a custom model that specifies 'm' as the default value for durationUnit and by adding the following to the modes.timeline config:

createEventOnDblClick: {
    useEventModelDefaults: true,
},

I have found this solution by checking the changelog of the recent version 4.2.3.

So now I'm able to use the same unit of time for all events, regardless of how they were created, in Timeline view.

However this solution only appears to be available for Scheduler, so is there any to apply the same solution to the Calendar views, which on double click create events with durations expressed as hours?

Also may I suggest that there should be a consistent approach to this, meaning that by default the durationUnit should always have the same value (according to the docs, it should be 'day'), and the user should not be required to use custom model and configuration options to work around this.

Thanks!


Post by Maxim Gorkovsky »

Hello.
Reproduced, ticket opened here: https://github.com/bryntum/support/issues/3393 Thank you for report!

If you want to normalize event duration, you can try subscribing to store add event and update duration there, smth like:

calendar.eventStore.on({
    add({ records }) {
        records.forEach(record => {
            record.setDuration(DateHelper.as('day', record.duration, record.durationUnit), 'day');
        });
    }
});

Post by tdset »

Your suggestion worked, thanks Maxim. 👍


Post Reply