Browse Source

Add search result to page title if searched

pull/607/head
baarkerlounger 3 years ago
parent
commit
44298218b7
  1. 5
      app/views/users/_user_list.html.erb
  2. 11
      app/views/users/index.html.erb

5
app/views/users/_user_list.html.erb

@ -1,9 +1,8 @@
<%= govuk_table do |table| %> <%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<span class="govuk-!-margin-right-4"> <span class="govuk-!-margin-right-4">
<% if searched %> <% if searched.present? %>
<% item_label = pagy.count > 1 ? "users" : "user" %> <strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_user_count %></strong> total users. <%= govuk_link_to("Clear search", request.path) %>
<strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= User.count %></strong> total users. <%= govuk_link_to("Clear search", request.path) %>
<% else %> <% else %>
<strong><%= pagy.count %></strong> total users. <strong><%= pagy.count %></strong> total users.
<% end %> <% end %>

11
app/views/users/index.html.erb

@ -1,7 +1,12 @@
<% if @searched.present? %> <% if @searched.present? %>
<% search_title = " (search results for ‘#{@searched})’" %> <% item_label = @pagy.count > 1 ? "users" : "user" %>
<% total_user_count = User.all.count %>
<% title = "Your organisation (#{@pagy.count} #{item_label} matching ‘#{@searched}’ of #{total_user_count} total users)" %>
<% else %>
<% item_label = "" %>
<% total_user_count = nil %>
<% title = "Your organisation (Users)" %>
<% end %> <% end %>
<% title = "Your organisation (Users)#{search_title}" %>
<% content_for :title, title %> <% content_for :title, title %>
@ -15,5 +20,5 @@
<%= render SearchComponent.new(current_user:, search_label: "Search by name or email address", value: @searched) %> <%= render SearchComponent.new(current_user:, search_label: "Search by name or email address", value: @searched) %>
<%= render partial: "users/user_list", locals: { users: @users, title:, pagy: @pagy, searched: @searched } %> <%= render partial: "users/user_list", locals: { users: @users, title:, pagy: @pagy, searched: @searched, item_label:, total_user_count: } %>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "users" } %> <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "users" } %>

Loading…
Cancel
Save