From 857a9c0195a2fb6281ff1981f3abceb35538444c Mon Sep 17 00:00:00 2001 From: Cameron Steele Date: Fri, 9 Feb 2024 02:58:13 +0000 Subject: [PATCH 1/2] Add full-calendar to calendar page --- assets/js/calendar.js | 52 ++++++++++++++++++++----------------------- pages/calendar.md | 6 ++--- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/assets/js/calendar.js b/assets/js/calendar.js index 49d62d9..1e50320 100644 --- a/assets/js/calendar.js +++ b/assets/js/calendar.js @@ -1,18 +1,15 @@ -fetchCalendarData().then(data => { - var e = document.getElementById("calendar"); - e.innerHTML = e.innerHTML || ""; - var locale = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; - data.forEach(el => { - e.innerHTML += `
-
-

${el.name}

- in ${el.daysUntil} days -
-

${el.membersOnly ? "Members Only" : "Open To The Public"}

-

${el.start.toLocaleDateString("en-us",locale)} from ${String(el.start.getHours()).padStart(2,'0')}:${String(el.start.getMinutes()).padStart(2,'0')} until ${String(el.end.getHours()).padStart(2,'0')}:${String(el.end.getMinutes()).padStart(2,'0')}

- ${el.description} -
`; - }); +fetchCalendarData().then(events => { + const calendarEl = document.getElementById("calendar"); + const calendar = new FullCalendar.Calendar(calendarEl, { + initialView: "listWeek", + events, + headerToolbar: { + left: 'prev,next today', + center: 'title', + right: 'dayGridMonth,timeGridWeek,timeGridDay' + }, + }); + calendar.render(); }); async function fetchCalendarData() { @@ -30,26 +27,25 @@ async function fetchCalendarData() { .then(data => { var now = new Date(Date.now()); var today = new Date(now.getFullYear(),now.getMonth(),now.getDate()); - data.forEach(element => { - var start = new Date(element.start * 1000); - var end = new Date(element.end * 1000); - var durationDay = new Date(start.getFullYear(),start.getMonth(), start.getDate()); - var diffTime = Math.abs(durationDay - today); - var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); - element.start = start; - element.end = end; - element.daysUntil = diffDays; - }); - data = data.sort((a,b) => { + + return data.map(element => { + const title = element.name; + const start = new Date(element.start * 1000); + const end = new Date(element.end * 1000); + const durationDay = new Date(start.getFullYear(),start.getMonth(), start.getDate()); + const diffTime = Math.abs(durationDay - today); + const daysUntil = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); + + return {title, start, end, daysUntil}; + }).sort((a,b) => { if (a.daysUntil > b.daysUntil) return 1; else if (b.daysUntil > a.daysUntil) return -1; else if (a.name > b.name) return -1; else if (b.name > a.name) return 1; return 0; }); - return data; }) .catch(error => { console.error('Error:', error); }); - } \ No newline at end of file + } diff --git a/pages/calendar.md b/pages/calendar.md index bc5f09f..c98ae76 100644 --- a/pages/calendar.md +++ b/pages/calendar.md @@ -11,6 +11,6 @@ hero: enabled: false --- -
- - \ No newline at end of file +
+ + From 882fe86919558c0d063e18e8b3a697021fa65244 Mon Sep 17 00:00:00 2001 From: Cameron Steele Date: Fri, 9 Feb 2024 02:59:53 +0000 Subject: [PATCH 2/2] Revert to dayGridMonth default --- assets/js/calendar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/calendar.js b/assets/js/calendar.js index 1e50320..fddd005 100644 --- a/assets/js/calendar.js +++ b/assets/js/calendar.js @@ -1,7 +1,7 @@ fetchCalendarData().then(events => { const calendarEl = document.getElementById("calendar"); const calendar = new FullCalendar.Calendar(calendarEl, { - initialView: "listWeek", + initialView: "dayGridMonth", events, headerToolbar: { left: 'prev,next today',