2023-01-15 20:00:18 +00:00
|
|
|
async function fetchEntry(){
|
|
|
|
var name = document.getElementById("name")
|
|
|
|
var crs = document.getElementById("3alpha")
|
|
|
|
var nlc = document.getElementById("nlc")
|
|
|
|
var tiploc = document.getElementById("tiploc")
|
|
|
|
var stanox = document.getElementById("stanox")
|
|
|
|
|
|
|
|
var values = {
|
|
|
|
name: name.value,
|
|
|
|
crs: crs.value,
|
|
|
|
nlc: nlc.value,
|
|
|
|
tiploc: tiploc.value,
|
|
|
|
stanox: stanox.value
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`Read values: ${JSON.stringify(values)}`)
|
|
|
|
|
|
|
|
parseData(values)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function parseData(values){
|
|
|
|
if (values.crs != ""){
|
|
|
|
getData("crs", values.crs)
|
|
|
|
} else if (values.nlc != ""){
|
|
|
|
getData("nlc", values.nlc)
|
|
|
|
} else if (values.tiploc != ""){
|
|
|
|
getData("tiploc", values.tiploc)
|
|
|
|
} else if (values.stanox != ""){
|
|
|
|
getData("stanox", values.stanox)
|
2023-01-15 20:09:00 +00:00
|
|
|
} else if (values.name != ""){
|
2023-01-15 20:00:18 +00:00
|
|
|
getData("name", values.name)
|
|
|
|
} else {
|
|
|
|
errorNoData()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getData(type, value){
|
|
|
|
console.log(`Looking for: ${type} ${value}`)
|
2023-01-15 20:09:00 +00:00
|
|
|
try {
|
2023-01-15 20:10:04 +00:00
|
|
|
var url = `${window.location.origin}/api/v1/find/${type}/${value}`;
|
2023-01-15 20:09:00 +00:00
|
|
|
var resp = await fetch(url);
|
|
|
|
console.log(`Response: ${resp.json}`)
|
|
|
|
return await resp.json()
|
|
|
|
} catch (err) {
|
|
|
|
errorFetch(err)
|
|
|
|
}
|
2023-01-15 20:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function errorNoData(){
|
2023-01-15 20:09:00 +00:00
|
|
|
console.log("No data entered")
|
2023-01-15 20:00:18 +00:00
|
|
|
window.alert("You haven't entered any data")
|
2023-01-15 20:09:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function errorFetch(err){
|
|
|
|
console.log("Error fetching data")
|
|
|
|
console.log(err)
|
2023-01-15 20:00:18 +00:00
|
|
|
}
|