Commit 9ea382dedb5ed7f22f408c4d86a0dfadd5c8ddc4

Authored by JoenioCosta
1 parent 92828c21

ActionItem354: created simple and advanced search

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1840 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/search_controller.rb
... ... @@ -29,8 +29,8 @@ class SearchController < ApplicationController
29 29 end
30 30  
31 31 def check_search_whole_site
32   - if params[:search_whole_site] == 'yes'
33   - redirect_to params.merge(:category_path => [], :search_whole_site => nil)
  32 + if params[:search_whole_site_yes] or params[:search_whole_site] == 'yes'
  33 + redirect_to params.merge(:category_path => [], :search_whole_site => nil, :search_whole_site_yes => nil)
34 34 end
35 35 end
36 36  
... ...
app/models/category.rb
... ... @@ -54,6 +54,7 @@ class Category < ActiveRecord::Base
54 54 def display_in_menu?
55 55 # FIXME don't hardcode like this. Should be a setting of the environment, maybe
56 56 total_items >= 10
  57 + true
57 58 end
58 59  
59 60 end
... ...
app/views/search/_display_results.rhtml
1 1 <div id="search-results" class="<%= 'only-one-result-box' if @results.size == 1 %>">
2 2  
3   -<% if @category && !@query.blank? %>
4   -<div id="search-whole-site">
5   -<%= link_to _('Search for "%s" in the whole site') % @query,
6   - :controller => 'search', :action => 'index', :category_path => [], :query => @query %>
7   -</div>
8   -<% end %>
9   -
10 3 <%
11   - pos2 = :odd # allow to format in a two colons layout
12   - pos3 = 3 # allow to format in a thre colons layout
  4 + pos2 = :odd # allow to format in a two columns layout
  5 + pos3 = 3 # allow to format in a thre columns layout
13 6 %>
14 7 <% @results.each do |name,results| %>
15 8 <%
... ...
app/views/search/_search_form.rhtml
... ... @@ -7,20 +7,13 @@
7 7 <%= text_field_tag 'query', @query, :id => ( lightbox? ? 'popup-search-input' : '' ), :size => 50 %>
8 8 <%= javascript_tag '$("popup-search-input").focus()' if lightbox? %>
9 9 </span>
10   - <%= submit_button(:search, _('Search')) %>
  10 + <%= submit_button(:search, _('Search'), :name => :search_whole_site_no) %>
  11 + <% if @category %>
  12 + <%= submit_button(:search, _('Search in whole site'), :name => :search_whole_site_yes) %>
  13 + <% end %>
11 14 </div>
12 15  
13   - <% if @category %>
14   - <div class="search-options search-in">
15   - <h4><%= _('Search in:') %></h4>
16   - <div>
17   - <%= labelled_radio_button _('Only in %s') % @category.name, :search_whole_site, 'no', true %>
18   - <%= labelled_radio_button _('Whole site'), :search_whole_site, 'yes' %>
19   - </div>
20   - </div><!-- fim class="search-options" -->
21   - <% end %>
22   -
23   - <div class="search-options search-for">
  16 + <div class="search-options search-for" id='advanced-search-options' style="display: <%= simple_search ? 'none' : 'block' %>">
24 17 <h4><%= _('Search for:') %></h4>
25 18 <ul>
26 19 <% @search_in.map { |t,n| [t,gettext(n)] } .
... ... @@ -33,6 +26,13 @@
33 26 <br style="clear:both" />
34 27 </div><!-- fim class="search-options" -->
35 28  
  29 + <% if simple_search %>
  30 + <%= link_to_function(_('Advanced search'), nil, :id => 'advanced_search_link') do |page|
  31 + page['advanced_search_link'].hide
  32 + page['advanced-search-options'].toggle
  33 + end %>
  34 + <% end %>
  35 +
36 36 <% if lightbox?; button_bar do %>
37 37 <%= lightbox_close_button _('Close') %>
38 38 <% end; end %>
... ...
app/views/search/index.rhtml
1 1 <h1> <%=h @category ? (_('Search results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Search results for "%s"') % @query) %> </h1>
2 2  
  3 +<%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %>
  4 +
3 5 <%= render :partial => 'display_results' %>
4 6  
5   -<%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search") } %>
6 7 <br style="clear:both" />
7   -
... ...
test/functional/search_controller_test.rb
... ... @@ -393,8 +393,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase
393 393 Category.create!(:name => 'sub', :environment => Environment.default, :parent => parent)
394 394  
395 395 get :popup, :category_path => [ 'cat', 'sub']
396   - assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'search_whole_site', :value => 'yes' }
397   - assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'search_whole_site', :value => 'no', :checked => 'checked' }
  396 + assert_tag :tag => 'input', :attributes => { :type => 'submit', :name => 'search_whole_site_yes' }
  397 + assert_tag :tag => 'input', :attributes => { :type => 'submit', :name => 'search_whole_site_no' }
398 398 end
399 399  
400 400 should 'search in whole site when told so' do
... ... @@ -534,9 +534,9 @@ class SearchControllerTest &lt; Test::Unit::TestCase
534 534 }
535 535 end
536 536  
537   - should 'offer link to do the same search as before in general context' do
  537 + should 'offer button search in the whole site' do
538 538 get :index, :category_path => [ 'my-category' ], :query => 'a sample search'
539   - assert_tag :tag => 'a', :attributes => { :href => "/search?query=a+sample+search" }, :content => 'Search for "a sample search" in the whole site'
  539 + assert_tag :tag => 'input', :attributes => { :type => 'submit', :name => 'search_whole_site_yes' }
540 540 end
541 541  
542 542 should 'display only category name in "search results for ..." title' do
... ... @@ -562,6 +562,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
562 562 assert_includes assigns(:results)[:people], p
563 563 end
564 564  
  565 + # FIXME how do test link_to_remote?
565 566 should 'keep asset selection for new searches' do
566 567 get :index, :query => 'a sample query', :find_in => [ 'people', 'communities' ]
567 568 assert_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'people', :checked => 'checked' }
... ...