Koha/koha-tmpl/intranet-tmpl/prog/js/job_progess.js
Martin Renvoize e0370e9975
Bug 31666: (QA follow-up) Remove ES template literals
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2022-10-05 16:08:20 -03:00

34 lines
1.6 KiB
JavaScript

function updateProgress(job_id) {
$.getJSON('/api/v1/jobs/' + job_id, function(job){
let recheck = true;
if ( job.status == "new" ) {
$('#job-percent-' + job_id).text(0);
$('#job-status-' + job_id).text(JOB_PROGRESS_NOT_STARTED);
$('#progress-bar-' + job_id).attr('aria-valuenow', 0).css("width", "100%");
} else if ( job.status == "started" ) {
const progress = job["progress"];
const size = job["size"];
const percent = progress > 0 ? ( progress / size ) * 100 : 0;
$('#job-percent-' + job_id).text(percent.toFixed(2));
$('#job-status-' + job_id).text(JOB_PROGRESS_STARTED);
$('#progress-bar-' + job_id).attr('aria-valuenow', percent).css("width", "percent+%");
} else if ( job.status == "finished" ) {
$('#job-percent-' + job_id).text(100);
$('#job-status-' + job_id).text(JOB_PROGRESS_FINISHED);
$('#progress-bar-' + job_id).addClass("progress-bar-success");
$('#progress-bar-' + job_id).attr('aria-valuenow', 100).css("width", "100%");
recheck = false;
} else if ( job.status == "failed" ) {
$('#job-percent-' + job_id).text(0);
$('#job-status-' + job_id).text(JOB_PROGRESS_FAILED);
$('#progress-bar-' + job_id).addClass("progress-bar-danger");
$('#progress-bar-' + job_id).attr('aria-valuenow', 0).css("width", "100%");
recheck = false;
}
if ( recheck ) {
setTimeout(function(){updateProgress(job_id)}, 1 * 1000);
}
});
}