mirror of
https://github.com/publiclab/mapknitter.git
synced 2025-12-11 18:59:59 +01:00
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:
committed by
Jeffrey Warren
parent
a13b97c370
commit
1ac63abb67
@@ -44,6 +44,20 @@ class FrontUiController < ApplicationController
|
|||||||
|
|
||||||
def about; end
|
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
|
def gallery
|
||||||
@maps = Map.page(params[:maps])
|
@maps = Map.page(params[:maps])
|
||||||
.per_page(20)
|
.per_page(20)
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" data-toggle="tab" href="#authors" role="tab" aria-selected="false">Authors</a>
|
<a class="nav-link" data-toggle="tab" href="#authors" role="tab" aria-selected="false">Authors</a>
|
||||||
</li>
|
</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" %>
|
<% if params[:controller] == "tags" %>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" role="tab" href="/feeds/tag/<%= params[:id] %>" aria-selected="false">RSS</a>
|
<a class="nav-link" role="tab" href="/feeds/tag/<%= params[:id] %>" aria-selected="false">RSS</a>
|
||||||
@@ -41,6 +44,16 @@
|
|||||||
<div class="tab-pane fade" id="authors" role="tabpanel">
|
<div class="tab-pane fade" id="authors" role="tabpanel">
|
||||||
<%= render :partial => 'front_ui/featured_mappers', :locals => { :mappers => @authors } %>
|
<%= render :partial => 'front_ui/featured_mappers', :locals => { :mappers => @authors } %>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
1
app/views/front_ui/location.js.erb
Normal file
1
app/views/front_ui/location.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$("#display-location").html("<%= j render :partial => 'front_ui/maps', :locals => { :maps => @maps} %>");
|
||||||
@@ -8,6 +8,7 @@ Mapknitter::Application.routes.draw do
|
|||||||
get 'all_maps', to: 'front_ui#all_maps'
|
get 'all_maps', to: 'front_ui#all_maps'
|
||||||
get 'anonymous', to: 'front_ui#anonymous'
|
get 'anonymous', to: 'front_ui#anonymous'
|
||||||
get 'gallery', to: 'front_ui#gallery'
|
get 'gallery', to: 'front_ui#gallery'
|
||||||
|
get 'location' => 'front_ui#location'
|
||||||
post 'save_location', to: 'front_ui#save_location'
|
post 'save_location', to: 'front_ui#save_location'
|
||||||
|
|
||||||
get 'legacy', to: 'maps#index' # remove once new front page is stable
|
get 'legacy', to: 'maps#index' # remove once new front page is stable
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ require 'test_helper'
|
|||||||
class FrontUiControllerTest < ActionController::TestCase
|
class FrontUiControllerTest < ActionController::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
@map = maps(:saugus)
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@@ -35,4 +36,14 @@ class FrontUiControllerTest < ActionController::TestCase
|
|||||||
assert assigns(:nearby_mappers)
|
assert assigns(:nearby_mappers)
|
||||||
assert_template 'front_ui/nearby_mappers'
|
assert_template 'front_ui/nearby_mappers'
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user