convert pagination into a macro

pull/225/head
Aevann 2024-03-03 03:25:02 +02:00
parent f15fe9bc6e
commit 6d6ba89a9a
35 changed files with 99 additions and 108 deletions

View File

@ -59,5 +59,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -17,5 +17,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -28,5 +28,5 @@
</div>
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -30,5 +30,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -37,5 +37,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -38,7 +38,7 @@
{% endfor %}
</tbody>
</table>
{% include "pagination.html" %}
{{macros.pagination("pb-0 pl-0 pt-1")}}
</div>
</div>
</div>

View File

@ -37,5 +37,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -37,5 +37,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -1,4 +1,3 @@
{%- import 'util/macros.html' as macros with context -%}
{% if not request.headers.get("xhr") %}
{% if focused_comment %}
<script defer src="{{'js/focused_comment.js' | asset}}"></script>

View File

@ -1,5 +1,4 @@
{% extends "default.html" %}
{%- import 'util/macros.html' as macros with context -%}
{% block pagetitle %}!{{group}}{% endblock %}
{% block content %}
<div class="mx-2">

View File

@ -89,8 +89,7 @@
<button type="submit" class="btn btn-{{pcolor}} text-{{pcolor}} mx-2"><i type="submit" class="fas fas fa-thumbtack fa-rotate--45 mr-2"></i>Pins</button>
</form>
{%- import 'util/macros.html' as macros with context -%}
{{- macros.time_filter_buttons() -}}
{{- macros.time_filter_buttons() -}}
{{- macros.sorting_buttons(POST_SORTS, True) -}}
</div>
{% endblock %}
@ -102,8 +101,8 @@
{% block PseudoSubmitForm %}{% endblock %}
{% block content %}
{% if SITE_NAME == 'WPD' and listing %}
{% include "pagination.html" %}
{% if (SITE_NAME == 'WPD' and listing) or True %}
{{macros.pagination("pl-1 py-0")}}
{% endif %}
<div class="row no-gutters {% if listing %}mt-md-3{% elif not listing %}my-md-3{% endif %}">
@ -117,7 +116,7 @@
{% block pagenav %}
{% if listing %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endif %}
{% if request.path == '/' and v %}

View File

@ -7,8 +7,7 @@
{% block content %}
<div class="d-flex justify-content-between align-items-center mt-1 mb-2">
<div class="d-flex px-2 align-items-center mt-4">
{%- import 'util/macros.html' as macros with context -%}
{{- macros.time_filter_buttons() -}}
{{- macros.time_filter_buttons() -}}
{{- macros.sorting_buttons(COMMENT_SORTS) -}}
</div>
</div>
@ -23,5 +22,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -86,7 +86,7 @@
<div class="p-3">There's nothing here right now.</div>
{% endfor %}
</div>
{% include "pagination.html" %}
{{macros.pagination()}}
</div>
</div>

View File

@ -130,7 +130,7 @@
{% block pagenav %}
{% if notifications %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endif %}
<link rel="stylesheet" href="{{('css/notifications.css') | asset}}">

View File

@ -23,5 +23,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -1,64 +0,0 @@
<nav>
<ul class="pagination pagination-sm mb-0 {% if request.path.endswith('/bank_statement') %}pb-0 pl-0 pt-1{% else %}pl-1 mt-4{% endif %}">
{% if not size %}
{% set size = PAGE_SIZE %}
{% endif %}
{% set num_pages = (total / size) | round(0, 'ceil') | int %}
{% set start_point = page - 2 %}
{% if start_point < 1 %}
{% set start_point = 1 %}
{% endif %}
{% set end_point = start_point+4 %}
{% if end_point > num_pages %}
{% set start_point = start_point-(end_point-num_pages) %}
{% set end_point = num_pages %}
{% endif %}
{% if start_point < 1 %}
{% set start_point = 1 %}
{% endif %}
{% if start_point > 1 %}
<li class="page-item">
<small><a class="page-link" href="{{'page'|change_arg(1, request.full_path)|safe}}">1</a></small>
</li>
{% if start_point == 3 %}
<li class="page-item">
<small><a class="page-link" href="{{'page'|change_arg(2, request.full_path)|safe}}">2</a></small>
</li>
{% elif start_point != 2 %}
<li class="page-item">
<small class="page-link dots">...</small>
</li>
{% set start_point = start_point + 1 %}
{% endif %}
{% endif %}
{% for x in range(start_point, end_point+1) %}
<li class="page-item">
<small><a class="page-link {% if x == page %}active disabled{% endif %}" href="{{'page'|change_arg(x, request.full_path)|safe}}">{{x}}</a></small>
</li>
{% endfor %}
{% if end_point < num_pages %}
{% if end_point == num_pages-2 %}
<li class="page-item">
<small><a class="page-link" href="{{'page'|change_arg(num_pages-1, request.full_path)|safe}}">{{num_pages-1}}</a></small>
</li>
{% elif end_point != num_pages-1 %}
<li class="page-item">
<small class="page-link dots">...</small>
</li>
{% endif %}
<li class="page-item">
<small><a class="page-link" href="{{'page'|change_arg(num_pages, request.full_path)|safe}}">{{num_pages}}</a></small>
</li>
{% endif %}
</ul>
</nav>

