Browse Source

Cldc 1667 location details page (#976)

* Add show location page

* Add availability to the locations table

* Add active status

* Add an empty deactivate page and button

* styling

* lint

* Extract feature toggle

* Update route

* Move display_attributes

* update path

* update paths
pull/985/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
4a3172e82c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/controllers/locations_controller.rb
  2. 14
      app/helpers/locations_helper.rb
  3. 2
      app/helpers/tag_helper.rb
  4. 16
      app/models/location.rb
  5. 2
      app/views/locations/edit_name.html.erb
  6. 2
      app/views/locations/index.html.erb
  7. 28
      app/views/locations/show.html.erb
  8. 0
      app/views/locations/toggle_active.html.erb
  9. 6
      config/initializers/feature_toggle.rb
  10. 1
      config/routes.rb
  11. 42
      spec/features/schemes_spec.rb
  12. 27
      spec/helpers/locations_helper_spec.rb

6
app/controllers/locations_controller.rb

@ -18,6 +18,12 @@ class LocationsController < ApplicationController
@location = Location.new @location = Location.new
end end
def show; end
def deactivate
render "toggle_active", locals: { action: "deactivate" }
end
def create def create
if date_params_missing?(location_params) || valid_date_params?(location_params) if date_params_missing?(location_params) || valid_date_params?(location_params)
@location = Location.new(location_params) @location = Location.new(location_params)

14
app/helpers/locations_helper.rb

@ -22,4 +22,18 @@ module LocationsHelper
resource.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } resource.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) }
end end
def display_attributes(location)
[
{ name: "Postcode", value: location.postcode },
{ name: "Local authority", value: location.location_admin_district },
{ name: "Location name", value: location.name, edit: true },
{ name: "Total number of units at this location", value: location.units },
{ name: "Common type of unit", value: location.type_of_unit },
{ name: "Mobility type", value: location.mobility_type },
{ name: "Code", value: location.location_code },
{ name: "Availability", value: "Available from #{location.available_from.to_formatted_s(:govuk_date)}" },
{ name: "Status", value: location.status },
]
end
end end

2
app/helpers/tag_helper.rb

@ -6,6 +6,7 @@ module TagHelper
cannot_start_yet: "Cannot start yet", cannot_start_yet: "Cannot start yet",
in_progress: "In progress", in_progress: "In progress",
completed: "Completed", completed: "Completed",
active: "Active",
}.freeze }.freeze
COLOUR = { COLOUR = {
@ -13,6 +14,7 @@ module TagHelper
cannot_start_yet: "grey", cannot_start_yet: "grey",
in_progress: "blue", in_progress: "blue",
completed: "green", completed: "green",
active: "green",
}.freeze }.freeze
def status_tag(status, classes = []) def status_tag(status, classes = [])

16
app/models/location.rb

@ -359,14 +359,6 @@ class Location < ApplicationRecord
enum type_of_unit: TYPE_OF_UNIT enum type_of_unit: TYPE_OF_UNIT
def display_attributes
[
{ name: "Location code ", value: location_code, suffix: false },
{ name: "Postcode", value: postcode, suffix: county },
{ name: "Type of unit", value: type_of_unit, suffix: false },
]
end
def postcode=(postcode) def postcode=(postcode)
if postcode if postcode
super UKPostcode.parse(postcode).to_s super UKPostcode.parse(postcode).to_s
@ -375,6 +367,14 @@ class Location < ApplicationRecord
end end
end end
def available_from
startdate || created_at
end
def status
"active"
end
private private
PIO = PostcodeService.new PIO = PostcodeService.new

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

@ -3,7 +3,7 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: "/schemes/#{@scheme.id}/locations", href: scheme_location_path(@scheme, @location),
) %> ) %>
<% end %> <% end %>

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

