Add find by PIS Code
This commit is contained in:
44
js/pis.js
44
js/pis.js
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user