Browse Source

correct and compact view for locations

pull/662/head
JG 3 years ago
parent
commit
a5b14958a3
  1. 19
      app/models/location.rb
  2. 62
      app/views/schemes/locations.html.erb
  3. 47
      db/seeds.rb
  4. 4
      spec/features/schemes_spec.rb
  5. 2
      spec/requests/schemes_controller_spec.rb

19
app/models/location.rb

@ -1,3 +1,22 @@
class Location < ApplicationRecord
belongs_to :scheme
WHEELCHAIR_ADAPTATION = {
0 => "No",
1 => "Yes",
}.freeze
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 },
{ name: "Type of building", value: type_of_building, suffix: false },
{ name: "Wheelchair adaptation", value: wheelchair_adaptation_display, suffix: false },
]
end
def wheelchair_adaptation_display
WHEELCHAIR_ADAPTATION[wheelchair_adaptation]
end
end

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

@ -5,15 +5,14 @@
<%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %>
<%= render SubNavigationComponent.new(
items: scheme_items(request.path, @scheme.id, @scheme.locations.count),
) %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters">
<section class="x-govuk-summary-card govuk-!-margin-bottom-6">
<% @scheme.locations.each do |location| %>
<% @scheme.locations.each do |location| %>
<section class="x-govuk-summary-card govuk-!-margin-bottom-6">
<header class="x-govuk-summary-card__header">
<h2 class="x-govuk-summary-card__title">
<%= "#{location.address_line1}, #{location.address_line2}" %>
@ -21,49 +20,22 @@
</header>
<div class="x-govuk-summary-card__body">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Location code
</dt>
<dd class="govuk-summary-list__key">
<%= location.location_code %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Postcode
</dt>
<dd class="govuk-summary-list__key">
<%= location.postcode %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Type of unit
</dt>
<dd class="govuk-summary-list__key">
<%= location.type_of_unit %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Type of building
</dt>
<dd class="govuk-summary-list__key">
<%= location.type_of_building %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Wheelchair adaptation
</dt>
<dd class="govuk-summary-list__key">
<%= location.wheelchair_adaptation %>
</dd>
</div>
<% location.display_attributes.each do |attribute| %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= attribute[:name] %>
</dt>
<dd class="govuk-summary-list__value app-!-font-tabular">
<span class="govuk-!-margin-right-4"><%= attribute[:value] %></span>
<% if attribute[:suffix] %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= attribute[:suffix] %></span>
<% end %>
</dd>
</div>
<% end %>
</dl>
</div>
<% end %>
</section>
</section>
<% end %>
</div>
</div>

47
db/seeds.rb

@ -70,7 +70,7 @@ unless Rails.env.test?
end
if Rails.env.development? && Scheme.count.zero?
Scheme.create!(
scheme1 = Scheme.create!(
code: "S878",
service_name: "Beulahside Care",
sensitive: 0,
@ -85,7 +85,7 @@ unless Rails.env.test?
created_at: Time.zone.now,
)
Scheme.create!(
scheme2 = Scheme.create!(
code: "S312",
service_name: "Abdullahview Point",
sensitive: 0,
@ -100,7 +100,7 @@ unless Rails.env.test?
created_at: Time.zone.now,
)
scheme = Scheme.create!(
Scheme.create!(
code: "7XYZ",
service_name: "Caspermouth Center",
sensitive: 1,
@ -115,16 +115,41 @@ unless Rails.env.test?
created_at: Time.zone.now,
)
Location.create(
scheme: scheme,
location_code: "7XYZ",
postcode: "ZX1 177",
address_line1: "1 High street",
address_line2: "London",
type_of_unit: "unit",
type_of_building: "building",
Location.create!(
scheme: scheme1,
location_code: "S254-CU193AA",
postcode: "CU19 3AA",
address_line1: "Rectory Road",
address_line2: "North Chaim",
type_of_unit: "Self-contained flat or bedsit",
type_of_building: "Purpose-built",
county: "Mid Sussex",
wheelchair_adaptation: 0,
)
Location.create!(
scheme: scheme1,
location_code: "S254-DM250DC",
postcode: "DM25 0DC",
address_line1: "Smithy Lane",
address_line2: "North Kellieworth",
type_of_unit: "Self-contained flat or bedsit with common facilities",
type_of_building: "Converted from previous residential or non-residential property",
county: "Fife",
wheelchair_adaptation: 1,
)
Location.create!(
scheme: scheme2,
location_code: "S254-YX130WP",
postcode: "YX13 0WP",
address_line1: "Smithy Lane",
address_line2: "East Darwin",
type_of_unit: "Shared house or hostel",
type_of_building: "Converted from previous residential or non-residential property",
county: "Rochford",
wheelchair_adaptation: 1,
)
end
pp "Seeded 3 dummy schemes"

4
spec/features/schemes_spec.rb

@ -112,7 +112,7 @@ RSpec.describe "Schemes scheme Features" do
end
context "when I click to see individual scheme" do
let(:scheme) { schemes.first }
let(:scheme) { schemes.first }
before do
click_link(scheme.service_name)
@ -134,7 +134,7 @@ RSpec.describe "Schemes scheme Features" do
context "when there are locations that belong to the selected scheme" do
let!(:schemes) { FactoryBot.create_list(:scheme, 5) }
let(:scheme) { schemes.first }
let!(:locations) { FactoryBot.create_list(:location, 3, scheme: scheme) }
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) }
before do
visit("schemes")

2
spec/requests/schemes_controller_spec.rb

@ -274,7 +274,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator user" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme: scheme) }
let!(:location) { FactoryBot.create(:location, scheme:) }
before do
sign_in user

Loading…
Cancel
Save