From 939cf7a4901ce4521515d5e91a96b194a1d93d6d Mon Sep 17 00:00:00 2001 From: Imko Schumacher Date: Sat, 17 Apr 2021 14:28:03 +0200 Subject: [PATCH] Replace pagination widget in backend module 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 --- Classes/Controller/BackendController.php | 60 ++++++++----- Resources/Private/Language/locallang.xlf | 21 +++++ Resources/Private/Partials/Backend/List.html | 81 +++++++++-------- .../Private/Partials/Backend/Pagination.html | 89 +++++++++++++++++++ Resources/Private/Partials/Backend/Row.html | 12 +-- Resources/Private/Templates/Backend/List.html | 3 +- ext_tables.php | 2 +- 7 files changed, 196 insertions(+), 72 deletions(-) create mode 100644 Resources/Private/Partials/Backend/Pagination.html diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 0c3bc718..90b7e3a0 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -10,30 +10,42 @@ 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, @@ -41,21 +53,12 @@ public function listAction() '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 = []; @@ -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)); } /** diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 57f90dda..beeb1125 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -666,6 +666,27 @@ Text + + previous + + + next + + + first + + + last + + + Items + + + Page + + + Refresh + diff --git a/Resources/Private/Partials/Backend/List.html b/Resources/Private/Partials/Backend/List.html index 1f1ef52f..25b7b4cb 100644 --- a/Resources/Private/Partials/Backend/List.html +++ b/Resources/Private/Partials/Backend/List.html @@ -1,44 +1,43 @@ - -
- - - - - - - - - - - - - - - - - - - - - -
- Title - - Date - - Type - - Language - - ID - - Action -
- - items -
-
-
+
+ + + + + + + + + + + + + + + + + + + + + +
+ Title + + Date + + Type + + Language + + ID + + Action +
+ {totalAmount} + items +
+
+ diff --git a/Resources/Private/Partials/Backend/Pagination.html b/Resources/Private/Partials/Backend/Pagination.html new file mode 100644 index 00000000..f768e5bf --- /dev/null +++ b/Resources/Private/Partials/Backend/Pagination.html @@ -0,0 +1,89 @@ + diff --git a/Resources/Private/Partials/Backend/Row.html b/Resources/Private/Partials/Backend/Row.html index 6be67b2d..2e3c26ce 100644 --- a/Resources/Private/Partials/Backend/Row.html +++ b/Resources/Private/Partials/Backend/Row.html @@ -21,11 +21,13 @@ {index.foreignUid} - - - - + +
+ + + +
diff --git a/Resources/Private/Templates/Backend/List.html b/Resources/Private/Templates/Backend/List.html index 44c52fde..2749d63d 100644 --- a/Resources/Private/Templates/Backend/List.html +++ b/Resources/Private/Templates/Backend/List.html @@ -1,7 +1,6 @@ @@ -13,7 +12,7 @@

Calendarize

- +
diff --git a/ext_tables.php b/ext_tables.php index 1a8621e3..04fa256f 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -55,7 +55,7 @@ 'web', 'calendarize', '', - ['Backend' => 'list,option'], + ['Backend' => 'list'], [ // Additional configuration 'access' => 'user, group',