Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show service area information on location lozenges #968

Merged
merged 5 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/stylesheets/base/turf.sass
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.neighbourhood
.neighbourhood, .service-area
// padding-top: 0.5rem
span
margin-top: 0.8rem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<li class="preview">
<div class="preview__header">
<h3><%= link_to name, link %></h3>
<% if show_neighbourhoods %>

<% if show_service_area? %>
<div class="service-area service-area--secondary preview__service-area">
<span><%= service_area_name %></span>
</div>
<% end %>

<% if show_neighbourhood? %>
<div class="neighbourhood <%= primary_neighbourhood? ? 'neighbourhood--primary' : 'neighbourhood--secondary' %> preview__neighbourhood">
<span><%= neighbourhood_name(badge_zoom_level) %></span>
</div>
<% end %>
</div>

<% if description %>
<div class="preview__details">
<%= content_tag :p, description %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# app/components/place/place_partner_preview_component.rb
class PlacePartnerPreviewComponent < MountainView::Presenter
properties :primary_neighbourhood, :previewee, :show_neighbourhoods, :badge_zoom_level
properties :primary_neighbourhood,
:previewee, :show_neighbourhoods, :badge_zoom_level, :service_areas

def name
previewee.name
Expand All @@ -12,6 +13,11 @@ def link
previewee
end

def show_neighbourhood?
return false if show_service_area?
show_neighbourhoods
end

def neighbourhood_name(badge_zoom_level)
return previewee.address&.neighbourhood&.district&.shortname if badge_zoom_level == 'district'

Expand All @@ -28,6 +34,18 @@ def primary_neighbourhood?
primary_neighbourhood && (previewee.address&.neighbourhood == primary_neighbourhood)
end

def show_service_area?
service_areas.count > 0
end

def service_area_name
if previewee.service_areas.count > 1
"various"
else
previewee.service_areas.first&.neighbourhood&.shortname
end
end

private

def previewee
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/partners_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@ def options_for_service_area_neighbourhoods
@all_neighbourhoods.filter { |e| e.name != '' }
.collect { |e| { name: e.contextual_name, id: e.id } }
end

def partner_service_area_text(partner)
neighbourhoods = partner.service_area_neighbourhoods.order(:name).all

if neighbourhoods.length == 1
neighbourhoods.first.name

else
head = neighbourhoods[0..-2]
tail = neighbourhoods[-1]

"#{head.map(&:name).join(', ')} and #{tail.name}"
end
end

end
4 changes: 4 additions & 0 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def should_generate_new_friendly_id?
slug.blank?
end

def has_service_areas?
service_areas.count > 0
end

def permalink
"https://placecal.org/partners/#{id}"
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/users/profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<ul>
<% current_user.neighbourhoods.each do |neighbourhood| %>
<li>
<%= link_to neighbourhood.name, edit_admin_neighbourhood_path(neighbourhood) %>
<%= link_to neighbourhood.contextual_name, edit_admin_neighbourhood_path(neighbourhood) %>
</li>
<% end %>
</ul>
Expand Down
1 change: 1 addition & 0 deletions app/views/partners/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<%= render_component("place_partner_preview",
previewee: partner,
primary_neighbourhood: @primary_neighbourhood,
service_areas: partner.service_areas,
show_neighbourhoods: @current_site.show_neighbourhoods?,
badge_zoom_level: @current_site.badge_zoom_level) %>
<% end %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/partners/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
%>

<h3 class="udl udl--fw allcaps h4">Address</h3>
<% if @partner.has_service_areas? %>
<p>We operate in <%= partner_service_area_text(@partner) %>.</p>
<% end %>
<%= render_component "address",
address: @partner.address
%>
Expand Down
43 changes: 43 additions & 0 deletions test/helpers/partners_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'test_helper'

class PartnersHelperTest < ActionView::TestCase
setup do
@partner = FactoryBot.create(:partner)
@hoods = [
FactoryBot.create(:neighbourhood, name: 'alpha'),
FactoryBot.create(:neighbourhood, name: 'beta'),
FactoryBot.create(:neighbourhood, name: 'cappa')
]
end

# testing partner_service_area_text

test "shows only one text correctly" do
@partner.service_areas.create neighbourhood: @hoods[0]

output = partner_service_area_text(@partner)

assert output == 'alpha'
end

test "shows two texts correctly" do
@partner.service_areas.create neighbourhood: @hoods[0]
@partner.service_areas.create neighbourhood: @hoods[1]

output = partner_service_area_text(@partner)

assert output == 'alpha and beta'
end

test "shows N texts correctly" do
@partner.service_areas.create neighbourhood: @hoods[0]
@partner.service_areas.create neighbourhood: @hoods[1]
@partner.service_areas.create neighbourhood: @hoods[2]

output = partner_service_area_text(@partner)

assert output == 'alpha, beta and cappa'
end
end
2 changes: 1 addition & 1 deletion test/integration/admin/user_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest
assert_select 'h3', text: 'Your neighbourhoods'
assert_select 'a[href=?]',
edit_admin_neighbourhood_path(@neighbourhood),
text: @neighbourhood.name
text: @neighbourhood.contextual_name
end

test "Profile form has correct fields for neighbourhood admin" do
Expand Down
22 changes: 22 additions & 0 deletions test/integration/partners_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,26 @@ class PartnersIntegrationTest < ActionDispatch::IntegrationTest
assert_select '.preview__header', text: @region_site_partners.first.name
assert_select '.preview__details', text: @region_site_partners.first.summary
end

test 'partner shows service area if available' do
partner = @default_site_partners.first
partner.service_areas.create! neighbourhood: @neighbourhood3

get partners_url
assert_response :success

assert_select '.service-area span', text: @neighbourhood3.shortname
end

test 'partner shows "various areas" if more than one service area present' do
partner = @default_site_partners.first
partner.service_areas.create! neighbourhood: @neighbourhood3
partner.service_areas.create! neighbourhood: @neighbourhood2

get partners_url
assert_response :success

assert_select '.service-area span', text: 'various'
end

end
Loading