Browse Source

Add a map to the search result page

tags/0.3.6^2
Bèr Kessels 1 month ago
parent
commit
dcc4de236c

+ 6
- 0
app/models/search_result.rb View File

@@ -20,6 +20,12 @@ module Hours
@paginator = paginator
end

def geometry
return Base::NULL_ISLAND if collection.empty?

collection.first.geometry
end

def collection
@collection.map do |item|
if item.nil?

+ 1
- 1
app/views/region.erb View File

@@ -4,7 +4,7 @@
</p>
<% else %>
<%- set_content_for(
:closing_js,
:closing_js,
erb(:map_js_partial, locals: { index: @region })
) %>


+ 5
- 0
app/views/search.erb View File

@@ -1,5 +1,10 @@
<h2>Zoekresultaat voor <%= @search_result.query %></h2>

<%- set_content_for(
:closing_js,
erb(:map_js_partial, locals: { index: @search_result })
) %>

<section class="row">
<div class="col-3 list-group">
<%- @search_result.collection.each do |place| %>

+ 0
- 2
test/models/place_test.rb View File

@@ -54,8 +54,6 @@ describe Hours::Models::Place do
end

describe 'geometry' do
let(:nijmegen) { GeoRuby::SimpleFeatures::Point.from_xy(51.8425, 5.85278) }

it 'takes the value if set' do
subject.geometry = nijmegen
assert_equal nijmegen, subject.geometry

+ 12
- 0
test/models/search_result_test.rb View File

@@ -24,6 +24,18 @@ describe Hours::Models::SearchResult do
end
end

describe '#geometry' do
it 'without results returns NULL_ISLAND' do
subject = Hours::Models::SearchResult.new(collection: [])
assert_equal null_island, subject.geometry
end
it 'returns geometry from first result' do
place = OpenStruct.new(geometry: nijmegen)
subject = Hours::Models::SearchResult.new(collection: [place])
assert_equal nijmegen, subject.geometry
end
end

describe '#error' do
subject do
Hours::Models::SearchResult.new(collection: collection, error: 'An Error')

+ 4
- 0
test/support/location_helpers.rb View File

@@ -11,6 +11,10 @@ module LocationHelpers
GeoRuby::SimpleFeatures::Point.from_xy(0, 0)
end

def nijmegen
GeoRuby::SimpleFeatures::Point.from_xy(51.8425, 5.85278)
end

def assert_nearby(expected, actual, delta = DISTANCE_DELTA, message = nil)
[0, 1].each do |index|
vector = index.zero? ? 'lat' : 'lon'

Loading…
Cancel
Save