Pedro Amorim
63b7d7e3c5
These patches change the current updateProgress function to accept a progress callback (a function that is called every time the bar progresses) in addition to the already existing callback that is called when the progress bar finishes. It's not expected to change any current behavior in master because updateProgress is only used once in the stage marc import tool using the already existing callback, and these patches aim to keep that. Test Plan: 1) Apply this patch 2) Stage a marc batch ( preferrably a large one to show the progress updating ) 3) Note the new progess bar, verify it functions correctly. Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
37 lines
1.9 KiB
JavaScript
37 lines
1.9 KiB
JavaScript
function updateProgress(job_id, callbacks) {
|
|
$.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);
|
|
$('#progress-bar-' + job_id).width(Math.floor(percent) +"%");
|
|
typeof callbacks.progress_callback === 'function' && callbacks.progress_callback();
|
|
} 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;
|
|
typeof callbacks.finish_callback === 'function' && callbacks.finish_callback();
|
|
} 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, callbacks)}, 1 * 1000);
|
|
}
|
|
});
|
|
}
|