mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Merge pull request #2787 from kolbyjack/broadcast_all_events
This commit is contained in:
commit
97b474665a
@ -21,6 +21,7 @@ _This release is scheduled to be released on 2022-04-01._
|
|||||||
- update `helmet` to v5, use defaults of v4.
|
- update `helmet` to v5, use defaults of v4.
|
||||||
- updates Font Awesome css class to new default style (fixes #2768)
|
- 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.
|
- 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
|
### Fixed
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ Module.register("calendar", {
|
|||||||
const oneHour = oneMinute * 60;
|
const oneHour = oneMinute * 60;
|
||||||
const oneDay = oneHour * 24;
|
const oneDay = oneHour * 24;
|
||||||
|
|
||||||
const events = this.createEventList();
|
const events = this.createEventList(true);
|
||||||
const wrapper = document.createElement("table");
|
const wrapper = document.createElement("table");
|
||||||
wrapper.className = this.config.tableClass;
|
wrapper.className = this.config.tableClass;
|
||||||
|
|
||||||
@ -477,9 +477,10 @@ Module.register("calendar", {
|
|||||||
/**
|
/**
|
||||||
* Creates the sorted list of all events.
|
* Creates the sorted list of all events.
|
||||||
*
|
*
|
||||||
|
* @param {boolean} limitNumberOfEntries Whether to filter returned events for display.
|
||||||
* @returns {object[]} Array with events.
|
* @returns {object[]} Array with events.
|
||||||
*/
|
*/
|
||||||
createEventList: function () {
|
createEventList: function (limitNumberOfEntries) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const today = moment().startOf("day");
|
const today = moment().startOf("day");
|
||||||
const future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
|
const future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
|
||||||
@ -490,7 +491,7 @@ Module.register("calendar", {
|
|||||||
for (const e in calendar) {
|
for (const e in calendar) {
|
||||||
const event = JSON.parse(JSON.stringify(calendar[e])); // clone object
|
const event = JSON.parse(JSON.stringify(calendar[e])); // clone object
|
||||||
|
|
||||||
if (event.endDate < now) {
|
if (event.endDate < now && limitNumberOfEntries) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (this.config.hidePrivate) {
|
if (this.config.hidePrivate) {
|
||||||
@ -499,7 +500,7 @@ Module.register("calendar", {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.config.hideOngoing) {
|
if (this.config.hideOngoing && limitNumberOfEntries) {
|
||||||
if (event.startDate < now) {
|
if (event.startDate < now) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -548,6 +549,10 @@ Module.register("calendar", {
|
|||||||
return a.startDate - b.startDate;
|
return a.startDate - b.startDate;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!limitNumberOfEntries) {
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
// Limit the number of days displayed
|
// Limit the number of days displayed
|
||||||
// If limitDays is set > 0, limit display to that number of days
|
// If limitDays is set > 0, limit display to that number of days
|
||||||
if (this.config.limitDays > 0) {
|
if (this.config.limitDays > 0) {
|
||||||
@ -835,22 +840,14 @@ Module.register("calendar", {
|
|||||||
* The all events available in one array, sorted on startdate.
|
* The all events available in one array, sorted on startdate.
|
||||||
*/
|
*/
|
||||||
broadcastEvents: function () {
|
broadcastEvents: function () {
|
||||||
const eventList = [];
|
const eventList = this.createEventList(false);
|
||||||
for (const url in this.calendarData) {
|
for (const event of eventList) {
|
||||||
for (const ev of this.calendarData[url]) {
|
event.symbol = this.symbolsForEvent(event);
|
||||||
const event = cloneObject(ev);
|
event.calendarName = this.calendarNameForUrl(event.url);
|
||||||
event.symbol = this.symbolsForEvent(event);
|
event.color = this.colorForUrl(event.url);
|
||||||
event.calendarName = this.calendarNameForUrl(url);
|
delete event.url;
|
||||||
event.color = this.colorForUrl(url);
|
|
||||||
delete event.url;
|
|
||||||
eventList.push(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eventList.sort(function (a, b) {
|
|
||||||
return a.startDate - b.startDate;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.sendNotification("CALENDAR_EVENTS", eventList);
|
this.sendNotification("CALENDAR_EVENTS", eventList);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -498,23 +498,7 @@ const CalendarUtils = {
|
|||||||
return a.startDate - b.startDate;
|
return a.startDate - b.startDate;
|
||||||
});
|
});
|
||||||
|
|
||||||
// include up to maximumEntries current or upcoming events
|
return newEvents;
|
||||||
// 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;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user