From 625cbc2f825fd63a76033931e871f5bebf03750e Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 28 Nov 2022 17:11:24 +0000 Subject: [PATCH] feat: add local_authority page (currenlty separate from edit_local_authority to avoid conflict with add location to newly created scheme path, to be fixed later). also copy and routing updates --- app/controllers/locations_controller.rb | 23 +++++++++---- app/helpers/locations_helper.rb | 2 +- app/views/locations/local_authority.html.erb | 35 ++++++++++++++++++++ app/views/locations/postcode.html.erb | 2 +- config/locales/en.yml | 6 ++-- config/routes.rb | 2 ++ 6 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 app/views/locations/local_authority.html.erb diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 5e51670d5..233b3f383 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -24,6 +24,21 @@ class LocationsController < ApplicationController if params[:location].present? @location.postcode = params[:location][:postcode] @location.save! + if @location.location_code.blank? || @location.location_admin_district.blank? + redirect_to scheme_location_local_authority_path(@scheme, @location, referrer: params[:referrer]) + elsif params[:referrer] == "check_answers" + redirect_to scheme_location_check_answers_path(@scheme, @location) + else + redirect_to scheme_location_name_path(@scheme, @location) + end + end + end + + def local_authority + if params[:location].present? + @location.location_admin_district = params[:location][:location_admin_district] + @location.location_code = Location.local_authorities.key(params[:location][:location_admin_district]) + @location.save! if params[:referrer] == "check_answers" redirect_to scheme_location_check_answers_path(@scheme, @location) else @@ -158,7 +173,7 @@ class LocationsController < ApplicationController @location = Location.new(location_params) if @location.save if @location.location_admin_district.nil? - redirect_to(scheme_location_edit_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location])) + redirect_to(scheme_location_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location])) elsif location_params[:add_another_location] == "Yes" redirect_to new_scheme_location_path(@scheme) else @@ -184,10 +199,6 @@ class LocationsController < ApplicationController render_not_found and return unless @location && @scheme end - def edit_local_authority - render_not_found and return unless @location && @scheme - end - def update render_not_found and return unless @location && @scheme @@ -204,7 +215,7 @@ class LocationsController < ApplicationController case page when "edit" if @location.location_admin_district.nil? - redirect_to(scheme_location_edit_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location])) + redirect_to(scheme_location_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location])) elsif location_params[:add_another_location] == "Yes" redirect_to(new_scheme_location_path(@location.scheme)) else diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index dcc6c028b..14d10668f 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -60,7 +60,7 @@ module LocationsHelper when "name" scheme_location_name_path(location.scheme, location, referrer: "check_answers") when "location_admin_district" - scheme_location_edit_local_authority_path(location.scheme, location, referrer: "check_answers") + scheme_location_local_authority_path(location.scheme, location, referrer: "check_answers") when "units" scheme_location_units_path(location.scheme, location, referrer: "check_answers") when "type_of_unit" diff --git a/app/views/locations/local_authority.html.erb b/app/views/locations/local_authority.html.erb new file mode 100644 index 000000000..493c4f9cf --- /dev/null +++ b/app/views/locations/local_authority.html.erb @@ -0,0 +1,35 @@ +<% content_for :title, "Add a location to this scheme" %> + +<% content_for :before_content do %> + <%= govuk_back_link( + text: "Back", + href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_postcode_path(@scheme), + ) %> +<% end %> + +<%= form_for(@location, method: :patch, url: scheme_location_local_authority_path(@scheme, @location, referrer: params[:referrer])) do |f| %> +
+
+ <%= f.govuk_error_summary %> + + <%= render partial: "organisations/headings", locals: { main: "What is the local authority of #{@location.postcode}?", sub: @scheme.service_name } %> + + <%= f.govuk_collection_select :location_admin_district, + local_authorities_selection, + :name, + :name, + label: { text: "Start typing to search for your local authority" }, + "data-controller": %w[conditional-filter accessible-autocomplete] %> + +
+ <% if params[:referrer] == "check_answers" %> + <%= f.govuk_submit "Save changes" %> + <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %> + <% else %> + <%= f.govuk_submit "Save and continue" %> + <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> + <% end %> +
+
+
+<% end %> diff --git a/app/views/locations/postcode.html.erb b/app/views/locations/postcode.html.erb index 0690e3254..c7c5ccad4 100644 --- a/app/views/locations/postcode.html.erb +++ b/app/views/locations/postcode.html.erb @@ -15,7 +15,7 @@ <%= render partial: "organisations/headings", locals: { main: I18n.t("questions.location.postcode"), sub: "Add a location to #{@scheme.service_name}" } %> <%= f.govuk_text_field :postcode, - label: { size: "m" }, + label: nil, hint: { text: I18n.t("hints.location.postcode") }, width: 5 %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 1398253c3..674d31485 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -393,9 +393,9 @@ en: descriptions: location: mobility_type: - W: "The majority of units are suitable for someone who uses a wheelchair and offer the full use of all rooms and facilities." - A: "For example, the majority of units have been fitted with stairlifts, ramps, level access showers or grab rails." - N: "The majority of units are not designed to wheelchair-user standards or fitted with any equipment and adaptations." + W: "Suitable for someone who uses a wheelchair and offers the full use of all rooms and facilities." + A: "Fitted with stairlifts, ramps, level access showers or grab rails." + N: "Not designed to wheelchair-user standards or fitted with any equipment or adaptations." hints: location: diff --git a/config/routes.rb b/config/routes.rb index b4b35d66e..72138f76a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,6 +66,8 @@ Rails.application.routes.draw do get "new-reactivation", to: "locations#new_reactivation" get "postcode", to: "locations#postcode" patch "postcode", to: "locations#postcode" + get "local-authority", to: "locations#local_authority" + patch "local-authority", to: "locations#local_authority" get "name", to: "locations#name" patch "name", to: "locations#name" get "units", to: "locations#units"