diff --git a/python-tools/static/app.js b/python-tools/static/app.js index c5ed806..f51ece6 100644 --- a/python-tools/static/app.js +++ b/python-tools/static/app.js @@ -2,6 +2,9 @@ const output = document.querySelector("#run-output"); if (output) { let refreshTimer; + let detailsFinalized = !["queued", "running"].includes( + document.querySelector("#run-status")?.textContent.trim(), + ); const refresh = async () => { const response = await fetch(output.dataset.outputUrl, { cache: "no-store" }); if (response.ok) { @@ -17,6 +20,22 @@ if (output) { const state = await stateResponse.json(); status.textContent = state.status; if (state.status !== "queued" && state.status !== "running") { + if (!detailsFinalized) { + const pageResponse = await fetch(window.location.href, { cache: "no-store" }); + if (!pageResponse.ok) { + return; + } + const page = new DOMParser().parseFromString(await pageResponse.text(), "text/html"); + const nextDetails = page.querySelector("#run-status")?.closest("dl"); + if (!nextDetails) { + return; + } + const actions = 'form[action$="/cancel"], form[action$="/execute"]'; + document.querySelectorAll(actions).forEach((form) => form.remove()); + status.closest("dl").replaceWith(nextDetails); + nextDetails.after(...page.querySelectorAll(actions)); + detailsFinalized = true; + } window.clearInterval(refreshTimer); } }