mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Add the possibility to set the maximum number of days.
This commit is contained in:
parent
6f5c86775b
commit
e38dd346d9
@ -40,6 +40,12 @@ The following properties can be configured:
|
|||||||
<br><b>Default value:</b> <code>10</code>
|
<br><b>Default value:</b> <code>10</code>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<td><code>displaySymbol</code></td>
|
<td><code>displaySymbol</code></td>
|
||||||
<td>Display a symbol in front of an entry.<br>
|
<td>Display a symbol in front of an entry.<br>
|
||||||
|
@ -12,6 +12,7 @@ Module.register('calendar',{
|
|||||||
// Define module defaults
|
// Define module defaults
|
||||||
defaults: {
|
defaults: {
|
||||||
maximumEntries: 10, // Total Maximum Entries
|
maximumEntries: 10, // Total Maximum Entries
|
||||||
|
maximumNumberOfDays: 365,
|
||||||
displaySymbol: true,
|
displaySymbol: true,
|
||||||
defaultSymbol: 'calendar', // Fontawsome Symbol see http://fontawesome.io/cheatsheet/
|
defaultSymbol: 'calendar', // Fontawsome Symbol see http://fontawesome.io/cheatsheet/
|
||||||
maxTitleLength: 25,
|
maxTitleLength: 25,
|
||||||
@ -180,6 +181,7 @@ Module.register('calendar',{
|
|||||||
this.sendSocketNotification('ADD_CALENDAR', {
|
this.sendSocketNotification('ADD_CALENDAR', {
|
||||||
url: url,
|
url: url,
|
||||||
maximumEntries: this.config.maximumEntries,
|
maximumEntries: this.config.maximumEntries,
|
||||||
|
maximumNumberOfDays: this.config.maximumNumberOfDays,
|
||||||
fetchInterval: this.config.fetchInterval
|
fetchInterval: this.config.fetchInterval
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -10,7 +10,7 @@ var ical = require('ical');
|
|||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
var validUrl = require('valid-url');
|
var validUrl = require('valid-url');
|
||||||
|
|
||||||
var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
|
var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumberOfDays) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var reloadTimer = null;
|
var reloadTimer = null;
|
||||||
@ -42,6 +42,7 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
|
|||||||
|
|
||||||
for (var e in data) {
|
for (var e in data) {
|
||||||
var event = data[e];
|
var event = data[e];
|
||||||
|
var today = moment().startOf('day');
|
||||||
|
|
||||||
if (event.type === 'VEVENT') {
|
if (event.type === 'VEVENT') {
|
||||||
var startDate = (event.start.length === 8) ? moment(event.start, 'YYYYMMDD') : moment(new Date(event.start));
|
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.
|
// This causes the times of the recurring event to be incorrect.
|
||||||
// By adjusting the timeset property, this issue is solved.
|
// By adjusting the timeset property, this issue is solved.
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
|
|
||||||
if (rule.timeset[0].hour == now.getHours(),
|
if (rule.timeset[0].hour == now.getHours(),
|
||||||
rule.timeset[0].minute == now.getMinutes(),
|
rule.timeset[0].minute == now.getMinutes(),
|
||||||
rule.timeset[0].second == now.getSeconds()) {
|
rule.timeset[0].second == now.getSeconds()) {
|
||||||
@ -63,10 +65,7 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
|
|||||||
rule.timeset[0].second = startDate.format('s');
|
rule.timeset[0].second = startDate.format('s');
|
||||||
}
|
}
|
||||||
|
|
||||||
var oneYear = new Date();
|
var dates = rule.between(new Date(), today.add(maximumNumberOfDays, 'days') , true, limitFunction);
|
||||||
oneYear.setFullYear(oneYear.getFullYear() + 1);
|
|
||||||
|
|
||||||
var dates = rule.between(new Date(), oneYear, true, limitFunction);
|
|
||||||
//console.log(dates);
|
//console.log(dates);
|
||||||
for (var d in dates) {
|
for (var d in dates) {
|
||||||
startDate = moment(new Date(dates[d]));
|
startDate = moment(new Date(dates[d]));
|
||||||
@ -78,8 +77,8 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries) {
|
|||||||
} else {
|
} else {
|
||||||
// Single event.
|
// Single event.
|
||||||
|
|
||||||
var today = moment().startOf('day');
|
|
||||||
if (startDate > today) {
|
if (startDate > today && startDate <= today.add(maximumNumberOfDays, 'days')) {
|
||||||
newEvents.push({
|
newEvents.push({
|
||||||
title: event.summary,
|
title: event.summary,
|
||||||
startDate: startDate.format('x')
|
startDate: startDate.format('x')
|
||||||
@ -187,7 +186,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.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.
|
* attribute reloadInterval number - Reload interval in milliseconds.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
createFetcher: function(url, fetchInterval, maximumEntries) {
|
createFetcher: function(url, fetchInterval, maximumEntries, maximumNumberOfDays) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (!validUrl.isUri(url)){
|
if (!validUrl.isUri(url)){
|
||||||
@ -210,7 +209,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, maximumEntries);
|
fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries, maximumNumberOfDays);
|
||||||
|
|
||||||
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