8000 Hide "Last" link when `pagination_total` is false (#5822) · activeadmin/activeadmin@d0cbadd · GitHub
[go: up one dir, main page]

Skip to content

Commit d0cbadd

Browse files
deivid-rodriguezjavierjulio
authored andcommitted
Hide "Last" link when pagination_total is false (#5822)
1 parent 2f67e13 commit d0cbadd

File tree

10 files changed

+86
-1
lines changed

10 files changed

+86
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* Fix CSVBuilder not respecting `ActiveAdmin.application.csv_options = { humanize_name: false }` setting. [#5800] by [@HappyKadaver]
88
* Fix crash when displaying current filters after filtering by a nested resource. [#5816] by [@deivid-rodriguez]
9+
* Fix pagination when `pagination_total` is false to not show a "Last" link, since it's incorrect because we don't have the total pages information. [#5822] by [@deivid-rodriguez]
910

1011
## 2.2.0 [](https://github.com/activeadmin/activeadmin/compare/v2.1.0..v2.2.0)
1112

@@ -483,6 +484,7 @@ Please check [0-6-stable] for previous changes.
483484
[#5801]: https://github.com/activeadmin/activeadmin/pull/5801
484485
[#5802]: https://github.com/activeadmin/activeadmin/pull/5802
485486
[#5816]: https://github.com/activeadmin/activeadmin/pull/5816
487+
[#5822]: https://github.com/activeadmin/activeadmin/pull/5822
486488

487489
[@5t111111]: https://github.com/5t111111
488490
[@aarek]: https://github.com/aarek
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%# Link to the "First" page
2+
- available local variables
3+
url: url to the first page
4+
current_page: a page object for the currently displayed page
5+
total_pages: total number of pages
6+
per_page: number of items to fetch per page
7+
remote: data-remote
8+
-%>
9+
<span class="first">
10+
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote %>
11+
</span>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%# Non-link tag that stands for skipped pages...
2+
- available local variables
3+
current_page: a page object for the currently displayed page
4+
total_pages: total number of pages
5+
per_page: number of items to fetch per page
6+
remote: data-remote
7+
-%>
8+
<span class="page gap"><%= t('views.pagination.truncate').html_safe %></span>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%# Link to the "Next" page
2+
- available local variables
3+
url: url to the next page
4+
current_page: a page object for the currently displayed page
5+
total_pages: total number of pages
6+
per_page: number of items to fetch per page
7+
remote: data-remote
8+
-%>
9+
<span class="next">
10+
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote %>
11+
</span>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%# Link showing page number
2+
- available local variables
3+
page: a page object for "this" page
4+
url: url to this page
5+
current_page: a page object for the currently displayed page
6+
total_pages: total number of pages
7+
per_page: number of items to fetch per page
8+
remote: data-remote
9+
-%>
10+
<span class="page<%= ' current' if page.current? %>">
11+
<%= link_to_unless page.current?, page, url, {remote: remote, rel: page.rel} %>
12+
</span>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<%# The container tag
2+
- available local variables
3+
current_page: a page object for the currently displayed page
4+
total_pages: total number of pages
5+
per_page: number of items to fetch per page
6+
remote: data-remote
7+
paginator: the paginator that renders the pagination tags inside
8+
-%>
9+
<%= paginator.render do -%>
10+
<nav class="pagination">
11+
<%= first_page_tag unless current_page.first? %>
12+
<%= prev_page_tag unless current_page.first? %>
13+
<% each_page do |page| -%>
14+
<% if page.display_tag? -%>
15+
<%= page_tag page %>
16+
<% elsif !page.was_truncated? -%>
17+
<%= gap_tag %>
18+
<% end -%>
19+
<% end -%>
20+
<% unless current_page.out_of_range? %>
21+
<%= next_page_tag unless current_page.last? %>
22+
<% end %>
23+
</nav>
24+
<% end -%>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%# Link to the "Previous" page
2+
- available local variables
3+
url: url to the previous page
4+
current_page: a page object for the currently displayed page
5+
total_pages: total number of pages
6+
per_page: number of items to fetch per page
7+
remote: data-remote
8+
-%>
9+
<span class="prev">
10+
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote %>
11+
</span>

features/index/pagination.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ Feature: Index Pagination
5656
Then I should see "Displaying Posts 1 - 10"
5757
And I should not see "11 in total"
5858
And I should see the pagination "Next" link
59+
And I should not see the pagination "Last" link
5960

6061
When I follow "Next"
6162
Then I should see "Displaying Posts 11 - 11"
6263
And I should not see the pagination "Next" link
64+
And I should not see the pagination "Last" link

features/step_definitions/pagination_steps.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
Then /^I should not see the pagination "Next" link/ do
1414
expect(page).to_not have_css "a", text: "Next"
1515
end
16+
17+
Then /^I should not see the pagination "Last" link/ do
18+
expect(page).to_not have_css "a", text: "Last"
19+
end

lib/active_admin/views/components/paginated_collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def build_per_page_select
9292
end
9393

9494
def build_pagination
95-
options = { theme: 'active_admin' }
95+
options = { theme: @display_total ? 'active_admin' : 'active_admin_countless' }
9696
options[:params] = @params if @params
9797
options[:param_name] = @param_name if @param_name
9898

0 commit comments

Comments
 (0)
0