-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-PublicTransportLeipzig.js
165 lines (126 loc) · 4.73 KB
/
MMM-PublicTransportLeipzig.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"use strict";
Module.register("MMM-PublicTransportLeipzig", {
// default values
defaults: {
name: "MMM-PublicTransportLeipzig",
hidden: false,
headerPrefix: "",
stationName: "Wilhelm-Leuschner-Platz",
stationId: "12992",
directions: [], // Which directions (final destinations) should be included? (You need to list all possible final destinations to see all possible departures. For instance for Str 1 you need to list "Schönefeld" and "Mockau" to see Str 1 and Str 1E.)
ignoredLines: [], // Which lines should be ignored? (comma-separated list of line names)
excludedTransportationTypes: [], // Which transportation types should not be shown on the mirror? (comma-separated list of types) possible values: StN for tram, BuN for bus, s for suburban
marqueeLongDirections: true, // Use Marquee effect for long station names?
timeToStation: 10, // How long do you need to walk to the next Station?
interval: 120, // How often should the table be updated in s?
showColoredLineSymbols: true, // Want colored line symbols?
useColorForRealtimeInfo: true, // Want colored real time information (timeToStation, early)?
showTableHeaders: true, // Show table headers?
showTableHeadersAsSymbols: true, // Table Headers as symbols or written?
maxUnreachableDepartures: 3, // How many unreachable departures should be shown?
maxReachableDepartures: 7, // How many reachable departures should be shown?
fadeUnreachableDepartures: true,
fadeReachableDepartures: true,
fadePointForReachableDepartures: 0.25
},
start: function () {
Log.info("Starting module: " + this.name);
this.departuresArray = [];
this.stationName = "";
this.loaded = false;
this.error = {};
this.sanitizeConfig();
this.sendSocketNotification('CREATE_FETCHER', this.config);
setInterval(() => {
this.sendSocketNotification('GET_DEPARTURES', this.config.stationId);
}, this.config.interval * 1000);
},
sanitizeConfig: function () {
if (this.config.timeToStation < 0) {
this.config.timeToStation = 0;
}
if (typeof this.config.ignoredLines === 'undefined') {
this.config.ignoredLines = [];
}
// set minimum interval to 30 seconds
if (this.config.interval < 30) {
this.config.interval = 30;
}
if (this.config.fadePointForReachableDepartures < 0) {
this.config.fadePointForReachableDepartures = 0;
}
},
getDom: function () {
let domCreator = new DomCreator(this.config, this.departuresArray);
if (this.isInitializing()) {
let message = this.translate("LOADING");
return domCreator.getInitializingDom(message);
}
if (this.hasErrors()) {
let message = this.translate("LVB_FETCH_ERROR", { "errorMessage": JSON.stringify(this.error.message) });
let hint = this.translate("LVB_ERROR_HINT");
return domCreator.getErrorDom(this.stationName, message, hint);
}
let headings = {
time: this.translate("LVB_DEPARTURE_TIME"),
delay: " ",
line: this.translate("LVB_LINE"),
direction: this.translate("LVB_TO")
};
let noDeparturesMessage = this.translate("LVB_NO_DEPARTURES");
return domCreator.getDom(this.stationName, headings, noDeparturesMessage);
},
isInitializing: function () {
return (this.departuresArray.length === 0 && !this.loaded);
},
hasErrors: function () {
return (Object.keys(this.error).length > 0);
},
getStyles: function () {
return [
'style.css',
'font-awesome.css'
];
},
getScripts: function () {
return [
"moment.js",
this.file("DomCreator.js")
];
},
getTranslations: function() {
return {
en: "translations/en.json",
de: "translations/de.json"
};
},
socketNotificationReceived: function (notification, payload) {
if (notification === 'FETCHER_INIT') {
if (this.isThisStation(payload)) {
this.stationName = payload.stationName;
this.loaded = true;
}
}
if (notification === 'DEPARTURES') {
this.config.loaded = true;
if (this.isThisStation(payload)) {
// Empty error object
this.error = {};
// Proceed with normal operation
this.departuresArray = payload.departuresArray;
this.updateDom(3000);
}
}
if (notification === 'FETCH_ERROR') {
this.config.loaded = true;
if (this.isThisStation(payload)) {
// Empty error object
this.error = payload;
this.updateDom(3000);
}
}
},
isThisStation: function (stationId) {
return stationId.stationId === this.config.stationId;
},
});