Oh you are right, I also forget a curly brace after the ‘else’, I changed all that but it still doesn’t work
I paste the code again if you want to see it clear
Module.register(“schedules”, {
defaults: {
updateInterval: 20000
fadeSpeed: 4000
},
getScripts: function() {
return ["moment.js"]
},
getStyles: function() {
return ["font-awesome.css", "schedules.css"]
},
start: function() {
Log.info("Starting module: " + this.name);
setInterval(() => {
this.getData();
this.updateDom();
}, 20 * 1000); //calls getData every 20 seconds
},
getDom: function() {
var wrapper = document.createElement("div")
if (this.dataDirSM && this.data) {
var realtable = document.createElement('table');
realtable.appendChild(this.createUpperRow());
for (var i = 0; i < Math.min(this.data.response.schedules.length, this.dataDirSM.response.schedules.length); i++) {
var row = document.createElement('tr')
row.appendChild(this.boxHeader(this.data.response.schedules[i].message))
row.appendChild(this.boxHeader(this.data.response.schedules[i].id))
row.appendChild(this.boxHeader(this.dataDirSM.response.schedules[i].id))
row.appendChild(this.boxHeader(this.dataDirSM.response.schedules[i].message))
realtable.appendChild(row)
}
wrapper.appendChild(realtable)
} else {
wrapper.innerHTML = "NO DATA";
};
return wrapper
},
getData: function() {
this.dataDirSM = loadJSON("https://api-ratp.pierre-grimaud.fr/v2/rers/B/stations/les+baconnets?destination=robinson+saint+remy+les+chevreuse&endingstation=les+baconnets");
this.data = loadJSON("https://api-ratp.pierre-grimaud.fr/v2/rers/B/stations/les+baconnets?destination=charles+de+gaulle+mitry+claye&endingstation=les+baconnets");
},
createUpperRow: function() {
var firstTableRow = document.createElement('tr');
var tableh1 = document.createElement('th');
tableh1.classList.add('align-left');
var tx1 = document.createTextNode('Time');
tableh1.appendChild(tx1);
firstTableRow.appendChild(tableh1);
var tableh2 = document.createElement('th');
tableh2.classList.add('align-left');
var tx2 = document.createTextNode('Paris');
tableh2.appendChild(tx2);
firstTableRow.appendChild(tableh2);
// deuxième moitier
var tableh3 = document.createElement('th');
tableh3.classList.add('align-right');
var tx3 = document.createTextNode('Sud');
tableh3.appendChild(tx3);
firstTableRow.appendChild(tableh3);
var tableh4 = document.createElement('th');
tableh4.classList.add('align-right');
var tx4 = document.createTextNode('Time');
tableh4.appendChild(tx4);
firstTableRow.appendChild(tableh4);
return firstTableRow;
},
boxHeader: function(inside) {
if (inside == 'Train à l\'approche' || inside == 'Train à quai') {
inside = 'no way'
} else if (inside == 'Train retardé') {
inside = 'retard'
}
var fillNode = document.createTextNode(inside);
var realBox = document.createElement('td')
realBox.appendChild(fillNode);
return realBox;
}
})