Skip to content

Commit

Permalink
Replace pagination widget in backend module
Browse files Browse the repository at this point in the history
Instead of using the be.widget.paginate, the events are now paginated
with the new pagination API.
Additionally the option action is now part of the list action.

Related #542
Fixes #535
  • Loading branch information
okmiim committed Apr 17, 2021
1 parent 9b84d06 commit 939cf7a
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 72 deletions.
60 changes: 37 additions & 23 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,55 @@
use HDNET\Calendarize\Domain\Model\Request\OptionRequest;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Pagination\ArrayPaginator;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;

/**
* BackendController.
*/
class BackendController extends AbstractController
{
const OPTIONS_KEY = 'calendarize_be';

/**
* Basic backend list.
*/
public function listAction()
public function listAction(OptionRequest $options = null, int $currentPage = 1)
{
$this->settings['timeFormat'] = 'H:i';
$this->settings['dateFormat'] = 'd.m.Y';

$options = $this->getOptions();
if (null === $options) {
$options = $this->getOptions();
} else {
$this->setOptions($options);
}

$typeLocations = $this->getDifferentTypesAndLocations();

$pids = $this->getPids($typeLocations);
if ($pids) {
$indices = $this->indexRepository->findAllForBackend($options, $pids);
$paginator = new QueryResultPaginator($indices, $currentPage, 50);
} else {
$indices = [];
$paginator = new ArrayPaginator($indices, $currentPage, 50);
}
$pagination = new SimplePagination($paginator);

$this->view->assignMultiple([
'indices' => $indices,
'typeLocations' => $typeLocations,
'pids' => $this->getPageTitles($pids),
'settings' => $this->settings,
'options' => $options,
'paginator' => $paginator,
'pagination' => $pagination,
'totalAmount' => $indices->count(),
]);
}

/**
* Option action.
*
* @param \HDNET\Calendarize\Domain\Model\Request\OptionRequest $options
*/
public function optionAction(OptionRequest $options)
{
$GLOBALS['BE_USER']->setAndSaveSessionData('calendarize_be', serialize($options));
$this->addFlashMessage('Options saved', '', FlashMessage::OK, true);
$this->forward('list');
}

protected function getPids(array $typeLocations)
{
$pids = [];
Expand Down Expand Up @@ -88,19 +91,30 @@ protected function getPageTitles(array $pids): array
*
* @return OptionRequest
*/
protected function getOptions()
protected function getOptions(): OptionRequest
{
try {
$info = $GLOBALS['BE_USER']->getSessionData('calendarize_be');
$object = @unserialize((string)$info);
if ($object instanceof OptionRequest) {
return $object;
$info = $GLOBALS['BE_USER']->getSessionData(self::OPTIONS_KEY) ?? '';
if ('' !== $info) {
$object = @unserialize($info, ['allowed_classes' => [OptionRequest::class]]);
if ($object instanceof OptionRequest) {
return $object;
}
}

return new OptionRequest();
} catch (\Exception $exception) {
return new OptionRequest();
}

return new OptionRequest();
}

/**
* Persists options data.
*
* @param OptionRequest $options
*/
protected function setOptions(OptionRequest $options)
{
$GLOBALS['BE_USER']->setAndSaveSessionData(self::OPTIONS_KEY, serialize($options));
}

/**
Expand Down
21 changes: 21 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,27 @@
<trans-unit id="search.text">
<source>Text</source>
</trans-unit>
<trans-unit id="pagination.previous" resname="pagination.previous">
<source>previous</source>
</trans-unit>
<trans-unit id="pagination.next" resname="pagination.next">
<source>next</source>
</trans-unit>
<trans-unit id="pagination.first" resname="pagination.first">
<source>first</source>
</trans-unit>
<trans-unit id="pagination.last" resname="pagination.last">
<source>last</source>
</trans-unit>
<trans-unit id="pagination.records" resname="pagination.records">
<source>Items</source>
</trans-unit>
<trans-unit id="pagination.page" resname="pagination.page">
<source>Page</source>
</trans-unit>
<trans-unit id="pagination.refresh" resname="pagination.refresh">
<source>Refresh</source>
</trans-unit>
</body>
</file>
</xliff>
81 changes: 40 additions & 41 deletions Resources/Private/Partials/Backend/List.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">

<f:be.widget.paginate objects="{indices}" as="indexBlock" configuration="{itemsPerPage: 50, insertBelow: 1}">
<div class="table-fit">
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="col-title">
Title
</th>
<th class="col-title">
Date
</th>
<th class="col-title">
Type
</th>
<th class="col-title">
Language
</th>
<th class="col-title">
ID
</th>
<th class="col-title">
Action
</th>
</tr>
</thead>
<tbody>
<f:for each="{indexBlock}" as="index">
<f:render partial="Backend/Row" arguments="{index: index}"/>
</f:for>
</tbody>
<tfoot>
<tr>
<td colspan="5">
<f:count subject="{indices}"/>
items
</td>
</tr>
</tfoot>
</table>
</div>
</f:be.widget.paginate>
<div class="table-fit">
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="col-title">
Title
</th>
<th class="col-title">
Date
</th>
<th class="col-title">
Type
</th>
<th class="col-title">
Language
</th>
<th class="col-title">
ID
</th>
<th class="col-title">
Action
</th>
</tr>
</thead>
<tbody>
<f:for each="{paginator.paginatedItems}" as="index">
<f:render partial="Backend/Row" arguments="{index: index}"/>
</f:for>
</tbody>
<tfoot>
<tr>
<td colspan="5">
{totalAmount}
items
</td>
</tr>
</tfoot>
</table>
</div>
<f:render partial="Backend/Pagination" arguments="{paginator:paginator, pagination:pagination}" />
</html>
89 changes: 89 additions & 0 deletions Resources/Private/Partials/Backend/Pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<nav class="pagination-wrap">
<ul class="pagination">
<f:if condition="{pagination.previousPageNumber} && {pagination.previousPageNumber} >= {pagination.firstPageNumber}">
<f:then>
<li class="page-item">
<a href="{f:uri.action(arguments:{currentPage: 1})}" title="{f:translate(key:'pagination.first')}" class="page-link">
<core:icon identifier="actions-view-paging-first" />
</a>
</li>
<li class="page-item">
<a href="{f:uri.action(arguments:{currentPage: pagination.previousPageNumber})}" title="{f:translate(key:'pagination.previous')}" class="page-link">
<core:icon identifier="actions-view-paging-previous" />
</a>
</li>
</f:then>
<f:else>
<li class="page-item disabled">
<span class="page-link">
<core:icon identifier="actions-view-paging-first" />
</span>
</li>
<li class="page-item disabled">
<span class="page-link">
<core:icon identifier="actions-view-paging-previous" />
</span>
</li>
</f:else>
</f:if>
<li class="page-item">
<span class="page-link">
<f:translate key="pagination.records" /> {pagination.startRecordNumber} - {pagination.endRecordNumber}
</span>
</li>
<li class="page-item">
<span class="page-link">
<f:translate key="pagination.page" />
<form style="display:inline;"
data-global-event="submit"
data-action-navigate="$form=~s/$value/"
data-navigate-value="{f:uri.action(arguments:'{currentPage: \'$[value]\'}')}"
data-value-selector="input[name='paginator-target-page']">
<input
min="{pagination.firstPageNumber}"
max="{pagination.lastPageNumber}"
data-number-of-pages="{paginator.numberOfPages}"
name="paginator-target-page"
class="form-control form-control-sm paginator-input"
size="5"
value="{paginator.currentPageNumber}"
type="number"
/>
</form>
/ {pagination.lastPageNumber}
</span>
</li>

<f:if condition="{pagination.nextPageNumber} && {pagination.nextPageNumber} <= {pagination.lastPageNumber}">
<f:then>
<li class="page-item">
<a href="{f:uri.action(arguments:{currentPage: pagination.nextPageNumber})}" title="{f:translate(key:'pagination.next')}" class="page-link">
<core:icon identifier="actions-view-paging-next" />
</a>
</li>
<li class="page-item">
<a href="{f:uri.action(arguments:{currentPage: pagination.lastPageNumber})}" title="{f:translate(key:'pagination.last')}" class="page-link">
<core:icon identifier="actions-view-paging-last" />
</a>
</li>
</f:then>
<f:else>
<li class="page-item disabled">
<span class="page-link">
<core:icon identifier="actions-view-paging-next" />
</span>
</li>
<li class="page-item disabled">
<span class="page-link">
<core:icon identifier="actions-view-paging-last" />
</span>
</li>
</f:else>
</f:if>
<li class="page-item">
<a href="{f:uri.action(arguments:{currentPage: paginator.currentPageNumber})}" title="{f:translate(key:'pagination.refresh')}" class="page-link">
<core:icon identifier="actions-refresh" />
</a>
</li>
</ul>
</nav>
12 changes: 7 additions & 5 deletions Resources/Private/Partials/Backend/Row.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
<td>
{index.foreignUid}
</td>
<td>
<be:link.editRecord class="btn btn-default" uid="{index.foreignUid}" table="{index.configuration.tableName}"
returnUrl="{f:be.uri(route: 'web_CalendarizeCalendarize')}">
<core:icon identifier="actions-document-open"/>
</be:link.editRecord>
<td class="col-control">
<div class="btn-group" role="group">
<be:link.editRecord class="btn btn-default" uid="{index.foreignUid}" table="{index.configuration.tableName}"
returnUrl="{f:be.uri(route: 'web_CalendarizeCalendarize')}">
<core:icon identifier="actions-open"/>
</be:link.editRecord>
</div>
</td>
</tr>
</html>
3 changes: 1 addition & 2 deletions Resources/Private/Templates/Backend/List.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
xmlns:c="http://typo3.org/ns/HDNET/Calendarize/ViewHelpers"
data-namespace-typo3-fluid="true">

<f:layout name="Backend"/>
Expand All @@ -13,7 +12,7 @@ <h1>Calendarize</h1>
<f:flashMessages/>

<fieldset class="form-group border">
<f:form action="option" object="{options}" name="options">
<f:form action="list" object="{options}" name="options">

<f:comment>
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'web',
'calendarize',
'',
['Backend' => 'list,option'],
['Backend' => 'list'],
[
// Additional configuration
'access' => 'user, group',
Expand Down

0 comments on commit 939cf7a

Please sign in to comment.