Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-406: Extract pagination logic into common component #390

Merged
merged 11 commits into from
Feb 6, 2022
57 changes: 23 additions & 34 deletions critiquebrainz/frontend/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-01-22 18:40+0000\n"
"POT-Creation-Date: 2022-01-29 06:35+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -536,6 +536,14 @@ msgstr ""
msgid "more"
msgstr ""

#: critiquebrainz/frontend/templates/macros.html:229
msgid "Previous"
msgstr ""

#: critiquebrainz/frontend/templates/macros.html:255
msgid "Next"
msgstr ""

#: critiquebrainz/frontend/templates/navbar.html:6
msgid "Toggle navigation"
msgstr ""
Expand Down Expand Up @@ -691,57 +699,45 @@ msgid_plural "%(num)d reviews"
msgstr[0] ""
msgstr[1] ""

#: critiquebrainz/frontend/templates/artist/entity.html:154
#: critiquebrainz/frontend/templates/review/browse.html:57
#: critiquebrainz/frontend/templates/work/entity.html:105
msgid "Previous"
msgstr ""

#: critiquebrainz/frontend/templates/artist/entity.html:157
#: critiquebrainz/frontend/templates/review/browse.html:60
#: critiquebrainz/frontend/templates/work/entity.html:108
msgid "Next"
msgstr ""

#: critiquebrainz/frontend/templates/artist/entity.html:168
#: critiquebrainz/frontend/templates/artist/entity.html:159
msgid "Artist information"
msgstr ""

#: critiquebrainz/frontend/templates/artist/entity.html:174
#: critiquebrainz/frontend/templates/artist/entity.html:165
msgid "Member of"
msgstr ""

#: critiquebrainz/frontend/templates/artist/entity.html:176
#: critiquebrainz/frontend/templates/artist/entity.html:167
msgid "Members"
msgstr ""

#: critiquebrainz/frontend/templates/artist/entity.html:185
#: critiquebrainz/frontend/templates/artist/entity.html:205
#: critiquebrainz/frontend/templates/artist/entity.html:176
#: critiquebrainz/frontend/templates/artist/entity.html:196
msgid "View all..."
msgstr ""

#: critiquebrainz/frontend/templates/artist/entity.html:193
#: critiquebrainz/frontend/templates/artist/entity.html:184
msgid "Former member of"
msgstr ""

#: critiquebrainz/frontend/templates/artist/entity.html:195
#: critiquebrainz/frontend/templates/artist/entity.html:186
msgid "Former members"
msgstr ""

#: critiquebrainz/frontend/templates/artist/entity.html:212
#: critiquebrainz/frontend/templates/artist/entity.html:203
#: critiquebrainz/frontend/templates/label/entity.html:75
#: critiquebrainz/frontend/templates/place/entity.html:105
#: critiquebrainz/frontend/templates/recording/entity.html:95
#: critiquebrainz/frontend/templates/work/entity.html:121
#: critiquebrainz/frontend/templates/work/entity.html:112
msgid "External links"
msgstr ""

#: critiquebrainz/frontend/templates/artist/entity.html:232
#: critiquebrainz/frontend/templates/artist/entity.html:223
#: critiquebrainz/frontend/templates/event/entity.html:142
#: critiquebrainz/frontend/templates/label/entity.html:95
#: critiquebrainz/frontend/templates/place/entity.html:135
#: critiquebrainz/frontend/templates/recording/entity.html:115
#: critiquebrainz/frontend/templates/work/entity.html:141
#: critiquebrainz/frontend/templates/work/entity.html:132
msgid "Edit on MusicBrainz"
msgstr ""

Expand Down Expand Up @@ -2125,14 +2121,6 @@ msgstr ""
msgid "Edit"
msgstr ""

#: critiquebrainz/frontend/templates/user/reviews.html:130
msgid "Newer"
msgstr ""

#: critiquebrainz/frontend/templates/user/reviews.html:133
msgid "Older"
msgstr ""

#: critiquebrainz/frontend/templates/work/entity.html:68
msgid "Recordings"
msgstr ""
Expand All @@ -2141,7 +2129,7 @@ msgstr ""
msgid "No recordings found"
msgstr ""

#: critiquebrainz/frontend/templates/work/entity.html:118
#: critiquebrainz/frontend/templates/work/entity.html:109
msgid "Work information"
msgstr ""

