eddiewebb / flarum-calendar

MIT License
16 stars 10 forks source link

how to retrieve a list of all events? #34

Closed justoverclockl closed 3 years ago

justoverclockl commented 3 years ago

i'm about to write a pr with a widget, but i do not know how fullcalendar works, how can i retrieve a list of last X events?

eddiewebb commented 3 years ago

you can pull in the frontend store, date range is required parameters. app.store.find('events', {start: info.start.toISOString(), end: info.end.toISOString()}) https://github.com/eddiewebb/flarum-calendar/blame/379c015491a2a63cdb552509f76499dfc7580a5c/js/src/forum/Components/CalendarPage.js#L111

Since it extends flarum lists api you should be able to just at sort and limit options to your needs. But in case you want to dig in,

https://github.com/eddiewebb/flarum-calendar/blob/379c015491a2a63cdb552509f76499dfc7580a5c/extend.php#L39 https://github.com/eddiewebb/flarum-calendar/blob/379c015491a2a63cdb552509f76499dfc7580a5c/src/Api/Controllers/EventsListController.php

justoverclockl commented 3 years ago

yes i do the exact code on your first example, but i get "info is not defined", maybe i need to import something from fullcalendar?

ive tried

const baseurl = app.forum.attribute('baseUrl') + '/api/events';
    console.log(baseurl)
    fetch(baseurl)
      .then(response => response.json())
      .then(data => console.log(data));

but i get empty object