Browse Source

feat: add my features branched off managing agents branch

pull/950/head
natdeanlewissoftwire 3 years ago
parent
commit
038fb6e485
  1. 2
      app/components/search_component.rb
  2. 23
      app/controllers/organisation_relationships_controller.rb
  3. 17
      app/helpers/navigation_items_helper.rb
  4. 3
      app/models/organisation.rb
  5. 21
      app/views/organisation_relationships/_housing_provider_list.erb
  6. 19
      app/views/organisation_relationships/housing_providers.erb
  7. 25
      app/views/organisations/housing_providers.html.erb
  8. 1
      config/routes.rb

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")

23
app/controllers/organisation_relationships_controller.rb

@ -1,5 +1,7 @@
class OrganisationRelationshipsController < ApplicationController class OrganisationRelationshipsController < ApplicationController
include Pagy::Backend include Pagy::Backend
include Modules::SearchFilter
before_action :authenticate_user! before_action :authenticate_user!
@ -9,9 +11,30 @@ class OrganisationRelationshipsController < ApplicationController
@managing_agents = organisation.managing_agents @managing_agents = organisation.managing_agents
end 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 private
def organisation def organisation
@organisation ||= Organisation.find(params[:id]) @organisation ||= Organisation.find(params[:id])
end end
def search_term
params["search"]
end
end end

17
app/helpers/navigation_items_helper.rb

@ -17,6 +17,7 @@ module NavigationItemsHelper
NavigationItem.new("Schemes", "/schemes", subnav_supported_housing_schemes_path?(path)), 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("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_organisation_path(current_user.organisation), subnav_housing_providers_path?(path)),
].compact ].compact
else else
[ [
@ -24,6 +25,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_organisation_path(current_user.organisation), subnav_housing_providers_path?(path)),
].compact ].compact
end end
@ -34,8 +36,8 @@ module NavigationItemsHelper
def secondary_items(path, current_organisation_id) def secondary_items(path, current_organisation_id)
if current_user.organisation.holds_own_stock? if current_user.organisation.holds_own_stock?
[ [
NavigationItem.new("Lettings logs", "/organisations/#{current_organisation_id}/lettings-logs", subnav_logs_path?(path)), 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", sales_logs_current?(path)) : nil, 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("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("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("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, 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("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("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 ].compact
end end
end end
@ -79,6 +82,10 @@ private
path == "/organisations" || path.include?("/organisations/") path == "/organisations" || path.include?("/organisations/")
end end
def subnav_housing_providers_path?(path)
path.include?("/organisations") && path.include?("/housing-providers")
end
def subnav_supported_housing_schemes_path?(path) def subnav_supported_housing_schemes_path?(path)
path.include?("/organisations") && path.include?("/schemes") || path.include?("/schemes/") path.include?("/organisations") && path.include?("/schemes") || path.include?("/schemes/")
end end
@ -87,10 +94,14 @@ private
(path.include?("/organisations") && path.include?("/users")) || path.include?("/users/") (path.include?("/organisations") && path.include?("/users")) || path.include?("/users/")
end end
def subnav_logs_path?(path) def subnav_lettings_logs_path?(path)
path.include?("/organisations") && path.include?("/lettings-logs") path.include?("/organisations") && path.include?("/lettings-logs")
end end
def subnav_sales_logs_path?(path)
path.include?("/organisations") && path.include?("/sales-logs")
end
def subnav_details_path?(path) def subnav_details_path?(path)
path.include?("/organisations") && path.include?("/details") path.include?("/organisations") && path.include?("/details")
end end

3
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_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 :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_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param) } scope :search_by, ->(param) { search_by_name(param) }

21
app/views/organisation_relationships/_housing_provider_list.erb

@ -0,0 +1,21 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= 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 %>
</section>

19
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 } %>
<p class="govuk-body">Your organisation can submit logs for its housing providers.</p>
<% if @total_count == 0 %>
<p class="govuk-body">You do not currently have any housing providers.</p>
<% 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 %>

25
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),
) %>
<h2 class="govuk-visually-hidden">Housing Providers</h2>
<% end %>
<p class="govuk-body">This organisation can submit logs for its housing providers.</p>
<% if @total_count == 0 %>
<p class="govuk-body">This organisation does not currently have any housing providers.</p>
<% 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 %>

1
config/routes.rb

@ -80,6 +80,7 @@ Rails.application.routes.draw do
get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation" get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation"
get "schemes", to: "organisations#schemes" get "schemes", to: "organisations#schemes"
get "managing-agents", to: "organisation_relationships#managing_agents" get "managing-agents", to: "organisation_relationships#managing_agents"
get "housing-providers", to: "organisation_relationships#housing_providers"
end end
end end

Loading…
Cancel
Save