From 0a73d3c3478696634008ff91919b0bf43f25c235 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 20 Oct 2022 09:33:10 +0100 Subject: [PATCH] feat: update nav behaviour --- .../organisation_relationships_controller.rb | 2 +- app/helpers/navigation_items_helper.rb | 15 ++++++++------- app/models/organisation.rb | 2 +- .../organisations/housing_providers.html.erb | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index 6256d7e02..224f435d5 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -12,7 +12,7 @@ class OrganisationRelationshipsController < ApplicationController end def housing_providers - housing_providers = organisation.index + housing_providers = organisation.housing_providers unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) respond_to do |format| format.html do diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index 812979cb6..0e97540c2 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -17,7 +17,7 @@ module NavigationItemsHelper NavigationItem.new("Schemes", "/schemes", subnav_supported_housing_schemes_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("Housing providers", housing_providers_organisation_path(current_user.organisation), subnav_housing_providers_path?(path)), + NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), housing_providers_path?(path)), ].compact else [ @@ -25,7 +25,7 @@ module NavigationItemsHelper 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("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)), - NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), subnav_housing_providers_path?(path)), + NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), housing_providers_path?(path)), ].compact end @@ -41,6 +41,7 @@ module NavigationItemsHelper NavigationItem.new("Schemes", "/organisations/#{current_organisation_id}/schemes", subnav_supported_housing_schemes_path?(path)), NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)), NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)), + NavigationItem.new("Housing providers", housing_providers_organisation_path, housing_providers_path?(path)), ].compact else [ @@ -48,7 +49,7 @@ module NavigationItemsHelper FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", "/organisations/#{current_organisation_id}/sales-logs", sales_logs_current?(path)) : nil, NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)), NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)), - NavigationItem.new("Housing providers", housing_providers_organisation_path, subnav_housing_providers_path?(path)), + NavigationItem.new("Housing providers", housing_providers_organisation_path, housing_providers_path?(path)), ].compact end end @@ -82,10 +83,6 @@ private path == "/organisations" || path.include?("/organisations/") end - def subnav_housing_providers_path?(path) - path.include?("/organisations") && path.include?("/housing-providers") - end - def subnav_supported_housing_schemes_path?(path) path.include?("/organisations") && path.include?("/schemes") || path.include?("/schemes/") end @@ -106,6 +103,10 @@ private path.include?("/organisations") && path.include?("/details") end + def housing_providers_path?(path) + path.include?("/housing-providers") + end + def managing_agents_path?(path) path.include?("/managing-agents") end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 675e3cfa7..db81cc807 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -16,7 +16,7 @@ class Organisation < ApplicationRecord has_many :managing_agent_relationships, -> { where(relationship_type: OrganisationRelationship::MANAGING) }, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" has_many :managing_agents, through: :managing_agent_relationships, source: :parent_organisation has_many :housing_provider_relationships, -> { where(relationship_type: OrganisationRelationship::OWNING) }, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" - has_many :index, through: :housing_provider_relationships, source: :parent_organisation + has_many :housing_providers, through: :housing_provider_relationships, source: :parent_organisation scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } diff --git a/app/views/organisations/housing_providers.html.erb b/app/views/organisations/housing_providers.html.erb index 974f1910f..e3f0e7339 100644 --- a/app/views/organisations/housing_providers.html.erb +++ b/app/views/organisations/housing_providers.html.erb @@ -15,7 +15,7 @@

This organisation does not currently have any housing providers.

<% end %> <% if current_user.data_coordinator? || current_user.support? %> - <%= 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", housing_providers_organisation_path(organisation_id: @organisation.id), html: { method: :get } %> <% end %> <% if @total_count != 0 %> <%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %>