]> git.openstreetmap.org Git - rails.git/commitdiff
Combine comments and traces pagination partials
authorAnton Khorev <tony29@yandex.ru>
Mon, 4 Sep 2023 13:25:35 +0000 (16:25 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 9 Sep 2023 11:33:59 +0000 (14:33 +0300)
app/controllers/diary_entries_controller.rb
app/views/diary_entries/comments.html.erb
app/views/diary_entries/index.html.erb
app/views/shared/_pagination.html.erb [moved from app/views/diary_entries/_pagination.html.erb with 76% similarity]
app/views/traces/_trace_paging_nav.html.erb [deleted file]
app/views/traces/index.html.erb

index 5b522988d2de1362a06bc10e51d8819fa717be44..a1cd6ab0ed2d9023a4f3a0e4f0da64ea4cd95d8f 100644 (file)
@@ -238,7 +238,7 @@ class DiaryEntriesController < ApplicationController
     comments = DiaryComment.where(:users => @user)
     comments = comments.visible unless can? :unhidecomment, DiaryEntry
 
-    @params = params.permit(:display_name)
+    @params = params.permit(:display_name, :before, :after)
 
     @comments, @newer_comments_id, @older_comments_id = get_page_items(comments, [:user])
   end
index e1d92b6bb804bb13e55a19b5326453edb446f672..f82373af0c5558d7678ec0df78e7f90aa7b959f3 100644 (file)
@@ -24,8 +24,9 @@
     <% end -%>
   </table>
 
-  <%= render "pagination", :newer_key => "diary_entries.comments.newer_comments",
-                           :older_key => "diary_entries.comments.older_comments",
-                           :newer_id => @newer_comments_id,
-                           :older_id => @older_comments_id %>
+  <%= render "shared/pagination",
+             :newer_key => "diary_entries.comments.newer_comments",
+             :older_key => "diary_entries.comments.older_comments",
+             :newer_id => @newer_comments_id,
+             :older_id => @older_comments_id %>
 <% end -%>
index f6e2c37c5f5ee9f9d408809a0f75022b16555bee..e464b99b4829d40758fcd7912d1b805c8393de64 100644 (file)
 
   <%= render @entries %>
 
-  <%= render "pagination", :newer_key => "diary_entries.index.newer_entries",
-                           :older_key => "diary_entries.index.older_entries",
-                           :newer_id => @newer_entries_id,
-                           :older_id => @older_entries_id %>
+  <%= render "shared/pagination",
+             :newer_key => "diary_entries.index.newer_entries",
+             :older_key => "diary_entries.index.older_entries",
+             :newer_id => @newer_entries_id,
+             :older_id => @older_entries_id %>
 <% end %>
 
 <% unless params[:friends] or params[:nearby] -%>
similarity index 76%
rename from app/views/diary_entries/_pagination.html.erb
rename to app/views/shared/_pagination.html.erb
index 4a948a4f53378fee502a599bd475d609b344fb18..fbb9dcf43321ccfc11abbdbd4771732942c451be 100644 (file)
@@ -2,7 +2,7 @@
   <ul class="pagination">
     <% if newer_id -%>
       <li class="page-item">
-        <%= link_to t(newer_key), @params.merge(:after => newer_id), :class => "page-link" %>
+        <%= link_to t(newer_key), @params.merge(:before => nil, :after => newer_id), :class => "page-link" %>
       </li>
     <% else -%>
       <li class="page-item disabled">
@@ -12,7 +12,7 @@
 
     <% if older_id -%>
       <li class="page-item">
-        <%= link_to t(older_key), @params.merge(:before => older_id), :class => "page-link" %>
+        <%= link_to t(older_key), @params.merge(:before => older_id, :after => nil), :class => "page-link" %>
       </li>
     <% else -%>
       <li class="page-item disabled">
diff --git a/app/views/traces/_trace_paging_nav.html.erb b/app/views/traces/_trace_paging_nav.html.erb
deleted file mode 100644 (file)
index 29e0d37..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<nav>
-  <ul class="pagination">
-    <% if newer_traces %>
-      <li class="page-item">
-        <%= link_to t(".newer"), params.merge(:before => nil, :after => traces.first.id), :class => "page-link" %>
-      </li>
-    <% else %>
-      <li class="page-item disabled">
-        <span class="page-link"><%= t(".newer") %></span>
-      </li>
-    <% end %>
-
-    <% if older_traces %>
-      <li class="page-item">
-        <%= link_to t(".older"), params.merge(:before => traces.last.id, :after => nil), :class => "page-link" %>
-      </li>
-    <% else %>
-      <li class="page-item disabled">
-        <span class="page-link"><%= t(".older") %></span>
-      </li>
-    <% end %>
-  </ul>
-</nav>
index 26e52add72998f06b224f6c9b3de939a56290548..ddbaa9e940677cbd9e8b1d1617bf481cda03d5e9 100644 (file)
 <% end %>
 
 <% if @traces.size > 0 %>
-  <%= render "trace_paging_nav", :older_traces => @older_traces, :newer_traces => @newer_traces, :traces => @traces, :params => @params %>
+  <%= render "shared/pagination",
+             :newer_key => "traces.trace_paging_nav.newer",
+             :older_key => "traces.trace_paging_nav.older",
+             :newer_id => @newer_traces && @traces.first.id,
+             :older_id => @older_traces && @traces.last.id %>
 
   <table id="trace_list" class="table table-borderless table-striped">
     <tbody>
     </tbody>
   </table>
 
-  <%= render "trace_paging_nav", :older_traces => @older_traces, :newer_traces => @newer_traces, :traces => @traces, :params => @params %>
+  <%= render "shared/pagination",
+             :newer_key => "traces.trace_paging_nav.newer",
+             :older_key => "traces.trace_paging_nav.older",
+             :newer_id => @newer_traces && @traces.first.id,
+             :older_id => @older_traces && @traces.last.id %>
 <% else %>
   <h2><%= t ".empty_title" %></h2>
   <p><%= t ".empty_upload_html", :upload_link => link_to(t(".upload_new"), new_trace_path),