Browse Source

refactor: simplify format response and paths and remove redundant rendering

pull/957/head
natdeanlewissoftwire 3 years ago
parent
commit
d5a5b91e57
  1. 25
      app/controllers/organisation_relationships_controller.rb
  2. 5
      app/views/organisation_relationships/housing_providers.html.erb
  3. 4
      app/views/organisation_relationships/managing_agents.html.erb

25
app/controllers/organisation_relationships_controller.rb

@ -9,48 +9,32 @@ class OrganisationRelationshipsController < ApplicationController
housing_providers = organisation.housing_providers housing_providers = organisation.housing_providers
unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term)
organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name) organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name)
respond_to do |format| respond_to :html
format.html do
@pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) @pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers)
@organisations = organisations @organisations = organisations
@searched = search_term.presence @searched = search_term.presence
@total_count = housing_providers.size @total_count = housing_providers.size
render "organisation_relationships/housing_providers", layout: "application"
end
end
end end
def managing_agents def managing_agents
managing_agents = organisation.managing_agents managing_agents = organisation.managing_agents
unpaginated_filtered_managing_agents = filtered_collection(managing_agents, search_term) unpaginated_filtered_managing_agents = filtered_collection(managing_agents, search_term)
organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name) organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name)
respond_to do |format| respond_to :html
format.html do
@pagy, @managing_agents = pagy(unpaginated_filtered_managing_agents) @pagy, @managing_agents = pagy(unpaginated_filtered_managing_agents)
@organisations = organisations @organisations = organisations
@searched = search_term.presence @searched = search_term.presence
@total_count = managing_agents.size @total_count = managing_agents.size
render "organisation_relationships/managing_agents", layout: "application"
end
end
end end
def add_housing_provider def add_housing_provider
@organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name) @organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name)
respond_to do |format| respond_to :html
format.html do
render "organisation_relationships/add_housing_provider", layout: "application"
end
end
end end
def add_managing_agent def add_managing_agent
@organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name) @organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name)
respond_to do |format| respond_to :html
format.html do
render "organisation_relationships/add_managing_agent", layout: "application"
end
end
end end
def create_housing_provider def create_housing_provider
@ -95,7 +79,6 @@ class OrganisationRelationshipsController < ApplicationController
def remove_housing_provider def remove_housing_provider
@target_organisation_id = target_organisation_id @target_organisation_id = target_organisation_id
render "organisation_relationships/remove_housing_provider", layout: "application"
end end
def delete_housing_provider def delete_housing_provider

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

@ -51,10 +51,7 @@
<p class="govuk-body">You do not currently have any housing providers.</p> <p class="govuk-body">You do not currently have any housing providers.</p>
<% end %> <% end %>
<% end %> <% end %>
<% if current_user.support? || current_user.data_coordinator? %>
<% if current_user.support? %>
<%= govuk_button_link_to "Add a housing provider", housing_providers_add_organisation_path(organisation_id: @organisation.id), html: { method: :get } %>
<% elsif current_user.data_coordinator? %>
<%= govuk_button_link_to "Add a housing provider", housing_providers_add_organisation_path, html: { method: :get } %> <%= govuk_button_link_to "Add a housing provider", housing_providers_add_organisation_path, html: { method: :get } %>
<% end %> <% end %>
<% if @total_count != 0 %> <% if @total_count != 0 %>

4
app/views/organisation_relationships/managing_agents.html.erb

@ -38,9 +38,7 @@
<p class="govuk-body">This organisation does not currently have any managing agents.</p> <p class="govuk-body">This organisation does not currently have any managing agents.</p>
<% end %> <% end %>
<% end %> <% end %>
<% if current_user.support? %> <% if current_user.support? || current_user.data_coordinator? %>
<%= govuk_button_link_to "Add a managing agent", managing_agents_add_organisation_path(organisation_id: @organisation.id), html: { method: :get } %>
<% elsif current_user.data_coordinator? %>
<%= govuk_button_link_to "Add a managing agent", managing_agents_add_organisation_path, html: { method: :get } %> <%= govuk_button_link_to "Add a managing agent", managing_agents_add_organisation_path, html: { method: :get } %>
<% end %> <% end %>
<% if @total_count != 0 %> <% if @total_count != 0 %>

Loading…
Cancel
Save