From a2afa9f50041d8be2cb6823d7682728c2aff9605 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 8 May 2023 21:27:49 +0100 Subject: [PATCH] Add departure board links to serviceDetail --- js/lib.board.js | 74 ++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/js/lib.board.js b/js/lib.board.js index ac70362..6cccbed 100644 --- a/js/lib.board.js +++ b/js/lib.board.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-vars */ /* Fetch Functions */ async function publicLdb(stn) { var url = `${window.location.origin}/api/v1/ldb/${stn}` @@ -25,15 +26,16 @@ async function displayNoTrains() { /* Parse the value of `platform` to account for unknown platforms */ async function parsePlatform(svc){ + let platform, changed if (svc.platform != undefined) { - var platform = svc.platform + platform = svc.platform } else { - var platform = '-' + platform = '-' } if (svc.platformChanged) { // Not present in public API, ready for staff version. - var changed = 'changed' + changed = 'changed' } else { - var changed = '' + changed = '' } return {num: platform, change: changed} } @@ -41,38 +43,40 @@ async function parsePlatform(svc){ /* Change value of time strings to fit well on small screens */ async function parseTime(string){ + let output + let change switch (string) { case 'Delayed': - var output = 'LATE' - var change = 'changed' + output = 'LATE' + change = 'changed' break case 'Cancelled': - var output = 'CANC' - var change = 'cancelled' + output = 'CANC' + change = 'cancelled' break case 'On time': - var output = 'RT' - var change = 'righttime' + output = 'RT' + change = 'righttime' break case '': - var output = '-' - var change = '' + output = '-' + change = '' break case undefined: - var output = '-' - var change = '' + output = '-' + change = '' break case 'No report': - var output = '-' - var change = '' + output = '-' + change = '' break case 'undefined': - var output = false - var change = '' + output = false + change = '' break default: - var output = string - var change = 'changed' + output = string + change = 'changed' } return {data: output, changed: change} } @@ -174,15 +178,18 @@ async function showCalls(id) { var thisSta = await parseTime(svcDetail.sta) var thisEta = await parseTime(svcDetail.eta) /* Prepare data for this station */ + let sTime + let eTime + let change if (thisStd.data != '-') { - var sTime = `${thisStd.data}` - var eTime = `${thisEtd.data}` - var change = thisEtd.changed + sTime = `${thisStd.data}` + eTime = `${thisEtd.data}` + change = thisEtd.changed } else { - var sTime = `${thisSta.data}` - var eTime = `${thisEta.data}` - var change = thisEta.changed - }; + sTime = `${thisSta.data}` + eTime = `${thisEta.data}` + change = thisEta.changed + } let here = ` ${sessionStorage.getItem('board_location')} @@ -218,13 +225,15 @@ async function hideCalls(id) { /* Builds the train data information in to a table row */ async function singleCall(data) { + let link = `./board.html?stn=${data.crs}` + let time if (typeof data.et != 'undefined') { - var time = await parseTime(data.et) + time = await parseTime(data.et) } else if (typeof data.at != 'undefined') { - var time = await parseTime(data.at) + time = await parseTime(data.at) } return ` - ${data.locationName} + ${data.st} ${time.data} ` @@ -232,10 +241,11 @@ async function singleCall(data) { /* Error Handler */ async function errorHandler() { + let errCount if (sessionStorage.getItem('failcount')) { - var errCount = parseInt(sessionStorage.getItem('failcount')) + errCount = parseInt(sessionStorage.getItem('failcount')) } else { - var errCount = 0 + errCount = 0 } errCount += 1 sessionStorage.setItem('failcount', errCount.toString())