From 75e6760a140cc83dedcac5f30d621e72a1b5c200 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 24 Nov 2022 17:03:31 +0000 Subject: [PATCH] feat: add check answers page, continue updating flow --- app/controllers/locations_controller.rb | 24 +++++++++--- app/helpers/locations_helper.rb | 37 ++++++++++++++----- app/views/locations/check_answers.html.erb | 30 +++++++++++++++ .../locations/mobility_standards.html.erb | 2 +- app/views/locations/name.html.erb | 4 +- app/views/locations/postcode.html.erb | 4 +- app/views/locations/show.html.erb | 4 +- app/views/locations/startdate.html.erb | 4 +- app/views/locations/type_of_unit.html.erb | 4 +- app/views/locations/units.html.erb | 4 +- config/routes.rb | 4 +- 11 files changed, 92 insertions(+), 29 deletions(-) create mode 100644 app/views/locations/check_answers.html.erb diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 0ef688570..3307bfa72 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -22,15 +22,29 @@ class LocationsController < ApplicationController def postcode; end - def name; end + def name + @location.update(location_params) + end - def type_of_unit; end + def units + @location.update(location_params) + end - def mobility_standards; end + def type_of_unit + @location.update(location_params) + end - def startdate; end + def mobility_standards + @location.update(location_params) + end - def check_answers; end + def startdate + @location.update(location_params) + end + + def check_answers + @location.update(location_params) + end def show; end diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index ca04826ba..5e47b9aa1 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -25,18 +25,18 @@ module LocationsHelper def display_location_attributes(location) base_attributes = [ - { name: "Postcode", value: location.postcode }, - { name: "Local authority", value: location.location_admin_district }, - { name: "Location name", value: location.name, edit: true }, - { name: "Total number of units at this location", value: location.units }, - { name: "Common type of unit", value: location.type_of_unit }, - { name: "Mobility type", value: location.mobility_type }, - { name: "Code", value: location.location_code }, - { name: "Availability", value: location_availability(location) }, + { name: "Postcode", value: location.postcode, attribute: "postcode" }, + { 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: "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: "startdate" }, ] if FeatureToggle.location_toggle_enabled? - base_attributes.append({ name: "Status", value: location.status }) + base_attributes.append({ name: "Status", value: location.status, attribute: "status" }) end base_attributes @@ -66,6 +66,25 @@ module LocationsHelper availability.strip end + def location_edit_path(location, page) + case page + when "postcode" + scheme_location_postcode_path(location.scheme, location) + when "name" + scheme_location_name_path(location.scheme, location) + when "location_admin_district" + scheme_location_edit_local_authority_path(location.scheme, location) + when "units" + scheme_location_units_path(location.scheme, location) + when "type_of_unit" + scheme_location_type_of_unit_path(location.scheme, location) + when "mobility_standards" + scheme_location_mobility_standards_path(location.scheme, location) + when "startdate" + scheme_location_startdate_path(location.scheme, location) + end + end + private def remove_overlapping_and_empty_periods(periods) diff --git a/app/views/locations/check_answers.html.erb b/app/views/locations/check_answers.html.erb new file mode 100644 index 000000000..c48a9f149 --- /dev/null +++ b/app/views/locations/check_answers.html.erb @@ -0,0 +1,30 @@ +<% title = @location.name %> +<% content_for :title, title %> + +<% content_for :before_content do %> + <%= govuk_back_link( + text: "Back", + href: scheme_locations_path(@scheme), + ) %> +<% end %> + +<%= render partial: "organisations/headings", locals: { main: "Check your answers", sub: "Add a location to #{@scheme.service_name}" } %> + +
+
+ <%= govuk_summary_list do |summary_list| %> + <% display_location_attributes(@location).each do |attr| %> + <% next if attr[:attribute] == "code" %> + <%= 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: location_edit_path(@location, attr[:attribute])) unless attr[:name] == "Status" %> + <% end %> + <% end %> + <% end %> +
+
+
+ <%= govuk_button_to "Add this location", scheme_locations_path(@scheme) %> + <%= govuk_button_link_to "Cancel", new_scheme_location_path(@scheme), secondary: true %> +
diff --git a/app/views/locations/mobility_standards.html.erb b/app/views/locations/mobility_standards.html.erb index f71b63359..f8120b2e4 100644 --- a/app/views/locations/mobility_standards.html.erb +++ b/app/views/locations/mobility_standards.html.erb @@ -23,7 +23,7 @@
<%= f.govuk_submit "Continue" %> - <%= govuk_link_to "Cancel", new_scheme_location_path(@scheme) %> + <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
diff --git a/app/views/locations/name.html.erb b/app/views/locations/name.html.erb index 5491108b4..0a400b45a 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: "/schemes/#{@scheme.id}/support", + href: scheme_locations_path(@scheme), ) %> <% end %> @@ -20,7 +20,7 @@
<%= f.govuk_submit "Continue" %> - <%= govuk_link_to "Cancel", new_scheme_location_path(@scheme) %> + <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
diff --git a/app/views/locations/postcode.html.erb b/app/views/locations/postcode.html.erb index dd1ab22b1..b238748b2 100644 --- a/app/views/locations/postcode.html.erb +++ b/app/views/locations/postcode.html.erb @@ -3,7 +3,7 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: "/schemes/#{@scheme.id}/support", + href: scheme_locations_path(@scheme), ) %> <% end %> @@ -21,7 +21,7 @@
<%= f.govuk_submit "Continue" %> - <%= govuk_link_to "Cancel", new_scheme_location_path(@scheme) %> + <%= 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 5ed049d08..cee41bd86 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -16,8 +16,8 @@ <% display_location_attributes(@location).each do |attr| %> <%= summary_list.row do |row| %> <% row.key { attr[:name] } %> - <% row.value { attr[:name].eql?("Status") ? status_tag(attr[:value]) : details_html(attr) } %> - <% row.action(text: "Change", href: scheme_location_edit_name_path(scheme_id: @scheme.id, location_id: @location.id)) if attr[:edit] %> + <% 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" %> <% end %> <% end %> <% end %> diff --git a/app/views/locations/startdate.html.erb b/app/views/locations/startdate.html.erb index 11df00aed..7c9e08dd5 100644 --- a/app/views/locations/startdate.html.erb +++ b/app/views/locations/startdate.html.erb @@ -3,7 +3,7 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: "/schemes/#{@scheme.id}/support", + href: scheme_locations_path(@scheme), ) %> <% end %> @@ -21,7 +21,7 @@
<%= f.govuk_submit "Continue" %> - <%= govuk_link_to "Cancel", new_scheme_location_path(@scheme) %> + <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
diff --git a/app/views/locations/type_of_unit.html.erb b/app/views/locations/type_of_unit.html.erb index 990245b64..947db1dc1 100644 --- a/app/views/locations/type_of_unit.html.erb +++ b/app/views/locations/type_of_unit.html.erb @@ -3,7 +3,7 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: "/schemes/#{@scheme.id}/support", + href: scheme_locations_path(@scheme), ) %> <% end %> @@ -22,7 +22,7 @@
<%= f.govuk_submit "Continue" %> - <%= govuk_link_to "Cancel", new_scheme_location_path(@scheme) %> + <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
diff --git a/app/views/locations/units.html.erb b/app/views/locations/units.html.erb index 5d1e1c677..11f854e3c 100644 --- a/app/views/locations/units.html.erb +++ b/app/views/locations/units.html.erb @@ -3,7 +3,7 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: "/schemes/#{@scheme.id}/support", + href: scheme_locations_path(@scheme), ) %> <% end %> @@ -22,7 +22,7 @@
<%= f.govuk_submit "Continue" %> - <%= govuk_link_to "Cancel", new_scheme_location_path(@scheme) %> + <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
diff --git a/config/routes.rb b/config/routes.rb index 2bdcedaf2..a50c41827 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -73,8 +73,8 @@ Rails.application.routes.draw do patch "mobility-standards", to: "locations#mobility_standards" get "startdate", to: "locations#startdate" patch "startdate", to: "locations#startdate" - get "check-answers", to: "locations#show" - patch "check-answers", to: "locations#show" + get "check-answers", to: "locations#check_answers" + patch "check-answers", to: "locations#check_answers" patch "new-deactivation", to: "locations#new_deactivation" patch "deactivate", to: "locations#deactivate" patch "reactivate", to: "locations#reactivate"