-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMMM-bergfex.js
executable file
·77 lines (68 loc) · 2.19 KB
/
MMM-bergfex.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
/* Magic Mirror
* Module: MMM-bergfex
*
* By Juergen Wolf-Hofer
* Apache Licensed.
*/
Module.register('MMM-bergfex', {
defaults: {
updateInterval: 30 * 60 * 1000,
animationSpeed: 0,
header: 'Bergfex.at',
skiareas: [
'Hauser Kaibling / Schladming - Ski amade',
'Hochkar',
],
shortenArea: 20,
cssclassrow: 'light',
cssclassheader: 'normal'
},
getStyles: function () {
return ["MMM-bergfex.css"];
},
// Define start sequence
start: function() {
Log.log('Starting module: ' + this.name);
this.snowreports = [{
skiarea: 'loading...',
tal: '',
berg: '',
neu: '',
lifte: '',
update: ''
}];
this.sendSocketNotification('CONFIG', this.config);
},
socketNotificationReceived: function(notification, payload) {
Log.log('MMM-bergfex: socketNotificationReceived ' + notification);
//Log.log(payload);
if (notification === 'SNOW_REPORT') {
this.snowreports = payload;
this.updateDom(this.config.animationSpeed);
}
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement('div');
var header = document.createElement("header");
var name = document.createElement("span");
name.innerHTML = "" + this.config.header;
header.appendChild(name);
wrapper.appendChild(header);
var table = document.createElement('table');
table.classList.add("small", "table");
var str = "<tr class='" + this.config.cssclassheader + "'><th>Gebiet</th><th>Tal</th><th>Berg</th><th>Neu</th><th>Lifte</th></tr>";
for (var i=0; i<this.snowreports.length; i++) {
str += '<tr>';
str += '<td class="' + this.config.cssclassrow + '">' + this.snowreports[i].skiarea.substring(0,this.config.shortenArea) + '...</td>';
str += '<td class="' + this.config.cssclassrow + '">' + this.snowreports[i].tal + '</td>';
str += '<td class="' + this.config.cssclassrow + '">' + this.snowreports[i].berg + '</td>';
str += '<td class="' + this.config.cssclassrow + '">' + this.snowreports[i].neu + '</td>';
str += '<td class="' + this.config.cssclassrow + '">' + this.snowreports[i].lifte + '</td>';
str += '</tr>';
}
table.innerHTML = str;
wrapper.appendChild(table);
return wrapper;
},
});