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

@ -0,0 +1 @@
# Build and push docker container to repository

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'

View File

@ -43,9 +43,9 @@
</div>
<div id="crs-box">
<p>Enter a services start and end station CRS codes to see code options and stopping patterns.</p>
<p>Currently supported (Beta): GWR: ex-Wessex, HEx<br>Duplicate stopping patterns have been removed.</p>
<p id="auth-required">You need to be logged into a free <a href="./settings.html#railstaff">rail staff version</a> account for this feature.</p>
<h3>Search by CRS Codes</h3>
<form action="javascript:findByOrigDest();">
<div id="crs-inputs">
<div class="crs-input">
@ -59,6 +59,16 @@
</div>
<button type="submit" value="Find" class="lookup-button">Submit</button>
</form>
<h3>Search by PIS Code</h3>
<form action="javascript:findByPisCode();">
<div id="crs-inputs">
<div class="crs-input">
<label for="pis">PIS Code:</label><br>
<input type="number" class="small-lookup-box pis-input" id="pis" name="pis" maxlength="4" autocomplete="off"><br><br>
</div>
</div>
<button type="submit" value="Find" class="lookup-button">Submit</button>
</form>
</div>
<div id="result-box">