Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions ts/WoltLabSuite/Core/Acp/Controller/ExceptionLog/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ import { wheneverFirstSeen } from "WoltLabSuite/Core/Helper/Selector";
import { getPhrase } from "WoltLabSuite/Core/Language";

async function showDialog(button: HTMLElement): Promise<void> {
const response = await renderException(button.closest("tr")!.dataset.objectId!);
if (!response.ok) {
return;
}
const { template } = await renderException(button.closest("tr")!.dataset.objectId!);

const dialog = dialogFactory().fromHtml(response.value.template).withoutControls();
const dialog = dialogFactory().fromHtml(template).withoutControls();
dialog.content.querySelector(".jsCopyButton")?.addEventListener("click", () => {
void copyTextToClipboard(dialog.content.querySelector<HTMLTextAreaElement>(".jsCopyException")!.value);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ function initRevertButtons(container: HTMLElement, objectType: string, objectId:
return;
}

const response = await revertVersion(objectType, objectId, parseInt(button.dataset.objectId!));
if (response.ok) {
showDefaultSuccessSnackbar().addEventListener("snackbar:close", () => {
window.location.reload();
});
}
await revertVersion(objectType, objectId, parseInt(button.dataset.objectId!));

showDefaultSuccessSnackbar().addEventListener("snackbar:close", () => {
window.location.reload();
});
});
});
}
Expand Down
15 changes: 5 additions & 10 deletions ts/WoltLabSuite/Core/Api/Articles/GetArticlePopover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "WoltLabSuite/Core/Api/Result";
import { fromInfallibleApiRequest } from "WoltLabSuite/Core/Api/Result";

type Response = {
template: string;
};

export async function getArticlePopover(articleId: number): Promise<ApiResult<string>> {
export async function getArticlePopover(articleId: number): Promise<string> {
const url = new URL(`${window.WSC_RPC_API_URL}core/articles/${articleId}/popover`);

let response: Response;
try {
response = (await prepareRequest(url).get().fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response.template);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).get().fetchAsJson();
});
}
14 changes: 5 additions & 9 deletions ts/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result";
import { fromInfallibleApiRequest } from "../../Result";

export async function clearLogs(): Promise<ApiResult<[]>> {
try {
await prepareRequest(`${window.WSC_RPC_API_URL}core/cronjobs/logs`).delete().fetchAsJson();
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue([]);
export async function clearLogs(): Promise<[]> {
return fromInfallibleApiRequest(() => {
return prepareRequest(`${window.WSC_RPC_API_URL}core/cronjobs/logs`).delete().fetchAsJson();
});
}
15 changes: 5 additions & 10 deletions ts/WoltLabSuite/Core/Api/Exceptions/RenderException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

type Response = {
template: string;
};

export async function renderException(exceptionId: string): Promise<ApiResult<Response>> {
export async function renderException(exceptionId: string): Promise<Response> {
const url = new URL(`${window.WSC_RPC_API_URL}core/exceptions/${exceptionId}/render`);

let response: Response;
try {
response = (await prepareRequest(url).get().fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).get().fetchAsJson();
});
}
15 changes: 5 additions & 10 deletions ts/WoltLabSuite/Core/Api/Gridviews/GetRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

type Response = {
template: string;
Expand All @@ -18,7 +18,7 @@ export async function getRow(
gridViewClass: string,
objectId: string | number,
gridViewParameters?: Map<string, string>,
): Promise<ApiResult<Response>> {
): Promise<Response> {
const url = new URL(`${window.WSC_RPC_API_URL}core/grid-views/row`);
url.searchParams.set("gridView", gridViewClass);
url.searchParams.set("objectID", objectId.toString());
Expand All @@ -34,12 +34,7 @@ export async function getRow(
});
}

let response: Response;
try {
response = (await prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson();
});
}
15 changes: 5 additions & 10 deletions ts/WoltLabSuite/Core/Api/Gridviews/GetRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

type Response = {
template: string;
Expand All @@ -24,7 +24,7 @@ export async function getRows(
sortOrder: string = "ASC",
filters?: Map<string, string>,
gridViewParameters?: Map<string, string>,
): Promise<ApiResult<Response>> {
): Promise<Response> {
const url = new URL(`${window.WSC_RPC_API_URL}core/grid-views/rows`);
url.searchParams.set("gridView", gridViewClass);
url.searchParams.set("pageNo", pageNo.toString());
Expand All @@ -47,12 +47,7 @@ export async function getRows(
});
}

let response: Response;
try {
response = (await prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson();
});
}
20 changes: 6 additions & 14 deletions ts/WoltLabSuite/Core/Api/Interactions/GetBulkContextMenuOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,17 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

type Response = {
template: string;
};

