Frontend: Further refactoring find-code.js
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
7ea8f153cd
commit
018ddf8c47
@ -1,4 +1,4 @@
|
||||
clearLoading();
|
||||
hideLoading();
|
||||
|
||||
async function fetchEntry(){ // This can be condensed
|
||||
showLoading();
|
||||
@ -35,22 +35,20 @@ async function parseData(values){
|
||||
setLoadingDesc(`Searching\n${values.name}`)
|
||||
var data = await getData("name", values.name)
|
||||
} else {
|
||||
log("No Data", "INFO")
|
||||
log("find-code.parseData: No data entered", "WARN")
|
||||
await clearForm();
|
||||
document.getElementById("name").value = "No data entered"
|
||||
hideLoading();
|
||||
return;
|
||||
}
|
||||
|
||||
displayData(data);
|
||||
}
|
||||
|
||||
async function getData(type, value){
|
||||
console.log(`Looking for: ${type} ${value}`)
|
||||
log(`find-code.getData: Looking for: ${type} '${value}'`, "INFO")
|
||||
try {
|
||||
var url = `${window.location.origin}/api/v1/find/${type}/${value}`;
|
||||
var resp = await fetch(url);
|
||||
console.log(`Response: ${resp.json}`)
|
||||
return await resp.json()
|
||||
} catch (err) {
|
||||
log(`find-code.getData: Error getting data: ${err}`, "WARN")
|
||||
@ -61,16 +59,27 @@ async function getData(type, value){
|
||||
async function displayData(data){
|
||||
hideLoading();
|
||||
if (data.status === "failed" || data == ""){
|
||||
log(`Unable to find data`, "WARN")
|
||||
log(`find-code.displayData: Unable to find data`, "WARN")
|
||||
clearForm();
|
||||
document.getElementById("name").value = "Not Found";
|
||||
}
|
||||
} else {
|
||||
log(`find-code.displayData: Inserting data`, "INFO")
|
||||
try {
|
||||
document.getElementById("name").value = data['0']['NLCDESC']
|
||||
} catch (err) {}
|
||||
try {
|
||||
document.getElementById("3alpha").value = data['0']['3ALPHA']
|
||||
} catch (err) {}
|
||||
try {
|
||||
document.getElementById("nlc").value = data['0']['NLC']
|
||||
} catch (err) {}
|
||||
try {
|
||||
document.getElementById("tiploc").value = data['0']['TIPLOC']
|
||||
} catch (err) {}
|
||||
try {
|
||||
document.getElementById("stanox").value = data['0']['STANOX']
|
||||
// document.getElementById("stanme").value = data['0']['STANME'] // NOT PRESENT IN CORPUS
|
||||
} catch (err) {}
|
||||
}
|
||||
}
|
||||
|
||||
async function clearForm(){
|
||||
|
Reference in New Issue
Block a user