Remove calendar script workaround

This commit is contained in:
sodoku 2019-01-28 22:31:39 +01:00
parent 81a2bb35dd
commit 6433810d98
2 changed files with 69 additions and 64 deletions

View file

@ -3,74 +3,80 @@ import '../elements/time';
function getEvents(number, callback) { function getEvents(number, callback) {
const now = new Date(); const now = new Date();
const allEvents = window.c_base_events.concat(window.c_base_regulars, window.c_base_seminars); fetch('/../calendar')
const current = allEvents.filter((event) => {
if (event.id === 45) {
return false;
}
const start = new Date(event.start);
if ((!event.data || event.allDay) && start.toDateString() !== now.toDateString()) {
return false;
}
const end = new Date(event.end);
if (start > now) {
return false;
}
if (end < now) {
return false;
}
return true;
});
const upcoming = allEvents.filter((event) => {
if (event.id === 45) {
return false;
}
const start = new Date(event.start);
if (start > now) {
return true;
}
return false;
});
fetch('https://launchlibrary.net/1.3/launch/next/2')
.then(res => res.json()) .then(res => res.json())
.then((res) => { .then((calendars) => {
const launches = res.launches.map((launch) => { const allEvents = calendars.c_base_events.concat(
const start = new Date(launch.windowstart); calendars.c_base_regulars, calendars.c_base_seminars,
const end = new Date(launch.windowend); );
return { const current = allEvents.filter((event) => {
allDay: false, if (event.id === 45) {
start: start.toISOString(), return false;
end: end.toISOString(), }
title: launch.name, const start = new Date(event.start);
id: launch.lsp.abbrev, if ((!event.data || event.allDay) && start.toDateString() !== now.toDateString()) {
type: 'launch', return false;
}; }
const end = new Date(event.end);
if (start > now) {
return false;
}
if (end < now) {
return false;
}
return true;
}); });
const events = current.concat(upcoming, launches); const upcoming = allEvents.filter((event) => {
events.sort((a, b) => { if (event.id === 45) {
if (a.start < b.start) { return false;
return -1;
} }
if (a.start > b.start) { const start = new Date(event.start);
return 1; if (start > now) {
return true;
} }
return 0; return false;
}); });
return callback(events.slice(0, number));
}) fetch('https://launchlibrary.net/1.3/launch/next/2')
.catch(() => { .then(res => res.json())
const events = current.concat(upcoming); .then((res) => {
events.sort((a, b) => { const launches = res.launches.map((launch) => {
if (a.start < b.start) { const start = new Date(launch.windowstart);
return -1; const end = new Date(launch.windowend);
} return {
if (a.start > b.start) { allDay: false,
return 1; start: start.toISOString(),
} end: end.toISOString(),
return 0; title: launch.name,
}); id: launch.lsp.abbrev,
return callback(events.slice(0, number)); type: 'launch',
};
});
const events = current.concat(upcoming, launches);
events.sort((a, b) => {
if (a.start < b.start) {
return -1;
}
if (a.start > b.start) {
return 1;
}
return 0;
});
return callback(events.slice(0, number));
})
.catch(() => {
const events = current.concat(upcoming);
events.sort((a, b) => {
if (a.start < b.start) {
return -1;
}
if (a.start > b.start) {
return 1;
}
return 0;
});
return callback(events.slice(0, number));
});
}); });
} }

View file

@ -5,7 +5,6 @@
<title>c-base event calendar</title> <title>c-base event calendar</title>
<script src="../vendor/webcomponentsjs/webcomponents-lite.js"></script> <script src="../vendor/webcomponentsjs/webcomponents-lite.js"></script>
<script src="../vendor/webcomponentsjs/custom-elements-es5-adapter.js"></script> <script src="../vendor/webcomponentsjs/custom-elements-es5-adapter.js"></script>
<script src="https://www.c-base.org/calendar/exported/events.js"></script>
<script src="../lib/calendar.js"></script> <script src="../lib/calendar.js"></script>
<link rel="stylesheet" href="../theme/c-base.css"> <link rel="stylesheet" href="../theme/c-base.css">
<style> <style>