Browse Source

feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC

pull/954/head
natdeanlewissoftwire 3 years ago
parent
commit
3b9f09cacf
  1. 12
      app/controllers/organisation_relationships_controller.rb
  2. 16
      app/views/organisation_relationships/_related_organisation_select_question.html.erb
  3. 24
      app/views/organisation_relationships/add_housing_provider.html.erb
  4. 2
      config/routes.rb
  5. 2
      spec/requests/organisations_controller_spec.rb

12
app/controllers/organisation_relationships_controller.rb

@ -19,18 +19,22 @@ class OrganisationRelationshipsController < ApplicationController
end end
def add_housing_provider def add_housing_provider
housing_providers = organisation.housing_providers organisations = Organisation.all
unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term)
respond_to do |format| respond_to do |format|
format.html do format.html do
@pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) @organisations = organisations
@searched = search_term.presence @searched = search_term.presence
@total_count = housing_providers.size
render "organisation_relationships/add_housing_provider", layout: "application" render "organisation_relationships/add_housing_provider", layout: "application"
end end
end end
end end
def create
@resource = OrganisationRelationship.new(child_organisation_id: 3, parent_organisation_id: 4, relationship_type: 0)
@resource.save!
redirect_to housing_providers_organisation_path
end
private private
def organisation def organisation

16
app/views/organisation_relationships/_related_organisation_select_question.html.erb

@ -1,15 +1,9 @@
<% answers = [OpenStruct.new(id: 1, name: "test1", resource: nil), OpenStruct.new(id: 2, name: "test2", resource: nil)] %> <% answers = question.answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } %>
<%= f.govuk_select(question.id.to_sym, <%= f.govuk_select(question.id.to_sym,
label: legend(question, page_header, conditional), "data-controller": "accessible-autocomplete",) do %>
"data-controller": "accessible-autocomplete",
caption: caption(caption_text, page_header, conditional),
hint: { text: question.hint_text&.html_safe }) do %>
<% answers.each do |answer| %> <% answers.each do |answer| %>
<option value="<%= answer.id %>" <option value="<%= answer.id %>">
data-synonyms="<%= question.answer_option_synonyms(answer.resource) %>" <%= answer.name %>
data-append="<%= question.answer_option_append(answer.resource) %>" </option>
data-hint="<%= question.answer_option_hint(answer.resource) %>"
<%= question.answer_selected?(@log, answer) ? "selected" : "" %>
<%= answer.id == "" ? "disabled" : "" %>><%= answer.name || answer.resource %></option>
<% end %> <% end %>
<% end %> <% end %>

24
app/views/organisation_relationships/add_housing_provider.html.erb

@ -1,9 +1,25 @@
<%= form_with model: nil, url: housing_providers_organisation_path, method: "post", local: true do |f| %>
<%= form_with model: nil, url: housing_providers_add_organisation_path, method: "post", local: true do |f| %>
<%# remove_other_page_errors(@log, @page) %> <%# remove_other_page_errors(@log, @page) %>
<%#= f.govuk_error_summary %> <%#= f.govuk_error_summary %>
<%= render partial: "organisations/headings", locals: { main: "What is the name of your housing provider?", sub: nil } %> <% if current_user.support? %>
<%#= render partial: "form/#{question.type}_question", locals: { question:, caption_text: @subsection.label, page_header: @page.header, lettings_log: @log, f:, conditional: false } %> <%= 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">Add Housing Provider</h2>
<% end %>
<% answer_options = { "" => "Select an option" } %>
<% @organisations.each do |organisation| %>
<% answer_options[organisation.id] = organisation.name unless organisation.id == @organisation.id %>
<% end %>
<% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's housing provider?", sub: nil } %>
<p class="govuk-body">Start typing to search for a housing provider</p>
<% else %>
<%= render partial: "organisations/headings", locals: { main: "What is the name of your housing provider?", sub: nil } %>
<p class="govuk-body">Start typing to search for your housing provider</p>
<% end %>
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: {
question: Form::Question.new("", {"answer_options" => answer_options}, nil),
f: } %>
<%= f.govuk_submit "Add" %> <%= f.govuk_submit "Add" %>
<%= govuk_details(summary_text: "Can't find the housing provider you're looking for?") do %> <%= govuk_details(summary_text: "Can't find the housing provider you're looking for?") do %>
<ul class="govuk-list govuk-list--bullet"> <ul class="govuk-list govuk-list--bullet">

2
config/routes.rb

@ -81,7 +81,7 @@ 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"
post "housing-providers/add", to: "organisation_relationships#housing_providers" post "housing-providers", to: "organisation_relationships#create"
end end
end end

2
spec/requests/organisations_controller_spec.rb

@ -254,7 +254,7 @@ RSpec.describe OrganisationsController, type: :request do
expect(response.body).to include(user.email) expect(response.body).to include(user.email)
end end
it "shows hidden accesibility fields only for active users in the current user's organisation" do it "shows hidden accessibility fields only for active users in the current user's organisation" do
expected_case_row_log = "<span class=\"govuk-visually-hidden\">User </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{user.email}</span>" expected_case_row_log = "<span class=\"govuk-visually-hidden\">User </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{user.email}</span>"
unauthorized_case_row_log = "<span class=\"govuk-visually-hidden\">User </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{other_org_user.email}</span>" unauthorized_case_row_log = "<span class=\"govuk-visually-hidden\">User </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{other_org_user.email}</span>"
expect(CGI.unescape_html(response.body)).to include(expected_case_row_log) expect(CGI.unescape_html(response.body)).to include(expected_case_row_log)

Loading…
Cancel
Save