Browse Source
* wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break Co-authored-by: Jack S <jacopo.scotti@softwire.com>pull/951/head
natdeanlewissoftwire
2 years ago
committed by
GitHub
23 changed files with 325 additions and 44 deletions
@ -0,0 +1,36 @@
|
||||
class OrganisationRelationshipsController < ApplicationController |
||||
include Pagy::Backend |
||||
include Modules::SearchFilter |
||||
|
||||
before_action :authenticate_user! |
||||
before_action :authenticate_scope! |
||||
|
||||
def housing_providers |
||||
housing_providers = organisation.housing_providers |
||||
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 |
||||
render "organisation_relationships/housing_providers", layout: "application" |
||||
end |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def organisation |
||||
@organisation ||= Organisation.find(params[:id]) |
||||
end |
||||
|
||||
def search_term |
||||
params["search"] |
||||
end |
||||
|
||||
def authenticate_scope! |
||||
if current_user.organisation != organisation |
||||
render_not_found |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,22 @@
|
||||
<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", |
||||
class: "govuk-!-text-align-right", |
||||
}) do %> |
||||
<%= govuk_link_to("Remove", "housing-providers/#{housing_provider.id}") %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
</section> |
@ -0,0 +1,24 @@
|
||||
<% item_label = format_label(@pagy.count, "housing providers") %> |
||||
<% title = "Housing Providers" %> |
||||
<% content_for :title, title %> |
||||
<% if current_user.support? %> |
||||
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> |
||||
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> |
||||
<h2 class="govuk-visually-hidden">Housing Providers</h2> |
||||
<p class="govuk-body">This organisation can submit logs for its housing providers.</p> |
||||
<% else %> |
||||
<%= 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> |
||||
<% end %> |
||||
|
||||
<% 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", 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) %> |
||||
<%= 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 %> |
@ -0,0 +1,5 @@
|
||||
class RenameManagingAgentsColumn < ActiveRecord::Migration[7.0] |
||||
def change |
||||
rename_column :organisations, :managing_agents, :managing_agents_label |
||||
end |
||||
end |
@ -0,0 +1,14 @@
|
||||
FactoryBot.define do |
||||
factory :organisation_relationship do |
||||
child_organisation { FactoryBot.create(:organisation) } |
||||
parent_organisation { FactoryBot.create(:organisation) } |
||||
|
||||
trait :owning do |
||||
relationship_type { OrganisationRelationship::OWNING } |
||||
end |
||||
|
||||
trait :managing do |
||||
relationship_type { OrganisationRelationship::MANAGING } |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue