#4113 -- Limit unauthenticated per-page rows on paginated tables.
This commit is contained in:
parent
974c9b39bf
commit
212c94cdd1
|
@ -162,6 +162,10 @@ export default {
|
|||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
pageOptions: {
|
||||
type: Array,
|
||||
default: [10, 25, 50, 0]
|
||||
},
|
||||
defaultPerPage: {
|
||||
type: Number,
|
||||
default: 10
|
||||
|
@ -201,7 +205,6 @@ export default {
|
|||
storeKey: 'datatable_' + this.id + '_settings',
|
||||
filter: null,
|
||||
perPage: (this.paginated) ? this.defaultPerPage : 0,
|
||||
pageOptions: [10, 25, 50, 0],
|
||||
currentPage: 1,
|
||||
totalRows: 0,
|
||||
flushCache: false
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<data-table ref="datatable" id="song_requests" paginated select-fields :fields="fields" :responsive="false"
|
||||
:api-url="requestListUri">
|
||||
<data-table ref="datatable" id="song_requests" paginated select-fields :page-options="pageOptions" :fields="fields"
|
||||
:responsive="false" :api-url="requestListUri">
|
||||
<template v-slot:cell(name)="row">
|
||||
<a :href="row.item.song_art" class="album-art float-left pr-3" target="_blank"
|
||||
v-if="row.item.song_art" data-fancybox="gallery">
|
||||
|
@ -76,7 +76,10 @@ export default {
|
|||
);
|
||||
|
||||
return {
|
||||
fields: fields
|
||||
fields: fields,
|
||||
pageOptions: [
|
||||
10, 25
|
||||
]
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
|
|
@ -17,28 +17,34 @@ use Psr\Http\Message\ResponseInterface;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Traversable;
|
||||
|
||||
class Paginator
|
||||
class Paginator implements \IteratorAggregate, \Countable
|
||||
{
|
||||
protected Pagerfanta $paginator;
|
||||
|
||||
protected RouterInterface $router;
|
||||
|
||||
protected int $maxPerPage = 50;
|
||||
/** @var int The maximum number of records that can be viewed per page for unauthenticated users. */
|
||||
protected int $maxPerPage = 25;
|
||||
|
||||
/** @var bool Whether the current request is from jQuery Bootgrid */
|
||||
protected bool $isBootgrid = false;
|
||||
|
||||
/** @var bool Whether the user is currently authenticated on this request. */
|
||||
protected bool $isAuthenticated = false;
|
||||
|
||||
/** @var bool Whether to show pagination controls. */
|
||||
protected bool $isDisabled = true;
|
||||
|
||||
/** @var callable|null A callable postprocessor that can be run on each result. */
|
||||
protected $postprocessor;
|
||||
|
||||
public function __construct(Pagerfanta $paginator, ServerRequestInterface $request)
|
||||
{
|
||||
$this->paginator = $paginator;
|
||||
public function __construct(
|
||||
protected Pagerfanta $paginator,
|
||||
ServerRequestInterface $request
|
||||
) {
|
||||
$this->router = $request->getAttribute(ServerRequest::ATTR_ROUTER);
|
||||
|
||||
$user = $request->getAttribute(ServerRequest::ATTR_USER);
|
||||
$this->isAuthenticated = ($user !== null);
|
||||
|
||||
$params = $request->getQueryParams();
|
||||
$this->isBootgrid = isset($params['rowCount']) || isset($params['searchPhrase']);
|
||||
|
||||
|
@ -84,12 +90,16 @@ class Paginator
|
|||
|
||||
public function setPerPage(int $perPage): void
|
||||
{
|
||||
if ($perPage > 0) {
|
||||
$this->paginator->setMaxPerPage(($perPage <= $this->maxPerPage) ? $perPage : $this->maxPerPage);
|
||||
} else {
|
||||
$this->paginator->setMaxPerPage(PHP_INT_MAX);
|
||||
if ($perPage <= 0) {
|
||||
$perPage = PHP_INT_MAX;
|
||||
}
|
||||
|
||||
$this->paginator->setMaxPerPage(
|
||||
$this->isAuthenticated
|
||||
? $perPage
|
||||
: min($perPage, $this->maxPerPage)
|
||||
);
|
||||
|
||||
$this->isDisabled = false;
|
||||
}
|
||||
|
||||
|
@ -118,7 +128,7 @@ class Paginator
|
|||
return $this->paginator->getIterator();
|
||||
}
|
||||
|
||||
public function getCount(): int
|
||||
public function count(): int
|
||||
{
|
||||
return $this->paginator->getNbResults();
|
||||
}
|
||||
|
@ -131,7 +141,7 @@ class Paginator
|
|||
}
|
||||
|
||||
$iterator = $this->getIterator();
|
||||
$total = $this->getCount();
|
||||
$total = $this->count();
|
||||
|
||||
$totalPages = $this->paginator->getNbPages();
|
||||
|
||||
|
|
Loading…
Reference in New Issue