-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-rusty-things.js
57 lines (53 loc) · 1.55 KB
/
MMM-rusty-things.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
Module.register("MMM-rusty-things", {
// Default module config.
defaults: {
maxEntriesToShow: 15,
},
todayEntries: [],
tomorrowEntries: [],
inboxEntries: [],
currentState: 0,
getTemplate: function () {
return `template.njk`;
},
getTemplateData: function () {
return {
config: this.config,
count: {
today: this.todayEntries.length,
tomorrow: this.tomorrowEntries.length,
inbox: this.inboxEntries.length,
},
todayEntries: this.todayEntries.slice(0, this.config.maxEntriesToShow),
hasMoreEntries: this.todayEntries.length > this.config.maxEntriesToShow,
};
},
start: function () {
const self = this;
self.sendSocketNotification("REQUEST_ENTRIES");
self.sendSocketNotification("CLIENT_ACTIVE", {
currentState: this.currentState,
});
setInterval(function () {
self.sendSocketNotification("CLIENT_ACTIVE", {
currentState: self.currentState,
});
}, 20 * 1000); //perform every 20 secs.
},
socketNotificationReceived: function (notification, payload) {
console.log("client:", notification, payload);
if (notification === "RESPONSE_ENTRIES") {
this.todayEntries = payload.today;
this.tomorrowEntries = payload.tomorrow;
this.inboxEntries = payload.inbox;
this.currentState = payload.currentState;
this.updateDom();
}
if (notification === "DB_UPDATED") {
this.sendSocketNotification("REQUEST_ENTRIES");
}
if (notification === "RELOAD") {
window.location.reload();
}
},
});