-
Notifications
You must be signed in to change notification settings - Fork 525
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
AO3-6880 Use pagy gem for pagination on select pages #5054
Merged
+125
−30
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e6aad78
Replace will_paginate with pagy for works
ceithir 0d3b628
Reproduce previous HTML
ceithir abf1a51
Simpler use code
ceithir 83a8530
Use for bookmarks
ceithir dd58c8e
Add pagy to history
ceithir 18fd9f6
Use query_result values, not defaults
ceithir 3fd4490
No ! means immutable
ceithir c06b383
Rescue overflow
ceithir 2e7f96b
Consistency
ceithir c52785f
Cop
ceithir 2708f85
Ignore Brakeman's warning
ceithir f1c217b
Move to own module
ceithir 955dd4a
Keep closer to Pagy's original syntax
ceithir e2e990b
Cop
ceithir 51f30bd
Explicit Pagy i18n keys
ceithir 1d4704e
Use existing key
ceithir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module PaginationHelper | ||
include Pagy::Frontend | ||
|
||
# change the default link renderer for will_paginate | ||
def will_paginate(collection_or_options = nil, options = {}) | ||
if collection_or_options.is_a? Hash | ||
options = collection_or_options | ||
collection_or_options = nil | ||
end | ||
options = options.merge renderer: PaginationListLinkRenderer unless options[:renderer] | ||
super(*[collection_or_options, options].compact) | ||
end | ||
|
||
# Cf https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/frontend.rb | ||
# i18n-tasks-use t("pagy.prev") | ||
# i18n-tasks-use t("pagy.next") | ||
# i18n-tasks-use t("pagy.aria_label.nav") | ||
def pagy_nav(pagy, id: nil, aria_label: nil, **vars) | ||
return nil unless pagy | ||
|
||
# Keep will_paginate behavior of showing nothing if only one page | ||
return nil if pagy.series.length <= 1 | ||
|
||
id = %( id="#{id}") if id | ||
a = pagy_anchor(pagy, **vars) | ||
|
||
html = %(<h4 class="landmark heading">#{t('a11y.navigation')}</h4>) | ||
|
||
html << %(<ol#{id} class="pagination actions pagy" role="navigation" #{nav_aria_label(pagy, aria_label: aria_label)}>) | ||
|
||
prev_text = pagy_t("pagy.prev") | ||
prev_a = | ||
if (p_prev = pagy.prev) | ||
a.call(p_prev, prev_text) | ||
else | ||
%(<span class="disabled">#{prev_text}</span>) | ||
end | ||
html << %(<li class="previous">#{prev_a}</li>) | ||
|
||
pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] | ||
html << %(<li>) | ||
html << case item | ||
when Integer | ||
a.call(item) | ||
when String | ||
%(<a role="link" aria-disabled="true" aria-current="page" class="current">#{pagy.label_for(item)}</a>) | ||
when :gap | ||
%(<span class="gap">#{pagy_t('pagy.gap')}</span>) | ||
else | ||
raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}" | ||
end | ||
html << %(</li>) | ||
end | ||
|
||
next_text = pagy_t("pagy.next") | ||
next_a = | ||
if (p_next = pagy.next) | ||
a.call(p_next, next_text) | ||
else | ||
%(<span class="disabled">#{next_text}</span>) | ||
end | ||
html << %(<li class="next">#{next_a}</li>) | ||
|
||
html << %(</ol>) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,5 @@ | |
<!--/content--> | ||
|
||
<!--subnav--> | ||
<%= will_paginate @readings %> | ||
<%== pagy_nav @pagy %> | ||
<!--/subnav--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--- | ||
:safe_methods: | ||
- :pagy_nav | ||
- :sanitize_field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
# https://ddnexus.github.io/pagy/docs/extras/i18n/ | ||
require "pagy/extras/i18n" | ||
|
||
# See https://ddnexus.github.io/pagy/docs/api/pagy#variables | ||
Pagy::DEFAULT[:limit] = ArchiveConfig.ITEMS_PER_PAGE | ||
Pagy::DEFAULT[:size] = 9 | ||
|
||
Pagy::DEFAULT.freeze |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the same behavior as now by not showing the pagination in case of overflow ("page 66 of 10").
pagy's alternative options for reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're not setting
Pagy::DEFAULT[:overflow]
, the default is:empty_page
instead of:exception
, do we need to wrap calls inpagy_overflow_handler
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the
require 'pagy/extras/overflow'
line, Pagy always raises an exception in case of overflow (source)