From 4ae4c607b8417e68861f395df614c67d8c8fba51 Mon Sep 17 00:00:00 2001 From: nertc <davidtsiklauri7@gmail.com> Date: Mon, 19 Aug 2024 22:35:19 +0400 Subject: [PATCH] Add turbo to Issues page --- app/controllers/issues_controller.rb | 1 + app/views/issues/_page.html.erb | 66 ++++++++++++++------------- app/views/shared/_pagination.html.erb | 4 +- test/system/issues_test.rb | 4 +- 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 1baf533f41..f53a8dad55 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -45,6 +45,7 @@ def index end @issues, @newer_issues_id, @older_issues_id = get_page_items(@issues, :limit => @params[:limit]) + render :partial => "page" if turbo_frame_request_id == "pagination" end def show diff --git a/app/views/issues/_page.html.erb b/app/views/issues/_page.html.erb index ed23fb8cdc..2c0340c110 100644 --- a/app/views/issues/_page.html.erb +++ b/app/views/issues/_page.html.erb @@ -1,34 +1,36 @@ -<table class="table table-sm"> - <thead> - <tr> - <th><%= t ".status" %></th> - <th><%= t ".reports" %></th> - <th><%= t ".reported_item" %></th> - <th><%= t ".reported_user" %></th> - <th><%= t ".last_updated" %></th> - </tr> - </thead> - <tbody> - <% @issues.each do |issue| %> +<turbo-frame id="pagination" target="_top"> + <table class="table table-sm"> + <thead> <tr> - <td><%= t ".states.#{issue.status}" %></td> - <td class="text-nowrap"><%= link_to t(".reports_count", :count => issue.reports_count), issue %></td> - <td><%= link_to reportable_title(issue.reportable), reportable_url(issue.reportable) %></td> - <td><%= link_to issue.reported_user.display_name, issue.reported_user if issue.reported_user %></td> - <td> - <% if issue.user_updated %> - <%= t ".last_updated_time_ago_user_html", :user => link_to(issue.user_updated.display_name, issue.user_updated), - :time_ago => friendly_date_ago(issue.updated_at) %> - <% else %> - <%= friendly_date_ago(issue.updated_at) %> - <% end %> - </td> + <th><%= t ".status" %></th> + <th><%= t ".reports" %></th> + <th><%= t ".reported_item" %></th> + <th><%= t ".reported_user" %></th> + <th><%= t ".last_updated" %></th> </tr> - <% end %> - </tbody> -</table> -<%= render "shared/pagination", - :newer_key => "issues.page.newer_issues", - :older_key => "issues.page.older_issues", - :newer_id => @newer_issues_id, - :older_id => @older_issues_id %> + </thead> + <tbody> + <% @issues.each do |issue| %> + <tr> + <td><%= t ".states.#{issue.status}" %></td> + <td class="text-nowrap"><%= link_to t(".reports_count", :count => issue.reports_count), issue %></td> + <td><%= link_to reportable_title(issue.reportable), reportable_url(issue.reportable) %></td> + <td><%= link_to issue.reported_user.display_name, issue.reported_user if issue.reported_user %></td> + <td> + <% if issue.user_updated %> + <%= t ".last_updated_time_ago_user_html", :user => link_to(issue.user_updated.display_name, issue.user_updated), + :time_ago => friendly_date_ago(issue.updated_at) %> + <% else %> + <%= friendly_date_ago(issue.updated_at) %> + <% end %> + </td> + </tr> + <% end %> + </tbody> + </table> + <%= render "shared/pagination", + :newer_key => "issues.page.newer_issues", + :older_key => "issues.page.older_issues", + :newer_id => @newer_issues_id, + :older_id => @older_issues_id %> +</turbo-frame> diff --git a/app/views/shared/_pagination.html.erb b/app/views/shared/_pagination.html.erb index 3dbce6f982..67b69e8645 100644 --- a/app/views/shared/_pagination.html.erb +++ b/app/views/shared/_pagination.html.erb @@ -7,7 +7,7 @@ <% end %> <% if newer_id -%> <li class="page-item d-flex"> - <%= link_to newer_link_content, @params.merge(:before => nil, :after => newer_id), :class => link_class %> + <%= link_to newer_link_content, @params.merge(:before => nil, :after => newer_id), :class => link_class, :data => { "turbo-frame" => "pagination", "turbo-action" => "advance" } %> </li> <% else -%> <li class="page-item d-flex disabled"> @@ -21,7 +21,7 @@ <% end %> <% if older_id -%> <li class="page-item d-flex"> - <%= link_to older_link_content, @params.merge(:before => older_id, :after => nil), :class => link_class %> + <%= link_to older_link_content, @params.merge(:before => older_id, :after => nil), :class => link_class, :data => { "turbo-frame" => "pagination", "turbo-action" => "advance" } %> </li> <% else -%> <li class="page-item d-flex disabled"> diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb index 4086a4fe48..90cef76e6b 100644 --- a/test/system/issues_test.rb +++ b/test/system/issues_test.rb @@ -181,12 +181,12 @@ def test_issues_pagination click_on I18n.t("issues.page.older_issues") assert_no_content I18n.t("issues.index.user_not_found") assert_no_content I18n.t("issues.index.issues_not_found") - assert_css "tr", :count => 31, :wait => 1 + assert_css "tr", :count => 31, :wait => 1.5 # Back to First Page click_on I18n.t("issues.page.newer_issues") assert_no_content I18n.t("issues.index.user_not_found") assert_no_content I18n.t("issues.index.issues_not_found") - assert_css "tr", :count => 51, :wait => 1 + assert_css "tr", :count => 51, :wait => 1.5 end end