Skip to content

Commit

Permalink
[FEATURE] Add pagination in backend module, closes #100
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbltr committed Apr 26, 2024
1 parent 60e3db5 commit 0381664
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 126 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ChangeLog

Upcoming verions
[FEATURE] Add pagination in the backend module "Indexed content" function and avoid out of memory error. https://github.com/tpwd/ke_search/issues/100

Version 5.4.1, 19 April 2024
[BUGFIX] Always remove duplicates from tags, not only when a tag is set in the indexer configuration. https://github.com/tpwd/ke_search/issues/211
[BUGFIX] Fix TypeError after 'RemoveLock'. Thanks to Stephan Bauer. https://github.com/tpwd/ke_search/issues/223
Expand Down
64 changes: 33 additions & 31 deletions Classes/Controller/BackendModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Tpwd\KeSearch\Indexer\IndexerRunner;
use Tpwd\KeSearch\Lib\Db;
use Tpwd\KeSearch\Lib\SearchHelper;
use Tpwd\KeSearch\Pagination\SlidingWindowPagination as BackportedSlidingWindowPagination;
use Tpwd\KeSearch\Service\IndexerStatusService;
use TYPO3\CMS\Backend\Module\ModuleData;
use TYPO3\CMS\Backend\Routing\UriBuilder;
Expand All @@ -39,7 +40,7 @@
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Pagination\ArrayPaginator;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Pagination\SlidingWindowPagination;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

Expand Down Expand Up @@ -281,51 +282,52 @@ public function startIndexingAction(ServerRequestInterface $request, ModuleTempl
*/
public function indexedContentAction(ServerRequestInterface $request, ModuleTemplate $moduleTemplate): ResponseInterface
{
$pagination = null;
$paginator = null;
$currentPageNumber = (int)($request->getQueryParams()['currentPageNumber'] ?? 1);

if ($this->pageId) {
$perms_clause = $this->getBackendUser()->getPagePermsClause(1);
$pageInfo = BackendUtility::readPageAccess($this->pageId, $perms_clause);
// page is selected: get indexed content
$content = '<h3>Index content for PID ' . $this->pageId;
$content .= '<span class="small">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path')
. ': ' . GeneralUtility::fixed_lgd_cs($pageInfo['_thePath'], -50) . '</span></h3>';
$pagePath = GeneralUtility::fixed_lgd_cs($pageInfo['_thePath'], -200);

$indexRecords = $this->indexRepository->findByPageUidToShowIndexedContent($this->pageId);
$paginator = new ArrayPaginator($indexRecords, $currentPageNumber, 20);
$pagination = new SimplePagination($paginator);
} else {
// no page selected: show message
$content = '<div class="alert alert-info">'
. LocalizationUtility::translate(
'LLL:EXT:ke_search/Resources/Private/Language/locallang_mod.xlf:select_a_page',
'KeSearch'
)
. '</div>';
$currentPage = (int)($request->getQueryParams()['currentPage'] ?? 1);
$paginator = new ArrayPaginator($indexRecords, $currentPage, 20);
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 12) {
$pagination = new BackportedSlidingWindowPagination($paginator, 15);
} else {
// PHPStan is complaining that the SlidingWindowPagination class does not exist in TYPO3 11,
// so we ignore this error for now
// Todo: Remove the PHPStan annotation below once support for TYPO3 11 is dropped
// @phpstan-ignore-next-line
$pagination = new SlidingWindowPagination($paginator, 15);
}
}

$this->addMainMenu($request, $moduleTemplate, 'indexedContent');

if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 12) {
$moduleTemplate->getView()->setTemplateRootPaths(['EXT:ke_search/Resources/Private/Templates/BackendModule']);
$moduleTemplate->getView()->setLayoutRootPaths(['EXT:ke_search/Resources/Private/Layouts/']);
$moduleTemplate->getView()->setPartialRootPaths(
array_merge(
$moduleTemplate->getView()->getPartialRootPaths(),
['EXT:ke_search/Resources/Private/Partials/']
)
);
$moduleTemplate->getView()->setTemplatePathAndFilename('EXT:ke_search/Resources/Private/Templates/BackendModule/IndexedContent.html');
$moduleTemplate->getView()->assign('content', $content);
$moduleTemplate->getView()->assign('pagination', $pagination);
$moduleTemplate->getView()->assign('paginator', $paginator);
$moduleTemplate->getView()->assign('do', $this->do);
$moduleTemplate->getView()->assign('id', $this->pageId);
$moduleTemplate->getView()->assign('currentPageNumber', $currentPageNumber);
$moduleTemplate->getView()->assign('pagination', $pagination ?? null);
$moduleTemplate->getView()->assign('paginator', $paginator ?? null);
$moduleTemplate->getView()->assign('do', $this->do ?? '');
$moduleTemplate->getView()->assign('pageId', $this->pageId ?? 0);
$moduleTemplate->getView()->assign('currentPage', $currentPage ?? 1);
$moduleTemplate->getView()->assign('pagePath', $pagePath ?? '');
// @extensionScannerIgnoreLine
return new HtmlResponse($moduleTemplate->renderContent());
}
$moduleTemplate->assign('content', $content);
$moduleTemplate->assign('pagination', $pagination);
$moduleTemplate->assign('paginator', $paginator);
$moduleTemplate->assign('do', $this->do);
$moduleTemplate->assign('id', $this->pageId);
$moduleTemplate->assign('currentPageNumber', $currentPageNumber);
$moduleTemplate->assign('pagination', $pagination ?? null);
$moduleTemplate->assign('paginator', $paginator ?? null);
$moduleTemplate->assign('do', $this->do ?? '');
$moduleTemplate->assign('pageId', $this->pageId ?? 0);
$moduleTemplate->assign('currentPage', $currentPage ?? 1);
$moduleTemplate->assign('pagePath', $pagePath ?? '');

