Commit d3c8e3c4f3d4bbb7bf07bf9395d81837c8936592
1 parent
82fbfb86
Exists in
staging
and in
42 other branches
[search-improvements] Refactor search page
Showing
7 changed files
with
37 additions
and
47 deletions
Show diff stats
app/controllers/public/search_controller.rb
... | ... | @@ -20,7 +20,7 @@ class SearchController < PublicController |
20 | 20 | |
21 | 21 | def index |
22 | 22 | @searches = {} |
23 | - @order = [] | |
23 | + @assets = [] | |
24 | 24 | @names = {} |
25 | 25 | @results_only = true |
26 | 26 | |
... | ... | @@ -28,7 +28,7 @@ class SearchController < PublicController |
28 | 28 | load_query |
29 | 29 | @asset = key |
30 | 30 | send(key) |
31 | - @order << key | |
31 | + @assets << key | |
32 | 32 | @names[key] = _(description) |
33 | 33 | end |
34 | 34 | @asset = nil |
... | ... | @@ -42,7 +42,7 @@ class SearchController < PublicController |
42 | 42 | # view the summary of one category |
43 | 43 | def category_index |
44 | 44 | @searches = {} |
45 | - @order = [] | |
45 | + @assets = [] | |
46 | 46 | @names = {} |
47 | 47 | limit = MULTIPLE_SEARCH_LIMIT |
48 | 48 | [ |
... | ... | @@ -53,7 +53,7 @@ class SearchController < PublicController |
53 | 53 | [ :communities, _('Communities'), :recent_communities ], |
54 | 54 | [ :articles, _('Contents'), :recent_articles ] |
55 | 55 | ].each do |asset, name, filter| |
56 | - @order << asset | |
56 | + @assets << asset | |
57 | 57 | @searches[asset]= {:results => @category.send(filter, limit)} |
58 | 58 | raise "No total_entries for: #{asset}" unless @searches[asset][:results].respond_to?(:total_entries) |
59 | 59 | @names[asset] = name | ... | ... |
app/helpers/search_helper.rb
... | ... | @@ -110,29 +110,26 @@ module SearchHelper |
110 | 110 | end |
111 | 111 | |
112 | 112 | def filters(asset) |
113 | + return if !asset | |
113 | 114 | klass = asset_class(asset) |
114 | 115 | content_tag('div', klass::SEARCH_FILTERS.map do |name, options| |
115 | 116 | select_filter(name, options) |
116 | 117 | end.join("\n"), :id => 'search-filters') |
117 | 118 | end |
119 | + | |
120 | + def assets_links(selected) | |
121 | + assets = SEARCHES.keys | |
122 | + content_tag('ul', | |
123 | + assets.map do |asset| | |
124 | + options = {} | |
125 | + options.merge!(:class => 'selected') if selected.to_s == asset.to_s | |
126 | + content_tag('li', asset_link(asset), options) | |
127 | + end.join("\n"), | |
128 | + :id => 'assets-links') | |
118 | 129 | end |
119 | 130 | |
120 | - def filter_title(asset, filter) | |
121 | - { | |
122 | - 'articles_more_recent' => _('More recent contents from network'), | |
123 | - 'articles_more_popular' => _('More viewed contents from network'), | |
124 | - 'articles_more_comments' => _('Most commented contents from network'), | |
125 | - 'people_more_recent' => _('More recent people from network'), | |
126 | - 'people_more_active' => _('More active people from network'), | |
127 | - 'people_more_popular' => _('More popular people from network'), | |
128 | - 'communities_more_recent' => _('More recent communities from network'), | |
129 | - 'communities_more_active' => _('More active communities from network'), | |
130 | - 'communities_more_popular' => _('More popular communities from network'), | |
131 | - 'enterprises_more_recent' => _('More recent enterprises from network'), | |
132 | - 'enterprises_more_active' => _('More active enterprises from network'), | |
133 | - 'enterprises_more_popular' => _('More popular enterprises from network'), | |
134 | - 'products_more_recent' => _('Highlights'), | |
135 | - }[asset.to_s + '_' + filter].to_s | |
131 | + def asset_link(asset) | |
132 | + link_to(SEARCHES[asset], "/search/#{asset}") | |
136 | 133 | end |
137 | 134 | |
138 | 135 | end | ... | ... |
app/views/search/_results_header.html.erb
... | ... | @@ -1,6 +0,0 @@ |
1 | -<div class="search-results-header <%= "search-no-results" if @searches[@asset].nil? or @searches[@asset].length == 0 %>"> | |
2 | - <div id='search-filter-title'><%= filter_title(@asset, @filter) %></div> | |
3 | - <%= display_selector(@asset, params[:display]) %> | |
4 | - <%= filter_selector(@asset, @filter) %> | |
5 | - <div style="clear: both"></div> | |
6 | -</div> |
app/views/search/_search_form.html.erb
1 | -<div class='search-form'> | |
2 | 1 | |
2 | +<div class='search-form'> | |
3 | 3 | <%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.path : nil ) }, |
4 | 4 | :method => 'get', :class => 'search_form' ) do %> |
5 | - | |
6 | - <%= hidden_field_tag :display, params[:display] %> | |
7 | - <%= hidden_field_tag :filter, params[:filter] %> | |
5 | + <div id='search-header'> | |
6 | + <%= assets_links(@asset) %> | |
7 | + <%= filters(@asset) %> | |
8 | + </div> | |
8 | 9 | |
9 | 10 | <div class="search-field"> |
10 | 11 | <span class="formfield"> |
11 | - <%= search_input_with_suggestions('query', @asset, @query, {:size => 50}) %> | |
12 | - <%= javascript_tag "jQuery('#search-input').attr('title', \"#{hint}\").hint()" if defined?(hint) %> | |
12 | + <%= search_input_with_suggestions('query', @asset, @query, {:size => 50, :placeholder => hint}) %> | |
13 | 13 | </span> |
14 | 14 | |
15 | 15 | <%= submit_button(:search, _('Search')) %> | ... | ... |
app/views/search/search_page.html.erb
1 | -<%= search_page_title( @titles[@asset], @category ) %> | |
2 | 1 | |
3 | 2 | <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> |
4 | -<%= render :partial => 'results_header' %> | |
5 | - | |
6 | 3 | <%= render :partial => 'search_content' %> |
7 | 4 | |
8 | 5 | <div style="clear: both"></div> | ... | ... |
public/javascripts/search.js
... | ... | @@ -20,10 +20,17 @@ |
20 | 20 | return false; |
21 | 21 | }); |
22 | 22 | |
23 | - $("input#search-input").typeWatch({ | |
24 | - callback: function (value) {$('form.search_form').submit()}, | |
25 | - wait: 750, | |
26 | - highlight: true, | |
27 | - captureLength: 2 | |
23 | + // Assets links | |
24 | + $('#assets-links a').click(function(e){ | |
25 | + e.preventDefault(); | |
26 | + window.location.href = $(this).attr("href") + '?query=' + $('#search-input').val(); | |
28 | 27 | }); |
28 | + | |
29 | + // Real time search | |
30 | + // $("input#search-input").typeWatch({ | |
31 | + // callback: function (value) {$('form.search_form').submit()}, | |
32 | + // wait: 750, | |
33 | + // highlight: true, | |
34 | + // captureLength: 2 | |
35 | + // }); | |
29 | 36 | })(jQuery); | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -283,7 +283,7 @@ class SearchControllerTest < ActionController::TestCase |
283 | 283 | should 'search all enabled assets in general search' do |
284 | 284 | ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise') |
285 | 285 | prod_cat = create(ProductCategory, :name => 'pctest', :environment => Environment.default) |
286 | - prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat) | |
286 | + prod = create(Product,:name => 'test product', :product_category => prod_cat, :enterprise => ent1) | |
287 | 287 | art = create(Article, :name => 'test article', :profile_id => fast_create(Person).id) |
288 | 288 | per = create(Person, :name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id) |
289 | 289 | com = create(Community, :name => 'test community') |
... | ... | @@ -301,7 +301,7 @@ class SearchControllerTest < ActionController::TestCase |
301 | 301 | should 'display category image while in directory' do |
302 | 302 | parent = Category.create!(:name => 'category1', :environment => Environment.default) |
303 | 303 | cat = Category.create!(:name => 'category2', :environment => Environment.default, :parent_id => parent.id, |
304 | - :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} | |
304 | + :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} | |
305 | 305 | ) |
306 | 306 | |
307 | 307 | process_delayed_job_queue |
... | ... | @@ -447,11 +447,6 @@ class SearchControllerTest < ActionController::TestCase |
447 | 447 | assert_tag :tag => 'div', :attributes => {:class => /search-results-articles/} , :descendant => {:tag => 'a', :attributes => { :href => '/search/articles/my-category'}} |
448 | 448 | end |
449 | 449 | |
450 | - should 'display correct title on list communities' do | |
451 | - get :communities | |
452 | - assert_tag :tag => 'h1', :content => 'Communities' | |
453 | - end | |
454 | - | |
455 | 450 | should 'indicate more than the page limit for total_entries' do |
456 | 451 | Enterprise.destroy_all |
457 | 452 | ('1'..'20').each do |n| | ... | ... |