hideLoading() versionDisplay() showHideAuthNotice() async function findByOrigDest() { showLoading() const formData = await fetchOrigDest() log(`findByOrigDest: Searching for PIS Code for ${JSON.stringify(formData)}`) const endpoint = `pis/origdest/${formData.origin}/${formData.destination}` console.time('findByOrigDest-GET') const json = await getApi(endpoint, auth = true) console.timeEnd('findByOrigDest-GET') if (json == false) { await displayNoData() } else if (json == 401) { await displayUnauthorised() } else { await insertData(json) } document.getElementById('crs-box').style = 'display:none' document.getElementById('result-box').style = 'display:block' hideLoading() } async function fetchOrigDest() { var orig = document.getElementById('origin').value var dest = document.getElementById('destination').value return {origin: orig, destination: dest} } async function insertData(json) { // Receives the JSON Respose ([{},{}]) containing one or more possible // PIS codes. Display the code and the stops with a method of scrolling between them. // Maybe as a table or a carousel? console.time('insertData') const div = document.getElementById('result-box') let tableData = `
Code | Stations |
---|---|
${json[i]['code']} | ${json[i]['stops'].join(', ')} |
No results found
' document.getElementById('result-box').insertAdjacentHTML('beforeend', msg) } async function displayUnauthorised() { const msg = 'Unauthorised - please ensure you are logged into the rail staff version
' document.getElementById('result-box').insertAdjacentHTML('beforeend', msg) } async function reset() { try { document.getElementById('origin').value = '' document.getElementById('destination').value = '' document.getElementById('result-box').style = 'display:none' document.getElementById('result-table').remove() document.getElementById('crs-box').style = 'display:block' document.getElementById('result-count').textContent = 0 } catch(e) { log('Nothing to reset') } }