Skip to content
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

Bug fix to correctly handle the logic for 'maxEntries' Issue #2050 #2052

Merged
merged 2 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ _This release is scheduled to be released on 2020-07-01._
- Support multiple instances of calendar module with different config [#1109](https://github.com/MichMich/MagicMirror/issues/1109)
- Fix the use of "maxNumberOfDays" in the module "weatherforecast" [#2018](https://github.com/MichMich/MagicMirror/issues/2018)
- Throw error when check_config fails [#1928](https://github.com/MichMich/MagicMirror/issues/1928)
- Bug fix related to 'maxEntries' not displaying Calendar events. [#2050](https://github.com/MichMich/MagicMirror/issues/2050)

## [2.11.0] - 2020-04-01

Expand Down
12 changes: 3 additions & 9 deletions modules/default/calendar/calendarfetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Log = require("../../../js/logger.js");
const ical = require("./vendor/ical.js");
const moment = require("moment");

var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents) {
var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumNumberOfDays, auth, includePastEvents) {
var self = this;

var reloadTimer = null;
Expand Down Expand Up @@ -219,12 +219,6 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr
var curEvent = event;
var showRecurrence = true;

// Stop parsing this event's recurrences if we've already found maximumEntries worth of recurrences.
// (The logic below would still filter the extras, but the check is simple since we're already tracking the count)
if (addedEvents >= maximumEntries) {
break;
}

startDate = moment(date);

// For each date that we"re checking, it"s possible that there is a recurrence override for that one day.
Expand Down Expand Up @@ -257,7 +251,7 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr
showRecurrence = false;
}

if (showRecurrence === true && addedEvents < maximumEntries) {
if (showRecurrence === true) {
addedEvents++;
newEvents.push({
title: recurrenceTitle,
Expand Down Expand Up @@ -327,7 +321,7 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr
return a.startDate - b.startDate;
});

events = newEvents.slice(0, maximumEntries);
events = newEvents;

self.broadcastEvents();
scheduleTimer();
Expand Down
6 changes: 3 additions & 3 deletions modules/default/calendar/node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = NodeHelper.create({
// Override socketNotificationReceived method.
socketNotificationReceived: function (notification, payload) {
if (notification === "ADD_CALENDAR") {
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.id);
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.id);
}
},

Expand All @@ -31,7 +31,7 @@ module.exports = NodeHelper.create({
* attribute url string - URL of the news feed.
* attribute reloadInterval number - Reload interval in milliseconds.
*/
createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, identifier) {
createFetcher: function (url, fetchInterval, excludedEvents, maximumNumberOfDays, auth, broadcastPastEvents, identifier) {
var self = this;

if (!validUrl.isUri(url)) {
Expand All @@ -42,7 +42,7 @@ module.exports = NodeHelper.create({
var fetcher;
if (typeof self.fetchers[identifier + url] === "undefined") {
Log.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval);
fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents);
fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumNumberOfDays, auth, broadcastPastEvents);

fetcher.onReceive(function (fetcher) {
self.sendSocketNotification("CALENDAR_EVENTS", {
Expand Down