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({
|
!production && dev({
|
||||||
dirs: ['public'],
|
dirs: ['public'],
|
||||||
proxy: [
|
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
|
port: 5000
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -1,31 +1,46 @@
|
||||||
import ICAL from 'ical.js';
|
import ICAL from 'ical.js';
|
||||||
|
|
||||||
|
const clouds = {
|
||||||
|
KLUB_RESEAU: "klub-reseau",
|
||||||
|
ELEVES_ENS: "eleves-ens"
|
||||||
|
};
|
||||||
|
|
||||||
const calendars = {
|
const calendars = {
|
||||||
"5WrcagPPARQ3BD87": {
|
"5WrcagPPARQ3BD87": {
|
||||||
|
cloud: clouds.KLUB_RESEAU,
|
||||||
name: "Club réseau",
|
name: "Club réseau",
|
||||||
color: null
|
color: null
|
||||||
},
|
},
|
||||||
"TFEAKjAgNFQZpNjo": {
|
"TFEAKjAgNFQZpNjo": {
|
||||||
|
cloud: clouds.KLUB_RESEAU,
|
||||||
name: "hackENS",
|
name: "hackENS",
|
||||||
color: null
|
color: null
|
||||||
}
|
},
|
||||||
|
"LLWm8qK9iC5YGrrR": {
|
||||||
|
cloud: clouds.ELEVES_ENS,
|
||||||
|
name: "Délégation Générale",
|
||||||
|
short_name: "DG",
|
||||||
|
color: null
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const calendarTree = {
|
export const calendarTree = {
|
||||||
"COF": [
|
"Clubs COF": [
|
||||||
"Club réseau",
|
"Club réseau",
|
||||||
"hackENS"
|
"hackENS",
|
||||||
]
|
],
|
||||||
|
"COF": [],
|
||||||
|
"Délégation Générale": [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const calendarIds = Object.keys(calendars);
|
const calendarIds = Object.keys(calendars);
|
||||||
|
|
||||||
function mkCalendarUrl(id) {
|
function mkCalendarUrl(id, { cloud }) {
|
||||||
return `/cal/${id}/?export&accept=jcal`;
|
return `/cal/${cloud}/${id}/?export&accept=jcal`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchCalendar(id) {
|
function fetchCalendar(id, cal) {
|
||||||
return fetch(mkCalendarUrl(id), { credentials: 'omit' }).then(resp => resp.json()).catch(err => console.error(err));
|
return fetch(mkCalendarUrl(id, cal), { credentials: 'omit' }).then(resp => resp.json()).catch(err => console.error(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
class Calendar {
|
class Calendar {
|
||||||
|
@ -51,8 +66,8 @@ function fcEventFromjCalEvent(cal) {
|
||||||
const end = new Date(evt.dtend);
|
const end = new Date(evt.dtend);
|
||||||
const fcEvent = {
|
const fcEvent = {
|
||||||
title: `${cal.name}: ${evt.summary}`,
|
title: `${cal.name}: ${evt.summary}`,
|
||||||
start,
|
start: evt.dtstart,
|
||||||
end,
|
end: evt.dtend,
|
||||||
color: cal.color,
|
color: cal.color,
|
||||||
duration: end - start // in ms
|
duration: end - start // in ms
|
||||||
};
|
};
|
||||||
|
@ -78,8 +93,8 @@ function fcEventFromjCalEvent(cal) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mkEventsFromCalendar(id) {
|
function mkEventsFromCalendar(id, cal) {
|
||||||
return fetchCalendar(id).then(calendar => {
|
return fetchCalendar(id, cal).then(calendar => {
|
||||||
if (calendar[0] !== 'vcalendar') return;
|
if (calendar[0] !== 'vcalendar') return;
|
||||||
const cal = new Calendar(id, calendar)
|
const cal = new Calendar(id, calendar)
|
||||||
return cal.events.map(fcEventFromjCalEvent(cal))
|
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.
|
// TODO: move to FullCalendar custom fetcher to control start&end.
|
||||||
export function refreshEvents(selectedCalendars) {
|
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