Browse Source

WIP

pull/1034/head
James Rose 4 years ago
parent
commit
d064b74006
  1. 24
      app/controllers/locations_controller.rb
  2. 23
      app/helpers/locations_helper.rb
  3. 47
      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_location, except: %i[create index]
before_action :find_scheme before_action :find_scheme
before_action :authenticate_action! 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 include Modules::SearchFilter
@ -27,7 +27,7 @@ class LocationsController < ApplicationController
if @location.save(context: :postcode) if @location.save(context: :postcode)
if @location.location_code.blank? || @location.location_admin_district.blank? 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]) 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]) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_name_path(@scheme, @location, route: params[:route]) 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_admin_district = location_params[:location_admin_district]
@location.location_code = Location.local_authorities.key(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 @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]) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_name_path(@scheme, @location, route: params[:route]) redirect_to scheme_location_name_path(@scheme, @location, route: params[:route])
@ -58,10 +58,9 @@ class LocationsController < ApplicationController
def update_name def update_name
@location.name = location_params[:name] @location.name = location_params[:name]
if @location.save(context: :name) if @location.save(context: :name)
case params[:referrer] if return_to_check_your_answers?
when "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) 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) redirect_to scheme_location_path(@scheme, @location)
else else
redirect_to scheme_location_units_path(@scheme, @location, route: params[:route]) redirect_to scheme_location_units_path(@scheme, @location, route: params[:route])
@ -76,7 +75,7 @@ class LocationsController < ApplicationController
def update_units def update_units
@location.units = location_params[:units] @location.units = location_params[:units]
if @location.save(context: :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]) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_type_of_unit_path(@scheme, @location, route: params[:route]) 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 def update_type_of_unit
@location.type_of_unit = location_params[:type_of_unit] @location.type_of_unit = location_params[:type_of_unit]
if @location.save(context: :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]) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_mobility_standards_path(@scheme, @location, route: params[:route]) redirect_to scheme_location_mobility_standards_path(@scheme, @location, route: params[:route])
@ -106,7 +105,7 @@ class LocationsController < ApplicationController
def update_mobility_standards def update_mobility_standards
@location.mobility_type = location_params[:mobility_type] @location.mobility_type = location_params[:mobility_type]
if @location.save(context: :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]) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_availability_path(@scheme, @location, route: params[:route]) redirect_to scheme_location_availability_path(@scheme, @location, route: params[:route])
@ -144,7 +143,7 @@ class LocationsController < ApplicationController
def check_answers; end def check_answers; end
def update_check_answers def confirm
@location.confirmed! @location.confirmed!
flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme"
redirect_to scheme_locations_path(@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) 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 end
def return_to_check_your_answers?
params[:referrer] == "check_answers"
end
helper_method :return_to_check_your_answers?
end end

23
app/helpers/locations_helper.rb

@ -27,12 +27,12 @@ module LocationsHelper
base_attributes = [ base_attributes = [
{ name: "Postcode", value: location.postcode, attribute: "postcode" }, { name: "Postcode", value: location.postcode, attribute: "postcode" },
{ name: "Location name", value: location.name, attribute: "name" }, { 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: "Number of units", value: location.units, attribute: "units" },
{ 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: "availability" }, { name: "Availability", value: location_availability(location), attribute: "startdate" },
] ]
if FeatureToggle.location_toggle_enabled? if FeatureToggle.location_toggle_enabled?
@ -42,6 +42,18 @@ module LocationsHelper
base_attributes base_attributes
end 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) def location_availability(location)
availability = "" availability = ""
location_active_periods(location).each do |period| location_active_periods(location).each do |period|
@ -54,12 +66,7 @@ module LocationsHelper
end end
def location_edit_path(location, page) def location_edit_path(location, page)
case page send("scheme_location_#{page}_path", location.scheme, location, referrer: "check_answers", route: params[:route])
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 end
def action_text_helper(attr, location) def action_text_helper(attr, location)

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

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