From 923c93121589e7e9e38fa3c691b8416ae4110864 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 28 Nov 2022 10:52:11 +0000 Subject: [PATCH] feat: add controller and details linking and lint --- app/controllers/locations_controller.rb | 29 ++++++++++++++++++++----- app/helpers/locations_helper.rb | 2 +- app/views/locations/name.html.erb | 5 ++++- app/views/locations/show.html.erb | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index b483560f7..5e51670d5 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -36,7 +36,14 @@ class LocationsController < ApplicationController if params[:location].present? @location.name = params[:location][:name] @location.save! - redirect_to scheme_location_units_path(@scheme, @location) + case params[:referrer] + when "check_answers" + redirect_to scheme_location_check_answers_path(@scheme, @location) + when "details" + redirect_to scheme_location_path(@scheme, @location) + else + redirect_to scheme_location_units_path(@scheme, @location) + end end end @@ -44,7 +51,11 @@ class LocationsController < ApplicationController if params[:location].present? @location.units = params[:location][:units] @location.save! - redirect_to scheme_location_type_of_unit_path(@scheme, @location) + if params[:referrer] == "check_answers" + redirect_to scheme_location_check_answers_path(@scheme, @location) + else + redirect_to scheme_location_type_of_unit_path(@scheme, @location) + end end end @@ -52,7 +63,11 @@ class LocationsController < ApplicationController if params[:location].present? @location.type_of_unit = params[:location][:type_of_unit] @location.save! - redirect_to scheme_location_mobility_standards_path(@scheme, @location) + if params[:referrer] == "check_answers" + redirect_to scheme_location_check_answers_path(@scheme, @location) + else + redirect_to scheme_location_mobility_standards_path(@scheme, @location) + end end end @@ -60,7 +75,11 @@ class LocationsController < ApplicationController if params[:location].present? @location.mobility_type = params[:location][:mobility_type] @location.save! - redirect_to scheme_location_availability_path(@scheme, @location) + if params[:referrer] == "check_answers" + redirect_to scheme_location_check_answers_path(@scheme, @location) + else + redirect_to scheme_location_availability_path(@scheme, @location) + end end end @@ -79,7 +98,7 @@ class LocationsController < ApplicationController 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" + flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" redirect_to scheme_locations_path(@scheme, @location) end end diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 5ae0a0d5e..dcc6c028b 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -29,7 +29,7 @@ module LocationsHelper { name: "Location name", value: location.name, attribute: "name" }, { name: "Local authority", value: location.location_admin_district, attribute: "location_admin_district" }, { name: "Number of units", value: location.units, attribute: "units" }, - { name: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit"}, + { name: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit" }, { name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" }, { name: "Code", value: location.location_code, attribute: "location_code" }, { name: "Availability", value: location_availability(location), attribute: "availability" }, diff --git a/app/views/locations/name.html.erb b/app/views/locations/name.html.erb index 9b07523cf..5f69868c8 100644 --- a/app/views/locations/name.html.erb +++ b/app/views/locations/name.html.erb @@ -3,7 +3,7 @@ <% 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, @location), + href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : params[:referrer] == "details" ? scheme_location_path(@scheme, @location) : scheme_location_postcode_path(@scheme, @location), ) %> <% end %> @@ -22,6 +22,9 @@ <% if params[:referrer] == "check_answers" %> <%= f.govuk_submit "Save changes" %> <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %> + <% elsif params[:referrer] == "details" %> + <%= f.govuk_submit "Save changes" %> + <%= govuk_button_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %> <% else %> <%= f.govuk_submit "Save and continue" %> <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index cee41bd86..4bda97205 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -17,7 +17,7 @@ <%= summary_list.row do |row| %> <% row.key { attr[:name] } %> <% row.value { attr[:attribute].eql?("status") ? status_tag(attr[:value]) : details_html(attr) } %> - <% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location)) if attr[:attribute] == "name" %> + <% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "name" %> <% end %> <% end %> <% end %>