From 8099dc8ffa3c87d86e1858f0b842a43cca86362e Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 25 Nov 2022 12:49:58 +0000 Subject: [PATCH] feat: further flow work and flash notice, name tidying --- app/controllers/locations_controller.rb | 13 ++++-- app/helpers/locations_helper.rb | 6 +-- .../{startdate.html.erb => availability.erb} | 2 +- app/views/locations/check_answers.html.erb | 43 ++++++++++--------- config/routes.rb | 5 ++- 5 files changed, 40 insertions(+), 29 deletions(-) rename app/views/locations/{startdate.html.erb => availability.erb} (89%) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index a54766bb2..b5efe1e04 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -56,11 +56,11 @@ class LocationsController < ApplicationController if params[:location].present? @location.mobility_type = params[:location][:mobility_type] @location.save! - redirect_to scheme_location_startdate_path(@scheme, @location) + redirect_to scheme_location_availability_path(@scheme, @location) end end - def startdate + def availability if params[:location].present? day = params[:location]["startdate(3i)"] month = params[:location]["startdate(2i)"] @@ -71,7 +71,14 @@ class LocationsController < ApplicationController end end - def check_answers; end + 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, @location) + end + end def show; end diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 6d797e7fc..1073e18d7 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -32,7 +32,7 @@ module LocationsHelper { 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" }, + { name: "Availability", value: location_availability(location), attribute: "availability" }, ] if FeatureToggle.location_toggle_enabled? @@ -67,8 +67,8 @@ module LocationsHelper scheme_location_type_of_unit_path(location.scheme, location, referrer: "check_answers") when "mobility_standards" scheme_location_mobility_standards_path(location.scheme, location, referrer: "check_answers") - when "startdate" - scheme_location_startdate_path(location.scheme, location, referrer: "check_answers") + when "avaliability" + scheme_location_availability_path(location.scheme, location, referrer: "check_answers") end end diff --git a/app/views/locations/startdate.html.erb b/app/views/locations/availability.erb similarity index 89% rename from app/views/locations/startdate.html.erb rename to app/views/locations/availability.erb index 52b39058a..b7659f28d 100644 --- a/app/views/locations/startdate.html.erb +++ b/app/views/locations/availability.erb @@ -7,7 +7,7 @@ ) %> <% end %> -<%= form_for(@location, method: :patch, url: scheme_location_startdate_path(@scheme, @location)) do |f| %> +<%= form_for(@location, method: :patch, url: scheme_location_availability_path(@scheme, @location)) do |f| %>
<%= f.govuk_error_summary %> diff --git a/app/views/locations/check_answers.html.erb b/app/views/locations/check_answers.html.erb index 211466bcf..e64b0f448 100644 --- a/app/views/locations/check_answers.html.erb +++ b/app/views/locations/check_answers.html.erb @@ -4,27 +4,30 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: scheme_location_startdate_path(@scheme, @location), + href: scheme_location_availability_path(@scheme, @location), ) %> <% end %> -<%= render partial: "organisations/headings", locals: { main: "Check your answers", sub: "Add a location to #{@scheme.service_name}" } %> +<%= form_for(@location, method: :patch, url: scheme_location_check_answers_path(@scheme, @location)) do |f| %> + <%= 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", scheme_locations_path(@scheme), secondary: true %> -
+
+
+ <%= 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 %> +
+
+ <%= f.hidden_field :confirmed %> +
+ <%= f.govuk_submit "Add this location" %> + <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index e58fb1d67..b4b35d66e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -74,9 +74,10 @@ Rails.application.routes.draw do patch "type-of-unit", to: "locations#type_of_unit" get "mobility-standards", to: "locations#mobility_standards" patch "mobility-standards", to: "locations#mobility_standards" - get "startdate", to: "locations#startdate" - patch "startdate", to: "locations#startdate" + get "availability", to: "locations#availability" + patch "availability", to: "locations#availability" 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"