From 2aec8840090d8c8f3168503ddc6031f7e4042ba3 Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 9 Jun 2023 23:58:04 +0200 Subject: [PATCH] Moved update interval for task-progress to own interval, progress gets continually updated. --- Website/interaction.js | 75 ++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/Website/interaction.js b/Website/interaction.js index 3d99587..979b642 100644 --- a/Website/interaction.js +++ b/Website/interaction.js @@ -40,6 +40,7 @@ const settingApiUri = document.querySelector("#settingApiUri"); const tagTasksRunning = document.querySelector("#tasksRunningTag"); const tagTasksQueued = document.querySelector("#tasksQueuedTag"); const downloadTasksPopup = document.querySelector("#downloadTasksPopup"); +const downloadTasksOutput = downloadTasksPopup.querySelector("popup-content"); searchbox.addEventListener("keyup", (event) => FilterResults()); settingsCog.addEventListener("click", () => OpenSettings()); @@ -359,33 +360,31 @@ function FilterResults(){ } function ShowTasksQueue(){ - downloadTasksPopup.style.display = "flex"; - var outputDom = downloadTasksPopup.querySelector("popup-content"); - outputDom.replaceChildren(); - GetRunningTasks().then((taskJson) => { - taskJson.forEach(task => { - outputDom.appendChild(CreateProgressChild(task)); - }); - }); - GetQueue().then((taskJson) => { - taskJson.forEach(task => { - outputDom.appendChild(CreateProgressChild(task)); - }); - }); - setInterval(() => { - GetRunningTasks().then((json) => { - json.forEach(task => { - if(task.chapter != undefined){ - document.querySelector(`#progress${task.publication.internalId}-${task.chapter.sortNumber}`).value = task.progress; - document.querySelector(`#progressStr${task.publication.internalId}-${task.chapter.sortNumber}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2}); - }else{ - document.querySelector(`#progress${task.publication.internalId}`).value = task.progress; - document.querySelector(`#progressStr${task.publication.internalId}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2}); - } - }); + downloadTasksOutput.replaceChildren(); + GetRunningTasks() + .then(json => { + tagTasksRunning.innerText = json.length; + json.forEach(task => { + downloadTasksOutput.appendChild(CreateProgressChild(task)); + }); + if(task.chapter != undefined){ + document.querySelector(`#progress${task.publication.internalId}-${task.chapter.sortNumber}`).value = task.progress; + document.querySelector(`#progressStr${task.publication.internalId}-${task.chapter.sortNumber}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2}); + }else{ + document.querySelector(`#progress${task.publication.internalId}`).value = task.progress; + document.querySelector(`#progressStr${task.publication.internalId}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2}); + } }); - },500); + + GetQueue() + .then(json => { + tagTasksQueued.innerText = json.length; + json.forEach(task => { + downloadTasksOutput.appendChild(CreateProgressChild(task)); + }); + }); + downloadTasksPopup.style.display = "flex"; } function CreateProgressChild(task){ @@ -433,6 +432,7 @@ function CreateProgressChild(task){ //Resets the tasks shown ResetContent(); +downloadTasksOutput.replaceChildren(); //Get Tasks and show them GetDownloadTasks() .then(json => json.forEach(task => { @@ -445,11 +445,17 @@ GetDownloadTasks() GetRunningTasks() .then(json => { tagTasksRunning.innerText = json.length; + json.forEach(task => { + downloadTasksOutput.appendChild(CreateProgressChild(task)); + }); }); GetQueue() .then(json => { tagTasksQueued.innerText = json.length; + json.forEach(task => { + downloadTasksOutput.appendChild(CreateProgressChild(task)); + }); }) setInterval(() => { @@ -482,6 +488,19 @@ setInterval(() => { GetQueue() .then(json => { tagTasksQueued.innerText = json.length; - }) - -}, 1000); \ No newline at end of file + }); +}, 1000); + +setInterval(() => { + GetRunningTasks().then((json) => { + json.forEach(task => { + if(task.chapter != undefined){ + document.querySelector(`#progress${task.publication.internalId}-${task.chapter.sortNumber}`).value = task.progress; + document.querySelector(`#progressStr${task.publication.internalId}-${task.chapter.sortNumber}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2}); + }else{ + document.querySelector(`#progress${task.publication.internalId}`).value = task.progress; + document.querySelector(`#progressStr${task.publication.internalId}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2}); + } + }); + }); +},500); \ No newline at end of file