Fix onclick action

This commit is contained in:
Fred Boniface 2023-06-08 14:09:36 +01:00
parent eb0dea084a
commit d341103aa5
2 changed files with 19 additions and 8 deletions

View File

@ -46,7 +46,7 @@ const delay = ms => new Promise(res => setTimeout(res, ms))
/* Maintains backwards compatibility for previous /* Maintains backwards compatibility for previous
implementation of log helper */ implementation of log helper */
async function log(msg, type) { async function log(msg, type) {
const mode = 'prod' const mode = 'dev'
if (mode === 'prod' && type != 'ERR') { if (mode === 'prod' && type != 'ERR') {
return return
} }

View File

@ -25,7 +25,7 @@ async function get(headcode) {
} }
async function parse(data) { async function parse(data) {
if (data.length === 1) { if (data.length <= 1) {
document.getElementById('train_options').style = 'display:none;' document.getElementById('train_options').style = 'display:none;'
displayOne(data[0]) displayOne(data[0])
} }
@ -34,16 +34,27 @@ async function parse(data) {
} }
async function displayOptions(data) { async function displayOptions(data) {
// for (service of data) { for (service in data) {
// create a button showing first departure time const serviceData = data[service]
// alongside the TOC, the origin and destination. const lastStop = serviceData['stops'][(serviceData['stops'].length - 1)]
// maybe implement an accordion? log(`displayOptions: data[${service}] = ${serviceData}`, 'dbug')
// } let button = `
<button class='service_button' onclick='displayOne(data[${service}])'>
<span class='service_toc'>GW</span>
<span class='service_origin_time'>${serviceData['stops'][0]['wttDeparture']}</span>
<span class='service_origin_tiploc'>${serviceData['stops'][0]['tiploc']}</span>
to
<span class='service_dest_tiploc'>${lastStop['tiploc']}</span>
</button>
`
document.getElementById('train_options').insertAdjacentHTML('beforeend', button)
}
document.getElementById('train_options').style = 'display:block;'
return data return data
} }
async function displayOne(object) { async function displayOne(object) {
// Display a single service immediately // Display a single service
const dataTableHead = ` const dataTableHead = `
<p id='data_headcode'>${object['headcode']}</p> <p id='data_headcode'>${object['headcode']}</p>
<p id='data_piscode'>PIS Code: ${object['pis']}</p> <p id='data_piscode'>PIS Code: ${object['pis']}</p>