This repository has been archived by the owner on Dec 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-Koket-by-Sodexo.js
82 lines (68 loc) · 2.27 KB
/
MMM-Koket-by-Sodexo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Magic Mirror
* Module: MMM-Koket-by-Sodexo
*
* By Johan Alvinger, https://github.com/Alvinger
* Based on the MMM-Skolmaten module by Johan Persson, https://github.com/retroflex
* MIT Licensed.
*/
Module.register('MMM-Koket-by-Sodexo', {
// Default configuration.
// days is the number of days to display.
// url is URL of feed, e.g. 'https://skolmaten.se/furuhallskolan/rss/'.
defaults: {
days: 1,
url: ''
},
getStyles: function() {
return [ 'MMM-Koket-by-Sodexo.css' ];
},
// Notification from node_helper.js.
// The items are received here and copied. Then module is redrawn.
// @param notification - Notification type.
// @param payload - Contains url and array of items of feed. Each item has a title and a description.
socketNotificationReceived: function(notification, payload) {
if (notification === 'ITEMS') {
if (payload.url === this.config.url) {
this.items = [];
var len = payload.items.length;
if(len > this.config.days) {len = this.config.days};
for (var i = 0; i < len; ++i) {
var item = payload.items[i];
this.items.push(item);
}
this.updateDom(0);
}
}
},
// Override dom generator.
getDom: function () {
var wrapper = document.createElement('div');
for (var i in this.items) {
var item = this.items[i];
var titleDiv = document.createElement('p');
titleDiv.className = 'itemtitle';
titleDiv.innerHTML = item.title;
wrapper.appendChild(titleDiv);
var descDiv = document.createElement('div');
descDiv.className = 'itemdescription';
descDiv.innerHTML = item.description;
wrapper.appendChild(descDiv);
}
return wrapper;
},
// Override start to init stuff.
start: function() {
// Send anything to initiate communication / node helper.
this.sendSocketNotification('START', {message: 'start connection'});
// Loading message.
this.items = [];
this.items.push( { title: this.translate('LOADING'), description: '' } );
// Tell node_helper to load RSS feed at startup.
this.sendSocketNotification('LOAD_FEED', { url: this.config.url });
// Make sure RSS feed is reloaded every 6 hours.
var self = this;
setInterval(function() {
self.sendSocketNotification('LOAD_FEED', { url: self.config.url });
}, 6 * 60 * 60 * 1000); // In millisecs. Refresh every hour.
}
});