-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMMM-DisneyWaitTimes.js
114 lines (95 loc) · 3.18 KB
/
MMM-DisneyWaitTimes.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Module.register("MMM-DisneyWaitTimes", {
defaults: {
updateInterval: 10 * 60 * 1000
},
getScripts: function () {
return ["moment.js"];
},
getStyles: function () {
return ["disney.css"];
},
getHeader: function () {
var headerDiv = document.createElement("div");
headerDiv.innerHTML = this.data.header;
var timeSpan = document.createElement("span");
timeSpan.className = "parkTime";
if (this.openingTime != null && this.closingTime != null) {
timeSpan.innerHTML = " " + this.openingTime + " - " + this.closingTime;
}
headerDiv.appendChild(timeSpan);
return headerDiv.innerHTML;
},
start: function () {
Log.info("Starting module: " + this.name);
const self = this;
this.rides = [];
this.openingTime;
this.closingTime;
this.errorMessage;
setInterval(function () {
self.processWaitTimes();
}, this.config.updateInterval);
this.processWaitTimes();
},
getDom: function () {
var table = document.createElement("table");
table.className = "small";
if (this.errorMessage) {
var row = document.createElement("tr");
row.className += "row";
table.appendChild(row);
var nameCell = document.createElement("td");
nameCell.className = "error";
nameCell.innerHTML = this.errorMessage;
row.appendChild(nameCell);
} else {
for (var i = 0, ride; (ride = this.rides[i++]); ) {
var row = document.createElement("tr");
row.className += "row";
table.appendChild(row);
var nameCell = document.createElement("td");
nameCell.className = "bright title";
nameCell.innerHTML = ride.name;
row.appendChild(nameCell);
var timeCell = document.createElement("td");
timeCell.className = "bright title light time";
if (ride.status === "Closed") {
timeCell.innerHTML = "closed";
} else if (ride.status === "Down") {
timeCell.innerHTML = "down";
} else if (ride.status === "Refurbishment") {
timeCell.innerHTML = "refurb";
} else if (ride.waitTime !== null) {
timeCell.innerHTML = ride.waitTime;
} else if (
ride.boardingGroup.currentGroupStart !== null &&
ride.boardingGroup.currentGroupEnd
) {
timeCell.innerHTML = `boarding: ${ride.boardingGroup.currentGroupStart} - ${ride.boardingGroup.currentGroupEnd}`;
}
row.appendChild(timeCell);
}
}
return table;
},
socketNotificationReceived: function (notification, payload) {
console.log("n: " + notification);
if (notification === "POPULATE_WAIT_TIMES_" + this.config.park.name) {
this.rides = payload.waitTimes;
this.updateDom();
} else if (
notification ===
"POPULATE_OPENING_TIMES_" + this.config.park.name
) {
this.openingTime = payload.openingTime;
this.closingTime = payload.closingTime;
this.updateDom();
} else if (notification === "ERROR_" + this.config.park.name) {
this.errorMessage = payload.errorMessage;
this.updateDom();
}
},
processWaitTimes: function () {
this.sendSocketNotification("GET_WAIT_TIMES", this.config.park);
}
});