Use turbo to update issue search results

This commit is contained in:
Tom Hughes 2024-08-27 19:19:49 +01:00
parent 5841813b82
commit 9416317e64
5 changed files with 62 additions and 59 deletions

View file

@ -27,12 +27,11 @@ class IssuesController < ApplicationController
# If search # If search
if params[:search_by_user].present? if params[:search_by_user].present?
@find_user = User.find_by(:display_name => params[:search_by_user]) @find_user = User.find_by(:display_name => params[:search_by_user])
if @find_user @issues = if @find_user
@issues = @issues.where(:reported_user => @find_user) @issues.where(:reported_user => @find_user)
else else
@issues = @issues.none @issues.none
flash.now[:warning] = t(".user_not_found") end
end
end end
@issues = @issues.where(:status => params[:status]) if params[:status].present? @issues = @issues.where(:status => params[:status]) if params[:status].present?

View file

@ -1,36 +1,44 @@
<turbo-frame id="pagination" target="_top"> <turbo-frame id="pagination" target="_top">
<table class="table table-sm"> <% if @issues.length == 0 %>
<thead> <% if params[:search_by_user].present? && !@find_user %>
<tr> <p><%= t ".user_not_found" %></p>
<th><%= t ".status" %></th> <% else %>
<th><%= t ".reports" %></th> <p><%= t ".issues_not_found" %></p>
<th><%= t ".reported_item" %></th> <% end %>
<th><%= t ".reported_user" %></th> <% else %>
<th><%= t ".last_updated" %></th> <table class="table table-sm">
</tr> <thead>
</thead>
<tbody>
<% @issues.each do |issue| %>
<tr> <tr>
<td><%= t ".states.#{issue.status}" %></td> <th><%= t ".status" %></th>
<td class="text-nowrap"><%= link_to t(".reports_count", :count => issue.reports_count), issue %></td> <th><%= t ".reports" %></th>
<td><%= link_to reportable_title(issue.reportable), reportable_url(issue.reportable) %></td> <th><%= t ".reported_item" %></th>
<td><%= link_to issue.reported_user.display_name, issue.reported_user if issue.reported_user %></td> <th><%= t ".reported_user" %></th>
<td> <th><%= t ".last_updated" %></th>
<% 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> </tr>
<% end %> </thead>
</tbody> <tbody>
</table> <% @issues.each do |issue| %>
<%= render "shared/pagination", <tr>
:newer_key => "issues.page.newer_issues", <td><%= t ".states.#{issue.status}" %></td>
:older_key => "issues.page.older_issues", <td class="text-nowrap"><%= link_to t(".reports_count", :count => issue.reports_count), issue %></td>
:newer_id => @newer_issues_id, <td><%= link_to reportable_title(issue.reportable), reportable_url(issue.reportable) %></td>
:older_id => @older_issues_id %> <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 %>
<% end %>
</turbo-frame> </turbo-frame>

View file

@ -4,7 +4,7 @@
<p><%= t ".search_guidance" %></p> <p><%= t ".search_guidance" %></p>
<%= form_tag(issues_path, :method => :get) do %> <%= form_tag(issues_path, :method => :get, :data => { "turbo" => true, "turbo-frame" => "pagination", "turbo-action" => "advance" }) do %>
<div class="row gx-1"> <div class="row gx-1">
<div class="mb-3 col-md-auto"> <div class="mb-3 col-md-auto">
<%= select_tag :status, <%= select_tag :status,
@ -40,8 +40,4 @@
</div> </div>
<% end %> <% end %>
<% if @issues.length == 0 %> <%= render :partial => "page" %>
<p><%= t ".issues_not_found" %></p>
<% else %>
<%= render :partial => "page" %>
<% end %>

View file

@ -1467,14 +1467,14 @@ en:
not_updated: Not Updated not_updated: Not Updated
search: Search search: Search
search_guidance: "Search Issues:" search_guidance: "Search Issues:"
user_not_found: User does not exist
issues_not_found: No such issues found
link_to_reports: View Reports link_to_reports: View Reports
states: states:
ignored: Ignored ignored: Ignored
open: Open open: Open
resolved: Resolved resolved: Resolved
page: page:
user_not_found: User does not exist
issues_not_found: No such issues found
reported_user: Reported User reported_user: Reported User
status: Status status: Status
reports: Reports reports: Reports

View file

@ -19,7 +19,7 @@ class IssuesTest < ApplicationSystemTestCase
sign_in_as(create(:moderator_user)) sign_in_as(create(:moderator_user))
visit issues_path visit issues_path
assert_content I18n.t("issues.index.issues_not_found") assert_content I18n.t("issues.page.issues_not_found")
end end
def test_view_issues def test_view_issues
@ -81,22 +81,22 @@ class IssuesTest < ApplicationSystemTestCase
visit issues_path visit issues_path
fill_in "search_by_user", :with => good_user.display_name fill_in "search_by_user", :with => good_user.display_name
click_on "Search" click_on "Search"
assert_no_content I18n.t("issues.index.user_not_found") assert_no_content I18n.t("issues.page.user_not_found")
assert_content I18n.t("issues.index.issues_not_found") assert_content I18n.t("issues.page.issues_not_found")
# User doesn't exist # User doesn't exist
visit issues_path visit issues_path
fill_in "search_by_user", :with => "Nonexistent User" fill_in "search_by_user", :with => "Nonexistent User"
click_on "Search" click_on "Search"
assert_content I18n.t("issues.index.user_not_found") assert_content I18n.t("issues.page.user_not_found")
assert_content I18n.t("issues.index.issues_not_found") assert_no_content I18n.t("issues.page.issues_not_found")
# Find Issue against bad_user # Find Issue against bad_user
visit issues_path visit issues_path
fill_in "search_by_user", :with => bad_user.display_name fill_in "search_by_user", :with => bad_user.display_name
click_on "Search" click_on "Search"
assert_no_content I18n.t("issues.index.user_not_found") assert_no_content I18n.t("issues.page.user_not_found")
assert_no_content I18n.t("issues.index.issues_not_found") assert_no_content I18n.t("issues.page.issues_not_found")
end end
def test_commenting def test_commenting
@ -173,20 +173,20 @@ class IssuesTest < ApplicationSystemTestCase
visit issues_path visit issues_path
# First Page # First Page
assert_no_content I18n.t("issues.index.user_not_found") assert_no_content I18n.t("issues.page.user_not_found")
assert_no_content I18n.t("issues.index.issues_not_found") assert_no_content I18n.t("issues.page.issues_not_found")
assert_css "tr", :count => 51 assert_css "tr", :count => 51
# Second Page # Second Page
click_on I18n.t("issues.page.older_issues") click_on I18n.t("issues.page.older_issues")
assert_no_content I18n.t("issues.index.user_not_found") assert_no_content I18n.t("issues.page.user_not_found")
assert_no_content I18n.t("issues.index.issues_not_found") assert_no_content I18n.t("issues.page.issues_not_found")
assert_css "tr", :count => 31 assert_css "tr", :count => 31
# Back to First Page # Back to First Page
click_on I18n.t("issues.page.newer_issues") click_on I18n.t("issues.page.newer_issues")
assert_no_content I18n.t("issues.index.user_not_found") assert_no_content I18n.t("issues.page.user_not_found")
assert_no_content I18n.t("issues.index.issues_not_found") assert_no_content I18n.t("issues.page.issues_not_found")
assert_css "tr", :count => 51 assert_css "tr", :count => 51
end end
end end