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,10 +15,7 @@ async function fetchEntry(){ // This can be condensed
tiploc: tiploc.value, tiploc: tiploc.value,
stanox: stanox.value stanox: stanox.value
} }
parseData(values)
console.log(`Read values: ${JSON.stringify(values)}`)
parseData(values)
} }
async function parseData(values){ async function parseData(values){
@ -35,11 +32,13 @@ async function parseData(values){
setLoadingDesc(`Searching\n${values.stanox.toUpperCase()}`) setLoadingDesc(`Searching\n${values.stanox.toUpperCase()}`)
var data = await getData("stanox", values.stanox) var data = await getData("stanox", values.stanox)
} else if (values.name != ""){ } else if (values.name != ""){
setLoadingDesc(`Searching\n${values.name.capitalize()}`) setLoadingDesc(`Searching\n${values.name}`)
var data = await getData("name", values.name) var data = await getData("name", values.name)
} else { } else {
errorNoData() log("No Data", "INFO")
hideLoading() await clearForm();
document.getElementById("name").value = "No data entered"
hideLoading();
return; return;
} }
@ -54,14 +53,17 @@ async function getData(type, value){
console.log(`Response: ${resp.json}`) console.log(`Response: ${resp.json}`)
return await resp.json() return await resp.json()
} catch (err) { } catch (err) {
errorFetch(err) log(`find-code.getData: Error getting data: ${err}`, "WARN")
return "";
} }
} }
async function displayData(data){ async function displayData(data){
hideLoading(); hideLoading();
if (data.status === "failed" || data == ""){ 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("name").value = data['0']['NLCDESC']
document.getElementById("3alpha").value = data['0']['3ALPHA'] document.getElementById("3alpha").value = data['0']['3ALPHA']
@ -79,26 +81,3 @@ async function clearForm(){
document.getElementById("stanox").value = "" document.getElementById("stanox").value = ""
hideLoading(); 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() { async function pageInit() {
await loadQuickLinks(); await loadQuickLinks();
hideLoading(); hideLoading(); // From lib.main
} }
async function gotoBoard(station){ async function gotoBoard(station){