Koha/koha-tmpl/intranet-tmpl/prog/js/job_progress.js
Koha Development Team d659526b5a
Bug 38664: Tidy the whole codebase
This commit is generated using:
  % perl misc/devel/tidy.pl
*within* ktd, to get the same version of perltidy than what will be used
by our CI (currently v20230309).

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
2025-02-11 14:58:24 +01:00

51 lines
2.1 KiB
JavaScript

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