Skip to content

Commit

Permalink
Pages tagged with place get a full-width map across the top of the p…
Browse files Browse the repository at this point in the history
…age (instead of in the sidebar) (publiclab#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
  • Loading branch information
sagarpreet-chadha authored and jywarren committed Apr 25, 2019
1 parent 1cb17d1 commit 77cb989
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 14 deletions.
6 changes: 5 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<body>

<%= render :partial => 'layouts/header' %>

<div id="top_map"> </div>
<div class="container">
<div class="row">

Expand Down
32 changes: 22 additions & 10 deletions app/views/map/_leaflet.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
<style>
#top_map { width:100%; height:300px; margin: 0 ; margin-top: -15px ; margin-bottom: 15px ; position: relative;}
</style>
<% else %>
<style>
#map<%= unique_id %> { width:100%; height:300px; margin: 0; position: relative;}
</style>
<div class="leaflet-map" id="map<%= unique_id %>"></div>
<% if defined? people %><p><i><small>Share your own location on <a href='/profile'>your profile</a>.</small></i></p><% end %>
<script>
<% end %>

<script>
var bounds = new L.LatLngBounds(new L.LatLng(84.67351257 , -172.96875) , new L.LatLng(-54.36775852 , 178.59375)) ;

var map<%= unique_id %> = L.map('map<%= unique_id %>' , {
maxBounds: bounds ,
maxBoundsViscosity: 0.75
}).setView([<%= lat %>,<%= lon %>], <%= lat.to_s.length.to_i %> + 6);
<% if top_map == true %>
var map<%= unique_id %> = L.map('top_map' , {
maxBounds: bounds ,
maxBoundsViscosity: 0.75
}).setView([<%= lat %>,<%= lon %>], <%= lat.to_s.length.to_i %> + 6);
<% else %>
var map<%= unique_id %> = L.map('map<%= unique_id %>' , {
maxBounds: bounds ,
maxBoundsViscosity: 0.75
}).setView([<%= lat %>,<%= lon %>], <%= lat.to_s.length.to_i %> + 6);
<% end %>

var markers_hash<%= unique_id %> = new Map() ;

var map_lat = <%= lat %> ;
var map_lon = <%= lon %> ;

Expand Down Expand Up @@ -110,6 +123,5 @@
map<%= unique_id %>.spin(false) ;
});
}) ;


</script>

</script>
4 changes: 3 additions & 1 deletion app/views/sidebar/_related.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
<div id="map_template" style="position: relative; display: inline-block;">
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/node_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ SubLatitudeLongitude2:
balloon:
tid: 26
name: balloon

place:
tid: 27
name: place
20 changes: 20 additions & 0 deletions test/system/place_tags_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 77cb989

Please sign in to comment.