Search maps by a location (#924)

* 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
This commit is contained in:
Divya Baid
2019-08-27 23:50:32 +05:30
committed by Jeffrey Warren
parent a13b97c370
commit 1ac63abb67
5 changed files with 41 additions and 1 deletions

View File

@@ -44,6 +44,20 @@ class FrontUiController < ApplicationController
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)

View File

@@ -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>
@@ -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>

View File

@@ -0,0 +1 @@
$("#display-location").html("<%= j render :partial => 'front_ui/maps', :locals => { :maps => @maps} %>");

View File

@@ -8,6 +8,7 @@ Mapknitter::Application.routes.draw do
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

View File

@@ -3,6 +3,7 @@ require 'test_helper'
class FrontUiControllerTest < ActionController::TestCase
def setup
@map = maps(:saugus)
end
def teardown
@@ -35,4 +36,14 @@ class FrontUiControllerTest < ActionController::TestCase
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