-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #5967
- Loading branch information
Showing
18 changed files
with
693 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div class="paginationTop"> | ||
<woltlab-core-pagination id="{$view->getID()}_topPagination" page="{$view->getPageNo()}" count="{$view->countPages()}"></woltlab-core-pagination> | ||
</div> | ||
|
||
<div class="section tabularBox"> | ||
<table class="table" id="{$view->getID()}_table"> | ||
<thead> | ||
<tr> | ||
{unsafe:$view->renderHeader()} | ||
</td> | ||
</thead> | ||
<tbody> | ||
{unsafe:$view->renderRows()} | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<div class="paginationBottom"> | ||
<woltlab-core-pagination id="{$view->getID()}_bottomPagination" page="{$view->getPageNo()}" count="{$view->countPages()}"></woltlab-core-pagination> | ||
</div> | ||
|
||
<script data-relocate="true"> | ||
require(['WoltLabSuite/Core/Component/GridView'], ({ GridView }) => { | ||
new GridView( | ||
'{unsafe:$view->getID()|encodeJs}', | ||
'{unsafe:$view->getClassName()|encodeJS}', | ||
{$view->getPageNo()}, | ||
'{unsafe:$view->getBaseUrl()|encodeJS}' | ||
); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend"; | ||
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result"; | ||
|
||
type Response = { | ||
template: string; | ||
}; | ||
|
||
export async function getRows(gridViewClass: string, pageNo: number): Promise<ApiResult<Response>> { | ||
const url = new URL(`${window.WSC_RPC_API_URL}core/gridViews/rows`); | ||
url.searchParams.set("gridView", gridViewClass); | ||
url.searchParams.set("pageNo", pageNo.toString()); | ||
|
||
let response: Response; | ||
try { | ||
response = (await prepareRequest(url).get().allowCaching().disableLoadingIndicator().fetchAsJson()) as Response; | ||
} catch (e) { | ||
return apiResultFromError(e); | ||
} | ||
|
||
return apiResultFromValue(response); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { getRows } from "../Api/GridViews/GetRows"; | ||
import DomUtil from "../Dom/Util"; | ||
|
||
export class GridView { | ||
readonly #gridClassName: string; | ||
readonly #table: HTMLTableElement; | ||
readonly #topPagination: WoltlabCorePaginationElement; | ||
readonly #bottomPagination: WoltlabCorePaginationElement; | ||
readonly #baseUrl: string; | ||
#pageNo: number; | ||
|
||
constructor(gridId: string, gridClassName: string, pageNo: number, baseUrl: string = "") { | ||
this.#gridClassName = gridClassName; | ||
this.#table = document.getElementById(`${gridId}_table`) as HTMLTableElement; | ||
this.#topPagination = document.getElementById(`${gridId}_topPagination`) as WoltlabCorePaginationElement; | ||
this.#bottomPagination = document.getElementById(`${gridId}_bottomPagination`) as WoltlabCorePaginationElement; | ||
this.#pageNo = pageNo; | ||
this.#baseUrl = baseUrl; | ||
|
||
this.#initPagination(); | ||
} | ||
|
||
#initPagination(): void { | ||
this.#topPagination.addEventListener("switchPage", (event: CustomEvent) => { | ||
this.#switchPage(event.detail); | ||
}); | ||
this.#bottomPagination.addEventListener("switchPage", (event: CustomEvent) => { | ||
this.#switchPage(event.detail); | ||
}); | ||
} | ||
|
||
async #switchPage(pageNo: number): Promise<void> { | ||
this.#topPagination.page = pageNo; | ||
this.#bottomPagination.page = pageNo; | ||
|
||
const response = await getRows(this.#gridClassName, pageNo); | ||
this.#pageNo = pageNo; | ||
DomUtil.setInnerHtml(this.#table.querySelector("tbody")!, response.unwrap().template); | ||
this.#updateQueryString(); | ||
} | ||
|
||
#updateQueryString(): void { | ||
if (!this.#baseUrl) { | ||
return; | ||
} | ||
|
||
const url = new URL(this.#baseUrl); | ||
|
||
const parameters: [string, string][] = []; | ||
if (this.#pageNo > 1) { | ||
parameters.push(["pageNo", this.#pageNo.toString()]); | ||
} | ||
|
||
if (parameters.length > 0) { | ||
url.search += url.search !== "" ? "&" : "?"; | ||
url.search += new URLSearchParams(parameters).toString(); | ||
} | ||
|
||
window.history.pushState({ name: "gridView" }, document.title, url.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
wcfsetup/install/files/js/WoltLabSuite/Core/Api/GridViews/GetRows.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
wcfsetup/install/files/lib/system/endpoint/controller/core/gridViews/GetRows.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?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\view\grid\AbstractGridView; | ||
|
||
#[GetRequest('/core/gridViews/rows')] | ||
final class GetRows implements IController | ||
{ | ||
#[\Override] | ||
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface | ||
{ | ||
$parameters = Helper::mapApiParameters($request, GetRowsParameters::class); | ||
|
||
if (!\is_subclass_of($parameters->gridView, AbstractGridView::class)) { | ||
throw new UserInputException('gridView', $parameters->gridView); | ||
} | ||
|
||
$view = new $parameters->gridView($parameters->pageNo); | ||
\assert($view instanceof AbstractGridView); | ||
|
||
if (!$view->isAccessible()) { | ||
throw new PermissionDeniedException(); | ||
} | ||
|
||
return new JsonResponse([ | ||
'template' => $view->renderRows(), | ||
]); | ||
} | ||
} | ||
|
||
/** @internal */ | ||
final class GetRowsParameters | ||
{ | ||
public function __construct( | ||
/** @var non-empty-string */ | ||
public readonly string $gridView, | ||
public readonly int $pageNo | ||
) {} | ||
} |
Oops, something went wrong.