diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 8bfa1c216..3cf231246 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -1,4 +1,5 @@ class LocationsController < ApplicationController + include Pagy::Backend before_action :authenticate_user! before_action :authenticate_scope! before_action :find_location, except: %i[new create] @@ -10,6 +11,7 @@ class LocationsController < ApplicationController end def create + debugger @location = Location.new(location_params) if @location.save @@ -29,6 +31,12 @@ class LocationsController < ApplicationController end end + def index + @scheme = Scheme.find_by(id: params[:id]) + @pagy, @locations = pagy(@scheme.locations) + @total_count = @scheme.locations.size + end + private def find_scheme diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 5d020f219..b79316f02 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -100,7 +100,7 @@ private when "secondary-client-group" scheme_support_path(@scheme) when "support" - location_new_scheme_path + new_location_path when "details" scheme_primary_client_group_path(@scheme) end diff --git a/app/helpers/tab_nav_helper.rb b/app/helpers/tab_nav_helper.rb index 2ea9f99c7..ef8b240bc 100644 --- a/app/helpers/tab_nav_helper.rb +++ b/app/helpers/tab_nav_helper.rb @@ -8,7 +8,7 @@ module TabNavHelper def location_cell(location) link_text = location.postcode - [govuk_link_to(link_text, location_scheme_path(location, scheme_id: location.scheme.id)), "Location #{location.name}"].join("\n") + [govuk_link_to(link_text, location_path(location)), "Location #{location.name}"].join("\n") end def scheme_cell(scheme) diff --git a/app/models/location.rb b/app/models/location.rb index 87f34cb98..c8be513eb 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -7,7 +7,7 @@ class Location < ApplicationRecord WHEELCHAIR_ADAPTATIONS = { Yes: 1, - No: 0 + No: 0, }.freeze enum wheelchair_adaptation: WHEELCHAIR_ADAPTATIONS diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb new file mode 100644 index 000000000..6d3cc3de3 --- /dev/null +++ b/app/views/locations/index.html.erb @@ -0,0 +1,49 @@ +<% 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)) %> + +
+
+ <%= govuk_table do |table| %> + <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> + <%= @scheme.locations.count %> <%= @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("#{location.type_of_unit}#{location.wheelchair_adaptation == 'Yes' ? "\nWith wheelchair adaptations" : ''}")) %> + <% end %> + <% end %> + <% end %> + <% end %> +
+
+ +<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "locations" } %> diff --git a/app/views/locations/new.html.erb b/app/views/locations/new.html.erb index 48839d8d4..8c8ff23c5 100644 --- a/app/views/locations/new.html.erb +++ b/app/views/locations/new.html.erb @@ -9,7 +9,7 @@ <%= render partial: "organisations/headings", locals: { main: "Add a location to this scheme", sub: @scheme.service_name } %> -<%= form_for(@location, method: :post, url: location_create_scheme_path) do |f| %> +<%= form_for(@location, method: :post, url: locations_path) do |f| %>
<%= f.govuk_error_summary %> diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index a198b703a..da0db6b15 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -83,9 +83,6 @@ <% row.cell(header: true, text: "Common unit type", html_attributes: { scope: "col", }) %> - <% row.cell(header: true, text: "Actions", html_attributes: { - scope: "col", - }) %> <% end %> <% end %> <% @scheme.locations.each do |location| %> @@ -95,12 +92,11 @@ <% row.cell(text: simple_format(location_cell(location), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: location.total_units) %> <% row.cell(text: simple_format("#{location.type_of_unit}#{location.wheelchair_adaptation == 'Yes' ? "\nWith wheelchair adaptations" : ''}")) %> - <% row.cell(text: "Delete") %> <% end %> <% end %> <% end %> <% end %> - <%= govuk_button_link_to "Add a location", location_new_scheme_path(id: @scheme.id), secondary: true %> + <%= govuk_button_link_to "Add a location", new_location_path(id: @scheme.id), secondary: true %> <% end %> <% end %>
diff --git a/app/views/schemes/locations.html.erb b/app/views/schemes/locations.html.erb index 9b66e5f3d..6d3cc3de3 100644 --- a/app/views/schemes/locations.html.erb +++ b/app/views/schemes/locations.html.erb @@ -30,9 +30,6 @@ <% row.cell(header: true, text: "Common unit type", html_attributes: { scope: "col", }) %> - <% row.cell(header: true, text: "Actions", html_attributes: { - scope: "col", - }) %> <% end %> <% end %> <% @locations.each do |location| %> @@ -42,7 +39,6 @@ <% row.cell(text: location.postcode) %> <% row.cell(text: location.total_units) %> <% row.cell(text: simple_format("#{location.type_of_unit}#{location.wheelchair_adaptation == 'Yes' ? "\nWith wheelchair adaptations" : ''}")) %> - <% row.cell(text: "Delete") %> <% end %> <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index db8cb3dad..d6e8b6a3a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,11 +44,12 @@ Rails.application.routes.draw do get "check-answers", to: "schemes#check_answers" member do - get "locations", to: "schemes#locations" - get "location/new", to: "locations#new" - post "location/create", to: "locations#create" - get "location", to: "locations#details" - patch "location", to: "locations#update" + resources :locations + # get "locations", to: "schemes#locations" + # get "location/new", to: "locations#new" + # post "location/create", to: "locations#create" + # get "location", to: "locations#details" + # patch "location", to: "locations#update" end end