From 038fb6e4853ebb065d043ca765b2c1384d3c44a3 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 20 Oct 2022 09:20:37 +0100 Subject: [PATCH] feat: add my features branched off managing agents branch --- app/components/search_component.rb | 2 ++ .../organisation_relationships_controller.rb | 23 +++++++++++++++++ app/helpers/navigation_items_helper.rb | 17 ++++++++++--- app/models/organisation.rb | 3 +++ .../_housing_provider_list.erb | 21 ++++++++++++++++ .../housing_providers.erb | 19 ++++++++++++++ .../organisations/housing_providers.html.erb | 25 +++++++++++++++++++ config/routes.rb | 1 + 8 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 app/views/organisation_relationships/_housing_provider_list.erb create mode 100644 app/views/organisation_relationships/housing_providers.erb create mode 100644 app/views/organisations/housing_providers.html.erb diff --git a/app/components/search_component.rb b/app/components/search_component.rb index 035500b54..23b5ea65e 100644 --- a/app/components/search_component.rb +++ b/app/components/search_component.rb @@ -15,6 +15,8 @@ class SearchComponent < ViewComponent::Base request.path elsif request.path.include?("organisations") && request.path.include?("schemes") request.path + elsif request.path.include?("organisations") && request.path.include?("housing-providers") + request.path elsif request.path.include?("users") user_path(current_user) elsif request.path.include?("organisations") diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index 1677239d0..6256d7e02 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -1,5 +1,7 @@ class OrganisationRelationshipsController < ApplicationController include Pagy::Backend + include Modules::SearchFilter + before_action :authenticate_user! @@ -9,9 +11,30 @@ class OrganisationRelationshipsController < ApplicationController @managing_agents = organisation.managing_agents end + def housing_providers + housing_providers = organisation.index + unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) + respond_to do |format| + format.html do + @pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) + @searched = search_term.presence + @total_count = housing_providers.size + if current_user.support? + render "organisations/housing_providers", layout: "application" + else + render "organisation_relationships/housing_providers" + end + end + end + end + private def organisation @organisation ||= Organisation.find(params[:id]) end + + def search_term + params["search"] + end end diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index 270a563e4..812979cb6 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -17,6 +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)), ].compact else [ @@ -24,6 +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)), ].compact end @@ -34,8 +36,8 @@ module NavigationItemsHelper def secondary_items(path, current_organisation_id) if current_user.organisation.holds_own_stock? [ - NavigationItem.new("Lettings logs", "/organisations/#{current_organisation_id}/lettings-logs", subnav_logs_path?(path)), - FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", "/organisations/#{current_organisation_id}/sales-logs", sales_logs_current?(path)) : nil, + NavigationItem.new("Lettings logs", "/organisations/#{current_organisation_id}/lettings-logs", subnav_lettings_logs_path?(path)), + FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", "/organisations/#{current_organisation_id}/sales-logs", subnav_sales_logs_path?(path)) : nil, 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)), @@ -46,6 +48,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)), ].compact end end @@ -79,6 +82,10 @@ 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 @@ -87,10 +94,14 @@ private (path.include?("/organisations") && path.include?("/users")) || path.include?("/users/") end - def subnav_logs_path?(path) + def subnav_lettings_logs_path?(path) path.include?("/organisations") && path.include?("/lettings-logs") end + def subnav_sales_logs_path?(path) + path.include?("/organisations") && path.include?("/sales-logs") + end + def subnav_details_path?(path) path.include?("/organisations") && path.include?("/details") end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index e86be1e9f..675e3cfa7 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -15,6 +15,9 @@ 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 + scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by, ->(param) { search_by_name(param) } diff --git a/app/views/organisation_relationships/_housing_provider_list.erb b/app/views/organisation_relationships/_housing_provider_list.erb new file mode 100644 index 000000000..b2bb9ba75 --- /dev/null +++ b/app/views/organisation_relationships/_housing_provider_list.erb @@ -0,0 +1,21 @@ +
+ <%= govuk_table do |table| %> + <%= 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)) %> + <% end %> + <% @housing_providers.each do |housing_provider| %> + <%= table.body do |body| %> + <%= body.row do |row| %> + <% row.cell(text: housing_provider.name) %> + <% if current_user.data_coordinator? || current_user.support? %> + <% row.cell(html_attributes: { + scope: "row", + }) do %> + <%= govuk_link_to("Remove", "housing-providers/#{housing_provider.id}") %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> +
diff --git a/app/views/organisation_relationships/housing_providers.erb b/app/views/organisation_relationships/housing_providers.erb new file mode 100644 index 000000000..dbda19d50 --- /dev/null +++ b/app/views/organisation_relationships/housing_providers.erb @@ -0,0 +1,19 @@ +<% item_label = format_label(@pagy.count, "housing provider") %> +<% title = "Housing Providers" %> +<% content_for :title, title %> +<%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: nil } %> + +

Your organisation can submit logs for its housing providers.

+ +<% if @total_count == 0 %> +

You do not currently have any housing providers.

+<% end %> +<% if current_user.data_coordinator? || current_user.support? %> + <%= govuk_button_link_to "Add a housing provider", housing_providers_organisation_path, html: { method: :get } %> +<% end %> +<% if @total_count != 0 %> + <%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> + <%= govuk_section_break(visible: true, size: "m") %> + <%= render partial: "organisation_relationships/housing_provider_list", locals: { index: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> + <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %> +<% end %> diff --git a/app/views/organisations/housing_providers.html.erb b/app/views/organisations/housing_providers.html.erb new file mode 100644 index 000000000..974f1910f --- /dev/null +++ b/app/views/organisations/housing_providers.html.erb @@ -0,0 +1,25 @@ +<% item_label = format_label(@pagy.count, "housing provider") %> +<% title = "Housing Providers" %> +<% content_for :title, title %> +<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> +<% if current_user.support? %> + <%= render SubNavigationComponent.new( + items: secondary_items(request.path, @organisation.id), + ) %> +

Housing Providers

+<% end %> + +

This organisation can submit logs for its housing providers.

+ +<% if @total_count == 0 %> +

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 } %> +<% end %> +<% if @total_count != 0 %> + <%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> + <%= govuk_section_break(visible: true, size: "m") %> + <%= render partial: "organisation_relationships/housing_provider_list", locals: { index: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> + <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 2dffe036e..bae96c98c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -80,6 +80,7 @@ Rails.application.routes.draw do get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation" get "schemes", to: "organisations#schemes" get "managing-agents", to: "organisation_relationships#managing_agents" + get "housing-providers", to: "organisation_relationships#housing_providers" end end