Skip to content

Commit 6e6e4b4

Browse files
authored
Make separate htmx-based pagers to prevent breaking other code (like that of log viewer) (#473)
1 parent ae7f483 commit 6e6e4b4

File tree

6 files changed

+92
-14
lines changed

6 files changed

+92
-14
lines changed

src/Config/Registrar.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
namespace Bonfire\Config;
44

5-
use Config\Filters;
6-
use CodeIgniter\Autoloader\Autoloader;
75
use Bonfire\Auth\Filters\Admin;
86
use Bonfire\Consent\Filters\ConsentFilter;
97
use Bonfire\Core\Filters\OnlineCheck;
108
use Bonfire\Users\Validation\UserRules;
119
use Bonfire\View\Decorator;
10+
use CodeIgniter\Autoloader\Autoloader;
1211
use CodeIgniter\Shield\Authentication\Passwords\ValidationRules as PasswordRules;
1312
use CodeIgniter\Shield\Filters\ChainAuth;
1413
use CodeIgniter\Shield\Filters\SessionAuth;
1514
use CodeIgniter\Shield\Filters\TokenAuth;
15+
use Config\Filters;
1616
use ReflectionClass;
1717
use ReflectionProperty;
1818

@@ -29,9 +29,11 @@ public static function Pager(): array
2929
{
3030
return [
3131
'templates' => [
32-
'bonfire_full' => 'Bonfire\Views\_pager_full',
33-
'bonfire_simple' => 'Bonfire\Views\_pager_simple',
34-
'bonfire_head' => 'Bonfire\Views\_pager_head',
32+
'bonfire_full' => 'Bonfire\Views\_pager_full',
33+
'bonfire_full_hx' => 'Bonfire\Views\_pager_full_htmx',
34+
'bonfire_simple' => 'Bonfire\Views\_pager_simple',
35+
'bonfire_simple_hx' => 'Bonfire\Views\_pager_simple_htmx',
36+
'bonfire_head' => 'Bonfire\Views\_pager_head',
3537
],
3638
];
3739
}
@@ -132,8 +134,8 @@ public static function registerNamespaces(): void
132134
}
133135

