search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Loading events from multiple sources (onto Scheduler)

Asked by TomHH
2 years ago.

I want to load and display events from more than one source.

I'm currently using:
dpRota.events.load("api/rotaevents/list/2?format=dp_events");
dpRota.events.load("api/events/list?format=dp_events");

but this only shows events from one source, when I inspect dpRota.events.list, I can only see the one list of events.

How can I load and show both on the same scheduler?

Comment posted by TomHH
2 years ago.

I should add, that if both sources have 'clashing' events, then they should be displayed stacked.

Answer posted by Dan Letecky [DayPilot]
2 years ago.

You need to make two requests manually and merge the results into a single array.

The following example uses two parallel requests, waits until both return a result and update the Scheduler:

const start = dpRota.visibleStart();
const end = dpRota.visibleEnd();

const p1 = fetch(`api/rotaevents/list/2?format=dp_events&start=${start}&end=${end}`).then(response => response.json());
const p2 = fetch(`api/events/list?format=dp_events&start=${start}&end=${end}`).then(response => response.json());

const [e1, e2] = await Promise.all([p1, p2]);

const events = e1.concat(e2);

dpRota.update({
  events
});

See also:
https://code.daypilot.org/49902/javascript-scheduler-wait-for-parallel-http-requests

Comment posted by TomHH
2 years ago.

Thank you!

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.