From 77cb989e5c5d466016a2dd970adfb3024fda9dc3 Mon Sep 17 00:00:00 2001 From: Sagarpreet Chadha Date: Thu, 25 Apr 2019 23:00:14 +0530 Subject: [PATCH] Pages tagged with place get a full-width map across the top of the page (instead of in the sidebar) (#5518) * full width map from sidebar * indentation done * code climate issue fixed * system test added * system test added * system test modification * assert presence of div * assert_selector used * tests modified --- app/helpers/application_helper.rb | 6 ++++- app/models/node.rb | 2 +- app/views/layouts/application.html.erb | 2 +- app/views/map/_leaflet.html.erb | 32 ++++++++++++++++++-------- app/views/sidebar/_related.html.erb | 4 +++- test/fixtures/node_tags.yml | 6 +++++ test/fixtures/tags.yml | 4 ++++ test/system/place_tags_test.rb | 20 ++++++++++++++++ 8 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 test/system/place_tags_test.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f07b8bfa4a1..f6e422959ba 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -94,7 +94,11 @@ def insert_extras(body) # we should move this to the Node model: def render_map(lat, lon) - render partial: 'map/leaflet', locals: { lat: lat, lon: lon } + render partial: 'map/leaflet', locals: { lat: lat, lon: lon, top_map: false } + end + + def render_top_map(lat, lon) + render partial: 'map/leaflet', locals: { lat: lat, lon: lon, top_map: true } end # we should move this to the Comment model: diff --git a/app/models/node.rb b/app/models/node.rb index 5a6bed732a1..a4a8068391e 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -436,7 +436,7 @@ def location_tags end end - # accests a tagname /or/ tagname ending in wildcard such as "tagnam*" + # access a tagname /or/ tagname ending in wildcard such as "tagnam*" # also searches for other tags whose parent field matches given tagname, # but not tags matching given tag's parent field def has_tag(tagname) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 247dd24ef3e..104d4ceb403 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -106,7 +106,7 @@ <%= render :partial => 'layouts/header' %> - +
diff --git a/app/views/map/_leaflet.html.erb b/app/views/map/_leaflet.html.erb index 4105deda187..e42d666e9c3 100644 --- a/app/views/map/_leaflet.html.erb +++ b/app/views/map/_leaflet.html.erb @@ -1,22 +1,35 @@ <%= render :partial => "map/mapDependencies" %> +<% top_map = top_map || false %> +<% unique_id = rand(1000) %> - <% unique_id = rand(1000) %> +<% if top_map == true %> + +<% else %>
<% if defined? people %>

Share your own location on your profile.

<% end %> - + + \ No newline at end of file diff --git a/app/views/sidebar/_related.html.erb b/app/views/sidebar/_related.html.erb index 55616bcf2ad..e3c8f3fe37c 100644 --- a/app/views/sidebar/_related.html.erb +++ b/app/views/sidebar/_related.html.erb @@ -44,7 +44,9 @@ <% if @node && @node.has_power_tag('response') %> <%= render partial: 'sidebar/notes', locals: { notes: @node.responses, title: I18n.t('sidebar._related.responses_to_note'), node: @node } %> <% end %> - <% if @node && !@node.has_power_tag('place') && @node.lat && @node.lon %> + <% if @node && @node.has_tag("place") && @node.lat && @node.lon %> + <%= render_top_map(@node.lat, @node.lon) %> + <% elsif @node && @node.lat && @node.lon %> <%= render_map(@node.lat, @node.lon) %> <% elsif @node&.has_power_tag('place') && !@node.lat && !@node.lon %>
diff --git a/test/fixtures/node_tags.yml b/test/fixtures/node_tags.yml index 5767cc51b22..4f1468e359b 100644 --- a/test/fixtures/node_tags.yml +++ b/test/fixtures/node_tags.yml @@ -76,6 +76,12 @@ blog2: nid: 13 date: <%= DateTime.now.to_i %> +place: + tid: 27 + uid: 1 + nid: 13 + date: <%= DateTime.now.to_i %> + question3: tid: 6 uid: 2 diff --git a/test/fixtures/tags.yml b/test/fixtures/tags.yml index 62e84a91f4d..c6c66b818b0 100644 --- a/test/fixtures/tags.yml +++ b/test/fixtures/tags.yml @@ -103,3 +103,7 @@ SubLatitudeLongitude2: balloon: tid: 26 name: balloon + +place: + tid: 27 + name: place diff --git a/test/system/place_tags_test.rb b/test/system/place_tags_test.rb new file mode 100644 index 00000000000..d9f2e3bf788 --- /dev/null +++ b/test/system/place_tags_test.rb @@ -0,0 +1,20 @@ +require "application_system_test_case" + +class PlaceTagsTest < ApplicationSystemTestCase + + # node blog has lat and lon tag and place tag . + test "pages tagged with place get a full-width map across the top of the page" do + visit nodes(:blog).path + assert_selector('h1', text: 'Blog post') + assert_selector('div#top_map') + assert_selector('div.leaflet-layer') + end + + # one map has no place tag . + test "pages not tagged with place gets a side map" do + visit nodes(:one).path + assert_selector('h1', text: 'Canon A1200 IR conversion at PLOTS Barnraising at LUMCON') + assert_selector('div.leaflet-layer' , count: 0) + end + +end