diff --git a/app/controllers/front_ui_controller.rb b/app/controllers/front_ui_controller.rb
index 4c68f927..7eb43482 100644
--- a/app/controllers/front_ui_controller.rb
+++ b/app/controllers/front_ui_controller.rb
@@ -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)
diff --git a/app/views/front_ui/gallery.html.erb b/app/views/front_ui/gallery.html.erb
index 45a93d85..e266e12f 100644
--- a/app/views/front_ui/gallery.html.erb
+++ b/app/views/front_ui/gallery.html.erb
@@ -20,6 +20,9 @@
Authors
+
+ Location
+
<% if params[:controller] == "tags" %>
RSS
@@ -41,7 +44,17 @@
<%= render :partial => 'front_ui/featured_mappers', :locals => { :mappers => @authors } %>
+
+
+ <%= form_tag("/location", method: "get", remote: true) do %>
+ <%= label_tag(:loc, "Enter location:") %>
+ <%= text_field_tag :loc %>
+ <%= submit_tag "Search"%>
+ <% end %>
+
+
+
<% end %>
-
+
\ No newline at end of file
diff --git a/app/views/front_ui/location.js.erb b/app/views/front_ui/location.js.erb
new file mode 100644
index 00000000..97062d76
--- /dev/null
+++ b/app/views/front_ui/location.js.erb
@@ -0,0 +1 @@
+$("#display-location").html("<%= j render :partial => 'front_ui/maps', :locals => { :maps => @maps} %>");
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index de570b36..8435a5b2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/test/controllers/front_ui_controller_test.rb b/test/controllers/front_ui_controller_test.rb
index 17ae6d6e..b3d6cab0 100644
--- a/test/controllers/front_ui_controller_test.rb
+++ b/test/controllers/front_ui_controller_test.rb
@@ -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