Browse Source

feat: add core removal functionality

pull/957/head
natdeanlewissoftwire 3 years ago
parent
commit
a5786c2544
  1. 18
      app/controllers/organisation_relationships_controller.rb
  2. 2
      app/views/organisation_relationships/_housing_provider_list.erb
  3. 18
      app/views/organisation_relationships/housing_providers.html.erb
  4. 23
      app/views/organisation_relationships/remove_housing_provider.html.erb
  5. 2
      config/routes.rb

18
app/controllers/organisation_relationships_controller.rb

@ -66,6 +66,20 @@ class OrganisationRelationshipsController < ApplicationController
@resource.save! @resource.save!
end end
def remove_housing_provider
render "organisation_relationships/remove_housing_provider", layout: "application"
end
def delete_housing_provider
organisation_relationship_to_remove_id = OrganisationRelationship.find_by(child_organisation_id: @organisation.id, parent_organisation_id: organisation_to_remove_id, relationship_type: OrganisationRelationship::OWNING).id
delete(organisation_relationship_to_remove_id)
redirect_to housing_providers_organisation_path(removed_organisation_id: organisation_to_remove_id)
end
def delete(organisation_relationship_to_remove_id)
OrganisationRelationship.destroy(organisation_relationship_to_remove_id)
end
private private
def organisation def organisation
@ -76,6 +90,10 @@ private
params["organisation"]["related_organisation_id"] params["organisation"]["related_organisation_id"]
end end
def organisation_to_remove_id
params["organisation_to_remove_id"]
end
def search_term def search_term
params["search"] params["search"]
end end

2
app/views/organisation_relationships/_housing_provider_list.erb

@ -12,7 +12,7 @@
scope: "row", scope: "row",
class: "govuk-!-text-align-right", class: "govuk-!-text-align-right",
}) do %> }) do %>
<%= govuk_link_to("Remove", "housing-providers/#{housing_provider.id}") %> <%= govuk_link_to("Remove", housing_providers_remove_organisation_path(organisation_to_remove_id: housing_provider.id)) %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

18
app/views/organisation_relationships/housing_providers.html.erb

@ -10,6 +10,15 @@
notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of your housing providers") notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of your housing providers")
end %> end %>
<% end %> <% end %>
<% if params["removed_organisation_id"] %>
<%= govuk_notification_banner(
title_text: "Success",
success: true, title_heading_level: 3,
title_id: "swanky-notifications"
) do |notification_banner|
notification_banner.heading(text: "#{Organisation.find(params['removed_organisation_id']).name} is no longer one of your housing providers")
end %>
<% end %>
<% end %> <% end %>
<% if current_user.support? %> <% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
@ -24,6 +33,15 @@
notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of this organisation's housing providers") notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of this organisation's housing providers")
end %> end %>
<% end %> <% end %>
<% if params["removed_organisation_id"] %>
<%= govuk_notification_banner(
title_text: "Success",
success: true, title_heading_level: 3,
title_id: "swanky-notifications"
) do |notification_banner|
notification_banner.heading(text: "#{Organisation.find(params['removed_organisation_id']).name} is no longer one of this organisation housing providers")
end %>
<% end %>
<p class="govuk-body">This organisation can submit logs for its housing providers.</p> <p class="govuk-body">This organisation can submit logs for its housing providers.</p>
<% if @total_count == 0 %> <% if @total_count == 0 %>
<p class="govuk-body">This organisation does not currently have any housing providers.</p> <p class="govuk-body">This organisation does not currently have any housing providers.</p>

23
app/views/organisation_relationships/remove_housing_provider.html.erb

@ -0,0 +1,23 @@
<% @organisation_to_remove_id = params['organisation_to_remove_id'] %>
<%= form_with url: housing_providers_organisation_path(organisation_to_remove_id: @organisation_to_remove_id), method: "delete", local: true do |f| %>
<% 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">Remove Housing Provider</h2>
<% end %>
<% @housing_provider = Organisation.find(@organisation_to_remove_id) %>
<% if current_user.support? %>
<%= govuk_back_link(href: :back) %>
<%= render partial: "organisations/headings", locals: { main: "You are removing '#{@housing_provider.name}' from this organisation's housing providers", sub: nil } %>
<% else %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<% end %>
<%= render partial: "organisations/headings", locals: { main: "You are removing #{@housing_provider.name} from your organisation's housing providers", sub: nil } %>
<% end %>
<%= govuk_warning_text text: "You will no longer be able to submit logs for #{@housing_provider.name}" %>
<div class="govuk-button-group">
<%= f.govuk_submit "Confirm" %>
<%= govuk_button_link_to "Cancel", housing_providers_organisation_path(current_user.organisation), html: { method: :get }, secondary: true %>
</div>
<% end %>

2
config/routes.rb

@ -81,7 +81,9 @@ Rails.application.routes.draw do
get "schemes", to: "organisations#schemes" get "schemes", to: "organisations#schemes"
get "housing-providers", to: "organisation_relationships#housing_providers" get "housing-providers", to: "organisation_relationships#housing_providers"
get "housing-providers/add", to: "organisation_relationships#add_housing_provider" get "housing-providers/add", to: "organisation_relationships#add_housing_provider"
get "housing-providers/remove", to: "organisation_relationships#remove_housing_provider"
post "housing-providers", to: "organisation_relationships#create_housing_provider" post "housing-providers", to: "organisation_relationships#create_housing_provider"
delete "housing-providers", to: "organisation_relationships#delete_housing_provider"
get "managing-agents", to: "organisation_relationships#managing_agents" get "managing-agents", to: "organisation_relationships#managing_agents"
end end
end end

Loading…
Cancel
Save