View File

@ -305,8 +305,7 @@
<div class="row border-md-0 comment-section pb-3">
<div class="col border-top">
<div class="comments-count py-3">
{%- import 'util/macros.html' as macros with context -%}
{{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
{{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
</div>
{{macros.comment_reply_box(p.fullname, 'comment-reply-' + p.fullname, subwrapper_css_classes='mb-3', enable_cancel_button=false)}}

View File

@ -49,8 +49,7 @@
</div>
<div class="comments-count py-3">
{%- import 'util/macros.html' as macros with context -%}
{{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
{{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
</div>
<div class="comment-section">

View File

@ -1,4 +1,3 @@
{%- import 'util/macros.html' as macros with context -%}
{% if v %}
{% include "modals/award.html" %}

View File

@ -103,8 +103,7 @@
{% if not '/users' in request.path %}
<div class="mt-3 d-flex align-items-center fl-r">
{%- import 'util/macros.html' as macros with context -%}
{{- macros.time_filter_buttons() -}}
{{- macros.time_filter_buttons() -}}
{% if "/posts" in request.path %}
{{- macros.sorting_buttons(POST_SORTS) -}}
{% else %}
@ -148,5 +147,5 @@
</div>
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -1,4 +1,3 @@
{%- import 'util/macros.html' as macros with context -%}
{% macro toggle_section(title, id, name, flag, below_text, disabled) %}
<div id="{{id}}_toggle" class="d-lg-flex border-bottom">

View File

@ -13,7 +13,7 @@
</div>
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
<div class="toast clipboard" id="toast-success" data-bs-animation="true" data-bs-autohide="true" data-bs-delay="5000">
<div class="toast-body text-center">
<i class="fas fa-check-circle text-success mr-2"></i>Link copied to clipboard

View File

@ -8,6 +8,6 @@
</div>
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}
{% block navbar %}{% endblock %}

View File

@ -23,7 +23,7 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}
({{total}} user{{macros.plural(total)}})

View File

@ -36,5 +36,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -35,5 +35,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -35,5 +35,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -31,8 +31,7 @@
<div class="d-flex justify-content-between align-items-center" style="padding-top:10px">
<div class="d-flex align-items-center">
{%- import 'util/macros.html' as macros with context -%}
{{- macros.time_filter_buttons() -}}
{{- macros.time_filter_buttons() -}}
{% if "/posts" in request.path %}
{{- macros.sorting_buttons(POST_SORTS) -}}
{% else %}

View File

@ -23,5 +23,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -35,5 +35,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -40,7 +40,7 @@
{% block pagenav %}
{% if listing %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endif %}
{% if request.path.endswith('/posts') %}

View File

@ -26,5 +26,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -29,5 +29,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -37,5 +37,5 @@
{% endblock %}
{% block pagenav %}
{% include "pagination.html" %}
{{macros.pagination()}}
{% endblock %}

View File

@ -439,3 +439,68 @@
</div>
</div>
{% endmacro %}
{% macro pagination(classes="pl-1 mt-4") %}
<ul class="pagination pagination-sm mb-0 {{classes}}">
{% if not size %}
{% set size = PAGE_SIZE %}
{% endif %}
{% set num_pages = (total / size) | round(0, 'ceil') | int %}
{% set start_point = page - 2 %}
{% if start_point < 1 %}
{% set start_point = 1 %}
{% endif %}
{% set end_point = start_point+4 %}
{% if end_point > num_pages %}
{% set start_point = start_point-(end_point-num_pages) %}
{% set end_point = num_pages %}
{% endif %}
{% if start_point < 1 %}
{% set start_point = 1 %}
{% endif %}
{% if start_point > 1 %}
<li class="page-item">
<small><a class="page-link" href="{{'page'|change_arg(1, request.full_path)|safe}}">1</a></small>
</li>
{% if start_point == 3 %}
<li class="page-item">
<small><a class="page-link" href="{{'page'|change_arg(2, request.full_path)|safe}}">2</a></small>
</li>
{% elif start_point != 2 %}
<li class="page-item">
<small class="page-link dots">...</small>
</li>
{% set start_point = start_point + 1 %}
{% endif %}
{% endif %}
{% for x in range(start_point, end_point+1) %}
<li class="page-item">
<small><a class="page-link {% if x == page %}active disabled{% endif %}" href="{{'page'|change_arg(x, request.full_path)|safe}}">{{x}}</a></small>
</li>
{% endfor %}
{% if end_point < num_pages %}
{% if end_point == num_pages-2 %}
<li class="page-item">
<small><a class="page-link" href="{{'page'|change_arg(num_pages-1, request.full_path)|safe}}">{{num_pages-1}}</a></small>
</li>
{% elif end_point != num_pages-1 %}
<li class="page-item">
<small class="page-link dots">...</small>
</li>
{% endif %}
<li class="page-item">
<small><a class="page-link" href="{{'page'|change_arg(num_pages, request.full_path)|safe}}">{{num_pages}}</a></small>
</li>
{% endif %}
</ul>
{% endmacro %}