Skip to content

Commit f4f9dd8

Browse files
committed
Added tests for the new Pagination class.
Signed-off-by: alexmerlin <alex.merlin.1985@gmail.com>
1 parent e458f08 commit f4f9dd8

3 files changed

Lines changed: 410 additions & 10 deletions

File tree

src/Admin/templates/admin/simple-logins.html.twig

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
</div>
7272
<div class="col-md-12">
7373
<div class="table-responsive">
74-
<table class="table table-bordered table-hover table-striped table-light" style="display: none;">
74+
<table id="admin-logins-table" class="table table-bordered table-hover table-striped table-light" style="display: none;">
7575
<thead>
7676
<tr>
7777
<th class="column-identity">
@@ -167,6 +167,12 @@
167167
{% endfor %}
168168
</tbody>
169169
</table>
170+
{% if pagination.isOutOfBounds() %}
171+
<div class="alert alert-warning text-center text-black fw-bold" role="alert">
172+
Out of bounds! Return to
173+
<a href="{{ path('admin', {action: 'simple-logins'}, params|merge({offset: pagination.getLastOffset()})) }}">page {{ pagination.getLastPage() }}</a>
174+
</div>
175+
{% endif %}
170176
</div>
171177
</div>
172178
<div class="col-md-12">
@@ -182,8 +188,8 @@
182188
{{ parent() }}
183189
<script>
184190
$(function() {
185-
const hideColumns = (visibleColumns) => {
186-
const table = $('table');
191+
const hideColumns = (tableId, visibleColumns) => {
192+
const table = $(tableId);
187193
if (visibleColumns.length === 0) {
188194
table.show();
189195
return;
@@ -242,11 +248,15 @@
242248
const columnsSettings = JSON.parse('{{ settings|json_encode()|raw }}');
243249
244250
populateColumnSelector('#column-selector', columnsSettings);
245-
hideColumns(columnsSettings);
251+
hideColumns('#admin-logins-table', columnsSettings);
246252
247253
$(document).on('change', '.toggle-column-checkbox', function () {
254+
$('#admin-logins-table').addClass('border-danger-subtle');
248255
saveColumnSettings('{{ identifier }}')
249256
.then(() => toggleColumnVisibility($(this).data('column'), $(this).prop('checked')))
257+
.then(() => {
258+
$('#admin-logins-table').removeClass('border-danger-subtle');
259+
})
250260
.catch(error => console.error('Error: ', error));
251261
});
252262
});

src/App/src/Pagination.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public function getCurrentPage(): int
5757
return $this->currentPage;
5858
}
5959

60-
public function getNextPage(): int
60+
public function hasNextPage(): bool
6161
{
62-
return min($this->currentPage + 1, $this->lastPage);
62+
return $this->currentPage < $this->lastPage;
6363
}
6464

65-
public function hasNextPage(): bool
65+
public function getNextPage(): int
6666
{
67-
return $this->currentPage < $this->lastPage;
67+
return min($this->currentPage + 1, $this->lastPage);
6868
}
6969

7070
public function getLastPage(): int
@@ -77,19 +77,24 @@ public function isLastPage(): bool
7777
return $this->currentPage === $this->lastPage;
7878
}
7979

80+
public function isOutOfBounds(): bool
81+
{
82+
return $this->currentPage > $this->lastPage;
83+
}
84+
8085
public function getFirstOffset(): int
8186
{
8287
return 0;
8388
}
8489

8590
public function getPreviousOffset(): int
8691
{
87-
return $this->offset - $this->limit;
92+
return max(0, $this->offset - $this->limit);
8893
}
8994

9095
public function getNextOffset(): int
9196
{
92-
return $this->offset + $this->limit;
97+
return min($this->offset + $this->limit, $this->getLastOffset());
9398
}
9499

95100
public function getLastOffset(): int

0 commit comments

Comments
 (0)