diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index a75111c..9235704 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -20,7 +20,7 @@ class SearchController < PublicController def index @searches = {} - @order = [] + @assets = [] @names = {} @results_only = true @@ -28,7 +28,7 @@ class SearchController < PublicController load_query @asset = key send(key) - @order << key + @assets << key @names[key] = _(description) end @asset = nil @@ -42,7 +42,7 @@ class SearchController < PublicController # view the summary of one category def category_index @searches = {} - @order = [] + @assets = [] @names = {} limit = MULTIPLE_SEARCH_LIMIT [ @@ -53,7 +53,7 @@ class SearchController < PublicController [ :communities, _('Communities'), :recent_communities ], [ :articles, _('Contents'), :recent_articles ] ].each do |asset, name, filter| - @order << asset + @assets << asset @searches[asset]= {:results => @category.send(filter, limit)} raise "No total_entries for: #{asset}" unless @searches[asset][:results].respond_to?(:total_entries) @names[asset] = name diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index c76b15e..14a6c3a 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -110,29 +110,26 @@ module SearchHelper end def filters(asset) + return if !asset klass = asset_class(asset) content_tag('div', klass::SEARCH_FILTERS.map do |name, options| select_filter(name, options) end.join("\n"), :id => 'search-filters') end + + def assets_links(selected) + assets = SEARCHES.keys + content_tag('ul', + assets.map do |asset| + options = {} + options.merge!(:class => 'selected') if selected.to_s == asset.to_s + content_tag('li', asset_link(asset), options) + end.join("\n"), + :id => 'assets-links') end - def filter_title(asset, filter) - { - 'articles_more_recent' => _('More recent contents from network'), - 'articles_more_popular' => _('More viewed contents from network'), - 'articles_more_comments' => _('Most commented contents from network'), - 'people_more_recent' => _('More recent people from network'), - 'people_more_active' => _('More active people from network'), - 'people_more_popular' => _('More popular people from network'), - 'communities_more_recent' => _('More recent communities from network'), - 'communities_more_active' => _('More active communities from network'), - 'communities_more_popular' => _('More popular communities from network'), - 'enterprises_more_recent' => _('More recent enterprises from network'), - 'enterprises_more_active' => _('More active enterprises from network'), - 'enterprises_more_popular' => _('More popular enterprises from network'), - 'products_more_recent' => _('Highlights'), - }[asset.to_s + '_' + filter].to_s + def asset_link(asset) + link_to(SEARCHES[asset], "/search/#{asset}") end end diff --git a/app/views/search/_results_header.html.erb b/app/views/search/_results_header.html.erb deleted file mode 100644 index 39fed43..0000000 --- a/app/views/search/_results_header.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -
"> -
<%= filter_title(@asset, @filter) %>
- <%= display_selector(@asset, params[:display]) %> - <%= filter_selector(@asset, @filter) %> -
-
diff --git a/app/views/search/_search_form.html.erb b/app/views/search/_search_form.html.erb index d044381..c4e77e2 100644 --- a/app/views/search/_search_form.html.erb +++ b/app/views/search/_search_form.html.erb @@ -1,15 +1,15 @@ -
+
<%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.path : nil ) }, :method => 'get', :class => 'search_form' ) do %> - - <%= hidden_field_tag :display, params[:display] %> - <%= hidden_field_tag :filter, params[:filter] %> +
+ <%= assets_links(@asset) %> + <%= filters(@asset) %> +
- <%= search_input_with_suggestions('query', @asset, @query, {:size => 50}) %> - <%= javascript_tag "jQuery('#search-input').attr('title', \"#{hint}\").hint()" if defined?(hint) %> + <%= search_input_with_suggestions('query', @asset, @query, {:size => 50, :placeholder => hint}) %> <%= submit_button(:search, _('Search')) %> diff --git a/app/views/search/search_page.html.erb b/app/views/search/search_page.html.erb index a7e0a14..33a507c 100644 --- a/app/views/search/search_page.html.erb +++ b/app/views/search/search_page.html.erb @@ -1,8 +1,5 @@ -<%= search_page_title( @titles[@asset], @category ) %> <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> -<%= render :partial => 'results_header' %> - <%= render :partial => 'search_content' %>
diff --git a/public/javascripts/search.js b/public/javascripts/search.js index 49c01c8..e2ebfff 100644 --- a/public/javascripts/search.js +++ b/public/javascripts/search.js @@ -20,10 +20,17 @@ return false; }); - $("input#search-input").typeWatch({ - callback: function (value) {$('form.search_form').submit()}, - wait: 750, - highlight: true, - captureLength: 2 + // Assets links + $('#assets-links a').click(function(e){ + e.preventDefault(); + window.location.href = $(this).attr("href") + '?query=' + $('#search-input').val(); }); + + // Real time search + // $("input#search-input").typeWatch({ + // callback: function (value) {$('form.search_form').submit()}, + // wait: 750, + // highlight: true, + // captureLength: 2 + // }); })(jQuery); diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 54babda..7d00890 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -283,7 +283,7 @@ class SearchControllerTest < ActionController::TestCase should 'search all enabled assets in general search' do ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise') prod_cat = create(ProductCategory, :name => 'pctest', :environment => Environment.default) - prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat) + prod = create(Product,:name => 'test product', :product_category => prod_cat, :enterprise => ent1) art = create(Article, :name => 'test article', :profile_id => fast_create(Person).id) per = create(Person, :name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id) com = create(Community, :name => 'test community') @@ -301,7 +301,7 @@ class SearchControllerTest < ActionController::TestCase should 'display category image while in directory' do parent = Category.create!(:name => 'category1', :environment => Environment.default) cat = Category.create!(:name => 'category2', :environment => Environment.default, :parent_id => parent.id, - :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} + :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} ) process_delayed_job_queue @@ -447,11 +447,6 @@ class SearchControllerTest < ActionController::TestCase assert_tag :tag => 'div', :attributes => {:class => /search-results-articles/} , :descendant => {:tag => 'a', :attributes => { :href => '/search/articles/my-category'}} end - should 'display correct title on list communities' do - get :communities - assert_tag :tag => 'h1', :content => 'Communities' - end - should 'indicate more than the page limit for total_entries' do Enterprise.destroy_all ('1'..'20').each do |n| -- libgit2 0.21.2