You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.2 KiB
73 lines
2.2 KiB
/* =======================================================================
|
|
File: static/js/progress.js
|
|
Purpose:
|
|
Update progress bars dynamically for the current book.
|
|
Only updates the main progress box (book_detail page).
|
|
======================================================================= */
|
|
|
|
console.log(">>> progress.js LOADED");
|
|
|
|
function updateProgressBars(data) {
|
|
console.log(">>> progress.js updateProgressBars() CALLED with:", data);
|
|
|
|
if (!data) {
|
|
console.warn(">>> progress.js: NO DATA RECEIVED");
|
|
return;
|
|
}
|
|
|
|
// We always update inside the main progress box:
|
|
const container = document.querySelector("#progressSection");
|
|
if (!container) {
|
|
console.warn(">>> progress.js: #progressSection NOT FOUND");
|
|
return;
|
|
}
|
|
|
|
// Select bars ONLY inside the correct section
|
|
const barDL = container.querySelector(
|
|
".progress-bar:not(.audio) .progress-bar-fill"
|
|
);
|
|
const barAU = container.querySelector(
|
|
".progress-bar.audio .progress-bar-fill"
|
|
);
|
|
|
|
const pctDL =
|
|
data.download_total > 0
|
|
? (100 * data.download_done) / data.download_total
|
|
: 0;
|
|
|
|
const pctAU =
|
|
data.audio_total > 0 ? (100 * data.audio_done) / data.audio_total : 0;
|
|
|
|
if (barDL) {
|
|
barDL.style.width = pctDL.toFixed(1) + "%";
|
|
console.log(">>> progress.js DL bar =", pctDL.toFixed(1) + "%");
|
|
} else {
|
|
console.warn(">>> progress.js: barDL NOT FOUND INSIDE #progressSection");
|
|
}
|
|
|
|
if (barAU) {
|
|
barAU.style.width = pctAU.toFixed(1) + "%";
|
|
console.log(">>> progress.js AU bar =", pctAU.toFixed(1) + "%");
|
|
} else {
|
|
console.warn(">>> progress.js: barAU NOT FOUND INSIDE #progressSection");
|
|
}
|
|
|
|
// Textual stats — only update inside progress box
|
|
const stats = container.querySelectorAll(".progress-stats span");
|
|
|
|
// Expected: [DL x/y, DL %, AU x/y, AU %]
|
|
if (stats.length >= 4) {
|
|
stats[0].innerText = `${data.download_done} / ${data.download_total}`;
|
|
stats[1].innerText = pctDL.toFixed(1) + "%";
|
|
stats[2].innerText = `${data.audio_done} / ${data.audio_total}`;
|
|
stats[3].innerText = pctAU.toFixed(1) + "%";
|
|
|
|
console.log(">>> progress.js stats updated");
|
|
} else {
|
|
console.warn(
|
|
">>> progress.js: not enough stats spans in the container, found",
|
|
stats.length
|
|
);
|
|
}
|
|
}
|