Skip to content

Commit

Permalink
Add loading animation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlinmack committed Sep 25, 2023
1 parent af048cd commit 91ec636
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions scholia/app/templates/q_curation.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ <h1 id="h1">Improve...</h1>
function get_dois_from_crossref(query_string) {
const button = document.getElementById("check-crossref-button");
button.innerHTML = "Loading...";
button.classList.remove("d-block");
button.classList.add("d-none");
button.insertAdjacentHTML('beforebegin',
"<div id='check-crossref-loader' class='loader'><div></div><div></div><div></div></div>"
)
const params = {
'query': query_string,
'select': 'DOI',
Expand All @@ -46,36 +51,40 @@ <h1 id="h1">Improve...</h1>
const url = `https://api.crossref.org/works/?${searchParams.toString()}`;
const error_message = "The API failed which could be due to a problem with your connection or with the upstream server. If the issue persists <a href='https://github.com/WDscholia/scholia/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=''>submit a bug report on GitHub</a>"

console.log(url)
fetch(url)
.then(response => response.json())
.then(data => {
console.log(data)
if (data['status'] == 'ok') {
console.count()
if (data["message"]["total-results"] > 0){
console.count()
items = data.message?.items
if (items) {
console.count()
dois = items.map(x => x.DOI).join(" ");
window.location.href = "/id-to-quickstatements?query=" + dois;
}
} else {
} else {
$('#check-crossref-loader').remove();
button.insertAdjacentHTML('afterend', `<div class="alert alert-secondary" role="alert">No results returned for ${data.message.query['status-terms']}</div>`);
button.innerHTML = "Check Crossref";
button.classList.remove("d-none");
button.classList.add("d-block");
}
} else {
console.error(`API status was ${data.status}`)
console.error(data)
$('#check-crossref-loader').remove();
button.insertAdjacentHTML('afterend', `<div class="alert alert-warning" role="alert">${error_message}</div>`);
button.innerHTML = "Check Crossref";
button.classList.remove("d-none");
button.classList.add("d-block");
}
})
.catch(error => {
console.error(error);
$('#check-crossref-loader').remove();
button.insertAdjacentHTML('afterend', `<div class="alert alert-warning" role="alert">${error_message}</div>`);
button.innerHTML = "Check Crossref";
button.classList.remove("d-none");
button.classList.add("d-block");
});
}
</script>
Expand Down

0 comments on commit 91ec636

Please sign in to comment.