From: Anton Khorev Date: Sun, 15 Oct 2023 19:59:00 +0000 (+0300) Subject: Move sidebar pagination to helpers X-Git-Tag: live~954^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/d404bc04d542d381a3233e8cf461f5c9fb981af2?hp=--cc Move sidebar pagination to helpers --- d404bc04d542d381a3233e8cf461f5c9fb981af2 diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index 0f533770b..be32737a4 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -64,6 +64,29 @@ module BrowseHelper 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 diff --git a/app/views/browse/_paging_nav.html.erb b/app/views/browse/_paging_nav.html.erb index 13cf7c283..ed129aad0 100644 --- a/app/views/browse/_paging_nav.html.erb +++ b/app/views/browse/_paging_nav.html.erb @@ -1,30 +1,6 @@

<%= heading %>

<% if pages.page_count > 1 %> - + <%= sidebar_classic_pagination(pages, page_param) %> <% end %>