Skip to content

Commit f2fb96f

Browse files
committed
Add perPage
1 parent 2c604ea commit f2fb96f

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

src/Controllers/Files.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,11 @@ protected function setDefaults(): self
616616
'userId' => null,
617617
'username' => '',
618618
'ajax' => $this->request->isAJAX(),
619+
'search' => $this->request->getVar('search'),
619620
'sort' => $this->getSort(),
620621
'order' => $this->getOrder(),
621622
'format' => $this->getFormat(),
622-
'search' => $this->request->getVar('search'),
623-
'perPage' => service('settings')->perPage,
623+
'perPage' => $this->getPerPage(),
624624
'page' => $this->request->getVar('page'),
625625
'pager' => null,
626626
'access' => $this->model->mayAdmin() ? 'manage' : 'display',
@@ -685,6 +685,33 @@ protected function getOrder(): string
685685
return 'asc';
686686
}
687687

688+
/**
689+
* Determines items per page.
690+
*
691+
* @return int
692+
*/
693+
protected function getPerPage(): int
694+
{
695+
// Check for a request, then load from Settings
696+
$nums = [
697+
$this->request->getVar('perPage'),
698+
service('settings')->perPage,
699+
];
700+
701+
foreach ($nums as $num)
702+
{
703+
// Validate
704+
if (is_numeric($num) && (int) $num > 0)
705+
{
706+
// Update user setting with the new preference
707+
service('settings')->perPage = $num;
708+
return $num;
709+
}
710+
}
711+
712+
return 10;
713+
}
714+
688715
/**
689716
* Determines the display format.
690717
*

src/Models/FileModel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class FileModel extends Model
4141

4242
// Permits
4343
protected $mode = 04660;
44+
protected $userKey = 'user_id';
4445
protected $pivotKey = 'file_id';
4546
protected $usersPivot = 'files_users';
4647

src/Views/Formats/cards.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?= $pager ? $pager->only(['search'])->links('default', 'files_bootstrap') : '' ?>
21

32
<?php if (empty($files)): ?>
43
<p>No files to display.</p>

src/Views/Formats/list.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?= $pager ? $pager->only(['search'])->links('default', 'files_bootstrap') : '' ?>
21

32
<?php if (empty($files)): ?>
43
<p>No files to display.</p>

src/Views/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
</p>
3737

3838
<?php else: ?>
39+
40+
<?= $pager ? view('Tatter\Files\Views\pages') : '' ?>
41+
3942
<form name="files-form" method="post" action="<?= site_url('files/bulk') ?>">
4043
<?= $format === 'select' ? view('Tatter\Files\Views\Menus\bulk', ['access' => $access, 'bulks' => $bulks]) : '' ?>
4144
<?= view('Tatter\Files\Views\Formats\\' . $format, ['files' => $files, 'access' => $access, 'exports' => $exports]); ?>

src/Views/pages.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
<div class="row">
3+
<div class="col-sm-6">
4+
<?= $pager->only(['search'])->links('default', 'files_bootstrap') ?>
5+
</div>
6+
<div class="col-sm-4"></div>
7+
<div class="col-2 float-right">
8+
<form name="files-pages" method="get" action="<?= current_url() ?>">
9+
<label class="sr-only" for="perPage">Per page</label>
10+
<select class="form-control" name="perPage" id="perPage" onchange="this.form.submit();">
11+
<?php foreach ([5, 10, 25, 50, 100, 200] as $num): ?>
12+
<option value="<?= $num ?>" <?= $num === $perPage ? 'selected' : '' ?>><?= $num ?></option>
13+
<?php endforeach; ?>
14+
</select>
15+
</form>
16+
</div>
17+
</div>

0 commit comments

Comments
 (0)