Browse Source

feat: add correct search behaviour, refactor and update linking

CLDC-1661-new-page-for-housing-providers
natdeanlewissoftwire 2 years ago
parent
commit
b04a8b6a74
  1. 2
      app/components/search_component.rb
  2. 4
      app/controllers/housing_providers_controller.rb
  3. 5
      app/controllers/organisations_controller.rb
  4. 2
      app/helpers/navigation_items_helper.rb
  5. 6
      app/views/housing_providers/_housing_provider_list.html.erb
  6. 6
      app/views/housing_providers/index.html.erb
  7. 7
      app/views/organisations/housing_providers.html.erb

2
app/components/search_component.rb

@ -15,6 +15,8 @@ class SearchComponent < ViewComponent::Base
request.path request.path
elsif request.path.include?("organisations") && request.path.include?("schemes") elsif request.path.include?("organisations") && request.path.include?("schemes")
request.path request.path
elsif request.path.include?("organisations") && request.path.include?("housing-providers")
request.path
elsif request.path.include?("users") elsif request.path.include?("users")
user_path(current_user) user_path(current_user)
elsif request.path.include?("organisations") elsif request.path.include?("organisations")

4
app/controllers/housing_providers_controller.rb

@ -4,7 +4,7 @@ class HousingProvidersController < ApplicationController
def index def index
housing_providers = housing_providers =
Organisation.joins(:child_organisations) Organisation.joins(:child_organisation_relationships)
.where(organisation_relationships: { .where(organisation_relationships: {
child_organisation_id: current_user.organisation_id, child_organisation_id: current_user.organisation_id,
relationship_type: OrganisationRelationship.relationship_types[:owning], relationship_type: OrganisationRelationship.relationship_types[:owning],
@ -12,7 +12,7 @@ class HousingProvidersController < ApplicationController
.order(:name) .order(:name)
respond_to do |format| respond_to do |format|
format.html do format.html do
@pagy, @organisations = pagy(filtered_collection(housing_providers, search_term)) @pagy, @housing_providers = pagy(filtered_collection(housing_providers, search_term))
@searched = search_term.presence @searched = search_term.presence
@total_count = housing_providers.size @total_count = housing_providers.size
render "housing_providers/index" render "housing_providers/index"

5
app/controllers/organisations_controller.rb

@ -137,15 +137,16 @@ class OrganisationsController < ApplicationController
def housing_providers def housing_providers
housing_providers = housing_providers =
Organisation.joins(:child_organisations) Organisation.joins(:child_organisation_relationships)
.where(organisation_relationships: { .where(organisation_relationships: {
child_organisation_id: @organisation.id, child_organisation_id: @organisation.id,
relationship_type: OrganisationRelationship.relationship_types[:owning], relationship_type: OrganisationRelationship.relationship_types[:owning],
}) })
.order(:name) .order(:name)
unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term)
respond_to do |format| respond_to do |format|
format.html do format.html do
@pagy, @organisations = pagy(filtered_collection(housing_providers, search_term)) @pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers)
@searched = search_term.presence @searched = search_term.presence
@total_count = housing_providers.size @total_count = housing_providers.size
render "housing_providers", layout: "application" render "housing_providers", layout: "application"

2
app/helpers/navigation_items_helper.rb

@ -24,7 +24,7 @@ module NavigationItemsHelper
FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", sales_logs_path, sales_logs_current?(path)) : nil, FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", sales_logs_path, sales_logs_current?(path)) : nil,
NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)), NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)),
NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)), NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)),
NavigationItem.new("Housing providers", "/housing-providers", housing_providers_current?(path)), NavigationItem.new("Housing providers", housing_providers_path, housing_providers_current?(path)),
].compact ].compact
end end
end end

6
app/views/housing_providers/_housing_provider_list.html.erb

@ -3,15 +3,15 @@
<%= 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| %>
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "housing providers", path: request.path)) %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "housing providers", path: request.path)) %>
<% end %> <% end %>
<% @organisations.each do |organisation| %> <% @housing_providers.each do |housing_provider| %>
<%= table.body do |body| %> <%= table.body do |body| %>
<%= body.row do |row| %> <%= body.row do |row| %>
<% row.cell(text: organisation.name) %> <% row.cell(text: housing_provider.name) %>
<% if current_user.data_coordinator? || current_user.support? %> <% if current_user.data_coordinator? || current_user.support? %>
<% row.cell(html_attributes: { <% row.cell(html_attributes: {
scope: "row", scope: "row",
}) do %> }) do %>
<%= govuk_link_to("Remove", "housing-providers/#{organisation.id}") %> <%= govuk_link_to("Remove", "housing-providers/#{housing_provider.id}") %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

6
app/views/housing_providers/index.html.erb

@ -1,4 +1,4 @@
<% item_label = format_label(@pagy.count, "organisation") %> <% item_label = format_label(@pagy.count, "housing provider") %>
<% title = "Housing Providers" %> <% title = "Housing Providers" %>
<% content_for :title, title %> <% content_for :title, title %>
@ -20,8 +20,8 @@
<%= govuk_section_break(visible: true, size: "m") %> <%= govuk_section_break(visible: true, size: "m") %>
<%= render partial: "housing_providers/housing_provider_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> <%= render partial: "housing_providers/housing_provider_list", locals: { housing_providers: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %> <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %>
<% end %> <% end %>

7
app/views/organisations/housing_providers.html.erb

@ -1,4 +1,4 @@
<% item_label = format_label(@pagy.count, "organisation") %> <% item_label = format_label(@pagy.count, "housing provider") %>
<% title = "Housing Providers" %> <% title = "Housing Providers" %>
<% content_for :title, title %> <% content_for :title, title %>
@ -22,12 +22,11 @@
<%= govuk_button_link_to "Add a housing provider", new_housing_provider_path(organisation_id: @organisation.id), html: { method: :get } %> <%= govuk_button_link_to "Add a housing provider", new_housing_provider_path(organisation_id: @organisation.id), html: { method: :get } %>
<% end %> <% end %>
<% if @total_count != 0 %> <% if @total_count != 0 %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> <%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %>
<%= govuk_section_break(visible: true, size: "m") %> <%= govuk_section_break(visible: true, size: "m") %>
<%= render partial: "housing_providers/housing_provider_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> <%= render partial: "housing_providers/housing_provider_list", locals: { housing_providers: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %> <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %>
<% end %> <% end %>

Loading…
Cancel
Save