Commit 807a3009809fb22a6182f1f556afee127c1558b8
1 parent
cf1a2316
Exists in
master
and in
29 other branches
ActionItem341: remembering search options from one search to another
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1731 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
14 additions
and
2 deletions
Show diff stats
app/controllers/public/search_controller.rb
@@ -13,6 +13,10 @@ class SearchController < ApplicationController | @@ -13,6 +13,10 @@ class SearchController < ApplicationController | ||
13 | 13 | ||
14 | def load_search_assets | 14 | def load_search_assets |
15 | @search_in = SEARCH_IN | 15 | @search_in = SEARCH_IN |
16 | + @searching = {} | ||
17 | + @search_in.each do |key, name| | ||
18 | + @searching[key] = params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s) | ||
19 | + end | ||
16 | end | 20 | end |
17 | 21 | ||
18 | def prepare_filter | 22 | def prepare_filter |
@@ -54,7 +58,7 @@ class SearchController < ApplicationController | @@ -54,7 +58,7 @@ class SearchController < ApplicationController | ||
54 | @results = {} | 58 | @results = {} |
55 | @names = {} | 59 | @names = {} |
56 | SEARCH_IN.each do |key, description| | 60 | SEARCH_IN.each do |key, description| |
57 | - @results[key] = @finder.send(key, @filtered_query) if params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s) | 61 | + @results[key] = @finder.send(key, @filtered_query) if @searching[key] |
58 | @names[key] = gettext(description) | 62 | @names[key] = gettext(description) |
59 | end | 63 | end |
60 | end | 64 | end |
app/views/search/_search_form.rhtml
@@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
26 | <% @search_in.map { |t,n| [t,gettext(n)] } . | 26 | <% @search_in.map { |t,n| [t,gettext(n)] } . |
27 | sort_by(&:last).each do |thing, name| %> | 27 | sort_by(&:last).each do |thing, name| %> |
28 | <li> | 28 | <li> |
29 | - <%= labelled_check_box name, 'find_in[]', thing.to_s, true %> | 29 | + <%= labelled_check_box name, 'find_in[]', thing.to_s, @searching[thing.to_sym] %> |
30 | </li> | 30 | </li> |
31 | <% end %> | 31 | <% end %> |
32 | </ul> | 32 | </ul> |
test/functional/search_controller_test.rb
@@ -550,5 +550,13 @@ class SearchControllerTest < Test::Unit::TestCase | @@ -550,5 +550,13 @@ class SearchControllerTest < Test::Unit::TestCase | ||
550 | 550 | ||
551 | assert_includes assigns(:results)[:people], p | 551 | assert_includes assigns(:results)[:people], p |
552 | end | 552 | end |
553 | + | ||
554 | + should 'keep asset selection for new searches' do | ||
555 | + get :index, :query => 'a sample query', :find_in => [ 'people', 'communities' ] | ||
556 | + assert_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'people', :checked => 'checked' } | ||
557 | + assert_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'communities', :checked => 'checked' } | ||
558 | + assert_no_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'enterprises', :checked => 'checked' } | ||
559 | + assert_no_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'products', :checked => 'checked' } | ||
560 | + end | ||
553 | 561 | ||
554 | end | 562 | end |