From 4b2424d548b66e3ef7f5269bc10d454b1ff7af8e Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 18 Oct 2022 17:44:28 +0100 Subject: [PATCH] feat: update erb text and filter table by housing providers --- .../housing_providers_controller.rb | 8 +++++++- app/controllers/organisations_controller.rb | 8 +++++++- .../_housing_provider_list.html.erb | 2 +- app/views/housing_providers/index.html.erb | 18 ++++++++++++----- .../organisations/housing_providers.html.erb | 20 +++++++++++++------ 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/app/controllers/housing_providers_controller.rb b/app/controllers/housing_providers_controller.rb index 8fd88fb76..c75c35f03 100644 --- a/app/controllers/housing_providers_controller.rb +++ b/app/controllers/housing_providers_controller.rb @@ -3,7 +3,13 @@ class HousingProvidersController < ApplicationController include Modules::SearchFilter def index - housing_providers = Organisation.order(:name) + housing_providers = + Organisation.joins(:parent_organisations) + .where(organisation_relationships: { + parent_organisation_id: current_user.organisation_id, + relationship_type: OrganisationRelationship.relationship_types[:owning], + }) + .order(:name) respond_to do |format| format.html do @pagy, @organisations = pagy(filtered_collection(housing_providers, search_term)) diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 830f7622f..849ea7015 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -136,7 +136,13 @@ class OrganisationsController < ApplicationController end def housing_providers - housing_providers = Organisation.order(:name) + housing_providers = + Organisation.joins(:parent_organisations) + .where(organisation_relationships: { + parent_organisation_id: current_user.organisation_id, + relationship_type: OrganisationRelationship.relationship_types[:owning], + }) + .order(:name) respond_to do |format| format.html do @pagy, @organisations = pagy(filtered_collection(housing_providers, search_term)) diff --git a/app/views/housing_providers/_housing_provider_list.html.erb b/app/views/housing_providers/_housing_provider_list.html.erb index 45a8ec6f3..998d7f808 100644 --- a/app/views/housing_providers/_housing_provider_list.html.erb +++ b/app/views/housing_providers/_housing_provider_list.html.erb @@ -10,7 +10,7 @@ <% row.cell(html_attributes: { scope: "row", }) do %> - <%= govuk_link_to("Remove", "organisations/#{organisation.id}") %> + <%= govuk_link_to("Remove", "housing-providers/#{organisation.id}") %> <% end %> <% end %> <% end %> diff --git a/app/views/housing_providers/index.html.erb b/app/views/housing_providers/index.html.erb index 5bf67d181..50a2d3d95 100644 --- a/app/views/housing_providers/index.html.erb +++ b/app/views/housing_providers/index.html.erb @@ -5,15 +5,23 @@ <%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: nil } %> -

Your organisation can submit logs for its housing providers.

+

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", new_housing_provider_path, html: { method: :get } %> <% end %> -<%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> +<% 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: "housing_providers/housing_provider_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> + <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %> +<% end %> -<%= 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: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %> diff --git a/app/views/organisations/housing_providers.html.erb b/app/views/organisations/housing_providers.html.erb index ca112993c..9a1a3d538 100644 --- a/app/views/organisations/housing_providers.html.erb +++ b/app/views/organisations/housing_providers.html.erb @@ -9,17 +9,25 @@ <%= render SubNavigationComponent.new( items: secondary_items(request.path, @organisation.id), ) %> -

Users

+

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, html: { method: :get } %> + <%= govuk_button_link_to "Add a housing provider", new_housing_provider_path(organisation_id: @organisation.id), html: { method: :get } %> <% end %> -<%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> -<%= govuk_section_break(visible: true, size: "m") %> +<% if @total_count != 0 %> + <%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> -<%= render partial: "housing_providers/housing_provider_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> -<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %> + <%= 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: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %> +<% end %>