134136
$map = directory_map($path, 1);
135-
foreach ($map as $row) {
136137

138+
foreach ($map as $row) {
137139
$name = trim($row, DIRECTORY_SEPARATOR);
138140

139141
$namespaces[$baseName . "\\{{$name}}"] = [realpath($path . "/{$name}")];

src/Users/Views/_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
</form>
2727

2828
<div class="text-center">
29-
<?= $pager->links('default', 'bonfire_full') ?>
29+
<?= $pager->links('default', 'bonfire_full_hx') ?>
3030
</div>

src/Views/_pager_full.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,40 @@
1010

1111
<?php if ($pager->getPageCount() > 1) : ?>
1212
<nav aria-label="<?= lang('Pager.pageNavigation') ?>" class="d-flex justify-content-center">
13-
<ul class="pagination" hx-target="#content-list">
13+
<ul class="pagination">
1414
<?php if ($pager->hasPrevious()) : ?>
1515
<li class="page-item">
16-
<a href="<?= $pager->getFirst() ?>" hx-get="<?= $pager->getFirst() ?>" aria-label="<?= lang('Pager.first') ?>" class="page-link">
16+
<a href="<?= $pager->getFirst() ?>" aria-label="<?= lang('Pager.first') ?>" class="page-link">
1717
<span aria-hidden="true"><?= lang('Pager.first') ?></span>
1818
</a>
1919
</li>
2020
<li class="page-item">
21-
<a href="<?= $pager->getPrevious() ?>" hx-get="<?= $pager->getPrevious() ?>" aria-label="<?= lang('Pager.previous') ?>" class="page-link">
21+
<a href="<?= $pager->getPrevious() ?>" aria-label="<?= lang('Pager.previous') ?>" class="page-link">
2222
<span aria-hidden="true"><?= lang('Pager.previous') ?></span>
2323
</a>
2424
</li>
2525
<?php endif ?>
2626

2727
<?php foreach ($pager->links() as $link) : ?>
2828
<li class="page-item <?= $link['active'] ? 'active' : '' ?>">
29-
<a href="<?= $link['uri'] ?>" hx-get="<?= $link['uri'] ?>" class="page-link">
29+
<a href="<?= $link['uri'] ?>" class="page-link">
3030
<?= $link['title'] ?>
3131
</a>
3232
</li>
3333
<?php endforeach ?>
3434

3535
<?php if ($pager->hasNext()) : ?>
3636
<li class="page-item">
37-
<a href="<?= $pager->getNext() ?>" hx-get="<?= $pager->getNext() ?>" aria-label="<?= lang('Pager.next') ?>" class="page-link">
37+
<a href="<?= $pager->getNext() ?>" aria-label="<?= lang('Pager.next') ?>" class="page-link">
3838
<span aria-hidden="true"><?= lang('Pager.next') ?></span>
3939
</a>
4040
</li>
4141
<li class="page-item">
42-
<a href="<?= $pager->getLast() ?>" hx-get="<?= $pager->getLast() ?>" aria-label="<?= lang('Pager.last') ?>" class="page-link">
42+
<a href="<?= $pager->getLast() ?>" aria-label="<?= lang('Pager.last') ?>" class="page-link">
4343
<span aria-hidden="true"><?= lang('Pager.last') ?></span>
4444
</a>
4545
</li>
4646
<?php endif ?>
4747
</ul>
4848
</nav>
49-
<?php endif ?>
49+
<?php endif ?>

src/Views/_pager_full_htmx.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
use CodeIgniter\Pager\PagerRenderer;
4+
5+
/**
6+
* @var PagerRenderer $pager
7+
*/
8+
$pager->setSurroundCount(2);
9+
?>
10+
11+
<?php if ($pager->getPageCount() > 1) : ?>
12+
<nav aria-label="<?= lang('Pager.pageNavigation') ?>" class="d-flex justify-content-center">
13+
<ul class="pagination" hx-target="#content-list">
14+
<?php if ($pager->hasPrevious()) : ?>
15+
<li class="page-item">
16+
<a href="<?= $pager->getFirst() ?>" hx-get="<?= $pager->getFirst() ?>" aria-label="<?= lang('Pager.first') ?>" class="page-link">
17+
<span aria-hidden="true"><?= lang('Pager.first') ?></span>
18+
</a>
19+
</li>
20+
<li class="page-item">
21+
<a href="<?= $pager->getPrevious() ?>" hx-get="<?= $pager->getPrevious() ?>" aria-label="<?= lang('Pager.previous') ?>" class="page-link">
22+
<span aria-hidden="true"><?= lang('Pager.previous') ?></span>
23+
</a>
24+
</li>
25+
<?php endif ?>
26+
27+
<?php foreach ($pager->links() as $link) : ?>
28+
<li class="page-item <?= $link['active'] ? 'active' : '' ?>">
29+
<a href="<?= $link['uri'] ?>" hx-get="<?= $link['uri'] ?>" class="page-link">
30+
<?= $link['title'] ?>
31+
</a>
32+
</li>
33+
<?php endforeach ?>
34+
35+
<?php if ($pager->hasNext()) : ?>
36+
<li class="page-item">
37+
<a href="<?= $pager->getNext() ?>" hx-get="<?= $pager->getNext() ?>" aria-label="<?= lang('Pager.next') ?>" class="page-link">
38+
<span aria-hidden="true"><?= lang('Pager.next') ?></span>
39+
</a>
40+
</li>
41+
<li class="page-item">
42+
<a href="<?= $pager->getLast() ?>" hx-get="<?= $pager->getLast() ?>" aria-label="<?= lang('Pager.last') ?>" class="page-link">
43+
<span aria-hidden="true"><?= lang('Pager.last') ?></span>
44+
</a>
45+
</li>
46+
<?php endif ?>
47+
</ul>
48+
</nav>
49+
<?php endif ?>

src/Views/_pager_simple.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @var PagerRenderer $pager
77
*/
88
$pager->setSurroundCount(0);
9+
if ($pager->getPageCount() > 1) : ?>
910
?>
1011
<nav>
1112
<ul class="pager">
@@ -21,3 +22,4 @@
2122
</li>
2223
</ul>
2324
</nav>
25+
<?php endif ?>

src/Views/_pager_simple_htmx.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use CodeIgniter\Pager\PagerRenderer;
4+
5+
/**
6+
* @var PagerRenderer $pager
7+
*/
8+
$pager->setSurroundCount(0);
9+
10+
if ($pager->getPageCount() > 1) : ?>
11+
<nav>
12+
<ul class="pager" hx-target="#content-list">
13+
<li class="page-item <?= $pager->hasPrevious() ? '' : 'disabled' ?>">
14+
<a href="<?= $pager->getPrevious() ?? '#' ?>" hx-get="<?= $pager->getPrevious() ?? '#' ?>" aria-label="<?= lang('Pager.previous') ?>" class="page-link">
15+
<span aria-hidden="true"><?= lang('Pager.newer') ?></span>
16+
</a>
17+
</li>
18+
<li class="page-item <?= $pager->hasNext() ? '' : 'disabled' ?>">
19+
<a href="<?= $pager->getNext() ?? '#' ?>" hx-get="<?= $pager->getNext() ?? '#' ?>" aria-label="<?= lang('Pager.next') ?>" class="page-link">
20+
<span aria-hidden="true"><?= lang('Pager.older') ?></span>
21+
</a>
22+
</li>
23+
</ul>
24+
</nav>
25+
<?php endif ?>

0 commit comments

Comments
 (0)