mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Merge pull request #1628 from kolbyjack/feature/calendar-past-events
Add includePastEvents global and calendar-specific settings
This commit is contained in:
commit
dd6b972be4
@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Finnish translation for "Feels" and "Weeks"
|
- Finnish translation for "Feels" and "Weeks"
|
||||||
- Russian translation for “Feels”
|
- Russian translation for “Feels”
|
||||||
|
|
||||||
|
- Add `broadcastPastEvents` config option for calendars to include events from the past `maximumNumberOfDays` in event broadcasts
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
- English translation for "Feels" to "Feels like"
|
- English translation for "Feels" to "Feels like"
|
||||||
- Fixed the example calender url in `config.js.sample`
|
- Fixed the example calender url in `config.js.sample`
|
||||||
|
@ -55,6 +55,7 @@ The following properties can be configured:
|
|||||||
| `hideOngoing` | Hides calendar events that have already started. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
| `hideOngoing` | Hides calendar events that have already started. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||||
| `excludedEvents` | An array of words / phrases from event titles that will be excluded from being shown. <br><br>Additionally advanced filter objects can be passed in. Below is the configuration for the advance filtering object.<br>**Required**<br>`filterBy` - string used to determine if filter is applied.<br>**Optional**<br>`until` - Time before an event to display it Ex: [`'3 days'`, `'2 months'`, `'1 week'`]<br>`caseSensitive` - By default, excludedEvents are case insensitive, set this to true to enforce case sensitivity<br>`regex` - set to `true` if filterBy is a regex. For those not familiar with regex it is used for pattern matching, please see [here](https://regexr.com/) for more info.<br><br> **Example:** `['Birthday', 'Hide This Event', {filterBy: 'Payment', until: '6 days', caseSensitive: true}, {filterBy: '^[0-9]{1,}.*', regex: true}]` <br> **Default value:** `[]`
|
| `excludedEvents` | An array of words / phrases from event titles that will be excluded from being shown. <br><br>Additionally advanced filter objects can be passed in. Below is the configuration for the advance filtering object.<br>**Required**<br>`filterBy` - string used to determine if filter is applied.<br>**Optional**<br>`until` - Time before an event to display it Ex: [`'3 days'`, `'2 months'`, `'1 week'`]<br>`caseSensitive` - By default, excludedEvents are case insensitive, set this to true to enforce case sensitivity<br>`regex` - set to `true` if filterBy is a regex. For those not familiar with regex it is used for pattern matching, please see [here](https://regexr.com/) for more info.<br><br> **Example:** `['Birthday', 'Hide This Event', {filterBy: 'Payment', until: '6 days', caseSensitive: true}, {filterBy: '^[0-9]{1,}.*', regex: true}]` <br> **Default value:** `[]`
|
||||||
| `sliceMultiDayEvents` | If this is set to true, events exceeding at least one midnight will be sliced into separate events including a counter like (1/2). This is especially helpful in "dateheaders" mode. Events will be sliced at midnight, end time for all events but the last will be 23:59 **Default value:** `false`
|
| `sliceMultiDayEvents` | If this is set to true, events exceeding at least one midnight will be sliced into separate events including a counter like (1/2). This is especially helpful in "dateheaders" mode. Events will be sliced at midnight, end time for all events but the last will be 23:59 **Default value:** `false`
|
||||||
|
| `broadcastPastEvents` | If this is set to true, events from the past `maximumNumberOfDays` will be included in event broadcasts <br> **Default value:** `false`
|
||||||
|
|
||||||
|
|
||||||
### Calendar configuration
|
### Calendar configuration
|
||||||
@ -96,6 +97,7 @@ config: {
|
|||||||
| `symbolClass` | Add a class to the cell of symbol.
|
| `symbolClass` | Add a class to the cell of symbol.
|
||||||
| `titleClass` | Add a class to the title's cell.
|
| `titleClass` | Add a class to the title's cell.
|
||||||
| `timeClass` | Add a class to the time's cell.
|
| `timeClass` | Add a class to the time's cell.
|
||||||
|
| `broadcastPastEvents` | Whether to include past events from this calendar. Overrides global setting
|
||||||
|
|
||||||
|
|
||||||
#### Calendar authentication options:
|
#### Calendar authentication options:
|
||||||
|
@ -49,7 +49,8 @@ Module.register("calendar", {
|
|||||||
},
|
},
|
||||||
broadcastEvents: true,
|
broadcastEvents: true,
|
||||||
excludedEvents: [],
|
excludedEvents: [],
|
||||||
sliceMultiDayEvents: false
|
sliceMultiDayEvents: false,
|
||||||
|
broadcastPastEvents: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
@ -83,7 +84,8 @@ Module.register("calendar", {
|
|||||||
|
|
||||||
var calendarConfig = {
|
var calendarConfig = {
|
||||||
maximumEntries: calendar.maximumEntries,
|
maximumEntries: calendar.maximumEntries,
|
||||||
maximumNumberOfDays: calendar.maximumNumberOfDays
|
maximumNumberOfDays: calendar.maximumNumberOfDays,
|
||||||
|
broadcastPastEvents: calendar.broadcastPastEvents,
|
||||||
};
|
};
|
||||||
if (calendar.symbolClass === "undefined" || calendar.symbolClass === null) {
|
if (calendar.symbolClass === "undefined" || calendar.symbolClass === null) {
|
||||||
calendarConfig.symbolClass = "";
|
calendarConfig.symbolClass = "";
|
||||||
@ -467,6 +469,9 @@ Module.register("calendar", {
|
|||||||
var calendar = this.calendarData[c];
|
var calendar = this.calendarData[c];
|
||||||
for (var e in calendar) {
|
for (var e in calendar) {
|
||||||
var event = JSON.parse(JSON.stringify(calendar[e])); // clone object
|
var event = JSON.parse(JSON.stringify(calendar[e])); // clone object
|
||||||
|
if(event.endDate < now) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(this.config.hidePrivate) {
|
if(this.config.hidePrivate) {
|
||||||
if(event.class === "PRIVATE") {
|
if(event.class === "PRIVATE") {
|
||||||
// do not add the current event, skip it
|
// do not add the current event, skip it
|
||||||
@ -550,7 +555,8 @@ Module.register("calendar", {
|
|||||||
symbolClass: calendarConfig.symbolClass,
|
symbolClass: calendarConfig.symbolClass,
|
||||||
titleClass: calendarConfig.titleClass,
|
titleClass: calendarConfig.titleClass,
|
||||||
timeClass: calendarConfig.timeClass,
|
timeClass: calendarConfig.timeClass,
|
||||||
auth: auth
|
auth: auth,
|
||||||
|
broadcastPastEvents: calendarConfig.broadcastPastEvents || this.config.broadcastPastEvents,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
var ical = require("./vendor/ical.js");
|
var ical = require("./vendor/ical.js");
|
||||||
var moment = require("moment");
|
var moment = require("moment");
|
||||||
|
|
||||||
var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth) {
|
var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var reloadTimer = null;
|
var reloadTimer = null;
|
||||||
@ -74,6 +74,11 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
|||||||
var now = new Date();
|
var now = new Date();
|
||||||
var today = moment().startOf("day").toDate();
|
var today = moment().startOf("day").toDate();
|
||||||
var future = moment().startOf("day").add(maximumNumberOfDays, "days").subtract(1,"seconds").toDate(); // Subtract 1 second so that events that start on the middle of the night will not repeat.
|
var future = moment().startOf("day").add(maximumNumberOfDays, "days").subtract(1,"seconds").toDate(); // Subtract 1 second so that events that start on the middle of the night will not repeat.
|
||||||
|
var past = today;
|
||||||
|
|
||||||
|
if (includePastEvents) {
|
||||||
|
past = moment().startOf("day").subtract(maximumNumberOfDays, "days").toDate();
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME:
|
// FIXME:
|
||||||
// Ugly fix to solve the facebook birthday issue.
|
// Ugly fix to solve the facebook birthday issue.
|
||||||
@ -181,7 +186,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
|||||||
rule.options.dtstart.setYear(1900);
|
rule.options.dtstart.setYear(1900);
|
||||||
}
|
}
|
||||||
|
|
||||||
var dates = rule.between(today, future, true, limitFunction);
|
var dates = rule.between(past, future, true, limitFunction);
|
||||||
|
|
||||||
for (var d in dates) {
|
for (var d in dates) {
|
||||||
startDate = moment(new Date(dates[d]));
|
startDate = moment(new Date(dates[d]));
|
||||||
@ -191,7 +196,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endDate.format("x") > now) {
|
if (includePastEvents || endDate.format("x") > now) {
|
||||||
newEvents.push({
|
newEvents.push({
|
||||||
title: title,
|
title: title,
|
||||||
startDate: startDate.format("x"),
|
startDate: startDate.format("x"),
|
||||||
@ -210,14 +215,21 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
|||||||
// Single event.
|
// Single event.
|
||||||
var fullDayEvent = (isFacebookBirthday) ? true : isFullDayEvent(event);
|
var fullDayEvent = (isFacebookBirthday) ? true : isFullDayEvent(event);
|
||||||
|
|
||||||
if (!fullDayEvent && endDate < new Date()) {
|
if (includePastEvents) {
|
||||||
//console.log("It's not a fullday event, and it is in the past. So skip: " + title);
|
if (endDate < past) {
|
||||||
continue;
|
//console.log("Past event is too far in the past. So skip: " + title);
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!fullDayEvent && endDate < new Date()) {
|
||||||
|
//console.log("It's not a fullday event, and it is in the past. So skip: " + title);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (fullDayEvent && endDate <= today) {
|
if (fullDayEvent && endDate <= today) {
|
||||||
//console.log("It's a fullday event, and it is before today. So skip: " + title);
|
//console.log("It's a fullday event, and it is before today. So skip: " + title);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startDate > future) {
|
if (startDate > future) {
|
||||||
|
@ -15,6 +15,7 @@ var maximumEntries = 10;
|
|||||||
var maximumNumberOfDays = 365;
|
var maximumNumberOfDays = 365;
|
||||||
var user = "magicmirror";
|
var user = "magicmirror";
|
||||||
var pass = "MyStrongPass";
|
var pass = "MyStrongPass";
|
||||||
|
var broadcastPastEvents = false;
|
||||||
|
|
||||||
var auth = {
|
var auth = {
|
||||||
user: user,
|
user: user,
|
||||||
|
@ -24,7 +24,7 @@ module.exports = NodeHelper.create({
|
|||||||
socketNotificationReceived: function(notification, payload) {
|
socketNotificationReceived: function(notification, payload) {
|
||||||
if (notification === "ADD_CALENDAR") {
|
if (notification === "ADD_CALENDAR") {
|
||||||
//console.log('ADD_CALENDAR: ');
|
//console.log('ADD_CALENDAR: ');
|
||||||
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth);
|
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ module.exports = NodeHelper.create({
|
|||||||
* attribute reloadInterval number - Reload interval in milliseconds.
|
* attribute reloadInterval number - Reload interval in milliseconds.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
createFetcher: function(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth) {
|
createFetcher: function(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (!validUrl.isUri(url)) {
|
if (!validUrl.isUri(url)) {
|
||||||
@ -47,7 +47,7 @@ module.exports = NodeHelper.create({
|
|||||||
var fetcher;
|
var fetcher;
|
||||||
if (typeof self.fetchers[url] === "undefined") {
|
if (typeof self.fetchers[url] === "undefined") {
|
||||||
console.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval);
|
console.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval);
|
||||||
fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth);
|
fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents);
|
||||||
|
|
||||||
fetcher.onReceive(function(fetcher) {
|
fetcher.onReceive(function(fetcher) {
|
||||||
//console.log('Broadcast events.');
|
//console.log('Broadcast events.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user