Browse Source

feat: add local_authority page (currenlty separate from edit_local_authority to avoid conflict with add location to newly created scheme path, to be fixed later). also copy and routing updates

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
625cbc2f82
  1. 23
      app/controllers/locations_controller.rb
  2. 2
      app/helpers/locations_helper.rb
  3. 35
      app/views/locations/local_authority.html.erb
  4. 2
      app/views/locations/postcode.html.erb
  5. 6
      config/locales/en.yml
  6. 2
      config/routes.rb

23
app/controllers/locations_controller.rb

@ -24,6 +24,21 @@ class LocationsController < ApplicationController
if params[:location].present?
@location.postcode = params[:location][:postcode]
@location.save!
if @location.location_code.blank? || @location.location_admin_district.blank?
redirect_to scheme_location_local_authority_path(@scheme, @location, referrer: params[:referrer])
elsif params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location)
else
redirect_to scheme_location_name_path(@scheme, @location)
end
end
end
def local_authority
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])
@location.save!
if params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location)
else
@ -158,7 +173,7 @@ class LocationsController < ApplicationController
@location = Location.new(location_params)
if @location.save
if @location.location_admin_district.nil?
redirect_to(scheme_location_edit_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location]))
redirect_to(scheme_location_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location]))
elsif location_params[:add_another_location] == "Yes"
redirect_to new_scheme_location_path(@scheme)
else
@ -184,10 +199,6 @@ class LocationsController < ApplicationController
render_not_found and return unless @location && @scheme
end
def edit_local_authority
render_not_found and return unless @location && @scheme
end
def update
render_not_found and return unless @location && @scheme
@ -204,7 +215,7 @@ class LocationsController < ApplicationController
case page
when "edit"
if @location.location_admin_district.nil?
redirect_to(scheme_location_edit_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location]))
redirect_to(scheme_location_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location]))
elsif location_params[:add_another_location] == "Yes"
redirect_to(new_scheme_location_path(@location.scheme))
else

2
app/helpers/locations_helper.rb

@ -60,7 +60,7 @@ module LocationsHelper
when "name"
scheme_location_name_path(location.scheme, location, referrer: "check_answers")
when "location_admin_district"
scheme_location_edit_local_authority_path(location.scheme, location, referrer: "check_answers")
scheme_location_local_authority_path(location.scheme, location, referrer: "check_answers")
when "units"
scheme_location_units_path(location.scheme, location, referrer: "check_answers")
when "type_of_unit"

35
app/views/locations/local_authority.html.erb

@ -0,0 +1,35 @@
<% content_for :title, "Add a location to this scheme" %>
<% 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),
) %>
<% end %>
<%= form_for(@location, method: :patch, url: scheme_location_local_authority_path(@scheme, @location, referrer: params[:referrer])) do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>
<%= render partial: "organisations/headings", locals: { main: "What is the local authority of #{@location.postcode}?", sub: @scheme.service_name } %>
<%= f.govuk_collection_select :location_admin_district,
local_authorities_selection,
:name,
:name,
label: { text: "Start typing to search for your local authority" },
"data-controller": %w[conditional-filter accessible-autocomplete] %>
<div class="govuk-button-group">
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
<% end %>
</div>
</div>
</div>
<% end %>

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

@ -15,7 +15,7 @@
<%= render partial: "organisations/headings", locals: { main: I18n.t("questions.location.postcode"), sub: "Add a location to #{@scheme.service_name}" } %>
<%= f.govuk_text_field :postcode,
label: { size: "m" },
label: nil,
hint: { text: I18n.t("hints.location.postcode") },
width: 5 %>

6
config/locales/en.yml

@ -393,9 +393,9 @@ en:
descriptions:
location:
mobility_type:
W: "The majority of units are suitable for someone who uses a wheelchair and offer the full use of all rooms and facilities."
A: "For example, the majority of units have been fitted with stairlifts, ramps, level access showers or grab rails."
N: "The majority of units are not designed to wheelchair-user standards or fitted with any equipment and adaptations."
W: "Suitable for someone who uses a wheelchair and offers the full use of all rooms and facilities."
A: "Fitted with stairlifts, ramps, level access showers or grab rails."
N: "Not designed to wheelchair-user standards or fitted with any equipment or adaptations."
hints:
location:

2
config/routes.rb

@ -66,6 +66,8 @@ Rails.application.routes.draw do
get "new-reactivation", to: "locations#new_reactivation"
get "postcode", to: "locations#postcode"
patch "postcode", to: "locations#postcode"
get "local-authority", to: "locations#local_authority"
patch "local-authority", to: "locations#local_authority"
get "name", to: "locations#name"
patch "name", to: "locations#name"
get "units", to: "locations#units"

Loading…
Cancel
Save