return $moduleTemplate->renderResponse('BackendModule/IndexedContent');
}
Expand Down
1 change: 0 additions & 1 deletion Classes/Domain/Repository/IndexRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,4 @@ public function findByPageUidToShowIndexedContent(int $pageUid)
->executeQuery()
->fetchAllAssociative();
}

}
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/Count/WordsViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Tpwd\KeSearch\ViewHelpers\Count;

use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
Expand All @@ -16,7 +17,7 @@ public function initializeArguments(): void
}

/**
* @return integer
* @return int
*/
public static function renderStatic(
array $arguments,
Expand Down
1 change: 1 addition & 0 deletions Classes/ViewHelpers/ExplodeViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Tpwd\KeSearch\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down
56 changes: 56 additions & 0 deletions Resources/Private/Partials/BackendModule/ListNavigation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
data-namespace-typo3-fluid="true"
>

<nav class="mb-2 mt-2" aria-labelledby="recordlist-pagination">
<f:comment><!--Number of records--></f:comment>
<f:variable name="firstElement" value="{paginator.keyOfFirstPaginatedItem + 1}"></f:variable>
<f:variable name="lastElement" value="{paginator.keyOfLastPaginatedItem + 1}"></f:variable>
<span id="recordlist-pagination" class="page-item ps-2 pe-2 pagination-label">
<f:translate key="LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:rangeIndicator" arguments="{firstElement: firstElement, lastElement: lastElement}" />
<span class="visually-hidden">, <f:translate key="LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:pageIndicator" arguments="{currentPage: currentPage, totalPages: totalPages}"/></span>
</span>

<ul class="pagination">
<f:comment><!--First page and previous page--></f:comment>
<f:if condition="{currentPage} > 1">
<f:then>
<f:variable name="previousPage" value="{currentPage - 1}" />
<li class="page-item ps-2"><f:be.link route="web_KeSearchBackendModule" parameters="{id: pageId, do: do, currentPage: 1}" title="{f:translate(key: 'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:first')}"><core:icon identifier="actions-view-paging-first"/></f:be.link></li>
<li class="page-item ps-2"><f:be.link route="web_KeSearchBackendModule" parameters="{id: pageId, do: do, currentPage: previousPage}" title="{f:translate(key: 'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:previous')}"><core:icon identifier="actions-view-paging-previous" /></f:be.link></li>
</f:then>
<f:else>
<li class="page-item ps-2" aria-hidden="true"><core:icon identifier="actions-view-paging-first" /></li>
<li class="page-item ps-2" aria-hidden="true"><core:icon identifier="actions-view-paging-previous" /></li>
</f:else>
</f:if>

<f:for each="{pagination.allPageNumbers}" as="page">
<li class="page-item ps-2">
<f:be.link route="web_KeSearchBackendModule" parameters="{id: pageId, do: do, currentPage: page}">
<f:if condition="{page} == {currentPage}">
<f:then> <strong>{page}</strong> </f:then>
<f:else> {page} </f:else>
</f:if>
</f:be.link>
</li>
</f:for>

<f:comment><!--Next page and last page--></f:comment>
<f:if condition="{currentPage} < {totalPages}">
<f:then>
<f:variable name="nextPage" value="{currentPage + 1}" />
<li class="page-item ps-2"><f:be.link route="web_KeSearchBackendModule" parameters="{id: pageId, do: do, currentPage: nextPage}" title="{f:translate(key: 'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:next')}"><core:icon identifier="actions-view-paging-next" /></f:be.link></li>
<li class="page-item ps-2"><f:be.link route="web_KeSearchBackendModule" parameters="{id: pageId, do: do, currentPage: totalPages}" title="{f:translate(key: 'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:last')}"><core:icon identifier="actions-view-paging-last" /></f:be.link></li>
</f:then>
<f:else>
<li class="page-item ps-2" aria-hidden="true"><core:icon identifier="actions-view-paging-next" /></li>
<li class="page-item ps-2" aria-hidden="true"><core:icon identifier="actions-view-paging-last" /></li>
</f:else>
</f:if>
</ul>
</nav>

</html>
Loading

0 comments on commit 0381664

Please sign in to comment.