@ -52,7 +52,7 @@
<%= table.body do |body| %> <%= table.body do |body| %>
<%= body.row do |row| %> <%= body.row do |row| %>
<% row.cell(text: location.id) %> <% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell_postcode(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-name"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: simple_format(location_cell_postcode(location, "/schemes/#{@scheme.id}/locations/#{location.id}"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.units) %> <% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %> <% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %> <% row.cell(text: location.mobility_type) %>

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

@ -0,0 +1,28 @@
<% title = @location.name %>
<% content_for :title, title %>
<% content_for :before_content do %>
<%= govuk_back_link(
text: "Back",
href: scheme_locations_path(@scheme),
) %>
<% end %>
<%= render partial: "organisations/headings", locals: { main: @location.postcode, sub: @location.name } %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<%= govuk_summary_list do |summary_list| %>
<% display_attributes(@location).each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<% row.value { attr[:name].eql?("Status") ? status_tag(attr[:value]) : details_html(attr) } %>
<% row.action(text: "Change", href: scheme_location_edit_name_path(scheme_id: @scheme.id, location_id: @location.id)) if attr[:edit] %>
<% end %>
<% end %>
<% end %>
</div>
</div>
<% if FeatureToggle.location_toggle_enabled? %>
<%= govuk_button_link_to "Deactivate this location", scheme_location_deactivate_path(scheme_id: @scheme.id, location_id: @location.id), warning: true %>
<% end %>

0
app/views/locations/toggle_active.html.erb

6
config/initializers/feature_toggle.rb

@ -14,4 +14,10 @@ class FeatureToggle
false false
end end
def self.location_toggle_enabled?
return true unless Rails.env.production?
false
end
end end

1
config/routes.rb

@ -53,6 +53,7 @@ Rails.application.routes.draw do
resources :locations do resources :locations do
get "edit-name", to: "locations#edit_name" get "edit-name", to: "locations#edit_name"
get "edit-local-authority", to: "locations#edit_local_authority" get "edit-local-authority", to: "locations#edit_local_authority"
get "deactivate", to: "locations#deactivate"
end end
end end

42
spec/features/schemes_spec.rb

@ -692,7 +692,7 @@ RSpec.describe "Schemes scheme Features" do
context "when I click to see individual scheme" do context "when I click to see individual scheme" do
let(:scheme) { schemes.first } let(:scheme) { schemes.first }
let!(:location) { FactoryBot.create(:location, scheme:) } let!(:location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 4), scheme:) }
before do before do
click_link(scheme.service_name) click_link(scheme.service_name)
@ -757,11 +757,31 @@ RSpec.describe "Schemes scheme Features" do
click_link(location.postcode) click_link(location.postcode)
end end
it "shows available fields to edit" do it "displays details about the selected location" do
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}/edit-name") expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}")
expect(page).to have_content(location.postcode)
expect(page).to have_content(location.location_admin_district)
expect(page).to have_content(location.name)
expect(page).to have_content(location.units)
expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.mobility_type)
expect(page).to have_content(location.location_code)
expect(page).to have_content("Available from 4 April 2022")
expect(page).to have_content("Active")
end
it "only allows to edit the location name" do
assert_selector "a", text: "Change", count: 1
click_link("Change")
expect(page).to have_content "Location name for #{location.postcode}" expect(page).to have_content "Location name for #{location.postcode}"
end end
it "allows to deactivate a location" do
click_link("Deactivate this location")
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}/deactivate")
end
context "when I press the back button" do context "when I press the back button" do
before do before do
click_link "Back" click_link "Back"
@ -775,15 +795,27 @@ RSpec.describe "Schemes scheme Features" do
context "and I change the location name" do context "and I change the location name" do
before do before do
fill_in "location-name-field", with: "NewName" click_link("Change")
click_button "Save and continue"
end end
it "returns to locations check your answers page and shows the new name" do it "returns to locations check your answers page and shows the new name" do
fill_in "location-name-field", with: "NewName"
click_button "Save and continue"
expect(page).to have_content location.id expect(page).to have_content location.id
expect(page).to have_content "NewName" expect(page).to have_content "NewName"
expect(page.current_url.split("/").last).to eq("check-answers#locations") expect(page.current_url.split("/").last).to eq("check-answers#locations")
end end
context "when I press the back button" do
before do
click_link "Back"
end
it "I see location details" do
expect(page).to have_content location.name
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}")
end
end
end end
end end

27
spec/helpers/locations_helper_spec.rb

@ -46,4 +46,31 @@ RSpec.describe LocationsHelper do
expect(selection_options(%w[example])).to eq([OpenStruct.new(id: "example", name: "Example")]) expect(selection_options(%w[example])).to eq([OpenStruct.new(id: "example", name: "Example")])
end end
end end
describe "display_attributes" do
let(:location) { FactoryBot.build(:location, startdate: Time.zone.local(2022, 8, 8)) }
it "returns correct display attributes" do
attributes = [
{ name: "Postcode", value: location.postcode },
{ name: "Local authority", value: location.location_admin_district },
{ name: "Location name", value: location.name, edit: true },
{ name: "Total number of units at this location", value: location.units },
{ name: "Common type of unit", value: location.type_of_unit },
{ name: "Mobility type", value: location.mobility_type },
{ name: "Code", value: location.location_code },
{ name: "Availability", value: "Available from 8 August 2022" },
{ name: "Status", value: "active" },
]
expect(display_attributes(location)).to eq(attributes)
end
it "displays created_at as availability date if startdate is not present" do
location.update!(startdate: nil)
availability_attribute = display_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Available from #{location.created_at.to_formatted_s(:govuk_date)}")
end
end
end end

Loading…
Cancel
Save