Commit d3482d96536d851a7a10af582ae6dfacfb267fce
1 parent
a528d454
Exists in
master
and in
29 other branches
ActionItem129: an initial form form specifing the parameters for search for sellers
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1776 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
41 additions
and
2 deletions
Show diff stats
app/controllers/public/search_controller.rb
... | ... | @@ -122,8 +122,11 @@ class SearchController < ApplicationController |
122 | 122 | end |
123 | 123 | |
124 | 124 | def sellers |
125 | + @categories = ProductCategory.find(:all) | |
126 | + @regions = Region.find(:all).select{|r|r.lat && r.lng} | |
127 | + @product_category = ProductCategory.find(params[:category]) if params[:category] | |
128 | + @region = Region.find(params[:region]) if params[:region] | |
125 | 129 | options = {} |
126 | - @product_category = ProductCategory.find_by_path(params[:product_category].join('/')) if params[:product_category] | |
127 | 130 | options.merge!({:include => :products, :conditions => ['products.product_category_id = ?', @product_category.id]}) if @product_category |
128 | 131 | options.merge!({:origin => [params[:lat].to_f, params[:long].to_f], :within => params[:radius] }) if params[:lat] && params[:long] && params[:radius] |
129 | 132 | @enterprises = Enterprise.find(:all, options) | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +<h2> | |
2 | +<% if @product_category %> | |
3 | + <% if params[:lat] && params[:long] && params[:radius] %> | |
4 | + <%= _('Listing sellers of %s witin %s km from %s %s') % [@product_category.name, params[:radius], params[:lat], params[:long]] %> | |
5 | + <% else %> | |
6 | + <%= _('Listing sellers of %s') % @product_category.name %> | |
7 | + <% end %> | |
8 | +<% else %> | |
9 | + <% if params[:lat] && params[:long] && params[:radius] %> | |
10 | + <%= _('Listing sellers witin %s km from %s %s') % [params[:radius], params[:lat], params[:long]] %> | |
11 | + <% else %> | |
12 | + <%= _('Listing sellers') %> | |
13 | + <% end %> | |
14 | +<% end %> | |
15 | +</h2> | |
16 | + | |
17 | +<% form_tag({}, {:method => 'get'}) do %> | |
18 | + <%= _('Category: ') %> <%= select_tag 'category', options_from_collection_for_select(@categories, :id, :name, @product_category) %><br/> | |
19 | + <%= _('Distance form point: ') %> <%= text_field_tag 'radius' %><br/> | |
20 | + <%= _('Region') %> <%= select_tag 'region', options_from_collection_for_select(@regions, :id, :name, @region) %><br/> | |
21 | + <%= submit_tag _('Search') %> | |
22 | +<% end %> | |
23 | + | |
24 | +<div class="search-results-innerbox search-results-type-profile common-profile-list-block %>"> | |
25 | + <ul> <%= render :partial => 'profile', :collection => @enterprises %> </ul> | |
26 | +</div> | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -759,6 +759,16 @@ class SearchControllerTest < Test::Unit::TestCase |
759 | 759 | assert_not_includes assigns(:results)[:comments], comment4 |
760 | 760 | end |
761 | 761 | |
762 | + should 'list all sellers' do | |
763 | + ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1') | |
764 | + ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2') | |
765 | + | |
766 | + get :sellers | |
767 | + | |
768 | + assert_includes assigns('enterprises'), ent1 | |
769 | + assert_includes assigns('enterprises'), ent2 | |
770 | + end | |
771 | + | |
762 | 772 | should 'find enterprise by product category' do |
763 | 773 | ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1') |
764 | 774 | prod_cat = ProductCategory.create!(:name => 'pc-test', :environment => Environment.default) |
... | ... | @@ -766,7 +776,7 @@ class SearchControllerTest < Test::Unit::TestCase |
766 | 776 | |
767 | 777 | ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2') |
768 | 778 | |
769 | - get :sellers, :product_category => ['pc-test'] | |
779 | + get :sellers, :category => prod_cat.id | |
770 | 780 | |
771 | 781 | assert_includes assigns('enterprises'), ent1 |
772 | 782 | assert_not_includes assigns('enterprises'), ent2 | ... | ... |