From b84cb3855cadd73733cfb7fe2abde6a343a0aeb0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 23 Feb 2021 12:15:09 +0100 Subject: [PATCH] Add button to run all rebuildData workers Resolves #3974 --- .../Core/Acp/Ui/Maintenance/RebuildData.ts | 55 ++++++++++++++++++ .../files/acp/templates/rebuildData.tpl | 56 +++++++------------ .../Core/Acp/Ui/Maintenance/RebuildData.js | 53 ++++++++++++++++++ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 5 files changed, 131 insertions(+), 35 deletions(-) create mode 100644 ts/WoltLabSuite/Core/Acp/Ui/Maintenance/RebuildData.ts create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Maintenance/RebuildData.js diff --git a/ts/WoltLabSuite/Core/Acp/Ui/Maintenance/RebuildData.ts b/ts/WoltLabSuite/Core/Acp/Ui/Maintenance/RebuildData.ts new file mode 100644 index 0000000000..4deae5b286 --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/Maintenance/RebuildData.ts @@ -0,0 +1,55 @@ +import Worker from "../Worker"; +import * as Language from "../../../Language"; + +const workers = new Map(); + +export function register(button: HTMLElement): void { + if (!button.dataset.className) { + throw new Error(`Missing 'data-class-name' attribute.`); + } + + workers.set(button, parseInt(button.dataset.nicevalue!, 10)); + + button.addEventListener("click", function (event) { + event.preventDefault(); + + void runWorker(button); + }); +} + +export async function runAllWorkers(): Promise { + const sorted = Array.from(workers) + .sort(([, a], [, b]) => { + return a - b; + }) + .map(([el]) => el); + + let i = 1; + for (const worker of sorted) { + await runWorker(worker, `${worker.textContent!} (${i++} / ${sorted.length})`); + } +} + +async function runWorker(button: HTMLElement, dialogTitle: string = button.textContent!): Promise { + return new Promise((resolve, reject) => { + new Worker({ + dialogId: "cache", + dialogTitle, + className: button.dataset.className, + callbackAbort() { + reject(); + }, + callbackSuccess() { + let span = button.nextElementSibling; + if (span && span.nodeName === "SPAN") { + span.remove(); + } + + span = document.createElement("span"); + span.innerHTML = ` ${Language.get("wcf.acp.worker.success")}`; + button.parentNode!.insertBefore(span, button.nextElementSibling); + resolve(); + }, + }); + }); +} diff --git a/wcfsetup/install/files/acp/templates/rebuildData.tpl b/wcfsetup/install/files/acp/templates/rebuildData.tpl index 4b7370de11..77b5e67394 100644 --- a/wcfsetup/install/files/acp/templates/rebuildData.tpl +++ b/wcfsetup/install/files/acp/templates/rebuildData.tpl @@ -1,34 +1,19 @@ {include file='header' pageTitle='wcf.acp.rebuildData'}