FRONTEND: Implement find-code API Calls
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
2147d2f106
commit
4463e8c8f1
@ -32,10 +32,10 @@
|
|||||||
<h2>Code Lookup</h2>
|
<h2>Code Lookup</h2>
|
||||||
<p>Enter one known code in the relevant box below and hit submit.
|
<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>
|
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>
|
<p>Station name search will be added in the future.</p>
|
||||||
<label for="name">Station name:</label><br>
|
<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>
|
<label for="3alpha">CRS/3ALPHA:</label><br>
|
||||||
<input type="text" class="small-lookup-box" id="3alpha" name="3alpha" maxlength="3"><br>
|
<input type="text" class="small-lookup-box" id="3alpha" name="3alpha" maxlength="3"><br>
|
||||||
<label for="nlc">NLC:</label><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>
|
<input type="text" class="small-lookup-box" id="tiploc" name="tiploc" maxlength="7"><br>
|
||||||
<label for="stanox">STANOX:</label><br>
|
<label for="stanox">STANOX:</label><br>
|
||||||
<input type="number" class="small-lookup-box" id="stanox" name="stanox"><br>
|
<input type="number" class="small-lookup-box" id="stanox" name="stanox"><br>
|
||||||
<label for="stanme">STANME:</label><br>
|
<label for="stanme" hidden>STANME:</label><br>
|
||||||
<input type="test" class="small-lookup-box" id="stanme" name="stanme" readonly=""><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="Find" class="lookup-button" onclick="fetchEntry()">
|
||||||
|
<input type="submit" value="Clear" class="lookup-button" onclick="clearForm()">
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -20,18 +20,22 @@ async function fetchEntry(){
|
|||||||
|
|
||||||
async function parseData(values){
|
async function parseData(values){
|
||||||
if (values.crs != ""){
|
if (values.crs != ""){
|
||||||
getData("crs", values.crs)
|
var data = await getData("crs", values.crs)
|
||||||
} else if (values.nlc != ""){
|
} else if (values.nlc != ""){
|
||||||
getData("nlc", values.nlc)
|
var data = await getData("nlc", values.nlc)
|
||||||
} else if (values.tiploc != ""){
|
} else if (values.tiploc != ""){
|
||||||
getData("tiploc", values.tiploc)
|
var data = await getData("tiploc", values.tiploc)
|
||||||
} else if (values.stanox != ""){
|
} else if (values.stanox != ""){
|
||||||
getData("stanox", values.stanox)
|
var data = await getData("stanox", values.stanox)
|
||||||
} else if (values.name != ""){
|
} else if (values.name != ""){
|
||||||
getData("name", values.name)
|
var data = await getData("name", values.name)
|
||||||
} else {
|
} else {
|
||||||
errorNoData()
|
errorNoData()
|
||||||
|
data = {status: "failed"}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
displayData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getData(type, value){
|
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(){
|
async function errorNoData(){
|
||||||
console.log("No data entered")
|
console.log("No data entered")
|
||||||
window.alert("You haven't entered any data")
|
window.alert("You haven't entered any data")
|
||||||
@ -55,3 +79,8 @@ async function errorFetch(err){
|
|||||||
console.log("Error fetching data")
|
console.log("Error fetching data")
|
||||||
console.log(err)
|
console.log(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function errorNotFound(){
|
||||||
|
console.log("Location not found")
|
||||||
|
window.alert("No location was found. Check and try again.")
|
||||||
|
}
|
Reference in New Issue
Block a user