Add find by PIS Code

This commit is contained in:
Fred Boniface
2023-05-24 20:52:55 +01:00
parent f3a488752e
commit 6b739bc42b
3 changed files with 56 additions and 1 deletions

View File

@@ -23,12 +23,55 @@ async function findByOrigDest() {
hideLoading()
}
async function findByPisCode() {
showLoading()
const formData = await fetchPisCode()
log(`findByPisCode: Searching for PIS Code ${formData}`)
const endpoint = `pis/code/${formData}`
console.time('findByPisCode-GET')
const json = await getApi(endpoint, auth = true)
console.timeEnd('findByPisCode-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 findRandomCode() {
showLoading()
log('findRandomCode: Fetching random PIS codes')
const endpoint = 'pis/random'
console.time('findRandomCode-GET')
const json = await getApi(endpoint, auth = true)
console.timeEnd('findRandomCode-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 fetchPisCode() {
return document.getElementById('pis').value
}
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.
@@ -66,6 +109,7 @@ async function reset() {
try {
document.getElementById('origin').value = ''
document.getElementById('destination').value = ''
document.getElementById('pis').value = ''
document.getElementById('result-box').style = 'display:none'
document.getElementById('result-table').remove()
document.getElementById('crs-box').style = 'display:block'