+/**
+ * Offers to install packages from the list of licensed products.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.0
+ */
+
+import { promiseMutex } from "WoltLabSuite/Core/Helper/PromiseMutex";
import AcpUiPackagePrepareInstallation from "../Ui/Package/PrepareInstallation";
-function installPackage(button: HTMLButtonElement): void {
+function installPackage(button: HTMLButtonElement): Promise<void> {
const installation = new AcpUiPackagePrepareInstallation();
- installation.start(button.dataset.package!, button.dataset.packageVersion!);
+ return installation.start(button.dataset.package!, button.dataset.packageVersion!);
}
export function setup(): void {
+ const callback = promiseMutex((button: HTMLButtonElement) => installPackage(button));
document.querySelectorAll<HTMLButtonElement>(".jsInstallPackage").forEach((button) => {
button.addEventListener("click", () => {
- installPackage(button);
+ callback(button);
});
});
}
class AcpUiPackagePrepareInstallation {
private identifier = "";
private version = "";
+ #resolve?: () => void;
+
+ start(identifier: string, version: string): Promise<void> {
+ if (this.#resolve !== undefined) {
+ throw new Error("There is already a pending installation.");
+ }
- start(identifier: string, version: string): void {
this.identifier = identifier;
this.version = version;
- this.prepare({});
+ return new Promise<void>((resolve) => {
+ this.#resolve = resolve;
+
+ this.prepare({});
+ });
}
private prepare(authData: ArbitraryObject): void {
} else if (data.returnValues.template) {
UiDialog.open(this, data.returnValues.template);
}
+
+ this.#resolve!();
+ this.#resolve = undefined;
}
_ajaxSetup(): ReturnType<AjaxCallbackSetup> {
import * as Ajax from "../../../Ajax";
import AjaxRequest from "../../../Ajax/Request";
import { AjaxCallbackObject, AjaxCallbackSetup } from "../../../Ajax/Data";
+import { promiseMutex } from "WoltLabSuite/Core/Helper/PromiseMutex";
interface AjaxResponse {
actionName: string;
this.setStatus("showResults");
+ const callback = promiseMutex((button: HTMLAnchorElement) => {
+ return this.installation.start(button.dataset.package!, button.dataset.packageVersion!);
+ });
this.resultList.querySelectorAll(".jsInstallPackage").forEach((button: HTMLAnchorElement) => {
button.addEventListener("click", (event) => {
event.preventDefault();
- button.blur();
- this.installation.start(button.dataset.package!, button.dataset.packageVersion!);
+ if (callback(button)) {
+ button.blur();
+ }
});
});
} else {
-define(["require", "exports", "tslib", "../Ui/Package/PrepareInstallation"], function (require, exports, tslib_1, PrepareInstallation_1) {
+/**
+ * Offers to install packages from the list of licensed products.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.0
+ */
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Helper/PromiseMutex", "../Ui/Package/PrepareInstallation"], function (require, exports, tslib_1, PromiseMutex_1, PrepareInstallation_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setup = void 0;
PrepareInstallation_1 = tslib_1.__importDefault(PrepareInstallation_1);
function installPackage(button) {
const installation = new PrepareInstallation_1.default();
- installation.start(button.dataset.package, button.dataset.packageVersion);
+ return installation.start(button.dataset.package, button.dataset.packageVersion);
}
function setup() {
+ const callback = (0, PromiseMutex_1.promiseMutex)((button) => installPackage(button));
document.querySelectorAll(".jsInstallPackage").forEach((button) => {
button.addEventListener("click", () => {
- installPackage(button);
+ callback(button);
});
});
}
class AcpUiPackagePrepareInstallation {
identifier = "";
version = "";
+ #resolve;
start(identifier, version) {
+ if (this.#resolve !== undefined) {
+ throw new Error("There is already a pending installation.");
+ }
this.identifier = identifier;
this.version = version;
- this.prepare({});
+ return new Promise((resolve) => {
+ this.#resolve = resolve;
+ this.prepare({});
+ });
}
prepare(authData) {
const packages = {};
else if (data.returnValues.template) {
Dialog_1.default.open(this, data.returnValues.template);
}
+ this.#resolve();
+ this.#resolve = undefined;
}
_ajaxSetup() {
return {
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
-define(["require", "exports", "tslib", "./PrepareInstallation", "../../../Ajax"], function (require, exports, tslib_1, PrepareInstallation_1, Ajax) {
+define(["require", "exports", "tslib", "./PrepareInstallation", "../../../Ajax", "WoltLabSuite/Core/Helper/PromiseMutex"], function (require, exports, tslib_1, PrepareInstallation_1, Ajax, PromiseMutex_1) {
"use strict";
PrepareInstallation_1 = tslib_1.__importDefault(PrepareInstallation_1);
Ajax = tslib_1.__importStar(Ajax);
this.resultList.innerHTML = data.returnValues.template;
this.resultCounter.textContent = data.returnValues.count.toString();
this.setStatus("showResults");
+ const callback = (0, PromiseMutex_1.promiseMutex)((button) => {
+ return this.installation.start(button.dataset.package, button.dataset.packageVersion);
+ });
this.resultList.querySelectorAll(".jsInstallPackage").forEach((button) => {
button.addEventListener("click", (event) => {
event.preventDefault();
- button.blur();
- this.installation.start(button.dataset.package, button.dataset.packageVersion);
+ if (callback(button)) {
+ button.blur();
+ }
});
});
}