wip: pagination
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
</thead>
|
||||
<tbody id="{{ table_body_id }}" class="divide-y divide-gray-200 dark:divide-gray-50">
|
||||
{% if this.downloads|length > 0 %}
|
||||
{% for download in this.downloads %}
|
||||
{% for download in this.downloads.items %}
|
||||
<tr id="ad_download_{{ download.id }}">
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-stone-800 min-w-[45ch] max-w-[45ch] truncate">
|
||||
{{ download.title }}
|
||||
@@ -40,5 +40,10 @@
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if this.downloads.items|length > 0 %}
|
||||
{% set paginator = this.downloads %}
|
||||
{% include 'partial/paginator.html.twig' %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-200 dark:divide-gray-50">
|
||||
<tbody class="divide-y divide-gray-50">
|
||||
{% if this.userMonitors()|length > 0 %}
|
||||
{% for monitor in this.userMonitors() %}
|
||||
<tr id="monitor_{{ monitor.id }}">
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-800 dark:text-stone-800 min-w-[45ch] max-w-[45ch] truncate">
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-stone-800 min-w-[50ch] max-w-[50ch] truncate">
|
||||
{{ monitor.title }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">
|
||||
@@ -54,7 +54,7 @@
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-xs uppercase text-center col-span-2 font-medium text-gray-800 dark:text-stone-800" colspan="2">
|
||||
<td class="px-6 py-4 whitespace-nowrap text-xs uppercase text-center col-span-2 font-medium text-stone-800" colspan="2">
|
||||
No monitors
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<span {{ attributes }} class="py-[3px] px-[7px] bg-{{ color|default('green') }}-600 rounded-lg inline-block text-center text-xs text-gray-50">
|
||||
<span {{ attributes }} class="py-[3px] px-[7px] bg-{{ color|default('green') }}-600 rounded-lg inline-block text-center text-xs text-white">
|
||||
{{ status }}
|
||||
</span>
|
||||
48
templates/partial/paginator.html.twig
Normal file
48
templates/partial/paginator.html.twig
Normal file
@@ -0,0 +1,48 @@
|
||||
{% set _currentPage = app.request.query.get('page') ?: 1 %}
|
||||
{% set _currentRoute = app.request.attributes.get('_route') %}
|
||||
{% set _lastPage = paginator.lastPage %}
|
||||
{% set _currentParams = app.request.query.all|merge(app.request.attributes.get('_route_params')) %}
|
||||
|
||||
{% if paginator.lastPage > 1 %}
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item{{ _currentPage <= 1 ? ' disabled' : '' }}">
|
||||
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: _currentPage - 1})) }}" aria-label="Previous">
|
||||
« {{ "Previous"|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% set startPage = max(1, _currentPage - 2) %}
|
||||
{% set endPage = min(_lastPage, startPage + 4) %}
|
||||
{% if startPage > 1 %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: 1})) }}">1</a>
|
||||
</li>
|
||||
{% if startPage > 2 %}
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">...</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% for i in startPage..endPage %}
|
||||
<li class="page-item {% if i == _currentPage %}active{% endif %}">
|
||||
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: i})) }}">{{ i }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% if endPage < _lastPage %}
|
||||
{% if endPage < _lastPage - 1 %}
|
||||
<li class="page-item disabled">
|
||||
<span class="page-link">...</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: _lastPage})) }}">{{ _lastPage }}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="page-item {{ _currentPage >= paginator.lastPage ? ' disabled' : '' }}">
|
||||
<a class="page-link" href="{{ path(_currentRoute, _currentParams|merge({page: _currentPage + 1})) }}" aria-label="Next">
|
||||
{{ "Next"|trans }} »
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user