Skip to content

Commit

Permalink
Merge pull request #358 from dgmstuart/dgms/more-map-fixes
Browse files Browse the repository at this point in the history
Fix: Map: "All" works correctly with date in URL
  • Loading branch information
dgmstuart authored Apr 15, 2024
2 parents 54a6352 + 113a560 commit 4fb1874
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/helpers/listings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def swingclass_listing(swingclass, day)
end

def class_map_url(day, venue)
map_classes_path(day:, venue_id: venue.id) unless venue.coordinates.nil?
map_classes_day_path(day:, venue_id: venue.id) unless venue.coordinates.nil?
end

def swingclass_link(event)
Expand Down
24 changes: 21 additions & 3 deletions app/helpers/map_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
# frozen_string_literal: true

module MapHelper
def map_update_control_link(text, query, selected:, url:)
link_to text, query, {
def map_update_control_link_item(url_helper, item)
map_update_control_link(
text: item.to_s,
html_url: public_send(url_helper, item.to_param),
json_url: public_send(url_helper, item.to_param, format: :json),
selected: item.selected?
)
end

def map_update_control_link_all(text, url_helper, selected:)
map_update_control_link(
text:,
html_url: public_send(url_helper),
json_url: public_send(url_helper, format: :json),
selected:
)
end

def map_update_control_link(text:, html_url:, json_url:, selected:)
link_to text, html_url, {
class: (:selected if selected),
data: {
action: "map#update:prevent map-menu#choose:prevent",
map_menu_target: "updateControl",
url:
url: json_url
}
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/social_listing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def location
def map_url(date)
return unless show_on_map?

url_helpers.map_socials_path(date: date.to_fs(:db), venue_id: event.venue_id)
url_helpers.map_socials_date_path(date: date.to_fs(:db), venue_id: event.venue_id)
end

private
Expand Down
14 changes: 2 additions & 12 deletions app/views/maps/classes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
<% @days.menu_days.each do |day| %>
<% if day.events? %>
<li>
<%= map_update_control_link(
day.to_s,
{ day: day.to_param},
selected: day.selected?,
url: map_classes_path(day.to_param, format: :json)
) %>
<%= map_update_control_link_item(:map_classes_day_path, day) %>
</li>
<% else %>
<li class="no-events">
Expand All @@ -33,12 +28,7 @@
<% end %>
<% end %>
<li>
<%= map_update_control_link(
"All",
"#",
selected: @days.selected_day.blank?,
url: map_classes_path(format: :json)
) %>
<%= map_update_control_link_all("All", :map_classes_path, selected: @days.selected_day.blank?) %>
</li>
</ul>
<p class="note">
Expand Down
14 changes: 2 additions & 12 deletions app/views/maps/socials.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
<% @map_dates.menu_dates.each do |date| %>
<% if date.events? %>
<%= tag.li class: ("end-of-week" if date.sunday?) do %>
<%= map_update_control_link(
date.to_s,
{ date: date.to_param },
selected: date.selected?,
url: map_socials_path(date.to_param, format: :json)
) %>
<%= map_update_control_link_item(:map_socials_date_path, date) %>
<% end %>
<% else %>
<%= tag.li class: ["no-events", ("end-of-week" if date.sunday?)] do %>
Expand All @@ -37,12 +32,7 @@
<% end %>
<% end %>
<li>
<%= map_update_control_link(
"All",
"#",
selected: @map_dates.selected_date.blank?,
url: map_socials_path(format: :json)
) %>
<%= map_update_control_link_all("All", :map_socials_path, selected: @map_dates.selected_date.blank?) %>
</li>
</ul>
<% end %>
2 changes: 1 addition & 1 deletion app/views/sitemaps/index.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ xml.tag!(
render("url", builder: xml, link_url: map_classes_url, change_frequency: "weekly", priority: 0.9)

DAYNAMES.each do |day|
render("url", builder: xml, link_url: map_classes_url(day:), change_frequency: "weekly", priority: 0.7)
render("url", builder: xml, link_url: map_classes_day_url(day:), change_frequency: "weekly", priority: 0.7)
end

render("url", builder: xml, link_url: privacy_url, change_frequency: "yearly", priority: 0.4)
Expand Down
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

resources :external_events, only: %i[edit update]

get "map/classes/(:day)" => "maps#classes", as: :map_classes
get "map/socials/(:date)" => "maps#socials", as: :map_socials
get "map/classes" => "maps#classes", as: :map_classes
get "map/classes/:day" => "maps#classes", as: :map_classes_day
get "map/socials" => "maps#socials", as: :map_socials
get "map/socials/:date" => "maps#socials", as: :map_socials_date
get "map" => "maps#socials"
get "venue_map_info/:id" => "maps#venue_map_info", :as => :venue_map_info
get "occasional" => "occasional_events#index"
Expand Down
5 changes: 3 additions & 2 deletions spec/presenters/social_listing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "active_support"
require "active_support/core_ext/module/delegation"
require "active_support/core_ext/string/conversions"
require "active_support/core_ext/object/blank" # needed for String#to_date
require "app/presenters/social_listing"
require "spec/support/time_formats_helper"

Expand Down Expand Up @@ -76,13 +77,13 @@
context "when the venue has coordinates" do
it "is a link to the venue on the map" do
event = instance_double("Event", venue_id: 5, venue_coordinates: double)
url_helpers = double(map_socials_path: "a-map-url") # rubocop:disable RSpec/VerifiedDoubles
url_helpers = double(map_socials_date_path: "a-map-url") # rubocop:disable RSpec/VerifiedDoubles

social_listing = described_class.new(event, url_helpers:)

aggregate_failures do
expect(social_listing.map_url("11 July 1936".to_date)).to eq("a-map-url")
expect(url_helpers).to have_received(:map_socials_path)
expect(url_helpers).to have_received(:map_socials_date_path)
.with(date: "1936-07-11", venue_id: 5)
end
end
Expand Down

0 comments on commit 4fb1874

Please sign in to comment.