Squashed commit of the following:

commit e38dd346d9
Author: Michael Teeuw <michael@xonaymedia.nl>
Date:   Sat Apr 2 19:17:30 2016 +0200

    Add the possibility to set the maximum number of days.

commit 6f5c86775b
Author: Sam Vendittelli <sam.vendittelli@hotmail.com>
Date:   Sat Apr 2 06:27:44 2016 +0100

    Fixed cursor appearing in margin

    Cursor was appearing in the margin so moved `cursor: none` property to html.

commit 576c668d84
Author: Domi-G <lessuseguy+githubdomig@gmail.com>
Date:   Fri Apr 1 22:52:32 2016 +0200

    Huge cleanup of white space
This commit is contained in:
Michael Teeuw
2016-04-03 19:52:13 +02:00
parent e2436ad796
commit 5eed80c28e
41 changed files with 152 additions and 184 deletions

View File

@@ -1,6 +1,6 @@
# Module: Calendar
The `calendar` module is one of the default modules of the MagicMirror.
This module displays events from a public .ical calendar. It can combine multiple calendars.
This module displays events from a public .ical calendar. It can combine multiple calendars.
## Using the module
@@ -13,7 +13,7 @@ modules: [
config: {
// The config property is optional.
// If no config is set, an example calendar is shown.
// See 'Configuration options' for more information.
// See 'Configuration options' for more information.
}
}
]
@@ -40,6 +40,12 @@ The following properties can be configured:
<br><b>Default value:</b> <code>10</code>
</td>
</tr>
<tr>
<td><code>maximumNumberOfDays</code></td>
<td>The maximum number of days in the future.<br>
<br><b>Default value:</b> <code>365</code>
</td>
</tr>
<tr>
<td><code>displaySymbol</code></td>
<td>Display a symbol in front of an entry.<br>
@@ -100,7 +106,7 @@ The following properties can be configured:
<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>
<br><b>Example:</b> <br>
<code>
titleReplace: {'Birthday of ' : '', 'foo':'bar'}
</code>
@@ -149,4 +155,4 @@ config: {
</td>
</tr>
</tbody>
</table>
</table>

View File

@@ -20,4 +20,4 @@
.calendar .time {
padding-left: 30px;
text-align: right;
}
}

View File

@@ -12,12 +12,13 @@ Module.register('calendar',{
// Define module defaults
defaults: {
maximumEntries: 10, // Total Maximum Entries
maximumNumberOfDays: 365,
displaySymbol: true,
defaultSymbol: 'calendar', // Fontawsome Symbol see http://fontawesome.io/cheatsheet/
maxTitleLength: 25,
maxTitleLength: 25,
fetchInterval: 5 * 60 * 1000, // Update every 5 minutes.
animationSpeed: 2000,
fade: true,
fade: true,
fadePoint: 0.25, // Start on 1/4th of the list.
calendars: [
{
@@ -58,7 +59,7 @@ Module.register('calendar',{
// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
if (notification === 'CALENDAR_EVENTS') {
if (notification === 'CALENDAR_EVENTS') {
if (this.hasCalendarURL(payload.url)) {
this.calendarData[payload.url] = payload.events;
}
@@ -180,6 +181,7 @@ Module.register('calendar',{
this.sendSocketNotification('ADD_CALENDAR', {
url: url,
maximumEntries: this.config.maximumEntries,
maximumNumberOfDays: this.config.maximumNumberOfDays,
fetchInterval: this.config.fetchInterval
});
},
@@ -237,4 +239,4 @@ Module.register('calendar',{
title = this.shorten(title, this.config.maxTitleLength);
return title;
}
});
});

View File

@@ -10,7 +10,7 @@ var ical = require('ical');
var moment = require('moment');
var validUrl = require('valid-url');
var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumberOfDays) {
var self = this;
var reloadTimer = null;
@@ -42,7 +42,8 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
for (var e in data) {
var event = data[e];
var today = moment().startOf('day');
if (event.type === 'VEVENT') {
var startDate = (event.start.length === 8) ? moment(event.start, 'YYYYMMDD') : moment(new Date(event.start));
@@ -54,6 +55,7 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
// This causes the times of the recurring event to be incorrect.
// By adjusting the timeset property, this issue is solved.
var now = new Date();
if (rule.timeset[0].hour == now.getHours(),
rule.timeset[0].minute == now.getMinutes(),
rule.timeset[0].second == now.getSeconds()) {
@@ -62,11 +64,8 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
rule.timeset[0].minute = startDate.format('m');
rule.timeset[0].second = startDate.format('s');
}
var oneYear = new Date();
oneYear.setFullYear(oneYear.getFullYear() + 1);
var dates = rule.between(new Date(), oneYear, true, limitFunction);
var dates = rule.between(new Date(), today.add(maximumNumberOfDays, 'days') , true, limitFunction);
//console.log(dates);
for (var d in dates) {
startDate = moment(new Date(dates[d]));
@@ -78,8 +77,8 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
} else {
// Single event.
var today = moment().startOf('day');
if (startDate > today) {
if (startDate > today && startDate <= today.add(maximumNumberOfDays, 'days')) {
newEvents.push({
title: event.summary,
startDate: startDate.format('x')
@@ -92,7 +91,7 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
newEvents.sort(function(a,b) {
return a.startDate - b.startDate;
});
events = newEvents.slice(0, maximumEntries);
self.broadcastEvents();
@@ -180,14 +179,14 @@ module.exports = NodeHelper.create({
console.log('Starting node helper for: ' + this.name);
},
// Override socketNotificationReceived method.
socketNotificationReceived: function(notification, payload) {
if (notification === 'ADD_CALENDAR') {
//console.log('ADD_CALENDAR: ');
this.createFetcher(payload.url, payload.fetchInterval, payload.maximumEntries);
this.createFetcher(payload.url, payload.fetchInterval, payload.maximumEntries, payload.maximumNumberOfDays);
}
},
@@ -199,7 +198,7 @@ module.exports = NodeHelper.create({
* attribute reloadInterval number - Reload interval in milliseconds.
*/
createFetcher: function(url, fetchInterval, maximumEntries) {
createFetcher: function(url, fetchInterval, maximumEntries, maximumNumberOfDays) {
var self = this;
if (!validUrl.isUri(url)){
@@ -210,8 +209,8 @@ module.exports = NodeHelper.create({
var fetcher;
if (typeof self.fetchers[url] === 'undefined') {
console.log('Create new calendar fetcher for url: ' + url + ' - Interval: ' + fetchInterval);
fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries);
fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries, maximumNumberOfDays);
fetcher.onReceive(function(fetcher) {
//console.log('Broadcast events.');
//console.log(fetcher.events());
@@ -239,4 +238,3 @@ module.exports = NodeHelper.create({
fetcher.startFetch();
}
});