Skip to content

Commit

Permalink
feat: support rrule in calendar and pass on location + description
Browse files Browse the repository at this point in the history
  • Loading branch information
tdely committed Mar 6, 2024
1 parent 6233426 commit 0f39fbc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
10 changes: 9 additions & 1 deletion calendar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ set -o nounset
set -o errexit
fcver="6.1.10"
icver="1.5.0"
rrver="2.6.4"
wdir="tmp/"
fcdir="${wdir}/fullcalendar-${fcver}"
fcout="${fcdir}.zip"
icout="${wdir}/ical.min.js"
rrout="${wdir}/rrule.min.js"
mkdir -p "${wdir}"
if [ ! -f "${icout}" ]; then
wget "https://github.com/kewisch/ical.js/releases/download/v${icver}/ical.min.js" -O "${icout}"
echo "" >> "${icout}"
echo "\n" >> "${icout}"
fi
if [ ! -f "${rrout}" ]; then
wget "https://cdn.jsdelivr.net/npm/rrule@${rrver}/dist/es5/rrule.min.js" -O "${rrout}"
fi
if [ ! -f "${fcout}" ]; then
wget "https://github.com/fullcalendar/fullcalendar/releases/download/v${fcver}/fullcalendar-${fcver}.zip" -O "${fcout}"
Expand All @@ -21,11 +26,14 @@ unzip -o "${fcout}" \
fullcalendar-${fcver}/packages/core/locales/sv.global.min.js \
fullcalendar-${fcver}/packages/daygrid/index.global.min.js \
fullcalendar-${fcver}/packages/list/index.global.min.js \
fullcalendar-${fcver}/packages/rrule/index.global.min.js \
-d "${wdir}"
cat "${icout}" \
${rrout} \
${fcdir}/packages/core/index.global.min.js \
${fcdir}/packages/core/locales/sv.global.min.js \
${fcdir}/packages/daygrid/index.global.min.js \
${fcdir}/packages/list/index.global.min.js \
${fcdir}/packages/rrule/index.global.min.js \
data/js/buildcalendar.js \
> data/js/calendar.min.js
20 changes: 17 additions & 3 deletions data/js/buildcalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ function pad(val) {
function buildCalendar(dlpath) {
document.addEventListener('DOMContentLoaded', () => {
const dialog = document.querySelector('#calendar-modal')
const dialogTitle = document.querySelector('#calendar-modal h3')
const dialogTime = document.querySelector('#calendar-modal p')
const dialogTitle = document.querySelector('#calendar-modal-title')
const dialogDate = document.querySelector('#calendar-modal-date')
const dialogPlace = document.querySelector('#calendar-modal-location')
const dialogDesc = document.querySelector('#calendar-modal-description')
document.querySelector('#calendar-modal button').addEventListener('click', () => {dialog.close()})
const cal = new FullCalendar.Calendar(document.getElementById('calendar'), {
headerToolbar: {
Expand Down Expand Up @@ -42,7 +44,9 @@ function buildCalendar(dlpath) {
}
}
dialogTitle.innerText = info.event.title
dialogTime.innerText = time
dialogDate.innerText = time
dialogPlace.innerText = info.event.extendedProps.location
dialogDesc.innerText = info.event.extendedProps.description
dialog.showModal()
},
})
Expand All @@ -56,6 +60,8 @@ function buildCalendar(dlpath) {
var res = {
'title': item.getFirstPropertyValue('summary'),
'location': item.getFirstPropertyValue('location'),
'description': item.getFirstPropertyValue('description'),
'categories': item.getFirstPropertyValue('categories'),
};
var rrule = item.getFirstPropertyValue('rrule')
if (rrule != null) {
Expand All @@ -72,6 +78,14 @@ function buildCalendar(dlpath) {
var startdate = new Date(dtstart)
var enddate = new Date(dtend)
res.duration = enddate - startdate
//exclusions
var exdate = item.getAllProperties('exdate')
if (exdate != null) {
res.exdate = []
for (i = 0; i < exdate.length; i++) {
res.exdate.push(exdate[i].getFirstValue())
}
}
} else {
if (item.hasProperty('dtstart') && item.hasProperty('dtend')) {
res.start = item.getFirstPropertyValue('dtstart').toString()
Expand Down
6 changes: 4 additions & 2 deletions src/information.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<div class="entry-content clearfix">
<h2 id="kalender">Kalender</h2>
<dialog id="calendar-modal">
<h3></h3>
<p></p>
<h3 id="calendar-modal-title"></h3>
<span id="calendar-modal-date"></span>
<p id="calendar-modal-location"></p>
<p id="calendar-modal-description"></p>
<button autofocus>Stäng</button>
</dialog>
<div id="calendar"></div>
Expand Down

0 comments on commit 0f39fbc

Please sign in to comment.