Skip to content

Commit

Permalink
feat: add support for excluded events, hide duplicates option and bro…
Browse files Browse the repository at this point in the history
…adcastPastEvents
  • Loading branch information
randomBrainstormer committed Mar 3, 2024
1 parent 9e6119e commit 79afa6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 12 additions & 4 deletions MMM-GoogleCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Module.register("MMM-GoogleCalendar", {
hidePrivate: false,
hideOngoing: false,
hideTime: false,
hideDuplicates: false,
colored: false,
coloredSymbolOnly: false,
customEvents: [], // Array of {keyword: "", symbol: "", color: ""} where Keyword is a regexp and symbol/color are to be applied for matched
Expand Down Expand Up @@ -366,7 +367,7 @@ Module.register("MMM-GoogleCalendar", {
if (this.config.showEnd) {
timeWrapper.innerHTML += ` - ${this.capFirst(moment(event.endDate, "x").format("LT"))}`;
}

eventWrapper.appendChild(timeWrapper);
titleWrapper.classList.add("align-right");
}
Expand Down Expand Up @@ -527,8 +528,10 @@ Module.register("MMM-GoogleCalendar", {
}

const calendarConfig = {
maximumEntries: calendar.maximumEntries,
maximumNumberOfDays: calendar.maximumNumberOfDays
maximumEntries: calendar.maximumEntries,
maximumNumberOfDays: calendar.maximumNumberOfDays,
broadcastPastEvents: calendar.broadcastPastEvents,
excludedEvents: calendar.excludedEvents,
};

if (
Expand Down Expand Up @@ -625,6 +628,11 @@ Module.register("MMM-GoogleCalendar", {
for (const e in calendar) {
const event = JSON.parse(JSON.stringify(calendar[e])); // clone object

// check if event is to be excluded
if (this.config.excludedEvents.includes(event.summary)) {
continue;
}

// added props
event.calendarID = calendarID;
event.endDate = this.extractCalendarDate(event.end);
Expand All @@ -644,7 +652,7 @@ Module.register("MMM-GoogleCalendar", {
continue;
}
}
if (this.listContainsEvent(events, event)) {
if (this.config.hideDuplicates && this.listContainsEvent(events, event)) {
continue;
}
event.url = event.htmlLink;
Expand Down
5 changes: 3 additions & 2 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@ module.exports = NodeHelper.create({
});
} else {
const events = res.data.items;

Log.info(
`${this.name}: ${events.length} events loaded for ${calendarID}`
);
this.broadcastEvents(events, identifier, calendarID);
this.broadcastEvents(events, identifier, calendarID);
}

this.scheduleNextCalendarFetch(
calendarID,
fetchInterval,
Expand Down

0 comments on commit 79afa6c

Please sign in to comment.