Add departure board links to serviceDetail
This commit is contained in:
parent
9fab253bd3
commit
a2afa9f500
@ -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 = `<tr>
|
||||
<td class="detail-name detail-name-here detail-table-content">${sessionStorage.getItem('board_location')}</td>
|
||||
@ -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 `<tr>
|
||||
<td class="detail-name detail-table-content">${data.locationName}</td>
|
||||
<td class="detail-name detail-table-content"><a href="${link}>"${data.locationName}</a></td>
|
||||
<td class="detail-table-content">${data.st}</td>
|
||||
<td class="detail-table-content ${time.changed}">${time.data}</td>
|
||||
</tr>`
|
||||
@ -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())
|
||||
|
Reference in New Issue
Block a user