Browse Source

WIP

pull/1034/head
James Rose 4 years ago
parent
commit
d064b74006
  1. 24
      app/controllers/locations_controller.rb
  2. 21
      app/helpers/locations_helper.rb
  3. 17
      app/views/locations/check_answers.html.erb
  4. 2
      config/routes.rb

24
app/controllers/locations_controller.rb

@ -5,7 +5,7 @@ class LocationsController < ApplicationController
before_action :find_location, except: %i[create index]
before_action :find_scheme
before_action :authenticate_action!
before_action :scheme_and_location_present, only: %i[postcode update_postcode local_authority update_local_authority name update_name units update_units type_of_unit update_type_of_unit mobility_standards update_mobility_standards availability update_availability check_answers update_check_answers]
before_action :scheme_and_location_present, except: %i[create index]
include Modules::SearchFilter
@ -27,7 +27,7 @@ class LocationsController < ApplicationController
if @location.save(context: :postcode)
if @location.location_code.blank? || @location.location_admin_district.blank?
redirect_to scheme_location_local_authority_path(@scheme, @location, route: params[:route], referrer: params[:referrer])
elsif params[:referrer] == "check_answers"
elsif return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else
redirect_to scheme_location_name_path(@scheme, @location, route: params[:route])
@ -43,7 +43,7 @@ class LocationsController < ApplicationController
@location.location_admin_district = location_params[:location_admin_district]
@location.location_code = Location.local_authorities.key(location_params[:location_admin_district])
if @location.save(context: :location_admin_district)
if params[:referrer] == "check_answers" || params[:referrer] == "check_local_authority"
if return_to_check_your_answers? || params[:referrer] == "check_local_authority"
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else
redirect_to scheme_location_name_path(@scheme, @location, route: params[:route])
@ -58,10 +58,9 @@ class LocationsController < ApplicationController
def update_name
@location.name = location_params[:name]
if @location.save(context: :name)
case params[:referrer]
when "check_answers"
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
when "details"
elsif params[:referrer] == "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_units_path(@scheme, @location, route: params[:route])
@ -76,7 +75,7 @@ class LocationsController < ApplicationController
def update_units
@location.units = location_params[:units]
if @location.save(context: :units)
if params[:referrer] == "check_answers"
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else
redirect_to scheme_location_type_of_unit_path(@scheme, @location, route: params[:route])
@ -91,7 +90,7 @@ class LocationsController < ApplicationController
def update_type_of_unit
@location.type_of_unit = location_params[:type_of_unit]
if @location.save(context: :type_of_unit)
if params[:referrer] == "check_answers"
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else
redirect_to scheme_location_mobility_standards_path(@scheme, @location, route: params[:route])
@ -106,7 +105,7 @@ class LocationsController < ApplicationController
def update_mobility_standards
@location.mobility_type = location_params[:mobility_type]
if @location.save(context: :mobility_type)
if params[:referrer] == "check_answers"
if return_to_check_your_answers?
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else
redirect_to scheme_location_availability_path(@scheme, @location, route: params[:route])
@ -144,7 +143,7 @@ class LocationsController < ApplicationController
def check_answers; end
def update_check_answers
def confirm
@location.confirmed!
flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme"
redirect_to scheme_locations_path(@scheme)
@ -282,4 +281,9 @@ private
Time.zone.local(year.to_i, month.to_i, day.to_i) if Date.valid_date?(year.to_i, month.to_i, day.to_i)
end
def return_to_check_your_answers?
params[:referrer] == "check_answers"
end
helper_method :return_to_check_your_answers?
end

21
app/helpers/locations_helper.rb

@ -27,12 +27,12 @@ module LocationsHelper
base_attributes = [
{ 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: "Local authority", value: location.location_admin_district, attribute: "local_authority" },
{ 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: "availability" },
{ name: "Availability", value: location_availability(location), attribute: "startdate" },
]
if FeatureToggle.location_toggle_enabled?
@ -42,6 +42,18 @@ module LocationsHelper
base_attributes
end
def display_location_attributes_for_check_answers(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: "local_authority" },
{ 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: "Availability", value: location&.startdate&.to_formatted_s(:govuk_date), attribute: "startdate" },
]
end
def location_availability(location)
availability = ""
location_active_periods(location).each do |period|
@ -54,13 +66,8 @@ module LocationsHelper
end
def location_edit_path(location, page)
case page
when "location_admin_district"
scheme_location_local_authority_path(location.scheme, location, referrer: "check_local_authority", route: params[:route])
else
send("scheme_location_#{page}_path", location.scheme, location, referrer: "check_answers", route: params[:route])
end
end
def action_text_helper(attr, location)
attr[:value].blank? || (attr[:attribute] == "availability" && location.startdate.blank?) ? "Answer" : "Change"

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

@ -13,23 +13,15 @@
) %>
<% end %>
<%= form_for(@location, method: :patch, url: scheme_location_check_answers_path(@scheme, @location, route: params[:route])) do |f| %>
<%= 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-column-two-thirds-from-desktop">
<%= govuk_summary_list do |summary_list| %>
<% display_location_attributes(@location).each do |attr| %>
<% next if %w[location_code status].include? attr[:attribute] %>
<% display_location_attributes_for_check_answers(@location).each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<%= row.value do %>
<% if attr[:attribute] == "availability"
details_html(name: "Availability", value: @location.startdate.present? ? @location.startdate.to_formatted_s(:govuk_date) : nil, attribute: "startdate")
else
details_html(attr)
end %>
<% end %>
<% row.value { details_html(attr) } %>
<% row.action(text: action_text_helper(attr, @location), href: location_edit_path(@location, attr[:attribute]))%>
<% end %>
<% end %>
@ -37,7 +29,8 @@
</div>
</div>
<div class="govuk-button-group">
<%= f.govuk_submit "Add this location", disabled: @location.incomplete? %>
<% if @location.incomplete? %>
<%= govuk_button_to "Add this location", scheme_location_confirm_path(@scheme, @location, route: params[:route])), method: :patch %>
<% end %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
</div>
<% end %>

2
config/routes.rb

@ -78,7 +78,7 @@ Rails.application.routes.draw do
get "availability", to: "locations#availability"
patch "availability", to: "locations#update_availability"
get "check-answers", to: "locations#check_answers"
patch "check-answers", to: "locations#update_check_answers"
patch "confirm", to: "locations#confirm"
patch "new-deactivation", to: "locations#new_deactivation"
patch "deactivate", to: "locations#deactivate"
patch "reactivate", to: "locations#reactivate"

Loading…
Cancel
Save