Browse Source

feat: add more back behaviour for new scheme path and fix local auth validation

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
e7dbb2b4fa
  1. 18
      app/controllers/locations_controller.rb
  2. 2
      app/views/locations/availability.erb
  3. 9
      app/views/locations/check_answers.html.erb
  4. 2
      app/views/locations/index.html.erb
  5. 2
      app/views/locations/local_authority.html.erb
  6. 2
      app/views/locations/mobility_standards.html.erb
  7. 2
      app/views/locations/name.html.erb
  8. 2
      app/views/locations/type_of_unit.html.erb
  9. 2
      app/views/locations/units.html.erb

18
app/controllers/locations_controller.rb

@ -36,7 +36,7 @@ class LocationsController < ApplicationController
elsif params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location)
else
redirect_to scheme_location_name_path(@scheme, @location)
redirect_to scheme_location_name_path(@scheme, @location, referrer: params[:referrer])
end
else
render :postcode, status: :unprocessable_entity
@ -48,12 +48,12 @@ class LocationsController < ApplicationController
if params[:location].present?
@location.location_admin_district = params[:location][:location_admin_district]
@location.location_code = Location.local_authorities.key(params[:location][:location_admin_district])
if @location.valid?(:local_authority)
if @location.valid?(:location_admin_district)
@location.save!
if params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location)
else
redirect_to scheme_location_name_path(@scheme, @location)
redirect_to scheme_location_name_path(@scheme, @location, referrer: params[:referrer])
end
else
render :local_authority, status: :unprocessable_entity
@ -72,7 +72,7 @@ class LocationsController < ApplicationController
when "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_units_path(@scheme, @location)
redirect_to scheme_location_units_path(@scheme, @location, referrer: params[:referrer])
end
else
render :name, status: :unprocessable_entity
@ -88,7 +88,7 @@ class LocationsController < ApplicationController
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)
redirect_to scheme_location_type_of_unit_path(@scheme, @location, referrer: params[:referrer])
end
else
render :units, status: :unprocessable_entity
@ -104,7 +104,7 @@ class LocationsController < ApplicationController
if params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location)
else
redirect_to scheme_location_mobility_standards_path(@scheme, @location)
redirect_to scheme_location_mobility_standards_path(@scheme, @location, referrer: params[:referrer])
end
else
render :type_of_unit, status: :unprocessable_entity
@ -120,7 +120,7 @@ class LocationsController < ApplicationController
if params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location)
else
redirect_to scheme_location_availability_path(@scheme, @location)
redirect_to scheme_location_availability_path(@scheme, @location, referrer: params[:referrer])
end
else
render :mobility_standards, status: :unprocessable_entity
@ -138,7 +138,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)
redirect_to scheme_location_check_answers_path(@scheme, @location, referrer: params[:referrer])
else
render :availability, status: :unprocessable_entity
end
@ -158,7 +158,7 @@ class LocationsController < ApplicationController
def check_answers
if params[:location].present?
flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme"
redirect_to scheme_locations_path(@scheme, @location)
redirect_to scheme_locations_path(@scheme)
end
end

2
app/views/locations/availability.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_mobility_standards_path(@scheme, @location),
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_mobility_standards_path(@scheme, @location, referrer: params[:referrer]),
) %>
<% end %>

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

@ -4,7 +4,14 @@
<% content_for :before_content do %>
<%= govuk_back_link(
text: "Back",
href: :back,
href: case params[:referrer]
when "new_scheme"
scheme_location_availability_path(@scheme, @location, referrer: params[:referrer])
when "locations"
scheme_locations_path(@scheme)
else
:back
end,
) %>
<% end %>

2
app/views/locations/index.html.erb

@ -52,7 +52,7 @@
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell_postcode(location, location.confirmed ? scheme_location_path(@scheme, location) : scheme_location_check_answers_path(@scheme, location)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: simple_format(location_cell_postcode(location, location.confirmed ? scheme_location_path(@scheme, location) : scheme_location_check_answers_path(@scheme, location, referrer: "locations")), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %>

2
app/views/locations/local_authority.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),
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_postcode_path(@scheme, @location, referrer: params[:referrer]),
) %>
<% end %>

2
app/views/locations/mobility_standards.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_type_of_unit_path(@scheme, @location),
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_type_of_unit_path(@scheme, @location, referrer: params[:referrer]),
) %>
<% end %>

2
app/views/locations/name.html.erb

@ -6,7 +6,7 @@
href: if params[:referrer] == "check_answers"
scheme_location_check_answers_path(@scheme, @location)
else
params[:referrer] == "details" ? scheme_location_path(@scheme, @location) : scheme_location_postcode_path(@scheme, @location)
params[:referrer] == "details" ? scheme_location_path(@scheme, @location) : scheme_location_postcode_path(@scheme, @location, referrer: params[:referrer])
end,
) %>
<% end %>

2
app/views/locations/type_of_unit.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_units_path(@scheme, @location),
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_units_path(@scheme, @location, referrer: params[:referrer]),
) %>
<% end %>

2
app/views/locations/units.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_name_path(@scheme, @location),
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_name_path(@scheme, @location, referrer: params[:referrer]),
) %>
<% end %>

Loading…
Cancel
Save