Frontend: Refactor fine-code.js - Will need work

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-01-23 19:46:41 +00:00
parent 0958bc92f5
commit 7ea8f153cd
2 changed files with 12 additions and 33 deletions

View File

@ -15,9 +15,6 @@ async function fetchEntry(){ // This can be condensed
tiploc: tiploc.value,
stanox: stanox.value
}
console.log(`Read values: ${JSON.stringify(values)}`)
parseData(values)
}
@ -35,11 +32,13 @@ async function parseData(values){
setLoadingDesc(`Searching\n${values.stanox.toUpperCase()}`)
var data = await getData("stanox", values.stanox)
} else if (values.name != ""){
setLoadingDesc(`Searching\n${values.name.capitalize()}`)
setLoadingDesc(`Searching\n${values.name}`)
var data = await getData("name", values.name)
} else {
errorNoData()
hideLoading()
log("No Data", "INFO")
await clearForm();
document.getElementById("name").value = "No data entered"
hideLoading();
return;
}
@ -54,14 +53,17 @@ async function getData(type, value){
console.log(`Response: ${resp.json}`)
return await resp.json()
} catch (err) {
errorFetch(err)
log(`find-code.getData: Error getting data: ${err}`, "WARN")
return "";
}
}
async function displayData(data){
hideLoading();
if (data.status === "failed" || data == ""){
errorNotFound()
log(`Unable to find data`, "WARN")
clearForm();
document.getElementById("name").value = "Not Found";
}
document.getElementById("name").value = data['0']['NLCDESC']
document.getElementById("3alpha").value = data['0']['3ALPHA']
@ -79,26 +81,3 @@ async function clearForm(){
document.getElementById("stanox").value = ""
hideLoading();
}
async function showLoading(){
document.getElementById("loading").style = "display: block;";
}
async function hideLoading(){
document.getElementById("loading").style = "display: none;";
}
async function errorNoData(){
console.log("No data entered")
window.alert("You haven't entered any data")
}
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.")
}

View File

@ -3,7 +3,7 @@ pageInit();
async function pageInit() {
await loadQuickLinks();
hideLoading();
hideLoading(); // From lib.main
}
async function gotoBoard(station){