-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMMM-Recipe.js
133 lines (109 loc) · 3.49 KB
/
MMM-Recipe.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
/* Magic Mirror
* Module: MMM-Recipe
*
* By cowboysdude with help from Sam and JimL
*
*/
var $;
Module.register("MMM-Recipe", {
// Module config defaults.
defaults: {
updateInterval: 180 * 60 * 1000, // every 3 hours
animationSpeed: 1000,
initialLoadDelay: 1130, // 0 seconds delay
retryDelay: 2500,
header: "",
maxWidth: "220px",
video: true
},
// Define required scripts.
getScripts: function() {
return ["moment.js", "jquery.js", "lity.js"];
},
getStyles: function() {
return ["MMM-Recipe.css", "lity.css"];
},
// Define start sequence.
start: function() {
var info = this.data;
var moduleInfo = JSON.parse(JSON.stringify(info));
Log.info("Starting module: " + this.name);
// Set locale.
moment.locale(config.language);
this.today = "";
this.recipe = [];
this.list = [];
this.image = "";
this.scheduleUpdate();
},
getDom: function() {
var mixins = this.recipe;
var list = this.list;
var wrapper = document.createElement("div");
//wrapper.id = "flex-container";
var x = document.createElement("div");
x.classList.add("video");
if (this.config.video != false) {
var vidID = mixins.videoId;
var vid = mixins.video;
var image = this.image;
x.innerHTML = '<a class="btn" href="//www.youtube.com/watch?v=' + vidID + '&rel=0" data-lity><img class ="click" src=' + image + ' width=136px; height=137px;></a>';
} else {
x.innerHTML = `<img class= thumbs src="${image}">`;
}
wrapper.appendChild(x);
let template = `${mixins.recipeName}<br>
Nationality: ${mixins.nation}<br>
Category: ${mixins.category}<br>
<br><br>
<label for="o">More info</label>
<input class="checker" type="checkbox" id="o" hidden>
<div class="modal">
<div class="modal-body">
<div class="modal-content">`
if (list.length) {
template += '<h3>Ingredients:</h3><ul>'
for (i = 0; i < list.length; i++) {
template += `<li>${list[i].ingredient}</li>`
}
template += '</ul>'
}
template += `<h3>Instructions:</h3>
<div class="columns">${mixins.instruction}</div>
</div>
<div class="modal-footer">
<label for="o">close</label>
</div>
</div>
</div> `;
var top = document.createElement("div");
top.innerHTML = template;
top.classList.add("title");
wrapper.appendChild(top);
return wrapper;
},
processRecipe: function(data) {
this.today = data.Today;
this.recipe = data;
this.list = data.ingredients;
this.image = data.thumb;
console.log(this.image);
this.loaded = false;
},
scheduleUpdate: function() {
setInterval(() => {
this.getRecipe();
}, this.config.updateInterval);
this.getRecipe(this.config.initialLoadDelay);
},
getRecipe: function() {
this.sendSocketNotification('GET_RECIPE');
},
socketNotificationReceived: function(notification, payload) {
if (notification === "RECIPE_RESULT") {
this.processRecipe(payload);
this.updateDom(this.config.fadeSpeed);
}
this.updateDom(this.config.initialLoadDelay);
},
});