-
Notifications
You must be signed in to change notification settings - Fork 8
changed office hours banner to use ical #1221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||
| async function displayOfficeHoursCalendar() { | ||||||
| const calendarDiv = document.getElementById('office-hours-calendar'); | ||||||
| const calendarP = document.getElementById('office-hours-calendar-message'); | ||||||
| if (!calendarDiv) return; | ||||||
|
|
||||||
| const text = await fetch("/assets/training_calendar.ics") | ||||||
| .then(r => r.ok ? r.text() : ""); | ||||||
| if (!text) { | ||||||
| calendarP.innerHTML = 'Failed to load calendar.'; | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| try { | ||||||
| const jcal = ICAL.parse(text); | ||||||
| const comp = new ICAL.Component(jcal); | ||||||
| const events = comp.getAllSubcomponents('vevent').map(vevent => { | ||||||
| const summary = vevent.getFirstPropertyValue('summary'); | ||||||
| const dtstart = vevent.getFirstPropertyValue('dtstart'); | ||||||
| const description = (vevent.getFirstPropertyValue('description') || '').replace(/\\n/g, '\n').replace(/\\,/g, ','); | ||||||
| const urlMatch = description.match(/(https?:\/\/[^\s]+)/); | ||||||
| const start = dtstart.toJSDate(); | ||||||
| return { | ||||||
| title: summary, | ||||||
| start, | ||||||
| description, | ||||||
| meetingLink: urlMatch ? urlMatch[1] : MEETING_LINK, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| day: start.toLocaleDateString('en-US', { weekday: 'long' }), | ||||||
| date: start.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }), | ||||||
| time: start.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }) | ||||||
| }; | ||||||
| }); | ||||||
|
|
||||||
| // Sort events by date | ||||||
| events.sort((a, b) => a.start - b.start); | ||||||
|
|
||||||
| // Create table | ||||||
| const tableWrap = document.createElement('div'); | ||||||
| tableWrap.className = 'md-typeset__table' | ||||||
| const table = document.createElement('table'); | ||||||
| let rows = ''; | ||||||
| events.forEach(event => { | ||||||
| rows += ` | ||||||
| <tr> | ||||||
| <td>${event.day}, ${event.date}</td> | ||||||
| <td>${event.time}</td> | ||||||
| <td><a href=" webcal://assets/training_calendar.ics" download class="md-button md-button--addcal"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M680-80v-120H560v-80h120v-120h80v120h120v80H760v120h-80Zm-480-80q-33 0-56.5-23.5T120-240v-480q0-33 23.5-56.5T200-800h40v-80h80v80h240v-80h80v80h40q33 0 56.5 23.5T760-720v244q-20-3-40-3t-40 3v-84H200v320h280q0 20 3 40t11 40H200Zm0-480h480v-80H200v80Zm0 0v-80 80Z"/></svg>Add to Calendar</a></td> | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arrr! That link be a mess, ye barnacle-brained lubber! Ye've got a leadin' space, a
Suggested change
|
||||||
| </tr> | ||||||
| `; | ||||||
| }); | ||||||
| table.innerHTML = `<tbody>${rows}</tbody>`; | ||||||
| tableWrap.appendChild(table); | ||||||
| calendarDiv.appendChild(tableWrap); | ||||||
| calendarP.innerHTML = ''; | ||||||
| } catch (error) { | ||||||
| console.error('Error parsing ICS:', error); | ||||||
| calendarP.innerHTML = '<div class="admonition bug"><p class="admonition-title">Error loading Calendar.</p></div>'; | ||||||
| } | ||||||
| } | ||||||
| window.addEventListener("load", displayOfficeHoursCalendar); | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,12 @@ | ||||||||||||||||
| .md-button.md-button--addcal { | ||||||||||||||||
| padding: 0.1em; | ||||||||||||||||
| margin: auto; | ||||||||||||||||
| font-size: medium; | ||||||||||||||||
| padding: 0.5em; | ||||||||||||||||
|
Comment on lines
+2
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ye be paintin' the hull twice! Why set the padding to
Suggested change
|
||||||||||||||||
| } | ||||||||||||||||
| .md-button.md-button--addcal > svg { | ||||||||||||||||
| height: 24px; | ||||||||||||||||
| margin: auto; | ||||||||||||||||
| vertical-align: middle; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,3 +126,4 @@ extra_javascript: | |
| - https://status.nesi.org.nz/embed/script.js | ||
| - assets/javascripts/mathjax.js | ||
| - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js | ||
| - https://cdnjs.cloudflare.com/ajax/libs/ical.js/1.3.0/ical.min.js | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arrr! Ye've put the cart before the horse, ye scurvy dog! Ye be callin' upon the |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrr! Ye be firin' the cannons before the ship is even in the water! Callin'
showOfficeBanner()immediately is risky business. Better to wait for theloadevent like ye did in the other scroll, or ye might find theICALlibrary hasn't even boarded yet.