export async function getBulkContextMenuOptions(
providerClassName: string,
objectIds: number[],
): Promise<ApiResult<Response>> {
let response: Response;
try {
response = (await prepareRequest(`${window.WSC_RPC_API_URL}core/interactions/bulk-context-menu-options`)
export async function getBulkContextMenuOptions(providerClassName: string, objectIds: number[]): Promise<Response> {
return fromInfallibleApiRequest(() => {
return prepareRequest(`${window.WSC_RPC_API_URL}core/interactions/bulk-context-menu-options`)
.post({ provider: providerClassName, objectIDs: objectIds })
.disableLoadingIndicator()
.fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response);
.fetchAsJson();
});
}
18 changes: 5 additions & 13 deletions ts/WoltLabSuite/Core/Api/Interactions/GetContextMenuOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,18 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

type Response = {
template: string;
};

export async function getContextMenuOptions(
providerClassName: string,
objectId: number | string,
): Promise<ApiResult<Response>> {
export async function getContextMenuOptions(providerClassName: string, objectId: number | string): Promise<Response> {
const url = new URL(`${window.WSC_RPC_API_URL}core/interactions/context-menu-options`);
url.searchParams.set("provider", providerClassName);
url.searchParams.set("objectID", objectId.toString());

let response: Response;
try {
response = (await prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson();
});
}
15 changes: 5 additions & 10 deletions ts/WoltLabSuite/Core/Api/ListViews/GetItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

type Response = {
template: string;
Expand All @@ -18,7 +18,7 @@ export async function getItem(
listViewClass: string,
objectId: string | number,
listViewParameters?: Map<string, string>,
): Promise<ApiResult<Response>> {
): Promise<Response> {
const url = new URL(`${window.WSC_RPC_API_URL}core/list-views/item`);
url.searchParams.set("listView", listViewClass);
url.searchParams.set("objectID", objectId.toString());
Expand All @@ -34,12 +34,7 @@ export async function getItem(
});
}

let response: Response;
try {
response = (await prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson();
});
}
15 changes: 5 additions & 10 deletions ts/WoltLabSuite/Core/Api/ListViews/GetItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

type Response = {
template: string;
Expand All @@ -24,7 +24,7 @@ export async function getItems(
sortOrder: string = "ASC",
filters?: Map<string, string>,
listViewParameters?: Map<string, string>,
): Promise<ApiResult<Response>> {
): Promise<Response> {
const url = new URL(`${window.WSC_RPC_API_URL}core/list-views/items`);
url.searchParams.set("listView", listViewClass);
url.searchParams.set("pageNo", pageNo.toString());
Expand All @@ -47,12 +47,7 @@ export async function getItems(
});
}

let response: Response;
try {
response = (await prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson();
});
}
15 changes: 5 additions & 10 deletions ts/WoltLabSuite/Core/Api/Messages/MentionSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

type Item =
| {
Expand All @@ -25,16 +25,11 @@ type Item =
};
type Response = Item[];

export async function mentionSuggestions(query: string): Promise<ApiResult<Response>> {
export async function mentionSuggestions(query: string): Promise<Response> {
const url = new URL(window.WSC_RPC_API_URL + "core/messages/mention-suggestions");
url.searchParams.set("query", query);

let response: Response;
try {
response = (await prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson();
});
}
19 changes: 5 additions & 14 deletions ts/WoltLabSuite/Core/Api/Messages/RenderQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

type Response = {
objectID: number;
Expand All @@ -20,22 +20,13 @@ type Response = {
rawMessage: string | null;
};

export async function renderQuote(
objectType: string,
objectID: number,
isFullQuote: boolean,
): Promise<ApiResult<Response>> {
export async function renderQuote(objectType: string, objectID: number, isFullQuote: boolean): Promise<Response> {
const url = new URL(window.WSC_RPC_API_URL + "core/messages/render-quote");
url.searchParams.set("objectType", objectType);
url.searchParams.set("isFullQuote", String(isFullQuote));
url.searchParams.set("objectID", objectID.toString());

let response: Response;
try {
response = (await prepareRequest(url).get().fetchAsJson()) as Response;
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue(response);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).get().fetchAsJson();
});
}
14 changes: 5 additions & 9 deletions ts/WoltLabSuite/Core/Api/Messages/ResetRemovalQuotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
import { fromInfallibleApiRequest } from "../Result";

export async function resetRemovalQuotes(): Promise<ApiResult<[]>> {
export async function resetRemovalQuotes(): Promise<[]> {
const url = new URL(window.WSC_RPC_API_URL + "core/messages/reset-removal-quotes");

try {
await prepareRequest(url).post().fetchAsJson();
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue([]);
return fromInfallibleApiRequest(() => {
return prepareRequest(url).post().fetchAsJson();
});
}
Loading