Skip to content
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 @@ -21,6 +21,7 @@ _This release is scheduled to be released on 2022-04-01._
- update `helmet` to v5, use defaults of v4.
- updates Font Awesome css class to new default style (fixes #2768)
- replaced deprecated modules `currentweather` and `weatherforecast` with dummy modules only displaying that they have to be replaced.
- include all calendar events from the configured date range when broadcasting.

### Fixed

Expand Down
33 changes: 15 additions & 18 deletions modules/default/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Module.register("calendar", {
const oneHour = oneMinute * 60;
const oneDay = oneHour * 24;

const events = this.createEventList();
const events = this.createEventList(true);
const wrapper = document.createElement("table");
wrapper.className = this.config.tableClass;

Expand Down Expand Up @@ -477,9 +477,10 @@ Module.register("calendar", {
/**
* Creates the sorted list of all events.
*
* @param {boolean} limitNumberOfEntries Whether to filter returned events for display.
* @returns {object[]} Array with events.
*/
createEventList: function () {
createEventList: function (limitNumberOfEntries) {
const now = new Date();
const today = moment().startOf("day");
const future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
Expand All @@ -490,7 +491,7 @@ Module.register("calendar", {
for (const e in calendar) {
const event = JSON.parse(JSON.stringify(calendar[e])); // clone object

if (event.endDate < now) {
if (event.endDate < now && limitNumberOfEntries) {
continue;
}
if (this.config.hidePrivate) {
Expand All @@ -499,7 +500,7 @@ Module.register("calendar", {
continue;
}
}
if (this.config.hideOngoing) {
if (this.config.hideOngoing && limitNumberOfEntries) {
if (event.startDate < now) {
continue;
}
Expand Down Expand Up @@ -548,6 +549,10 @@ Module.register("calendar", {
return a.startDate - b.startDate;
});

if (!limitNumberOfEntries) {
return events;
}

// Limit the number of days displayed
// If limitDays is set > 0, limit display to that number of days
if (this.config.limitDays > 0) {
Expand Down Expand Up @@ -835,22 +840,14 @@ Module.register("calendar", {
* The all events available in one array, sorted on startdate.
*/
broadcastEvents: function () {
const eventList = [];
for (const url in this.calendarData) {
for (const ev of this.calendarData[url]) {
const event = cloneObject(ev);
event.symbol = this.symbolsForEvent(event);
event.calendarName = this.calendarNameForUrl(url);
event.color = this.colorForUrl(url);
delete event.url;
eventList.push(event);
}
const eventList = this.createEventList(false);
for (const event of eventList) {
event.symbol = this.symbolsForEvent(event);
event.calendarName = this.calendarNameForUrl(event.url);
event.color = this.colorForUrl(event.url);
delete event.url;
}

eventList.sort(function (a, b) {
return a.startDate - b.startDate;
});

this.sendNotification("CALENDAR_EVENTS", eventList);
}
});
18 changes: 1 addition & 17 deletions modules/default/calendar/calendarutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,23 +498,7 @@ const CalendarUtils = {
return a.startDate - b.startDate;
});

// include up to maximumEntries current or upcoming events
// If past events should be included, include all past events
const now = moment();
let entries = 0;
let events = [];
for (let ne of newEvents) {
if (moment(ne.endDate, "x").isBefore(now)) {
if (config.includePastEvents) events.push(ne);
continue;
}
entries++;
// If max events has been saved, skip the rest
if (entries > config.maximumEntries) break;
events.push(ne);
}

return events;
return newEvents;
},

/**
Expand Down