]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/4272'
authorTom Hughes <tom@compton.nu>
Sun, 25 Feb 2024 13:40:11 +0000 (13:40 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 25 Feb 2024 13:40:11 +0000 (13:40 +0000)
app/assets/stylesheets/common.scss
app/helpers/browse_helper.rb
app/views/browse/_paging_nav.html.erb
app/views/browse/changeset.html.erb
lib/classic_pagination/pagination_helper.rb

index 1f7c45db504ab41f3fdb64efb96055937f5e29ee..35c5ba845f0d0085b135d4efead8af8f71e89fa7 100644 (file)
@@ -72,10 +72,6 @@ time[title] {
   border-color: $grey !important;
 }
 
-.border-lightgrey {
-  border-color: $lightgrey !important;
-}
-
 /* Rules for the header */
 
 #menu-icon {
index 7aa6e4754d9078344fde557e4f256b34ec2067e3..67b3c7cf77fcdb2ed07b1d23a02babdcf513c47e 100644 (file)
@@ -82,6 +82,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
index e13b1a9b85e84abe2e3efcf27e2ad9dfd93a4e26..aa7ee23b9372342b0b9b04664051beda3a4225ef 100644 (file)
@@ -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>
index ee8eee66e710fdd045a23ca562ed095324e31e59..db6b9c966e924a55db0840975df655281b611299 100644 (file)
@@ -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 %>
@@ -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 %>
   <% 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 %>
index 3ff3c3b950974f515bb4f41cc9e09617d320d3f0..72d16fc983cdbfd80b28201f1ce9b239c1b3b939 100644 (file)
@@ -130,6 +130,40 @@ module ActionView
 
         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