Browse Source

feat: add different user behaviours

CLDC-1661-new-page-for-housing-providers
natdeanlewissoftwire 2 years ago
parent
commit
884daf540f
  1. 12
      app/controllers/organisations_controller.rb
  2. 21
      app/helpers/navigation_items_helper.rb
  3. 20
      app/views/housing_providers/_housing_provider_list.html.erb
  4. 4
      app/views/housing_providers/index.html.erb
  5. 25
      app/views/organisations/housing_providers.html.erb
  6. 1
      config/routes.rb

12
app/controllers/organisations_controller.rb

@ -135,6 +135,18 @@ class OrganisationsController < ApplicationController
end
end
def housing_providers
respond_to do |format|
format.html do
all_organisations = Organisation.order(:name)
@pagy, @organisations = pagy(filtered_collection(all_organisations, search_term))
@searched = search_term.presence
@total_count = all_organisations.size
render "housing_providers", layout: "application"
end
end
end
private
def org_params

21
app/helpers/navigation_items_helper.rb

@ -9,7 +9,6 @@ module NavigationItemsHelper
NavigationItem.new("Lettings logs", lettings_logs_path, lettings_logs_current?(path)),
FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", sales_logs_path, sales_logs_current?(path)) : nil,
NavigationItem.new("Schemes", "/schemes", supported_housing_schemes_current?(path)),
NavigationItem.new("Housing providers", "/housing-providers", housing_providers_current?(path)),
].compact
elsif current_user.data_coordinator? && current_user.organisation.holds_own_stock?
[
@ -25,6 +24,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", subnav_housing_providers_path?(path)),
].compact
end
end
@ -32,18 +32,19 @@ 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)),
].compact
else
[
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("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", "/organisations/#{current_organisation_id}/housing-providers", subnav_housing_providers_path?(path)),
].compact
end
end
@ -76,8 +77,8 @@ private
def organisations_current?(path)
path == "/organisations" || path.include?("/organisations/")
end
def housing_providers_current?(path)
path == "/housing-providers"
def subnav_housing_providers_path?(path)
path.include?("/organisations") && path.include?("/housing-providers")
end
def subnav_supported_housing_schemes_path?(path)
@ -88,10 +89,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

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

@ -0,0 +1,20 @@
<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 %>
<% @organisations.each do |organisation| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: organisation.name) %>
<% row.cell(html_attributes: {
scope: "row",
}) do %>
<%= govuk_link_to("Remove", "organisations/#{organisation.id}") %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</section>

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

@ -7,7 +7,7 @@
<p>Your organisation can submit logs for its housing providers.</p>
<% if current_user.support? %>
<% if current_user.data_coordinator? || current_user.support? %>
<%= govuk_button_link_to "Add a housing provider", new_housing_provider_path, html: { method: :get } %>
<% end %>
@ -15,5 +15,5 @@
<%= govuk_section_break(visible: true, size: "m") %>
<%= render partial: "organisations/organisation_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<%= 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" } %>

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

@ -0,0 +1,25 @@
<% item_label = format_label(@pagy.count, "organisation") %>
<% 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">Users</h2>
<% 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) %>
<%= 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" } %>

1
config/routes.rb

@ -79,6 +79,7 @@ Rails.application.routes.draw do
post "logs/email-csv", to: "organisations#email_csv"
get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation"
get "schemes", to: "organisations#schemes"
get "housing-providers", to: "organisations#housing_providers"
end
end

Loading…
Cancel
Save