FRONTEND: Implement find-code API Calls

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-01-15 21:20:08 +00:00
parent 2147d2f106
commit 4463e8c8f1
2 changed files with 39 additions and 9 deletions

View File

@ -32,10 +32,10 @@
<h2>Code Lookup</h2>
<p>Enter one known code in the relevant box below and hit submit.
Where they exist, the other code types will be filled in.</p>
<p>You cannot lookup by STANME as the values are not unique.</p>
<p>You cannot yet lookup by Station name as the values are not unique.</p>
<p>Station name search will be added in the future.</p>
<label for="name">Station name:</label><br>
<input type="text" class="small-lookup-box" id="name" name="name"><br>
<input type="text" class="small-lookup-box" id="name" name="name" readonly=""><br>
<label for="3alpha">CRS/3ALPHA:</label><br>
<input type="text" class="small-lookup-box" id="3alpha" name="3alpha" maxlength="3"><br>
<label for="nlc">NLC:</label><br>
@ -44,8 +44,9 @@
<input type="text" class="small-lookup-box" id="tiploc" name="tiploc" maxlength="7"><br>
<label for="stanox">STANOX:</label><br>
<input type="number" class="small-lookup-box" id="stanox" name="stanox"><br>
<label for="stanme">STANME:</label><br>
<input type="test" class="small-lookup-box" id="stanme" name="stanme" readonly=""><br>
<label for="stanme" hidden>STANME:</label><br>
<input type="test" class="small-lookup-box" id="stanme" name="stanme" readonly="" hidden><br>
<input type="submit" value="Find" class="lookup-button" onclick="fetchEntry()">
<input type="submit" value="Clear" class="lookup-button" onclick="clearForm()">
</body>
</html>

View File

@ -20,18 +20,22 @@ async function fetchEntry(){
async function parseData(values){
if (values.crs != ""){
getData("crs", values.crs)
var data = await getData("crs", values.crs)
} else if (values.nlc != ""){
getData("nlc", values.nlc)
var data = await getData("nlc", values.nlc)
} else if (values.tiploc != ""){
getData("tiploc", values.tiploc)
var data = await getData("tiploc", values.tiploc)
} else if (values.stanox != ""){
getData("stanox", values.stanox)
var data = await getData("stanox", values.stanox)
} else if (values.name != ""){
getData("name", values.name)
var data = await getData("name", values.name)
} else {
errorNoData()
data = {status: "failed"}
return
}
displayData(data);
}
async function getData(type, value){
@ -46,6 +50,26 @@ async function getData(type, value){
}
}
async function displayData(data){
if (data.status === "failed" || data == ""){
errorNotFound()
}
document.getElementById("name").value = data['0']['NLCDESC']
document.getElementById("3alpha").value = data['0']['3ALPHA']
document.getElementById("nlc").value = data['0']['NLC']
document.getElementById("tiploc").value = data['0']['TIPLOC']
document.getElementById("stanox").value = data['0']['STANOX']
// document.getElementById("stanme").value = data['0']['STANME'] // NOT PRESENT IN CORPUS
}
async function clearForm(){
document.getElementById("name").value = ""
document.getElementById("3alpha").value = ""
document.getElementById("nlc").value = ""
document.getElementById("tiploc").value = ""
document.getElementById("stanox").value = ""
}
async function errorNoData(){
console.log("No data entered")
window.alert("You haven't entered any data")
@ -54,4 +78,9 @@ async function errorNoData(){
async function errorFetch(err){
console.log("Error fetching data")
console.log(err)
}
async function errorNotFound(){
console.log("Location not found")
window.alert("No location was found. Check and try again.")
}