Browse Source

Move to list partial pattern

pull/607/head
baarkerlounger 3 years ago
parent
commit
bc6ce30469
  1. 2
      app/controllers/modules/users_filter.rb
  2. 2
      app/controllers/organisations_controller.rb
  3. 2
      app/controllers/users_controller.rb
  4. 54
      app/views/users/_user_list.html.erb
  5. 58
      app/views/users/index.html.erb

2
app/controllers/modules/users_filter.rb

@ -1,6 +1,6 @@
module Modules::UsersFilter module Modules::UsersFilter
def filtered_users(base_collection) def filtered_users(base_collection)
search_param = params["search-field"] search_param = params["search"]
if search_param.present? if search_param.present?
base_collection.search_by(search_param) base_collection.search_by(search_param)
else else

2
app/controllers/organisations_controller.rb

@ -19,7 +19,7 @@ class OrganisationsController < ApplicationController
def users def users
@pagy, @users = pagy(filtered_users(@organisation.users)) @pagy, @users = pagy(filtered_users(@organisation.users))
@searched = params["search-field"].presence @searched = params["search"].presence
render "users/index" render "users/index"
end end

2
app/controllers/users_controller.rb

@ -11,7 +11,7 @@ class UsersController < ApplicationController
redirect_to users_organisation_path(current_user.organisation) unless current_user.support? redirect_to users_organisation_path(current_user.organisation) unless current_user.support?
@pagy, @users = pagy(filtered_users(User.all)) @pagy, @users = pagy(filtered_users(User.all))
@searched = params["search-field"].presence @searched = params["search"].presence
respond_to do |format| respond_to do |format|
format.html format.html

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

@ -0,0 +1,54 @@
<%= 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 %>
<% item_label = pagy.count > 1 ? "users" : "user" %>
<strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= User.count %></strong> total users. <%= govuk_link_to("Clear search", request.path) %>
<% else %>
<strong><%= pagy.count %></strong> total users.
<% end %>
</span>
<% if current_user.support? %>
<%= govuk_link_to "Download (CSV)", "/users.csv", type: "text/csv" %>
<% end %>
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>
<% row.cell(header: true, text: "Name and email adress", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Organisation and role", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Last logged in", html_attributes: {
scope: "col",
}) %>
<% end %>
<% end %>
<% users.each do |user| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(header: true, html_attributes: {
scope: "row",
}) do %>
<%= simple_format(user_cell(user), {}, wrapper_tag: "span") %>
<% if user.is_data_protection_officer? || user.is_key_contact? %>
<br>
<% end %>
<%= user.is_data_protection_officer? ? govuk_tag(
classes: "app-tag--small",
colour: "turquoise",
text: "Data protection officer",
) : "" %>
<%= user.is_key_contact? ? govuk_tag(
classes: "app-tag--small",
colour: "turquoise",
text: "Key contact",
) : "" %>
<% end %>
<% row.cell(text: simple_format(org_cell(user), {}, wrapper_tag: "div")) %>
<% row.cell(text: user.last_sign_in_at&.to_formatted_s(:govuk_date)) %>
<% end %>
<% end %>
<% end %>
<% end %>

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

@ -1,4 +1,5 @@
<% content_for :title, "Your organisation (Users)" %> <% title = "Your organisation (Users)" %>
<% content_for :title, title %>
<% content_for :tab_title do %> <% content_for :tab_title do %>
<%= "Users" %> <%= "Users" %>
@ -10,58 +11,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) %>
<%= govuk_table do |table| %> <%= render partial: "user_list", locals: { users: @users, title:, pagy: @pagy, searched: @searched } %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<span class="govuk-!-margin-right-4">
<% if @searched %>
<% item_label = @pagy.count > 1 ? "users" : "user" %>
<strong><%= @pagy.count %></strong> <%= item_label %> found matching ‘<%= @searched %>’ of <strong><%= User.count %></strong> total users. <%= govuk_link_to("Clear search", request.path) %>
<% else %>
<strong><%= @pagy.count %></strong> total users.
<% end %>
</span>
<% if current_user.support? %>
<%= govuk_link_to "Download (CSV)", "/users.csv", type: "text/csv" %>
<% end %>
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>
<% row.cell(header: true, text: "Name and email adress", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Organisation and role", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Last logged in", html_attributes: {
scope: "col",
}) %>
<% end %>
<% end %>
<% @users.each do |user| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(header: true, html_attributes: {
scope: "row",
}) do %>
<%= simple_format(user_cell(user), {}, wrapper_tag: "span") %>
<% if user.is_data_protection_officer? || user.is_key_contact? %>
<br>
<% end %>
<%= user.is_data_protection_officer? ? govuk_tag(
classes: "app-tag--small",
colour: "turquoise",
text: "Data protection officer",
) : "" %>
<%= user.is_key_contact? ? govuk_tag(
classes: "app-tag--small",
colour: "turquoise",
text: "Key contact",
) : "" %>
<% end %>
<% row.cell(text: simple_format(org_cell(user), {}, wrapper_tag: "div")) %>
<% row.cell(text: user.last_sign_in_at&.to_formatted_s(:govuk_date)) %>
<% end %>
<% end %>
<% end %>
<% end %>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "users" } %> <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "users" } %>

Loading…
Cancel
Save