Browse Source

further chanegs

pull/704/head
JG 3 years ago
parent
commit
ab0389b6f9
  1. 14
      app/controllers/locations_controller.rb
  2. 49
      app/views/schemes/locations.html.erb

14
app/controllers/locations_controller.rb

@ -19,7 +19,7 @@ class LocationsController < ApplicationController
@location = Location.new(location_params) @location = Location.new(location_params)
if @location.save if @location.save
location_params[:add_another_location] == "Yes" ? redirect_to(location_new_scheme_path) : redirect_to(scheme_check_answers_path(scheme_id: @scheme.id)) location_params[:add_another_location] == "Yes" ? redirect_to(new_location_path(id: @scheme.id)) : redirect_to(scheme_check_answers_path(scheme_id: @scheme.id))
else else
render :new, status: :unprocessable_entity render :new, status: :unprocessable_entity
end end
@ -29,7 +29,7 @@ class LocationsController < ApplicationController
def update def update
if @location.update(location_params) if @location.update(location_params)
location_params[:add_another_location] == "Yes" ? redirect_to(location_new_scheme_path) : redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) location_params[:add_another_location] == "Yes" ? redirect_to(new_location_path) : redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
else else
render :details, status: :unprocessable_entity render :details, status: :unprocessable_entity
end end
@ -38,11 +38,11 @@ class LocationsController < ApplicationController
private private
def find_scheme def find_scheme
if %w[new create].include?(action_name) @scheme = if %w[new create].include?(action_name)
@scheme = Scheme.find(params[:id]) Scheme.find(params[:id])
else else
@scheme = @location.scheme @location.scheme
end end
end end
def find_location def find_location

49
app/views/schemes/locations.html.erb

@ -1,49 +0,0 @@
<% title = @scheme.service_name %>
<% content_for :title, title %>
<% content_for :before_content do %>
<%= govuk_back_link(
text: "Back",
href: "/schemes/#{@scheme.id}",
) %>
<% end %>
<%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %>
<% location_caption = @scheme.locations.count.eql?(1) ? "1 location" : "#{@scheme.locations.count} locations" %>
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, location_caption)) %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters">
<%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<strong><%= @scheme.locations.count %></strong> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>.
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>
<% row.cell(header: true, text: "Code", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Postcode", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Units", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Common unit type", html_attributes: {
scope: "col",
}) %>
<% end %>
<% end %>
<% @locations.each do |location| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: location.id) %>
<% row.cell(text: location.postcode) %>
<% row.cell(text: location.total_units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %>
<% end %>
<% end %>
<% end %>
<% end %>
</div>
</div>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "locations" } %>
Loading…
Cancel
Save