-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-FoodTrucks.js
executable file
·115 lines (98 loc) · 2.35 KB
/
MMM-FoodTrucks.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
/* global Module */
/* Magic Mirror
* Module: MMM-FoodTrucks
*
* By Stefan Nachtrab
* MIT Licensed.
*/
Module.register("MMM-FoodTrucks", {
defaults: {
updateInterval: 1000 * 60 * 60 * 4, //every 4 hours
foodTruckUrl: "",
foodTrucksDuration: "week",
limitResult: 2,
showLogo: true,
showPaymentOptions: true,
showLocation: true,
dateFormat: "DD.MM.YYYY",
timeFormat: "HH:mm"
},
requiresVersion: "2.1.0", // Required version of MagicMirror
start: function () {
var self = this;
console.log("Starting module MMM-FoodTrucks");
//Flag for check if module is loaded
this.loaded = false;
self.getData();
setInterval(function () {
self.getData();
self.updateDom();
}, this.config.updateInterval);
this.loaded = true;
},
getData: function () {
this.sendSocketNotification("MMM-FoodTrucks-NOTIFICATION_FOODTRUCK_DATA_REQUESTED", {
config: this.config
});
},
getHeader: function () {
return this.translate("TITLE");
},
getTemplate: function () {
if (!this.loaded) {
return "templates/error.njk";
}
return "templates/default.njk";
},
getTemplateData: function () {
if (this.config.foodTruckUrl === "" || this.config.foodTrucksDuration === "") {
return {
status: "Missing configuration for MMM-NewEmployees.",
config: this.config
};
}
if (!this.loaded) {
return {
status: "Loading MMM-FoodTrucks...",
config: this.config
};
}
if (this.dataBackend !== undefined) {
this.dataBackend.result = this.dataBackend.result.slice(0, this.config.limitResult);
return {
config: this.config,
translations: {
title: this.translate("TITLE"),
notfound: this.translate("NOT_FOUND")
},
data: this.dataBackend
};
}
return {
status: "Loading MMM-FoodTrucks...",
config: this.config
};
},
getScripts: function () {
return [];
},
getStyles: function () {
return ["MMM-FoodTrucks.css", "font-awesome.css"];
},
// Load translations files
getTranslations: function () {
return {
en: "translations/en.json",
de: "translations/de.json"
};
},
// socketNotificationReceived from helper
socketNotificationReceived: function (notification, payload) {
if (notification === "MMM-FoodTrucks-NOTIFICATION_FOODTRUCK_DATA_RECEIVED") {
console.log(payload);
// set dataNotification
this.dataBackend = payload;
this.updateDom();
}
}
});