diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 7b13353f6..0d3ede8bb 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -15,13 +15,9 @@ class LocationsController < ApplicationController end def new - @location = if params[:referrer] == "new_scheme" && @scheme.locations.present? - @scheme.locations.first - else - Location.new(scheme: @scheme) - end + @location = Location.new(scheme: @scheme) @location.save! - redirect_to scheme_location_postcode_path(@scheme, @location, referrer: params[:referrer]) + redirect_to scheme_location_postcode_path(@scheme, @location, route: params[:route]) end def postcode @@ -32,11 +28,11 @@ class LocationsController < ApplicationController if @location.valid?(: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]) + redirect_to scheme_location_local_authority_path(@scheme, @location, route: params[:route], referrer: params[:referrer]) elsif params[:referrer] == "check_answers" - redirect_to scheme_location_check_answers_path(@scheme, @location) + redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) else - redirect_to scheme_location_name_path(@scheme, @location, referrer: params[:referrer]) + redirect_to scheme_location_name_path(@scheme, @location, route: params[:route]) end else render :postcode, status: :unprocessable_entity @@ -50,10 +46,10 @@ class LocationsController < ApplicationController @location.location_code = Location.local_authorities.key(params[:location][:location_admin_district]) if @location.valid?(:location_admin_district) @location.save! - if params[:referrer] == "check_answers" - redirect_to scheme_location_check_answers_path(@scheme, @location) + if params[:referrer] == "check_answers" || params[:referrer] == "check_local_authority" + redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) else - redirect_to scheme_location_name_path(@scheme, @location, referrer: params[:referrer]) + redirect_to scheme_location_name_path(@scheme, @location, route: params[:route]) end else render :local_authority, status: :unprocessable_entity @@ -68,11 +64,11 @@ class LocationsController < ApplicationController @location.save! case params[:referrer] when "check_answers" - redirect_to scheme_location_check_answers_path(@scheme, @location) + redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) when "details" redirect_to scheme_location_path(@scheme, @location) else - redirect_to scheme_location_units_path(@scheme, @location, referrer: params[:referrer]) + redirect_to scheme_location_units_path(@scheme, @location, route: params[:route]) end else render :name, status: :unprocessable_entity @@ -86,9 +82,9 @@ class LocationsController < ApplicationController if @location.valid?(:units) @location.save! if params[:referrer] == "check_answers" - redirect_to scheme_location_check_answers_path(@scheme, @location) + redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) else - redirect_to scheme_location_type_of_unit_path(@scheme, @location, referrer: params[:referrer]) + redirect_to scheme_location_type_of_unit_path(@scheme, @location, route: params[:route]) end else render :units, status: :unprocessable_entity @@ -102,9 +98,9 @@ class LocationsController < ApplicationController if @location.valid?(:type_of_unit) @location.save! if params[:referrer] == "check_answers" - redirect_to scheme_location_check_answers_path(@scheme, @location) + redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) else - redirect_to scheme_location_mobility_standards_path(@scheme, @location, referrer: params[:referrer]) + redirect_to scheme_location_mobility_standards_path(@scheme, @location, route: params[:route]) end else render :type_of_unit, status: :unprocessable_entity @@ -118,9 +114,9 @@ class LocationsController < ApplicationController if @location.valid?(:mobility_type) @location.save! if params[:referrer] == "check_answers" - redirect_to scheme_location_check_answers_path(@scheme, @location) + redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) else - redirect_to scheme_location_availability_path(@scheme, @location, referrer: params[:referrer]) + redirect_to scheme_location_availability_path(@scheme, @location, route: params[:route]) end else render :mobility_standards, status: :unprocessable_entity @@ -138,7 +134,7 @@ class LocationsController < ApplicationController @location.startdate = Time.zone.local(year.to_i, month.to_i, day.to_i) if @location.valid?(:startdate) @location.save! - redirect_to scheme_location_check_answers_path(@scheme, @location, referrer: params[:referrer]) + redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) else render :availability, status: :unprocessable_entity end @@ -157,6 +153,8 @@ class LocationsController < ApplicationController def check_answers if params[:location].present? + @location.confirmed = true + @location.save! flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" redirect_to scheme_locations_path(@scheme) end diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index fd5c1a2c1..fae591445 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -229,7 +229,7 @@ private when "secondary-client-group" scheme_support_path(@scheme) when "support" - new_scheme_location_path(@scheme, referrer: "new_scheme") + scheme_check_answers_path(@scheme) when "details" if @scheme.arrangement_type_before_type_cast == "D" scheme_primary_client_group_path(@scheme) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 1d4a1a9aa..709bbacd6 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -16,18 +16,6 @@ module CheckAnswersHelper !scheme.confirmed? || editable_attributes.include?(attribute_name) end - def get_location_change_link_href_postcode(scheme, location) - if location.confirmed? - scheme_location_path(scheme_id: scheme.id, id: location.id) - else - edit_scheme_location_path(scheme_id: scheme.id, id: location.id) - end - end - - def get_location_change_link_href_location_admin_district(scheme, location) - scheme_location_edit_local_authority_path(scheme_id: scheme.id, location_id: location.id) - end - def any_questions_have_summary_card_number?(subsection, lettings_log) subsection.applicable_questions(lettings_log).map(&:check_answers_card_number).compact.length.positive? end diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 14d10668f..b775e8ec0 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -56,19 +56,19 @@ module LocationsHelper def location_edit_path(location, page) case page when "postcode" - scheme_location_postcode_path(location.scheme, location, referrer: "check_answers") + scheme_location_postcode_path(location.scheme, location, referrer: "check_answers", route: params[:route]) when "name" - scheme_location_name_path(location.scheme, location, referrer: "check_answers") + scheme_location_name_path(location.scheme, location, referrer: "check_answers", route: params[:route]) when "location_admin_district" - scheme_location_local_authority_path(location.scheme, location, referrer: "check_answers") + scheme_location_local_authority_path(location.scheme, location, referrer: "check_local_authority", route: params[:route]) when "units" - scheme_location_units_path(location.scheme, location, referrer: "check_answers") + scheme_location_units_path(location.scheme, location, referrer: "check_answers", route: params[:route]) when "type_of_unit" - scheme_location_type_of_unit_path(location.scheme, location, referrer: "check_answers") + scheme_location_type_of_unit_path(location.scheme, location, referrer: "check_answers", route: params[:route]) when "mobility_standards" - scheme_location_mobility_standards_path(location.scheme, location, referrer: "check_answers") + scheme_location_mobility_standards_path(location.scheme, location, referrer: "check_answers", route: params[:route]) when "availability" - scheme_location_availability_path(location.scheme, location, referrer: "check_answers") + scheme_location_availability_path(location.scheme, location, referrer: "check_answers", route: params[:route]) end end diff --git a/app/helpers/tab_nav_helper.rb b/app/helpers/tab_nav_helper.rb index 1d42332f9..3c61c9de0 100644 --- a/app/helpers/tab_nav_helper.rb +++ b/app/helpers/tab_nav_helper.rb @@ -11,17 +11,6 @@ module TabNavHelper [govuk_link_to(link_text, link, method: :patch), "Location #{location.name}"].join("\n") end - def location_cell_location_admin_district(location, link) - la = location.location_admin_district - if location.confirmed? - la - elsif la - govuk_link_to(la, link, method: :patch) - else - govuk_link_to("Select local authority", link, method: :patch) - end - end - def scheme_cell(scheme) link_text = scheme.service_name link = scheme.confirmed? ? scheme : scheme_check_answers_path(scheme) diff --git a/app/views/locations/availability.erb b/app/views/locations/availability.erb index 702ea9258..264c81869 100644 --- a/app/views/locations/availability.erb +++ b/app/views/locations/availability.erb @@ -3,11 +3,11 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_mobility_standards_path(@scheme, @location, referrer: params[:referrer]), + href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location, route: params[:route]) : scheme_location_mobility_standards_path(@scheme, @location, route: params[:route]), ) %> <% end %> -<%= form_for(@location, method: :patch, url: scheme_location_availability_path(@scheme, @location, referrer: params[:referrer])) do |f| %> +<%= form_for(@location, method: :patch, url: scheme_location_availability_path(@scheme, @location, route: params[:route], referrer: params[:referrer])) do |f| %>