Frontend: Improve code tidyness
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
393c59c1d7
commit
c221639c89
@ -6,7 +6,6 @@
|
||||
* Frontend - Implement paginated NRCC Notices as they take up lots of space.
|
||||
- Carousel: https://www.section.io/engineering-education/how-to-make-an-image-carousel-for-your-website/
|
||||
* Frontend - If Ferry Services Present - Load at bottom of screen.
|
||||
* Frontend - Load train services to screen.
|
||||
* Frontend - Decide what to do with Bus Services.
|
||||
* Frontend - Implement error pages - will need to look at including these on the proxy container too?
|
||||
- https://expressjs.com/en/guide/error-handling.html
|
@ -104,56 +104,95 @@ async function displayNoTrains() {
|
||||
|
||||
async function displayTrains(data) {
|
||||
log(`Inserting data in DOM`)
|
||||
var table = document.getElementById("output");
|
||||
for(var i = 0; i < data.GetStationBoardResult.trainServices.service.length; i++) {
|
||||
// Reset Vars
|
||||
var svc = data.GetStationBoardResult.trainServices.service[i];
|
||||
var eaChg = "";
|
||||
var edChg = "";
|
||||
// Determine Time Message
|
||||
if (svc.sta){var sta = svc.sta}else{var sta = '-'};
|
||||
if (svc.eta){var eta = svc.eta}else{var eta = '-'};
|
||||
if (eta=="On time"){var eta='RT'}else if(eta=="Delayed"){var eta="LATE";var eaChg="changed";}else if(eta!='-'){var eaChg="changed";};
|
||||
if (svc.std){var std = svc.std}else{var std = '-'};
|
||||
if (svc.etd){var etd = svc.etd}else{var etd = '-'};
|
||||
if (etd=="On time"){var etd='RT';}else if(etd=="Delayed"){var etd="LATE";var edChg="changed";}else if(etd!='-'){var edChg="changed";};
|
||||
// Determine Platform Message
|
||||
if (svc.platform){var plt = svc.platform}else{var plt = "-"};
|
||||
// Define Table Row
|
||||
var row = `
|
||||
<table>
|
||||
<tr>
|
||||
<td class="name">${svc.origin.location.locationName}</td>
|
||||
<td class="name">${svc.destination.location.locationName}</td>
|
||||
<td class="plat">${plt}</td>
|
||||
<td class="time">${sta}</td>
|
||||
<td class="time ${eaChg}">${eta}</td>
|
||||
<td class="time">${std}</td>
|
||||
<td class="time ${edChg}">${etd}</td>
|
||||
</tr>
|
||||
</table>`
|
||||
// Put Table Row
|
||||
table.insertAdjacentHTML("beforeend", row)
|
||||
// Parse cancelReason & delayReason
|
||||
if (svc.cancelReason) {
|
||||
console.log(`Cancel reason: ${svc.cancelReason}`)
|
||||
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", cancelRow);
|
||||
}
|
||||
if (svc.delayReason) {
|
||||
console.log(`Delay reason: ${svc.delayReason}`)
|
||||
var delayRow = `<p class="msg">${svc.delayReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", delayRow);
|
||||
}
|
||||
displayService(svc);
|
||||
}
|
||||
|
||||
clearLoading();
|
||||
log(`Insertion complete`)
|
||||
}
|
||||
|
||||
async function parsePlatform(){
|
||||
async function displayService(svc) {
|
||||
var table = document.getElementById("output");
|
||||
|
||||
// Determine Time Message
|
||||
var sta = await parseTime(svc.sta);
|
||||
var eta = await parseTime(svc.eta);
|
||||
var std = await parseTime(svc.std);
|
||||
var etd = await parseTime(svc.etd);
|
||||
// Determine Platform Message
|
||||
//if (svc.platform != undefined){var plt = svc.platform} else {var plt = "-"};
|
||||
var plt = await parsePlatform(svc);
|
||||
// Define Table Row
|
||||
var row = `
|
||||
<table>
|
||||
<tr>
|
||||
<td class="name">${svc.origin.location.locationName}</td>
|
||||
<td class="name">${svc.destination.location.locationName}</td>
|
||||
<td class="plat">${plt.num}</td>
|
||||
<td class="time">${sta.data}</td>
|
||||
<td class="time ${eta.changed}">${eta.data}</td>
|
||||
<td class="time">${std.data}</td>
|
||||
<td class="time ${etd.changed}">${etd.data}</td>
|
||||
</tr>
|
||||
</table>`
|
||||
// Put Table Row
|
||||
table.insertAdjacentHTML("beforeend", row)
|
||||
// Parse cancelReason & delayReason
|
||||
if (svc.cancelReason) {
|
||||
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", cancelRow);
|
||||
}
|
||||
if (svc.delayReason) {
|
||||
var delayRow = `<p class="msg">${svc.delayReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", delayRow);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function parseExpTime(){
|
||||
async function parsePlatform(svc){
|
||||
if (svc.platform != undefined) {
|
||||
var platform = svc.platform;
|
||||
} else {
|
||||
var platform = "-";
|
||||
}
|
||||
if (svc.platformChanged) {
|
||||
var changed = "changed";
|
||||
} else {
|
||||
var changed = "";
|
||||
}
|
||||
return {num: platform, change: changed}
|
||||
}
|
||||
|
||||
async function parseTime(string){
|
||||
switch (string) {
|
||||
case "Delayed":
|
||||
var output = "LATE";
|
||||
var change = "changed";
|
||||
break;
|
||||
case "Cancelled":
|
||||
var output = "CANC";
|
||||
var change = "changed";
|
||||
break;
|
||||
case "On time":
|
||||
var output = "RT";
|
||||
var change = "";
|
||||
break;
|
||||
case "":
|
||||
var output = "-";
|
||||
var change = "";
|
||||
break;
|
||||
case undefined:
|
||||
var output = "";
|
||||
var change = "";
|
||||
break;
|
||||
default:
|
||||
var output = string;
|
||||
var change = "changed";
|
||||
}
|
||||
return {data: output, changed: change};
|
||||
}
|
||||
|
||||
async function parseName(){
|
||||
|
Reference in New Issue
Block a user