Skip to content

Commit

Permalink
Search maps by a location (publiclab#924)
Browse files Browse the repository at this point in the history
* Search maps by location

* mend

* Search by location -2

* Error fixed

* routes updated

* Naming changed

* Changes fixed

* Like operation fixed

* Error 500 solved

* Test added
  • Loading branch information
divyabaid16 authored and chen-robert committed Dec 5, 2019
1 parent e107c19 commit 7316b63
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/controllers/front_ui_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ def save_location

def about; end

def location
@loc = params[:loc]

@maps = Map.page(params[:maps])
.per_page(20)
.where('archived = ? and password = ? and location LIKE ?', false, '', "%#{@loc}%")
.order('updated_at DESC')
.group('maps.id')

respond_to do |format|
format.js
end
end

def gallery
@maps = Map.page(params[:maps])
.per_page(20)
Expand Down
15 changes: 14 additions & 1 deletion app/views/front_ui/gallery.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#authors" role="tab" aria-selected="false">Authors</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#location" role="tab" aria-selected="false">Location</a>
</li>
<% if params[:controller] == "tags" %>
<li class="nav-item">
<a class="nav-link" role="tab" href="/feeds/tag/<%= params[:id] %>" aria-selected="false">RSS</a>
Expand All @@ -41,7 +44,17 @@
<div class="tab-pane fade" id="authors" role="tabpanel">
<%= render :partial => 'front_ui/featured_mappers', :locals => { :mappers => @authors } %>
</div>
<div class="tab-pane fade" id="location" role="tabpanel">
<div style="text-align: center;">
<%= form_tag("/location", method: "get", remote: true) do %>
<%= label_tag(:loc, "Enter location:") %>
<%= text_field_tag :loc %>
<%= submit_tag "Search"%>
<% end %>
</div>
<div id="display-location"></div>
</div>
</div>
<% end %>

</div>
</div>
1 change: 1 addition & 0 deletions app/views/front_ui/location.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#display-location").html("<%= j render :partial => 'front_ui/maps', :locals => { :maps => @maps} %>");
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
get 'all_maps', to: 'front_ui#all_maps'
get 'anonymous', to: 'front_ui#anonymous'
get 'gallery', to: 'front_ui#gallery'
get 'location' => 'front_ui#location'
post 'save_location', to: 'front_ui#save_location'

get 'legacy', to: 'maps#index' # remove once new front page is stable
Expand Down
11 changes: 11 additions & 0 deletions test/controllers/front_ui_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class FrontUiControllerTest < ActionController::TestCase

def setup
@map = maps(:saugus)
end

def teardown
Expand Down Expand Up @@ -35,4 +36,14 @@ def teardown
assert assigns(:nearby_mappers)
assert_template 'front_ui/nearby_mappers'
end

test 'search map by location' do
get :location, params: { loc: 'India'}, xhr: true
@maps = assigns(:maps)

assert_response :success
assert !@maps.collect(&:name).include?('Saugus Landfill Incinerator')
assert @maps.collect(&:name).include?('Cubbon Park')
end

end

0 comments on commit 7316b63

Please sign in to comment.