--- /dev/null
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";
+
+type Response = {
+ template: string;
+};
+
+export async function getRow(gridViewClass: string, objectId: string | number): Promise<ApiResult<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());
+
+ let response: Response;
+ try {
+ response = (await prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson()) as Response;
+ } catch (e) {
+ return apiResultFromError(e);
+ }
+
+ return apiResultFromValue(response);
+}
+import { getRow } from "../Api/Gridviews/GetRow";
import { getRows } from "../Api/Gridviews/GetRows";
import DomChangeListener from "../Dom/Change/Listener";
import DomUtil from "../Dom/Util";
this.#initSorting();
this.#initActions();
this.#initFilters();
+ this.#initEventListeners();
window.addEventListener("popstate", () => {
this.#handlePopState();
this.#initActions();
}
+ async #refreshRow(row: HTMLElement): Promise<void> {
+ const response = (await getRow(this.#gridClassName, row.dataset.objectId!)).unwrap();
+ row.replaceWith(DomUtil.createFragmentFromHtml(response.template));
+ DomChangeListener.trigger();
+ }
+
#updateQueryString(): void {
if (!this.#baseUrl) {
return;
this.#switchPage(pageNo, false);
}
+
+ #initEventListeners(): void {
+ this.#table.addEventListener("refresh", (event) => {
+ void this.#refreshRow(event.target as HTMLElement);
+ });
+ }
}
--- /dev/null
+define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../Result"], function (require, exports, Backend_1, Result_1) {
+ "use strict";
+ Object.defineProperty(exports, "__esModule", { value: true });
+ exports.getRow = getRow;
+ async function getRow(gridViewClass, objectId) {
+ const url = new URL(`${window.WSC_RPC_API_URL}core/grid-views/row`);
+ url.searchParams.set("gridView", gridViewClass);
+ url.searchParams.set("objectID", objectId.toString());
+ let response;
+ try {
+ response = (await (0, Backend_1.prepareRequest)(url).get().allowCaching().disableLoadingIndicator().fetchAsJson());
+ }
+ catch (e) {
+ return (0, Result_1.apiResultFromError)(e);
+ }
+ return (0, Result_1.apiResultFromValue)(response);
+ }
+});
-define(["require", "exports", "tslib", "../Api/Gridviews/GetRows", "../Dom/Change/Listener", "../Dom/Util", "../Helper/PromiseMutex", "../Ui/Dropdown/Simple", "./Dialog"], function (require, exports, tslib_1, GetRows_1, Listener_1, Util_1, PromiseMutex_1, Simple_1, Dialog_1) {
+define(["require", "exports", "tslib", "../Api/Gridviews/GetRow", "../Api/Gridviews/GetRows", "../Dom/Change/Listener", "../Dom/Util", "../Helper/PromiseMutex", "../Ui/Dropdown/Simple", "./Dialog"], function (require, exports, tslib_1, GetRow_1, GetRows_1, Listener_1, Util_1, PromiseMutex_1, Simple_1, Dialog_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GridView = void 0;
this.#initSorting();
this.#initActions();
this.#initFilters();
+ this.#initEventListeners();
window.addEventListener("popstate", () => {
this.#handlePopState();
});
this.#renderFilters(response.filterLabels);
this.#initActions();
}
+ async #refreshRow(row) {
+ const response = (await (0, GetRow_1.getRow)(this.#gridClassName, row.dataset.objectId)).unwrap();
+ row.replaceWith(Util_1.default.createFragmentFromHtml(response.template));
+ Listener_1.default.trigger();
+ }
#updateQueryString() {
if (!this.#baseUrl) {
return;
});
this.#switchPage(pageNo, false);
}
+ #initEventListeners() {
+ this.#table.addEventListener("refresh", (event) => {
+ void this.#refreshRow(event.target);
+ });
+ }
}
exports.GridView = GridView;
});
$event->register(new \wcf\system\endpoint\controller\core\comments\responses\UpdateResponse);
$event->register(new \wcf\system\endpoint\controller\core\exceptions\RenderException);
$event->register(new \wcf\system\endpoint\controller\core\gridViews\GetRows);
+ $event->register(new \wcf\system\endpoint\controller\core\gridViews\GetRow);
$event->register(new \wcf\system\endpoint\controller\core\messages\GetMentionSuggestions);
$event->register(new \wcf\system\endpoint\controller\core\sessions\DeleteSession);
$event->register(new \wcf\system\endpoint\controller\core\users\options\DeleteOption);
--- /dev/null
+<?php
+
+namespace wcf\system\endpoint\controller\core\gridViews;
+
+use Laminas\Diactoros\Response\JsonResponse;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use wcf\http\Helper;
+use wcf\system\endpoint\GetRequest;
+use wcf\system\endpoint\IController;
+use wcf\system\exception\PermissionDeniedException;
+use wcf\system\exception\UserInputException;
+use wcf\system\gridView\AbstractGridView;
+
+/**
+ * Retrieves a row for a grid view.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.2
+ */
+#[GetRequest('/core/grid-views/row')]
+final class GetRow implements IController
+{
+ #[\Override]
+ public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
+ {
+ $parameters = Helper::mapApiParameters($request, GetRowParameters::class);
+
+ if (!\is_subclass_of($parameters->gridView, AbstractGridView::class)) {
+ throw new UserInputException('gridView', 'invalid');
+ }
+
+ $view = new $parameters->gridView();
+ \assert($view instanceof AbstractGridView);
+
+ if (!$view->isAccessible()) {
+ throw new PermissionDeniedException();
+ }
+
+ $view->setObjectIDFilter($parameters->objectID);
+
+ return new JsonResponse([
+ 'template' => $view->renderRows(),
+ ]);
+ }
+}
+
+/** @internal */
+final class GetRowParameters
+{
+ public function __construct(
+ /** @var non-empty-string */
+ public readonly string $gridView,
+ public readonly string|int $objectID,
+ ) {}
+}
private string $sortOrder = 'ASC';
private int $pageNo = 1;
private array $activeFilters = [];
+ private string|int|null $objectIDFilter = null;
/**
* Adds a new column to the grid view.
return '';
}
+ public function setObjectIDFilter(string|int|null $objectID): void
+ {
+ $this->objectIDFilter = $objectID;
+ }
+
+ public function getObjectIDFilter(): string|int|null
+ {
+ return $this->objectIDFilter;
+ }
+
/**
* Fires the initialized event.
*/
$this->objectList->sqlOrderBy .= ',' . $this->objectList->getDatabaseTableAlias() .
'.' . $this->objectList->getDatabaseTableIndexName() . ' ' . $this->getSortOrder();
}
+ if ($this->getObjectIDFilter() !== null) {
+ $this->objectList->getConditionBuilder()->add(
+ $this->objectList->getDatabaseTableAlias() . '.' . $this->objectList->getDatabaseTableIndexName() . ' = ?',
+ [$this->getObjectIDFilter()]
+ );
+ }
$this->applyFilters();
$this->validate();
$this->fireInitializedEvent();