calendars: add DG and support many clouds (federation!)
This commit is contained in:
parent
6053feff3b
commit
511bb2b0a6
2 changed files with 34 additions and 14 deletions
|
@ -69,7 +69,8 @@ export default {
|
|||
!production && dev({
|
||||
dirs: ['public'],
|
||||
proxy: [
|
||||
{ from: '/cal', to: 'https://nuage.beta.rz.ens.wtf/remote.php/dav/public-calendars/' }
|
||||
{ from: '/cal/klub-reseau', to: 'https://nuage.beta.rz.ens.wtf/remote.php/dav/public-calendars/' },
|
||||
{ from: '/cal/eleves-ens', to: 'https://cloud.eleves.ens.fr/remote.php/dav/public-calendars/' }
|
||||
],
|
||||
port: 5000
|
||||
}),
|
||||
|
|
|
@ -1,31 +1,46 @@
|
|||
import ICAL from 'ical.js';
|
||||
|
||||
const clouds = {
|
||||
KLUB_RESEAU: "klub-reseau",
|
||||
ELEVES_ENS: "eleves-ens"
|
||||
};
|
||||
|
||||
const calendars = {
|
||||
"5WrcagPPARQ3BD87": {
|
||||
cloud: clouds.KLUB_RESEAU,
|
||||
name: "Club réseau",
|
||||
color: null
|
||||
},
|
||||
"TFEAKjAgNFQZpNjo": {
|
||||
cloud: clouds.KLUB_RESEAU,
|
||||
name: "hackENS",
|
||||
color: null
|
||||
}
|
||||
},
|
||||
"LLWm8qK9iC5YGrrR": {
|
||||
cloud: clouds.ELEVES_ENS,
|
||||
name: "Délégation Générale",
|
||||
short_name: "DG",
|
||||
color: null
|
||||
},
|
||||
};
|
||||
|
||||
export const calendarTree = {
|
||||
"COF": [
|
||||
"Clubs COF": [
|
||||
"Club réseau",
|
||||
"hackENS"
|
||||
]
|
||||
"hackENS",
|
||||
],
|
||||
"COF": [],
|
||||
"Délégation Générale": [],
|
||||
};
|
||||
|
||||
const calendarIds = Object.keys(calendars);
|
||||
|
||||
function mkCalendarUrl(id) {
|
||||
return `/cal/${id}/?export&accept=jcal`;
|
||||
function mkCalendarUrl(id, { cloud }) {
|
||||
return `/cal/${cloud}/${id}/?export&accept=jcal`;
|
||||
}
|
||||
|
||||
function fetchCalendar(id) {
|
||||
return fetch(mkCalendarUrl(id), { credentials: 'omit' }).then(resp => resp.json()).catch(err => console.error(err));
|
||||
function fetchCalendar(id, cal) {
|
||||
return fetch(mkCalendarUrl(id, cal), { credentials: 'omit' }).then(resp => resp.json()).catch(err => console.error(err));
|
||||
}
|
||||
|
||||
class Calendar {
|
||||
|
@ -51,8 +66,8 @@ function fcEventFromjCalEvent(cal) {
|
|||
const end = new Date(evt.dtend);
|
||||
const fcEvent = {
|
||||
title: `${cal.name}: ${evt.summary}`,
|
||||
start,
|
||||
end,
|
||||
start: evt.dtstart,
|
||||
end: evt.dtend,
|
||||
color: cal.color,
|
||||
duration: end - start // in ms
|
||||
};
|
||||
|
@ -78,8 +93,8 @@ function fcEventFromjCalEvent(cal) {
|
|||
}
|
||||
}
|
||||
|
||||
function mkEventsFromCalendar(id) {
|
||||
return fetchCalendar(id).then(calendar => {
|
||||
function mkEventsFromCalendar(id, cal) {
|
||||
return fetchCalendar(id, cal).then(calendar => {
|
||||
if (calendar[0] !== 'vcalendar') return;
|
||||
const cal = new Calendar(id, calendar)
|
||||
return cal.events.map(fcEventFromjCalEvent(cal))
|
||||
|
@ -100,5 +115,9 @@ export function mkEvent(title, start, duration, ...rest) {
|
|||
|
||||
// TODO: move to FullCalendar custom fetcher to control start&end.
|
||||
export function refreshEvents(selectedCalendars) {
|
||||
return Promise.all(calendarIds.filter(id => selectedCalendars ? selectedCalendars.includes(id) : true).map(mkEventsFromCalendar))
|
||||
return Promise.all(
|
||||
calendarIds
|
||||
.filter(id => selectedCalendars ? selectedCalendars.includes(id) : true)
|
||||
.map(id => mkEventsFromCalendar(id, calendars[id]))
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue