diff --git a/UpNext.md b/UpNext.md index 72cbaf9..47762f5 100644 --- a/UpNext.md +++ b/UpNext.md @@ -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 \ No newline at end of file diff --git a/static/js/boards.js b/static/js/boards.js index 0ca49b0..af0fcbb 100644 --- a/static/js/boards.js +++ b/static/js/boards.js @@ -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 = ` -
${svc.origin.location.locationName} | -${svc.destination.location.locationName} | -${plt} | -${sta} | -${eta} | -${std} | -${etd} | -
${svc.cancelReason}
` - table.insertAdjacentHTML("beforeend", cancelRow); - } - if (svc.delayReason) { - console.log(`Delay reason: ${svc.delayReason}`) - var delayRow = `${svc.delayReason}
` - 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 = ` +${svc.origin.location.locationName} | +${svc.destination.location.locationName} | +${plt.num} | +${sta.data} | +${eta.data} | +${std.data} | +${etd.data} | +
${svc.cancelReason}
` + table.insertAdjacentHTML("beforeend", cancelRow); + } + if (svc.delayReason) { + var delayRow = `${svc.delayReason}
` + 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(){