Browse Source

Added repeated code to view component for table in orgs, schemes, users and logs

pull/673/head
Ted 3 years ago committed by JG
parent
commit
5e31ea808e
  1. 7
      app/components/view_result_component.html.erb
  2. 13
      app/components/view_result_component.rb
  3. 8
      app/views/case_logs/_log_list.html.erb
  4. 6
      app/views/organisations/_organisation_list.html.erb
  5. 8
      app/views/schemes/_scheme_list.html.erb
  6. 8
      app/views/users/_user_list.html.erb

7
app/components/view_result_component.html.erb

@ -0,0 +1,7 @@
<span class="govuk-!-margin-right-4">
<% if searched.present? %>
<strong><%= count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total <%= item %>. <%= govuk_link_to("Clear search", request.path) %>
<% else %>
<strong><%= count %></strong> total <%= item %>.
<% end %>
</span>

13
app/components/view_result_component.rb

@ -0,0 +1,13 @@
class ViewResultComponent < ViewComponent::Base
attr_reader :searched, :count, :item_label, :total_count, :item, :request
def initialize(searched:, count:, item_label:, total_count:, item:, request:)
@searched = searched
@count = count
@item_label = item_label
@total_count = total_count
@item = item
@request = request
super
end
end

8
app/views/case_logs/_log_list.html.erb

@ -1,13 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular], id: title.dasherize) do |caption| %>
<span class="govuk-!-margin-right-4">
<% if defined?(searched) && searched.present? %>
<strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total <%= title.downcase %>. <%= govuk_link_to("Clear search", request.path) %>
<% else %>
<strong><%= pagy.count %></strong> total <%= title.downcase %>
<% end %>
</span>
<%= render(ViewResultComponent.new(searched: searched, count: pagy.count, item_label: item_label, total_count: total_count, item: "logs", request: request)) %>
<%= govuk_link_to "Download (CSV)", "/logs.csv", type: "text/csv" %>
<% end %>
<%= table.head do |head| %>

6
app/views/organisations/_organisation_list.html.erb

@ -1,11 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<% if searched.present? %>
<strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total organisations. <%= govuk_link_to("Clear search", request.path) %>
<% else %>
<strong><%= pagy.count %></strong> total organisations.
<% end %>
<%= render(ViewResultComponent.new(searched: searched, count: pagy.count, item_label: item_label, total_count: total_count, item: "organisations", request: request)) %>
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>

8
app/views/schemes/_scheme_list.html.erb

@ -1,13 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<span class="govuk-!-margin-right-4">
<% if searched.present? %>
<strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total schemes. <%= govuk_link_to("Clear search", request.path) %>
<% else %>
<strong><%= pagy.count %></strong> total schemes.
<% end %>
</span>
<%= render(ViewResultComponent.new(searched: searched, count: pagy.count, item_label: item_label, total_count: total_count, item: "schemes", request: request)) %>
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>

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

@ -1,13 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<span class="govuk-!-margin-right-4">
<% if searched.present? %>
<strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total users. <%= govuk_link_to("Clear search", request.path) %>
<% else %>
<strong><%= pagy.count %></strong> total users.
<% end %>
</span>
<%= render(ViewResultComponent.new(searched: searched, count: pagy.count, item_label: item_label, total_count: total_count, item: "users", request: request)) %>
<% if current_user.support? %>
<% query = searched.present? ? "?search=#{searched}" : nil %>
<%= govuk_link_to "Download (CSV)", "/users.csv#{query}", type: "text/csv" %>

Loading…
Cancel
Save