mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-29 04:29:41 +00:00
Broadcast calendar eventlist to other modules.
This commit is contained in:
parent
8b004a549a
commit
5858e862d9
@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Module API: Add Visibility locking to module system. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules#visibility-locking) for more information.
|
- Module API: Add Visibility locking to module system. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules#visibility-locking) for more information.
|
||||||
- Module API: Method to overwrite the module's header. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules#getheader) for more information.
|
- Module API: Method to overwrite the module's header. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules#getheader) for more information.
|
||||||
- Module API: Option to define the minimumn MagicMirror version to run a module. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules#requiresversion) for more information.
|
- Module API: Option to define the minimumn MagicMirror version to run a module. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules#requiresversion) for more information.
|
||||||
|
- Calendar module now broadcasts the event list to all other modules using the notification system. [See documentation](https://github.com/MichMich/MagicMirror/tree/master/modules/default/calendar) for more information.
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
- Modified translations for Frysk.
|
- Modified translations for Frysk.
|
||||||
|
37
js/class.js
37
js/class.js
@ -11,24 +11,6 @@
|
|||||||
// The base Class implementation (does nothing)
|
// The base Class implementation (does nothing)
|
||||||
this.Class = function() {};
|
this.Class = function() {};
|
||||||
|
|
||||||
//Define the clone method for later use.
|
|
||||||
function cloneObject(obj) {
|
|
||||||
if (obj === null || typeof obj !== "object") {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
var temp = obj.constructor(); // give temp the original obj's constructor
|
|
||||||
for (var key in obj) {
|
|
||||||
temp[key] = cloneObject(obj[key]);
|
|
||||||
|
|
||||||
if (key === "lockStrings") {
|
|
||||||
Log.log(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new Class that inherits from this class
|
// Create a new Class that inherits from this class
|
||||||
Class.extend = function(prop) {
|
Class.extend = function(prop) {
|
||||||
var _super = this.prototype;
|
var _super = this.prototype;
|
||||||
@ -87,5 +69,24 @@
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
//Define the clone method for later use.
|
||||||
|
//Helper Method
|
||||||
|
function cloneObject(obj) {
|
||||||
|
if (obj === null || typeof obj !== "object") {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
var temp = obj.constructor(); // give temp the original obj's constructor
|
||||||
|
for (var key in obj) {
|
||||||
|
temp[key] = cloneObject(obj[key]);
|
||||||
|
|
||||||
|
if (key === "lockStrings") {
|
||||||
|
Log.log(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||||
if (typeof module !== "undefined") {module.exports = Class;}
|
if (typeof module !== "undefined") {module.exports = Class;}
|
||||||
|
14
js/module.js
14
js/module.js
@ -371,20 +371,6 @@ Module.create = function (name) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Define the clone method for later use.
|
|
||||||
function cloneObject(obj) {
|
|
||||||
if (obj === null || typeof obj !== "object") {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
var temp = obj.constructor(); // give temp the original obj's constructor
|
|
||||||
for (var key in obj) {
|
|
||||||
temp[key] = cloneObject(obj[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
var moduleDefinition = Module.definitions[name];
|
var moduleDefinition = Module.definitions[name];
|
||||||
var clonedDefinition = cloneObject(moduleDefinition);
|
var clonedDefinition = cloneObject(moduleDefinition);
|
||||||
|
|
||||||
|
@ -106,7 +106,6 @@ The following properties can be configured:
|
|||||||
<td><code>titleReplace</code></td>
|
<td><code>titleReplace</code></td>
|
||||||
<td>An object of textual replacements applied to the tile of the event. This allow to remove or replace certains words in the title.<br>
|
<td>An object of textual replacements applied to the tile of the event. This allow to remove or replace certains words in the title.<br>
|
||||||
<br><b>Example:</b> <br>
|
<br><b>Example:</b> <br>
|
||||||
|
|
||||||
<code>
|
<code>
|
||||||
titleReplace: {'Birthday of ' : '', 'foo':'bar'}
|
titleReplace: {'Birthday of ' : '', 'foo':'bar'}
|
||||||
</code>
|
</code>
|
||||||
@ -141,6 +140,13 @@ The following properties can be configured:
|
|||||||
<br><b>Default value:</b> <code>0</code> (disabled)
|
<br><b>Default value:</b> <code>0</code> (disabled)
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><code>broadcastEvents</code></td>
|
||||||
|
<td>If this property is set to true, the calendar will broadcast all the events to all other modules with the notification message: <code>CALENDAR_EVENTS</code>. The event objects are stored in an array and contain the following fields: <code>title</code>, <code>startDate</code>, <code>endDate</code>, <code>fullDayEvent</code>, <code>location</code> and <code>geo</code>.<br>
|
||||||
|
<br><b>Possible values:</b> <code>true</code>, <code>false</code> <br>
|
||||||
|
<br><b>Default value:</b> <code>true</code>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ Module.register("calendar",{
|
|||||||
displaySymbol: true,
|
displaySymbol: true,
|
||||||
defaultSymbol: "calendar", // Fontawesome Symbol see http://fontawesome.io/cheatsheet/
|
defaultSymbol: "calendar", // Fontawesome Symbol see http://fontawesome.io/cheatsheet/
|
||||||
displayRepeatingCountTitle: false,
|
displayRepeatingCountTitle: false,
|
||||||
defaultRepeatingCountTitle: '',
|
defaultRepeatingCountTitle: "",
|
||||||
maxTitleLength: 25,
|
maxTitleLength: 25,
|
||||||
fetchInterval: 5 * 60 * 1000, // Update every 5 minutes.
|
fetchInterval: 5 * 60 * 1000, // Update every 5 minutes.
|
||||||
animationSpeed: 2000,
|
animationSpeed: 2000,
|
||||||
@ -35,6 +35,7 @@ Module.register("calendar",{
|
|||||||
"De verjaardag van ": "",
|
"De verjaardag van ": "",
|
||||||
"'s birthday": ""
|
"'s birthday": ""
|
||||||
},
|
},
|
||||||
|
broadcastEvents: true
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
@ -78,6 +79,10 @@ Module.register("calendar",{
|
|||||||
if (this.hasCalendarURL(payload.url)) {
|
if (this.hasCalendarURL(payload.url)) {
|
||||||
this.calendarData[payload.url] = payload.events;
|
this.calendarData[payload.url] = payload.events;
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
|
|
||||||
|
if (this.config.broadcastEvents) {
|
||||||
|
this.broadcastEvents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (notification === "FETCH_ERROR") {
|
} else if (notification === "FETCH_ERROR") {
|
||||||
Log.error("Calendar Error. Could not fetch calendar: " + payload.url);
|
Log.error("Calendar Error. Could not fetch calendar: " + payload.url);
|
||||||
@ -119,18 +124,18 @@ Module.register("calendar",{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var titleWrapper = document.createElement("td"),
|
var titleWrapper = document.createElement("td"),
|
||||||
repeatingCountTitle = '';
|
repeatingCountTitle = "";
|
||||||
|
|
||||||
|
|
||||||
if (this.config.displayRepeatingCountTitle) {
|
if (this.config.displayRepeatingCountTitle) {
|
||||||
|
|
||||||
repeatingCountTitle = this.countTitleForUrl(event.url);
|
repeatingCountTitle = this.countTitleForUrl(event.url);
|
||||||
|
|
||||||
if(repeatingCountTitle !== '') {
|
if (repeatingCountTitle !== "") {
|
||||||
var thisYear = new Date().getFullYear(),
|
var thisYear = new Date().getFullYear(),
|
||||||
yearDiff = thisYear - event.firstYear;
|
yearDiff = thisYear - event.firstYear;
|
||||||
|
|
||||||
repeatingCountTitle = ', '+ yearDiff + '. ' + repeatingCountTitle;
|
repeatingCountTitle = ", " + yearDiff + ". " + repeatingCountTitle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,17 +147,17 @@ Module.register("calendar",{
|
|||||||
//console.log(event.today);
|
//console.log(event.today);
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
// Define second, minute, hour, and day variables
|
// Define second, minute, hour, and day variables
|
||||||
var one_second = 1000; // 1,000 milliseconds
|
var oneSecond = 1000; // 1,000 milliseconds
|
||||||
var one_minute = one_second * 60;
|
var oneMinute = oneSecond * 60;
|
||||||
var one_hour = one_minute * 60;
|
var oneHour = oneMinute * 60;
|
||||||
var one_day = one_hour * 24;
|
var oneDay = oneHour * 24;
|
||||||
if (event.fullDayEvent) {
|
if (event.fullDayEvent) {
|
||||||
if (event.today) {
|
if (event.today) {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("TODAY"));
|
timeWrapper.innerHTML = this.capFirst(this.translate("TODAY"));
|
||||||
} else if (event.startDate - now < one_day && event.startDate - now > 0) {
|
} else if (event.startDate - now < oneDay && event.startDate - now > 0) {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("TOMORROW"));
|
timeWrapper.innerHTML = this.capFirst(this.translate("TOMORROW"));
|
||||||
} else if (event.startDate - now < 2*one_day && event.startDate - now > 0) {
|
} else if (event.startDate - now < 2 * oneDay && event.startDate - now > 0) {
|
||||||
if (this.translate('DAYAFTERTOMORROW') !== 'DAYAFTERTOMORROW') {
|
if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("DAYAFTERTOMORROW"));
|
timeWrapper.innerHTML = this.capFirst(this.translate("DAYAFTERTOMORROW"));
|
||||||
} else {
|
} else {
|
||||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
||||||
@ -166,7 +171,7 @@ Module.register("calendar",{
|
|||||||
* Note: this needs to be put in its own function, as the whole thing repeats again verbatim
|
* Note: this needs to be put in its own function, as the whole thing repeats again verbatim
|
||||||
*/
|
*/
|
||||||
if (this.config.timeFormat === "absolute") {
|
if (this.config.timeFormat === "absolute") {
|
||||||
if ((this.config.urgency > 1) && (event.startDate - now < (this.config.urgency * one_day))) {
|
if ((this.config.urgency > 1) && (event.startDate - now < (this.config.urgency * oneDay))) {
|
||||||
// This event falls within the config.urgency period that the user has set
|
// This event falls within the config.urgency period that the user has set
|
||||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
||||||
} else {
|
} else {
|
||||||
@ -178,9 +183,9 @@ Module.register("calendar",{
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (event.startDate >= new Date()) {
|
if (event.startDate >= new Date()) {
|
||||||
if (event.startDate - now < 2 * one_day) {
|
if (event.startDate - now < 2 * oneDay) {
|
||||||
// This event is within the next 48 hours (2 days)
|
// This event is within the next 48 hours (2 days)
|
||||||
if (event.startDate - now < this.config.getRelative * one_hour) {
|
if (event.startDate - now < this.config.getRelative * oneHour) {
|
||||||
// If event is within 6 hour, display 'in xxx' time format or moment.fromNow()
|
// If event is within 6 hour, display 'in xxx' time format or moment.fromNow()
|
||||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
||||||
} else {
|
} else {
|
||||||
@ -196,7 +201,7 @@ Module.register("calendar",{
|
|||||||
* Note: this needs to be put in its own function, as the whole thing repeats again verbatim
|
* Note: this needs to be put in its own function, as the whole thing repeats again verbatim
|
||||||
*/
|
*/
|
||||||
if (this.config.timeFormat === "absolute") {
|
if (this.config.timeFormat === "absolute") {
|
||||||
if ((this.config.urgency > 1) && (event.startDate - now < (this.config.urgency * one_day))) {
|
if ((this.config.urgency > 1) && (event.startDate - now < (this.config.urgency * oneDay))) {
|
||||||
// This event falls within the config.urgency period that the user has set
|
// This event falls within the config.urgency period that the user has set
|
||||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
||||||
} else {
|
} else {
|
||||||
@ -207,7 +212,7 @@ Module.register("calendar",{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("RUNNING")) + ' ' + moment(event.endDate,"x").fromNow(true);
|
timeWrapper.innerHTML = this.capFirst(this.translate("RUNNING")) + " " + moment(event.endDate, "x").fromNow(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//timeWrapper.innerHTML += ' - '+ moment(event.startDate,'x').format('lll');
|
//timeWrapper.innerHTML += ' - '+ moment(event.startDate,'x').format('lll');
|
||||||
@ -371,5 +376,28 @@ Module.register("calendar",{
|
|||||||
|
|
||||||
title = this.shorten(title, this.config.maxTitleLength);
|
title = this.shorten(title, this.config.maxTitleLength);
|
||||||
return title;
|
return title;
|
||||||
|
},
|
||||||
|
|
||||||
|
/* broadcastEvents()
|
||||||
|
* Broadcasts the events to all other modules for reuse.
|
||||||
|
* The all events available in one array, sorted on startdate.
|
||||||
|
*/
|
||||||
|
broadcastEvents: function () {
|
||||||
|
var eventList = [];
|
||||||
|
for (url in this.calendarData) {
|
||||||
|
var calendar = this.calendarData[url];
|
||||||
|
for (e in calendar) {
|
||||||
|
var event = cloneObject(calendar[e]);
|
||||||
|
delete event.url;
|
||||||
|
eventList.push(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eventList.sort(function(a,b) {
|
||||||
|
return a.startDate - b.startDate;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.sendNotification("CALENDAR_EVENTS", eventList);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -27,7 +27,7 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
|
|||||||
|
|
||||||
var opts = {
|
var opts = {
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'Mozilla/5.0 (Node.js 6.0.0) MagicMirror/v2 (https://github.com/MichMich/MagicMirror/)'
|
"User-Agent": "Mozilla/5.0 (Node.js 6.0.0) MagicMirror/v2 (https://github.com/MichMich/MagicMirror/)"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
|
|||||||
if (!isFacebookBirthday) {
|
if (!isFacebookBirthday) {
|
||||||
endDate = startDate;
|
endDate = startDate;
|
||||||
} else {
|
} else {
|
||||||
endDate = moment(startDate).add(1, 'days');
|
endDate = moment(startDate).add(1, "days");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
|
|||||||
|
|
||||||
for (var d in dates) {
|
for (var d in dates) {
|
||||||
startDate = moment(new Date(dates[d]));
|
startDate = moment(new Date(dates[d]));
|
||||||
endDate = moment(parseInt(startDate.format("x")) + duration, 'x');
|
endDate = moment(parseInt(startDate.format("x")) + duration, "x");
|
||||||
if (endDate.format("x") > now) {
|
if (endDate.format("x") > now) {
|
||||||
newEvents.push({
|
newEvents.push({
|
||||||
title: title,
|
title: title,
|
||||||
@ -132,12 +132,19 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var location = event.location || false;
|
||||||
|
var geo = event.geo || false;
|
||||||
|
|
||||||
// Every thing is good. Add it to the list.
|
// Every thing is good. Add it to the list.
|
||||||
|
|
||||||
newEvents.push({
|
newEvents.push({
|
||||||
title: title,
|
title: title,
|
||||||
startDate: startDate.format("x"),
|
startDate: startDate.format("x"),
|
||||||
endDate: endDate.format("x"),
|
endDate: endDate.format("x"),
|
||||||
fullDayEvent: fullDayEvent
|
fullDayEvent: fullDayEvent,
|
||||||
|
location: location,
|
||||||
|
geo: geo
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user