diff --git a/lib/Db/AccountFileMapper.php b/lib/Db/AccountFileMapper.php index e811b61bc..c892be7a0 100644 --- a/lib/Db/AccountFileMapper.php +++ b/lib/Db/AccountFileMapper.php @@ -151,7 +151,7 @@ private function getUserAccountFile(array $filter = []): Pagination { $qb->setMaxResults($filter['length']); } - $pagination = new Pagination($qb); + $pagination = new Pagination($qb, $this->urlGenerator); return $pagination; } diff --git a/lib/Db/SignRequestMapper.php b/lib/Db/SignRequestMapper.php index 61a6c5c32..027dbe590 100644 --- a/lib/Db/SignRequestMapper.php +++ b/lib/Db/SignRequestMapper.php @@ -526,7 +526,7 @@ private function getFilesAssociatedFilesWithMeStmt( return (int)$qb->executeQuery()->fetchOne(); }; - $pagination = new Pagination($qb); + $pagination = new Pagination($qb, $this->urlGenerator); return $pagination; } diff --git a/lib/Helper/Pagination.php b/lib/Helper/Pagination.php index 3ed5cf674..d5a779918 100644 --- a/lib/Helper/Pagination.php +++ b/lib/Helper/Pagination.php @@ -9,14 +9,15 @@ namespace OCA\Libresign\Helper; use OCA\Libresign\Db\PagerFantaQueryAdapter; +use OCP\IURLGenerator; use OCP\DB\QueryBuilder\IQueryBuilder; use Pagerfanta\Pagerfanta; class Pagination extends Pagerfanta { - /** @var string */ - private $rootPath; + private string $routeName; public function __construct( IQueryBuilder $queryBuilder, + private IURLGenerator $urlGenerator, ) { $adapter = new PagerFantaQueryAdapter($queryBuilder); parent::__construct($adapter); @@ -25,20 +26,28 @@ public function __construct( /** * @return static */ - public function setRootPath(string $rootPath = ''): self { - $this->rootPath = $rootPath; + public function setRouteName(string $routeName = ''): self { + $this->routeName = $routeName; return $this; } - public function getPagination(?int $page, ?int $length): array { + public function getPagination(?int $page, ?int $length, array $filter = []): array { $this->setMaxPerPage($length); $pagination['total'] = $this->count(); if ($pagination['total'] > $length) { - $pagination['current'] = $this->rootPath . '?page=' . $page . '&length=' . $length; - $pagination['next'] = $this->hasNextPage() ? $this->rootPath . '?page=' . $this->getNextPage() . '&length=' . $length : null; - $pagination['prev'] = $this->hasPreviousPage() ? $this->rootPath . '?page=' . $this->getPreviousPage() . '&length=' . $length : null; - $pagination['last'] = $this->hasNextPage() ? $this->rootPath . '?page=' . $this->getNbPages() . '&length=' . $length : null; - $pagination['first'] = $this->hasPreviousPage() ? $this->rootPath . '?page=1&length=' . $length : null; + $pagination['current'] = $this->linkToRoute($page, $length, $filter); + $pagination['next'] = $this->hasNextPage() + ? $this->linkToRoute($this->getNextPage(), $length, $filter) + : null; + $pagination['prev'] = $this->hasPreviousPage() + ? $this->linkToRoute($this->getPreviousPage(), $length, $filter) + : null; + $pagination['last'] = $this->hasNextPage() + ? $this->linkToRoute($this->getNbPages(), $length, $filter) + : null; + $pagination['first'] = $this->hasPreviousPage() + ? $this->linkToRoute(1, $length, $filter) + : null; } else { $pagination['current'] = null; $pagination['next'] = null; @@ -48,4 +57,11 @@ public function getPagination(?int $page, ?int $length): array { } return $pagination; } + + private function linkToRoute(int $page, int $length, array $filter): string { + return $this->urlGenerator->linkToRoute( + $this->routeName, + array_merge(['page' => $page, 'length' => $length, 'apiVersion' => 'v1'], $filter) + ); + } } diff --git a/lib/Service/AccountFileService.php b/lib/Service/AccountFileService.php index 48efb4357..396019550 100644 --- a/lib/Service/AccountFileService.php +++ b/lib/Service/AccountFileService.php @@ -49,10 +49,10 @@ public function accountFileList(array $filter, ?int $page = null, ?int $length = $page = $page ?? 1; $length = $length ?? (int)$this->appConfig->getAppValue('length_of_page', '100'); $data = $this->accountFileMapper->accountFileList($filter, $page, $length); - $data['pagination']->setRootPath('/file/list'); + $data['pagination']->setRouteName('ocs.libresign.File.list'); return [ 'data' => $data['data'], - 'pagination' => $data['pagination']->getPagination($page, $length) + 'pagination' => $data['pagination']->getPagination($page, $length, $filter) ]; } } diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index da777230e..57ce58d6c 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -454,10 +454,10 @@ public function listAssociatedFilesOfSignFlow( $visibleElements = $this->signRequestMapper->getVisibleElementsFromSigners($signers); $return['data'] = $this->associateAllAndFormat($this->me, $return['data'], $signers, $identifyMethods, $visibleElements); - $return['pagination']->setRootPath('/file/list'); + $return['pagination']->setRouteName('ocs.libresign.File.list'); return [ 'data' => $return['data'], - 'pagination' => $return['pagination']->getPagination($page, $length) + 'pagination' => $return['pagination']->getPagination($page, $length, $filter) ]; } diff --git a/src/store/files.js b/src/store/files.js index e9ffa2ae1..4bdef5ae9 100644 --- a/src/store/files.js +++ b/src/store/files.js @@ -29,9 +29,9 @@ export const useFilesStore = function(...args) { filterActive: 'all', canRequestSign: loadState('libresign', 'can_request_sign', false), ordered: [], - paginationCurrent: '', - paginationNext: '', - paginationLast: '', + paginationCurrentUrl: '', + paginationNextUrl: '', + paginationLastUrl: '', paginationLength: '', } }, @@ -245,16 +245,12 @@ export const useFilesStore = function(...args) { filter.sortDirection = sortingDirection } - // Build pagination params object - const pagination = {} - if (this.paginationNext) pagination.page = this.paginationNext - if (this.paginationLength) pagination.length = this.paginationNext - // Call API - const response = await axios.get(generateOcsUrl('/apps/libresign/api/v1/file/list'), { params: {...filter, ...pagination} }) - + const response = this.paginationNextUrl + ? await axios.get(this.paginationNextUrl) + : await axios.get(generateOcsUrl('/apps/libresign/api/v1/file/list'), { params: filter }) // Update state according to API response - if (!this.paginationCurrent) { + if (!this.paginationCurrentUrl) { this.files = {} this.ordered = [] }