Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/4272'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Feb 25, 2024
2 parents 3360f91 + f9ab1e0 commit 71cb2c5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
4 changes: 0 additions & 4 deletions app/assets/stylesheets/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ time[title] {
border-color: $grey !important;
}

.border-lightgrey {
border-color: $lightgrey !important;
}

/* Rules for the header */

#menu-icon {
Expand Down
23 changes: 23 additions & 0 deletions app/helpers/browse_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ def type_and_paginated_count(type, pages)
end
end

def sidebar_classic_pagination(pages, page_param)
max_width_for_default_padding = 35

width = 0
pagination_items(pages, {}).each do |body|
width += 2 # padding width
width += body.length
end
link_classes = ["page-link", { "px-1" => width > max_width_for_default_padding }]

tag.ul :class => "pagination pagination-sm mb-1 ms-auto" do
pagination_items(pages, {}).each do |body, n|
linked = !(n.is_a? String)
link = if linked
link_to body, url_for(page_param => n), :class => link_classes
else
tag.span body, :class => link_classes
end
concat tag.li link, :class => ["page-item", { n => !linked }]
end
end
end

private

ICON_TAGS = %w[aeroway amenity barrier building highway historic landuse leisure man_made natural railway shop tourism waterway].freeze
Expand Down
14 changes: 3 additions & 11 deletions app/views/browse/_paging_nav.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<div class="row">
<div class="col">
<h4><%= heading %></h4>
</div>
<div class="d-flex flex-wrap gap-2">
<h4 class="fs-5 mb-0"><%= type_and_paginated_count(type, pages) %></h4>
<% if pages.page_count > 1 %>
<div class="col-auto">
<h4>
<span class="border border-lightgrey rounded p-1">
<%= raw pagination_links_each(pages, {}) { |n| link_to(n, page_param => n) } %>
</span>
</h4>
</div>
<%= sidebar_classic_pagination(pages, "#{type}_page") %>
<% end %>
</div>
6 changes: 3 additions & 3 deletions app/views/browse/changeset.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<% end %>
<% unless @ways.empty? %>
<%= render :partial => "paging_nav", :locals => { :heading => type_and_paginated_count("way", @way_pages), :pages => @way_pages, :page_param => "way_page" } %>
<%= render :partial => "paging_nav", :locals => { :type => "way", :pages => @way_pages } %>
<ul class="list-unstyled">
<% @ways.each do |way| %>
<%= element_list_item "way", way do %>
Expand All @@ -90,7 +90,7 @@
<% end %>
<% unless @relations.empty? %>
<%= render :partial => "paging_nav", :locals => { :heading => type_and_paginated_count("relation", @relation_pages), :pages => @relation_pages, :page_param => "relation_page" } %>
<%= render :partial => "paging_nav", :locals => { :type => "relation", :pages => @relation_pages } %>
<ul class="list-unstyled">
<% @relations.each do |relation| %>
<%= element_list_item "relation", relation do %>
Expand All @@ -103,7 +103,7 @@
<% end %>
<% unless @nodes.empty? %>
<%= render :partial => "paging_nav", :locals => { :heading => type_and_paginated_count("node", @node_pages), :pages => @node_pages, :page_param => "node_page" } %>
<%= render :partial => "paging_nav", :locals => { :type => "node", :pages => @node_pages } %>
<ul class="list-unstyled">
<% @nodes.each do |node| %>
<%= element_list_item "node", node do %>
Expand Down
34 changes: 34 additions & 0 deletions lib/classic_pagination/pagination_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,40 @@ def pagination_links_each(paginator, options, prefix = nil, suffix = nil)

html
end

def pagination_items(paginator, options)
options = DEFAULT_OPTIONS.merge(options)
link_to_current_page = options[:link_to_current_page]
always_show_anchors = options[:always_show_anchors]

current_page = paginator.current_page
window_pages = current_page.window(options[:window_size]).pages

first = paginator.first
last = paginator.last

items = []

if always_show_anchors && !(wp_first = window_pages[0]).first?
items.push [first.number.to_s, first.number]
items.push ["...", "disabled"] if wp_first.number - first.number > 1
end

window_pages.each do |page|
if current_page == page && !link_to_current_page
items.push [page.number.to_s, "active"]
else
items.push [page.number.to_s, page.number]
end
end

if always_show_anchors && !(wp_last = window_pages[-1]).last?
items.push ["...", "disabled"] if last.number - wp_last.number > 1
items.push [last.number.to_s, last.number]
end

items
end
end
end
end

0 comments on commit 71cb2c5

Please sign in to comment.