Skip to content

Commit

Permalink
corrige função para atualizar tela de busca (impede que haja repetiçã…
Browse files Browse the repository at this point in the history
…o de request)
  • Loading branch information
rafaelpezzuto committed Nov 10, 2021
1 parent 6b56d39 commit 3f3fa3c
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions app/core/templates/ingress/package_download.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,42 @@ <h2 class="h4">{% trans 'Results for document' %} <strong>{{ pid }}</strong></h2

</div>
<script type="text/javascript">
var xhr;
var checkStatus = '{{ check_status }}';
var intervals = {}
var loader = document.getElementById('divLoader');
var button = document.getElementById('buttonSearch');
var requested = false;
var timer;

function update(){
xhr = $.ajax({
url: '/task/update_status/?task_id={{ task_id }}',
type: 'GET',
success: function(result) {
divSpinner = document.createElement('div');
divSpinner.classList.add('spinner-border');
divSpinner.setAttribute('role', 'status');
function checkTaskStatus() {
if (!requested){
$.ajax({
url: '/task/update_status/?task_id={{ task_id }}',
type: 'GET',
success: function(result) {
// mostra loader e desativa botão pesquisar
showLoader(loader, button);

spanLoading = document.createElement('span');
spanLoading.classList.add('sr-only');
spanLoading.text = "{% trans 'Loading' %}...";
if (result.data && 'doc_pkgs' in result.data) {
// adiciona conteúdo à tabela
ingressPackageDownloadCreateTable(result.data);

divSpinner.appendChild(spanLoading);
// impede que requisições continuem sendo realizadas
requested = true;
window.clearTimeout(timer);

$('user-package-download-results').add(divSpinner);

if (result.data && 'doc_pkgs' in result.data) {
clearInterval(intervals[0]);
ingressPackageDownloadCreateTable(result.data);
ingressPackageDownloadToggleSpinner();
// remove loader e reativa botão pesquisar
hideLoader(loader, button);
}
}
}
});
});
}
}

if (checkStatus) {
intervals[0] = setInterval(update, 200);
ingressPackageDownloadToggleSpinner();
if(checkStatus){
checkTaskStatus();
var timer = setInterval(function(){
checkTaskStatus();
}, 2000);
}
</script>
{% endblock %}

0 comments on commit 3f3fa3c

Please sign in to comment.