Merge pull request #2787 from kolbyjack/broadcast_all_events

This commit is contained in:
Michael Teeuw 2022-01-19 20:03:49 +01:00 committed by GitHub
commit 97b474665a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 35 deletions

View File

@ -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

View File

@ -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;
@ -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();
@ -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) {
@ -499,7 +500,7 @@ Module.register("calendar", {
continue;
}
}
if (this.config.hideOngoing) {
if (this.config.hideOngoing && limitNumberOfEntries) {
if (event.startDate < now) {
continue;
}
@ -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) {
@ -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);
}
});

View File

@ -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;
},
/**