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 */
|
/* Fetch Functions */
|
||||||
async function publicLdb(stn) {
|
async function publicLdb(stn) {
|
||||||
var url = `${window.location.origin}/api/v1/ldb/${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 */
|
/* Parse the value of `platform` to account for unknown platforms */
|
||||||
async function parsePlatform(svc){
|
async function parsePlatform(svc){
|
||||||
|
let platform, changed
|
||||||
if (svc.platform != undefined) {
|
if (svc.platform != undefined) {
|
||||||
var platform = svc.platform
|
platform = svc.platform
|
||||||
} else {
|
} else {
|
||||||
var platform = '-'
|
platform = '-'
|
||||||
}
|
}
|
||||||
if (svc.platformChanged) { // Not present in public API, ready for staff version.
|
if (svc.platformChanged) { // Not present in public API, ready for staff version.
|
||||||
var changed = 'changed'
|
changed = 'changed'
|
||||||
} else {
|
} else {
|
||||||
var changed = ''
|
changed = ''
|
||||||
}
|
}
|
||||||
return {num: platform, change: 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 */
|
/* Change value of time strings to fit well on small screens */
|
||||||
async function parseTime(string){
|
async function parseTime(string){
|
||||||
|
let output
|
||||||
|
let change
|
||||||
switch (string) {
|
switch (string) {
|
||||||
case 'Delayed':
|
case 'Delayed':
|
||||||
var output = 'LATE'
|
output = 'LATE'
|
||||||
var change = 'changed'
|
change = 'changed'
|
||||||
break
|
break
|
||||||
case 'Cancelled':
|
case 'Cancelled':
|
||||||
var output = 'CANC'
|
output = 'CANC'
|
||||||
var change = 'cancelled'
|
change = 'cancelled'
|
||||||
break
|
break
|
||||||
case 'On time':
|
case 'On time':
|
||||||
var output = 'RT'
|
output = 'RT'
|
||||||
var change = 'righttime'
|
change = 'righttime'
|
||||||
break
|
break
|
||||||
case '':
|
case '':
|
||||||
var output = '-'
|
output = '-'
|
||||||
var change = ''
|
change = ''
|
||||||
break
|
break
|
||||||
case undefined:
|
case undefined:
|
||||||
var output = '-'
|
output = '-'
|
||||||
var change = ''
|
change = ''
|
||||||
break
|
break
|
||||||
case 'No report':
|
case 'No report':
|
||||||
var output = '-'
|
output = '-'
|
||||||
var change = ''
|
change = ''
|
||||||
break
|
break
|
||||||
case 'undefined':
|
case 'undefined':
|
||||||
var output = false
|
output = false
|
||||||
var change = ''
|
change = ''
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
var output = string
|
output = string
|
||||||
var change = 'changed'
|
change = 'changed'
|
||||||
}
|
}
|
||||||
return {data: output, changed: change}
|
return {data: output, changed: change}
|
||||||
}
|
}
|
||||||
@ -174,15 +178,18 @@ async function showCalls(id) {
|
|||||||
var thisSta = await parseTime(svcDetail.sta)
|
var thisSta = await parseTime(svcDetail.sta)
|
||||||
var thisEta = await parseTime(svcDetail.eta)
|
var thisEta = await parseTime(svcDetail.eta)
|
||||||
/* Prepare data for this station */
|
/* Prepare data for this station */
|
||||||
|
let sTime
|
||||||
|
let eTime
|
||||||
|
let change
|
||||||
if (thisStd.data != '-') {
|
if (thisStd.data != '-') {
|
||||||
var sTime = `${thisStd.data}`
|
sTime = `${thisStd.data}`
|
||||||
var eTime = `${thisEtd.data}`
|
eTime = `${thisEtd.data}`
|
||||||
var change = thisEtd.changed
|
change = thisEtd.changed
|
||||||
} else {
|
} else {
|
||||||
var sTime = `${thisSta.data}`
|
sTime = `${thisSta.data}`
|
||||||
var eTime = `${thisEta.data}`
|
eTime = `${thisEta.data}`
|
||||||
var change = thisEta.changed
|
change = thisEta.changed
|
||||||
};
|
}
|
||||||
|
|
||||||
let here = `<tr>
|
let here = `<tr>
|
||||||
<td class="detail-name detail-name-here detail-table-content">${sessionStorage.getItem('board_location')}</td>
|
<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 */
|
/* Builds the train data information in to a table row */
|
||||||
async function singleCall(data) {
|
async function singleCall(data) {
|
||||||
|
let link = `./board.html?stn=${data.crs}`
|
||||||
|
let time
|
||||||
if (typeof data.et != 'undefined') {
|
if (typeof data.et != 'undefined') {
|
||||||
var time = await parseTime(data.et)
|
time = await parseTime(data.et)
|
||||||
} else if (typeof data.at != 'undefined') {
|
} else if (typeof data.at != 'undefined') {
|
||||||
var time = await parseTime(data.at)
|
time = await parseTime(data.at)
|
||||||
}
|
}
|
||||||
return `<tr>
|
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">${data.st}</td>
|
||||||
<td class="detail-table-content ${time.changed}">${time.data}</td>
|
<td class="detail-table-content ${time.changed}">${time.data}</td>
|
||||||
</tr>`
|
</tr>`
|
||||||
@ -232,10 +241,11 @@ async function singleCall(data) {
|
|||||||
|
|
||||||
/* Error Handler */
|
/* Error Handler */
|
||||||
async function errorHandler() {
|
async function errorHandler() {
|
||||||
|
let errCount
|
||||||
if (sessionStorage.getItem('failcount')) {
|
if (sessionStorage.getItem('failcount')) {
|
||||||
var errCount = parseInt(sessionStorage.getItem('failcount'))
|
errCount = parseInt(sessionStorage.getItem('failcount'))
|
||||||
} else {
|
} else {
|
||||||
var errCount = 0
|
errCount = 0
|
||||||
}
|
}
|
||||||
errCount += 1
|
errCount += 1
|
||||||
sessionStorage.setItem('failcount', errCount.toString())
|
sessionStorage.setItem('failcount', errCount.toString())
|
||||||
|
Reference in New Issue
Block a user