Browse Source

feat: further flow work and flash notice, name tidying

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
8099dc8ffa
  1. 13
      app/controllers/locations_controller.rb
  2. 6
      app/helpers/locations_helper.rb
  3. 2
      app/views/locations/availability.erb
  4. 7
      app/views/locations/check_answers.html.erb
  5. 5
      config/routes.rb

13
app/controllers/locations_controller.rb

@ -56,11 +56,11 @@ class LocationsController < ApplicationController
if params[:location].present? if params[:location].present?
@location.mobility_type = params[:location][:mobility_type] @location.mobility_type = params[:location][:mobility_type]
@location.save! @location.save!
redirect_to scheme_location_startdate_path(@scheme, @location) redirect_to scheme_location_availability_path(@scheme, @location)
end end
end end
def startdate def availability
if params[:location].present? if params[:location].present?
day = params[:location]["startdate(3i)"] day = params[:location]["startdate(3i)"]
month = params[:location]["startdate(2i)"] month = params[:location]["startdate(2i)"]
@ -71,7 +71,14 @@ class LocationsController < ApplicationController
end end
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 def show; end

6
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: "Most common unit", value: location.type_of_unit, attribute: "type_of_unit"},
{ name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" }, { name: "Mobility standards", value: location.mobility_type, attribute: "mobility_standards" },
{ name: "Code", value: location.location_code, attribute: "location_code" }, { 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? if FeatureToggle.location_toggle_enabled?
@ -67,8 +67,8 @@ module LocationsHelper
scheme_location_type_of_unit_path(location.scheme, location, referrer: "check_answers") scheme_location_type_of_unit_path(location.scheme, location, referrer: "check_answers")
when "mobility_standards" 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")
when "startdate" when "avaliability"
scheme_location_startdate_path(location.scheme, location, referrer: "check_answers") scheme_location_availability_path(location.scheme, location, referrer: "check_answers")
end end
end end

2
app/views/locations/startdate.html.erb → app/views/locations/availability.erb

@ -7,7 +7,7 @@
) %> ) %>
<% end %> <% 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| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>

7
app/views/locations/check_answers.html.erb

@ -4,10 +4,11 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: scheme_location_startdate_path(@scheme, @location), href: scheme_location_availability_path(@scheme, @location),
) %> ) %>
<% end %> <% end %>
<%= 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}" } %> <%= render partial: "organisations/headings", locals: { main: "Check your answers", sub: "Add a location to #{@scheme.service_name}" } %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
@ -24,7 +25,9 @@
<% end %> <% end %>
</div> </div>
</div> </div>
<%= f.hidden_field :confirmed %>
<div class="govuk-button-group"> <div class="govuk-button-group">
<%= govuk_button_to "Add this location", scheme_locations_path(@scheme) %> <%= f.govuk_submit "Add this location" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
</div> </div>
<% end %>

5
config/routes.rb

@ -74,9 +74,10 @@ Rails.application.routes.draw do
patch "type-of-unit", to: "locations#type_of_unit" patch "type-of-unit", to: "locations#type_of_unit"
get "mobility-standards", to: "locations#mobility_standards" get "mobility-standards", to: "locations#mobility_standards"
patch "mobility-standards", to: "locations#mobility_standards" patch "mobility-standards", to: "locations#mobility_standards"
get "startdate", to: "locations#startdate" get "availability", to: "locations#availability"
patch "startdate", to: "locations#startdate" patch "availability", to: "locations#availability"
get "check-answers", to: "locations#check_answers" get "check-answers", to: "locations#check_answers"
patch "check-answers", to: "locations#check_answers"
patch "new-deactivation", to: "locations#new_deactivation" patch "new-deactivation", to: "locations#new_deactivation"
patch "deactivate", to: "locations#deactivate" patch "deactivate", to: "locations#deactivate"
patch "reactivate", to: "locations#reactivate" patch "reactivate", to: "locations#reactivate"

Loading…
Cancel
Save