Skip to content

Commit

Permalink
Add turbo to Issues page
Browse files Browse the repository at this point in the history
  • Loading branch information
nertc committed Aug 19, 2024
1 parent 01f770d commit 4ae4c60
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 36 deletions.
1 change: 1 addition & 0 deletions app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 34 additions & 32 deletions app/views/issues/_page.html.erb
Original file line number Diff line number Diff line change
@@ -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>
4 changes: 2 additions & 2 deletions app/views/shared/_pagination.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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">
Expand Down
4 changes: 2 additions & 2 deletions test/system/issues_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4ae4c60

Please sign in to comment.