diff --git a/app/public/static/js/polltask.js b/app/public/static/js/polltask.js index d7a9bd87..6a0519a7 100644 --- a/app/public/static/js/polltask.js +++ b/app/public/static/js/polltask.js @@ -22,7 +22,7 @@ function sleep(interval) { } -async function pollTask(poll_url, disableTimeout) { +async function pollTask(poll_url, disableTimeout, onProgress) { let tries = 0; while (true) { @@ -43,30 +43,7 @@ async function pollTask(poll_url, disableTimeout) { } if (res && res.status) { - let status = res.status.toLowerCase(); - - const progress = document.getElementById("progress"); - - if (status === "progress") { - progress.classList.remove("d-none"); - const bar = progress.children[0]; - - const {current, total, running} = res.result; - const perc = Math.min( Math.max(100 * current / total, 0), 100); - bar.style.width = `${perc}%`; - bar.setAttribute("aria-valuenow", current); - bar.setAttribute("aria-valuemax", total); - - const packages = running.map(x => `${x.author}/${x.name}`).join(", "); - document.getElementById("status").textContent = `Status: in progress (${current} / ${total})\n\n${packages}`; - } else { - progress.classList.add("d-none"); - - if (status === "pending") { - status = "pending or unknown"; - } - document.getElementById("status").textContent = `Status: ${status}`; - } + onProgress?.(res); } if (res && res.status === "SUCCESS") { @@ -89,3 +66,38 @@ async function performTask(url) { throw "Start task didn't return string!"; } } + +window.addEventListener("load", () => { + const taskId = document.querySelector("[data-task-id]")?.getAttribute("data-task-id"); + if (taskId) { + const progress = document.getElementById("progress"); + + function onProgress(res) { + let status = res.status.toLowerCase(); + if (status === "progress") { + progress.classList.remove("d-none"); + const bar = progress.children[0]; + + const {current, total, running} = res.result; + const perc = Math.min(Math.max(100 * current / total, 0), 100); + bar.style.width = `${perc}%`; + bar.setAttribute("aria-valuenow", current); + bar.setAttribute("aria-valuemax", total); + + const packages = running.map(x => `${x.author}/${x.name}`).join(", "); + document.getElementById("status").textContent = `Status: in progress (${current} / ${total})\n\n${packages}`; + } else { + progress.classList.add("d-none"); + + if (status === "pending") { + status = "pending or unknown"; + } + document.getElementById("status").textContent = `Status: ${status}`; + } + } + + pollTask(`/tasks/${taskId}/`, true, onProgress) + .then(function() { location.reload() }) + .catch(function() { location.reload() }) + } +}); diff --git a/app/templates/packages/create_edit.html b/app/templates/packages/create_edit.html index 41cb7969..715fd8f0 100644 --- a/app/templates/packages/create_edit.html +++ b/app/templates/packages/create_edit.html @@ -18,7 +18,7 @@ {{ form_scripts() }} {{ easymde_scripts() }} {% if enable_wizard %} - + {% endif %} diff --git a/app/templates/tasks/view.html b/app/templates/tasks/view.html index c90d891a..9bb102e1 100644 --- a/app/templates/tasks/view.html +++ b/app/templates/tasks/view.html @@ -10,22 +10,17 @@ {% block content %}
{{ info.error }}
{% else %}
-
-
+