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