Browse Source

feat: add controller and details linking and lint

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
923c931215
  1. 29
      app/controllers/locations_controller.rb
  2. 2
      app/helpers/locations_helper.rb
  3. 5
      app/views/locations/name.html.erb
  4. 2
      app/views/locations/show.html.erb

29
app/controllers/locations_controller.rb

@ -36,7 +36,14 @@ class LocationsController < ApplicationController
if params[:location].present?
@location.name = params[:location][:name]
@location.save!
redirect_to scheme_location_units_path(@scheme, @location)
case params[:referrer]
when "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location)
when "details"
redirect_to scheme_location_path(@scheme, @location)
else
redirect_to scheme_location_units_path(@scheme, @location)
end
end
end
@ -44,7 +51,11 @@ class LocationsController < ApplicationController
if params[:location].present?
@location.units = params[:location][:units]
@location.save!
redirect_to scheme_location_type_of_unit_path(@scheme, @location)
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)
end
end
end
@ -52,7 +63,11 @@ class LocationsController < ApplicationController
if params[:location].present?
@location.type_of_unit = params[:location][:type_of_unit]
@location.save!
redirect_to scheme_location_mobility_standards_path(@scheme, @location)
if params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location)
else
redirect_to scheme_location_mobility_standards_path(@scheme, @location)
end
end
end
@ -60,7 +75,11 @@ class LocationsController < ApplicationController
if params[:location].present?
@location.mobility_type = params[:location][:mobility_type]
@location.save!
redirect_to scheme_location_availability_path(@scheme, @location)
if params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location)
else
redirect_to scheme_location_availability_path(@scheme, @location)
end
end
end
@ -79,7 +98,7 @@ class LocationsController < ApplicationController
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"
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

2
app/helpers/locations_helper.rb

@ -29,7 +29,7 @@ module LocationsHelper
{ name: "Location name", value: location.name, attribute: "name" },
{ name: "Local authority", value: location.location_admin_district, attribute: "location_admin_district" },
{ 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: "Code", value: location.location_code, attribute: "location_code" },
{ name: "Availability", value: location_availability(location), attribute: "availability" },

5
app/views/locations/name.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, @location),
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : params[:referrer] == "details" ? scheme_location_path(@scheme, @location) : scheme_location_postcode_path(@scheme, @location),
) %>
<% end %>
@ -22,6 +22,9 @@
<% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %>
<% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>
<% else %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>

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

@ -17,7 +17,7 @@
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<% row.value { attr[:attribute].eql?("status") ? status_tag(attr[:value]) : details_html(attr) } %>
<% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location)) if attr[:attribute] == "name" %>
<% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "name" %>
<% end %>
<% end %>
<% end %>

Loading…
Cancel
Save