Frontend: Add support for bus services

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-01-20 20:48:59 +00:00
parent e4e81d0145
commit 7096995401
2 changed files with 62 additions and 0 deletions

View File

@ -76,6 +76,21 @@
</table>
</div>
<div id="bus" class="hide-when-loading">
<p>Bus Services</p>
<table>
<tr>
<th class="name">Origin</th>
<th class="name">Dest.</th>
<th class="plat"></th>
<th class="time">Sch Arr.</th>
<th class="time">Exp Arr.</th>
<th class="time">Sch Dep.</th>
<th class="time">Exp Dep.</th>
</tr>
</table>
</div>
<div id="error_notice" class="main-notice hide-when-loading">
<h1 class="error">Oops</h1>
<p class="error">There was an error with your request</p>

View File

@ -71,6 +71,9 @@ async function buildPage(data) {
if (data.GetStationBoardResult.ferryServices) {
displayFerry(data.GetStationBoardResult.ferryServices)
}
if (data.GetStationBoardResult.busServices) {
displayBus(data.GetStationBoardResult.busServices)
}
}
async function displayNoTrains() {
@ -97,6 +100,13 @@ async function displayFerry(ferrySvc) {
}
}
async function displayBus(busSvc) {
log(JSON.stringify(busSvc))
for(var i = 0; i < busSvc.service.length; i++) {
displayBusService(busSvc.service[i])
}
}
async function displayService(svc) {
var table = document.getElementById("output");
@ -170,3 +180,40 @@ async function displayFerryService(svc) {
}
document.getElementById("ferry").style = "display:block"
}
async function displayBusService(svc) {
var table = document.getElementById("bus");
log(JSON.stringify(svc))
// 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
var plt = "";
// Define Table Row
var row = `
<table>
<tr>
<td class="name name-item">${svc.origin.location.locationName}</td>
<td class="name name-item">${svc.destination.location.locationName}</td>
<td class="plat}">${plt}</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);
}
document.getElementById("bus").style = "display:block"
}