2023-04-22 21:46:34 +01:00
|
|
|
hideLoading()
|
2023-04-28 13:52:26 +01:00
|
|
|
versionDisplay()
|
2023-04-28 13:56:24 +01:00
|
|
|
showHideAuthNotice()
|
2023-04-22 21:46:34 +01:00
|
|
|
|
|
|
|
async function findByOrigDest() {
|
|
|
|
showLoading()
|
|
|
|
const formData = await fetchOrigDest()
|
|
|
|
log(`findByOrigDest: Searching for PIS Code for ${JSON.stringify(formData)}`)
|
2023-04-24 12:14:45 +01:00
|
|
|
const endpoint = `pis/origdest/${formData.origin}/${formData.destination}`
|
2023-04-30 20:28:30 +01:00
|
|
|
const json = await getApi(endpoint, auth = true)
|
2023-04-22 21:46:34 +01:00
|
|
|
if (json == false) {
|
2023-04-30 21:10:37 +01:00
|
|
|
await displayNoData()
|
|
|
|
} else if (json == 401) {
|
|
|
|
await displayUnauthorised()
|
2023-04-22 21:46:34 +01:00
|
|
|
} else {
|
2023-04-22 22:23:36 +01:00
|
|
|
await insertData(json)
|
2023-04-22 21:46:34 +01:00
|
|
|
}
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
2023-04-22 22:23:36 +01:00
|
|
|
async function insertData(json) {
|
2023-04-22 21:48:55 +01:00
|
|
|
// 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?
|
2023-04-22 22:19:37 +01:00
|
|
|
const div = document.getElementById('result-box')
|
2023-04-22 22:44:32 +01:00
|
|
|
let tableData = `<table id="result-table">
|
2023-04-22 22:23:36 +01:00
|
|
|
<tr>
|
2023-04-25 00:32:45 +01:00
|
|
|
<th>Code</th>
|
|
|
|
<th>Stations</th>
|
2023-04-22 22:44:32 +01:00
|
|
|
</tr>`
|
|
|
|
let results = 0
|
2023-04-25 00:16:24 +01:00
|
|
|
for(var i = 0; i < json.length; i++) { // Hopefully can style output with CSS
|
2023-04-25 00:32:45 +01:00
|
|
|
tableData += `<tr><td class="pis-code">${json[i]['code']}</td>
|
2023-04-25 19:30:54 +01:00
|
|
|
<td class="station">${json[i]['stops'].join(', ')}</td></tr>`
|
2023-04-22 22:44:32 +01:00
|
|
|
results++
|
2023-04-22 22:19:37 +01:00
|
|
|
}
|
2023-04-22 22:44:32 +01:00
|
|
|
tableData += "</table>"
|
2023-04-24 12:50:57 +01:00
|
|
|
div.insertAdjacentHTML("beforeend", tableData)
|
2023-04-25 20:50:19 +01:00
|
|
|
document.getElementById('result-count').textContent = results.toString()
|
2023-04-22 21:46:34 +01:00
|
|
|
}
|
|
|
|
|
2023-04-30 21:10:37 +01:00
|
|
|
async function displayNoData() {
|
2023-04-25 00:16:24 +01:00
|
|
|
const msg = '<p id="result-table">No results found</p>'
|
2023-04-22 21:46:34 +01:00
|
|
|
document.getElementById('result-box').insertAdjacentHTML("beforeend", msg)
|
|
|
|
}
|
|
|
|
|
2023-04-30 21:10:37 +01:00
|
|
|
async function displayUnauthorised() {
|
|
|
|
const msg = '<p id="result-table">Unauthorised - please ensure you are logged into the <a href="./settings.html">rail staff version</a></p>'
|
|
|
|
document.getElementById('result-box').insertAdjacentHTML("beforeend", msg)
|
|
|
|
}
|
|
|
|
|
2023-04-22 21:46:34 +01:00
|
|
|
async function reset() {
|
2023-04-22 21:52:42 +01:00
|
|
|
document.getElementById('origin').value = ""
|
|
|
|
document.getElementById('destination').value = ""
|
2023-04-22 21:46:34 +01:00
|
|
|
document.getElementById('result-box').style = 'display:none'
|
2023-04-25 00:16:24 +01:00
|
|
|
document.getElementById('result-table').remove()
|
2023-04-22 21:46:34 +01:00
|
|
|
document.getElementById('crs-box').style = 'display:block'
|
2023-04-30 21:18:46 +01:00
|
|
|
document.getElementById('result-count').textContent = 0
|
2023-04-22 21:46:34 +01:00
|
|
|
}
|