Skip to content

Commit

Permalink
Filter events in "next events" list
Browse files Browse the repository at this point in the history
Most people just want to see when the next
(Open|Self|Rad|Zerspanungs|...)Lab takes place. They are not interested
in internal events like "OrgaTreffen". So we have to filter out such
events from the "Nächste Termine" list on the start page.

The easiest (but dirtiest) way is to do this with javascript 🎉
  • Loading branch information
sedrubal committed Aug 17, 2017
1 parent 4b32c4d commit 15a6d2d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ implementation](https://github.com/fau-fablab/spaceapi/)

- Ensure that jQuery is available as `jQuery` variable
- Add the widget called "Türstatus" in the WordPress "Customizer"
- The door state will additionally be displayed in the `.site-description` below the page title

### Filter events in "Nächste Termine" list on start page

Most people just want to see when the next (Open|Self|Rad|Zerspanungs|...)Lab takes place.
They are not interested in internal events like "OrgaTreffen".
So we have to filter out such events from the "Nächste Termine" list on the start page.

The easiest (but dirtiest) way is to do this with Javascript :tada:

#### Usage:

- Ensure that jQuery is available as `jQuery` variable
- Ensure that the `NEXT_EVENTS_CALENDAR_ID` in `script.js` is the ID of the events calendar list
(check its class name)
- Ensure that all possible event names, that should be displayed in the list, are listed in
`EVENT_NAMES_TO_DISPLAY` in `script.js` (lowercase, without `-`). An event will be show if one of
the words in this list is part of the event title.

## License

Expand Down
26 changes: 26 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* DoorState
*/

function setDoorState(state, text) {
jQuery(".fablab_doorstate_widget, .fablab_doorstate_text").each(function(){
var element = jQuery(this);
Expand Down Expand Up @@ -42,3 +46,25 @@ jQuery(document).ready(function() {
updateDoorState();
window.setInterval(updateDoorState, 60 * 1000);
});

/*
* Filter calendar events in next events list
*/
var EVENT_NAMES_TO_DISPLAY = ['openlab', 'selflab', 'betreuertreffen', 'radlab', 'näh', 'stick', 'zerspanungslab', 'fräsen', 'drehbank', 'beratung'];
var NEXT_EVENTS_CALENDAR_ID = '267';

jQuery(document).ready(function() {
var calendarList = jQuery(`[data-calendar-id="${NEXT_EVENTS_CALENDAR_ID}"]`);
calendarList.find('.simcal-event-title').each(function() {
var eventName = jQuery(this).text().replace('-', '').toLowerCase();
for (var validNameIndex in EVENT_NAMES_TO_DISPLAY) {
if (eventName.indexOf(EVENT_NAMES_TO_DISPLAY[validNameIndex]) >= 0) {
return; // is valid -> keep
}
}
jQuery(this).parents('.simcal-event').remove();
});
if (calendarList.find('.simcal-calendar-list').text().trim() === '') {
calendarList.find('.simcal-calendar-list').text('Diese Woche sind keine öffentlichen Termine eingetragen.');
}
});

0 comments on commit 15a6d2d

Please sign in to comment.