Expand Down Expand Up @@ -2202,7 +2190,8 @@ msgstr ""
msgid "No logs to display."
msgstr ""

#: critiquebrainz/frontend/views/login.py:34
#: critiquebrainz/frontend/views/login.py:36
#: critiquebrainz/frontend/views/login.py:38
msgid "Login failed."
msgstr ""

Expand Down
15 changes: 2 additions & 13 deletions critiquebrainz/frontend/templates/artist/entity.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% from 'macros.html' import cover_art, entity_rate_form, show_avg_rating with context %}
{% from 'macros.html' import cover_art, entity_rate_form, show_avg_rating, display_pagination with context %}
{% from 'common.html' import rating_script with context %}

{% block title %}{{ artist.name }} - CritiqueBrainz{% endblock %}
Expand Down Expand Up @@ -147,18 +147,7 @@ <h4>{{ _('Discography') }}</h4>
{% endfor %}
<div class="clearfix"></div>

{% if release_group_count > release_groups_limit %}
<div class="col-md-12">
<ul class="pager">
{% if page > 1 %}
<li class="previous"><a href="{{ url_for('artist.entity', id=id, release_type=release_type, page=page-1) }}">&larr; {{ _('Previous') }}</a></li>
{% endif %}
{% if page-1 < release_group_count//release_groups_limit %}
<li class="next"><a href="{{ url_for('artist.entity', id=id, release_type=release_type, page=page+1) }}">{{ _('Next') }} &rarr;</a></li>
{% endif %}
</ul>
</div>
{% endif %}
{{ display_pagination(page, release_group_count, release_groups_limit, 'artist.entity', {'id': id, 'release_type':release_type}) }}
</div>
{% endif %}
<ul class="pagination"></ul>
Expand Down
34 changes: 33 additions & 1 deletion critiquebrainz/frontend/templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<script>
$('img').last()
.on('error', function () {
$(this).attr('src', '{{ get_static_path('images/placeholder_disc.svg') }}');
$(this).attr('src', "{{ get_static_path('images/placeholder_disc.svg') }}");
if ('{{ release_group_page }}' == 'True')
$("#mb-call-to-act").css('display','block');
else
Expand Down Expand Up @@ -220,3 +220,35 @@ <h4 style="margin-bottom:0;">{{ _('Rate this {}:'.format(entity_type_readable))
-
{% endif %}
{% endmacro %}

{% macro display_pagination(current_page, count, limit, page_info, parameter) %}
amCap1712 marked this conversation as resolved.
Show resolved Hide resolved
{% set total_pages = (count/limit)|round(method='ceil')|int %}
{% if count > limit %}
<div class="col-md-12 text-center">
<nav aria-label="Page navigation">
<ul class="pagination">

<li class="previous {{'disabled' if current_page <= 1 }}"><a aria-label="Previous" href="{{ url_for(page_info, page=page-1, **parameter) }}">&larr; {{ _('Previous') }}</a></li>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the aria-label should probably also be translated


<li {{ "class=active" if current_page == 1 }}><a href="{{ url_for(page_info, page=1, **parameter) }}">{{ 1 }}</a></li>

{% if current_page >= 5 %}
<li class="disabled"><a>{{ '...' }}</a></li>
{% endif %}

{% for page_index in range([2,current_page-2]|max, [total_pages,current_page+3]|min) %}
<li {{ "class=active" if current_page == page_index }}><a href="{{ url_for(page_info, page=page_index, **parameter) }}">{{ page_index }}</a></li>
{% endfor %}

{% if (current_page <= (total_pages - 4)) %}
<li class='disabled'><a>{{ '...' }}</a></li>
{% endif %}

<li {{ "class=active" if current_page == total_pages }}><a href="{{ url_for(page_info, page=total_pages, **parameter) }}">{{ total_pages }}</a></li>

<li class="next {{'disabled' if current_page == total_pages }}"><a aria-label="Next" href="{{ url_for(page_info, page=page+1, **parameter) }}">{{ _('Next') }} &rarr;</a></li>
</ul>
</nav>
</div>
{% endif %}
{% endmacro %}
17 changes: 2 additions & 15 deletions critiquebrainz/frontend/templates/mapping/spotify.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}

{% from 'macros.html' import display_pagination with context %}
{% block title %}{{ _('Spotify album mapping') }} - CritiqueBrainz{% endblock %}

{% block content %}
Expand Down Expand Up @@ -46,20 +46,7 @@ <h2>{{ _('Spotify album mapping') }}</h2>
</div>
{% endfor %}
</div>
{% if count > limit %}
<div class="row">
<div class="col-md-12">
<ul class="pager">
{% if page > 1 %}
<li class="previous"><a href="{{ url_for('mapping.spotify_add', release_group_id=release_group.id, page=page-1) }}">&larr; {{ _('Previous') }}</a></li>
{% endif %}
{% if page-1 < count//limit %}
<li class="next"><a href="{{ url_for('mapping.spotify_add', release_group_id=release_group.id, page=page + 1) }}">{{ _('Next') }} &rarr;</a></li>
{% endif %}
</ul>
</div>
</div>
{% endif %}
{{ display_pagination(page, count, limit, 'mapping.spotify_add', {'release_group_id':release_group.id}) }}
{% else %}
<p class="lead" style="text-align:center; margin-top:20px;">{{ _('No similar albums found') }}</p>
{% endif %}
Expand Down
15 changes: 2 additions & 13 deletions critiquebrainz/frontend/templates/review/browse.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% from 'macros.html' import cover_art, review_credit with context %}
{% from 'macros.html' import cover_art, review_credit, display_pagination with context %}

{% block title %}{{ _('Reviews') }} - CritiqueBrainz{% endblock %}

Expand Down Expand Up @@ -50,17 +50,6 @@ <h2>{{ _('Reviews') }}</h2>
{% endif %}
</div>

{% if count > limit %}
<div class="col-md-12">
<ul class="pager">
{% if page > 1 %}
<li class="previous"><a href="{{ url_for('review.browse', entity_type=entity_type, page=page-1) }}">&larr; {{ _('Previous') }}</a></li>
{% endif %}
{% if page-1 < count//limit %}
<li class="next"><a href="{{ url_for('review.browse', entity_type=entity_type, page=page+1) }}">{{ _('Next') }} &rarr;</a></li>
{% endif %}
</ul>
</div>
{% endif %}
{{ display_pagination(page, count, limit, 'review.browse', {'entity_type':entity_type}) }}

{% endblock %}
14 changes: 3 additions & 11 deletions critiquebrainz/frontend/templates/user/reviews.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'user/base.html' %}

{% from 'macros.html' import display_pagination with context %}
{% block title %}{{ user.display_name }} - {{ _('Reviews') }} - CritiqueBrainz{% endblock %}

{% block profile_content %}
Expand Down Expand Up @@ -124,16 +124,8 @@
</tbody>
</table>

{% if count > limit %}
<ul class="pager">
{% if page > 1 %}
<li class="previous"><a href="{{ url_for('user.reviews', user_id=user.id, page=page-1) }}">&larr; {{ _('Newer') }}</a></li>
{% endif %}
{% if page-1 < count//limit %}
<li class="next"><a href="{{ url_for('user.reviews', user_id=user.id, page=page+1) }}">{{ _('Older') }} &rarr;</a></li>
{% endif %}
</ul>
{% endif %}
{{ display_pagination(page, count, limit, 'user.reviews', {'user_id':user.id}) }}

{% endif %}
{% endblock %}

Expand Down
15 changes: 2 additions & 13 deletions critiquebrainz/frontend/templates/work/entity.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% from 'macros.html' import entity_rate_form, show_avg_rating with context %}
{% from 'macros.html' import entity_rate_form, show_avg_rating, display_pagination with context %}
{% from 'common.html' import rating_script with context %}

{% block title %}{{ work.name }} - CritiqueBrainz{% endblock %}
Expand Down Expand Up @@ -98,18 +98,7 @@ <h4>{{ _('Recordings') }}</h4>
{% endfor %}
</tbody>
</table>
{% if recording_count > recording_limit %}
<div class="col-md-12">
<ul class="pager">
{% if page > 1 %}
<li class="previous"><a href="{{ url_for('work.entity', id=id, page=page-1) }}">&larr; {{ _('Previous') }}</a></li>
{% endif %}
{% if page < recording_count//recording_limit %}
<li class="next"><a href="{{ url_for('work.entity', id=id, page=page+1) }}">{{ _('Next') }} &rarr;</a></li>
{% endif %}
</ul>
</div>
{% endif %}
{{ display_pagination(page, recording_count, recording_limit, 'work.entity', {'id':id}) }}
{% endif %}
<ul class="pagination"></ul>
</div>
Expand Down