Commit b9a0b4d3e38dc31550135c3b26023f5d7d9fd855
1 parent
1e4f68ac
Exists in
master
and in
29 other branches
Preparing search filter scheme
Showing
8 changed files
with
63 additions
and
51 deletions
Show diff stats
app/controllers/public/search_controller.rb
... | ... | @@ -8,6 +8,7 @@ class SearchController < PublicController |
8 | 8 | before_filter :load_category |
9 | 9 | before_filter :load_search_assets |
10 | 10 | before_filter :load_query |
11 | + before_filter :load_filter | |
11 | 12 | |
12 | 13 | # Backwards compatibility with old URLs |
13 | 14 | def redirect_asset_param |
... | ... | @@ -145,8 +146,6 @@ class SearchController < PublicController |
145 | 146 | @order ||= [@asset] |
146 | 147 | params[:display] ||= 'list' |
147 | 148 | @searches ||= {} |
148 | - @filter = filter | |
149 | - @filter_title = filter_description(@asset, @filter) | |
150 | 149 | |
151 | 150 | @query = params[:query] || '' |
152 | 151 | @empty_query = @category.nil? && @query.blank? |
... | ... | @@ -166,42 +165,13 @@ class SearchController < PublicController |
166 | 165 | end |
167 | 166 | end |
168 | 167 | |
169 | - FILTERS = %w( | |
170 | - more_recent | |
171 | - more_active | |
172 | - more_popular | |
173 | - more_comments | |
174 | - ) | |
175 | - def filter | |
176 | - if FILTERS.include?(params[:filter]) | |
177 | - params[:filter] | |
178 | - else | |
179 | - 'more_recent' | |
180 | - end | |
181 | - end | |
182 | - | |
183 | - def filter_description(asset, filter) | |
184 | - { | |
185 | - 'articles_more_recent' => _('More recent contents from network'), | |
186 | - 'articles_more_popular' => _('More viewed contents from network'), | |
187 | - 'articles_more_comments' => _('Most commented contents from network'), | |
188 | - 'people_more_recent' => _('More recent people from network'), | |
189 | - 'people_more_active' => _('More active people from network'), | |
190 | - 'people_more_popular' => _('More popular people from network'), | |
191 | - 'communities_more_recent' => _('More recent communities from network'), | |
192 | - 'communities_more_active' => _('More active communities from network'), | |
193 | - 'communities_more_popular' => _('More popular communities from network'), | |
194 | - 'products_more_recent' => _('Highlights'), | |
195 | - }[asset.to_s + '_' + filter] | |
196 | - end | |
197 | - | |
198 | 168 | def load_search_assets |
199 | - if Searches.keys.include?(params[:action].to_sym) and environment.enabled?("disable_asset_#{params[:action]}") | |
169 | + if SEARCHES.keys.include?(params[:action].to_sym) && environment.enabled?("disable_asset_#{params[:action]}") | |
200 | 170 | render_not_found |
201 | 171 | return |
202 | 172 | end |
203 | 173 | |
204 | - @enabled_searches = Searches.select {|key, name| environment.disabled?("disable_asset_#{params[:action]}") } | |
174 | + @enabled_searches = SEARCHES.select {|key, name| environment.disabled?("disable_asset_#{params[:action]}") } | |
205 | 175 | @searching = {} |
206 | 176 | @titles = {} |
207 | 177 | @enabled_searches.each do |key, name| |
... | ... | @@ -211,6 +181,14 @@ class SearchController < PublicController |
211 | 181 | @names = @titles if @names.nil? |
212 | 182 | end |
213 | 183 | |
184 | + def load_filter | |
185 | + @filter = 'more_recent' | |
186 | + if SEARCHES.keys.include?(@asset.to_sym) | |
187 | + available_filters = asset_class(@asset)::SEARCH_FILTERS | |
188 | + @filter = params[:filter] if available_filters.include?(params[:filter]) | |
189 | + end | |
190 | + end | |
191 | + | |
214 | 192 | def limit |
215 | 193 | if map_search? |
216 | 194 | MAP_SEARCH_LIMIT |
... | ... | @@ -226,7 +204,7 @@ class SearchController < PublicController |
226 | 204 | end |
227 | 205 | |
228 | 206 | def paginate_options(page = params[:page]) |
229 | - page = 1 if multiple_search? or @display == 'map' | |
207 | + page = 1 if multiple_search? || params[:display] == 'map' | |
230 | 208 | { :per_page => limit, :page => page } |
231 | 209 | end |
232 | 210 | ... | ... |
app/helpers/search_helper.rb
... | ... | @@ -5,7 +5,7 @@ module SearchHelper |
5 | 5 | BLOCKS_SEARCH_LIMIT = 24 |
6 | 6 | MULTIPLE_SEARCH_LIMIT = 8 |
7 | 7 | |
8 | - Searches = ActiveSupport::OrderedHash[ | |
8 | + SEARCHES = ActiveSupport::OrderedHash[ | |
9 | 9 | :articles, _('Contents'), |
10 | 10 | :enterprises, _('Enterprises'), |
11 | 11 | :people, _('People'), |
... | ... | @@ -22,7 +22,7 @@ module SearchHelper |
22 | 22 | end |
23 | 23 | |
24 | 24 | def map_search? |
25 | - !multiple_search? and params[:display] == 'map' | |
25 | + !multiple_search? && params[:display] == 'map' | |
26 | 26 | end |
27 | 27 | |
28 | 28 | def asset_class(asset) |
... | ... | @@ -86,4 +86,22 @@ module SearchHelper |
86 | 86 | end |
87 | 87 | end |
88 | 88 | |
89 | + def filter_title(asset, filter) | |
90 | + { | |
91 | + 'articles_more_recent' => _('More recent contents from network'), | |
92 | + 'articles_more_popular' => _('More viewed contents from network'), | |
93 | + 'articles_more_comments' => _('Most commented contents from network'), | |
94 | + 'people_more_recent' => _('More recent people from network'), | |
95 | + 'people_more_active' => _('More active people from network'), | |
96 | + 'people_more_popular' => _('More popular people from network'), | |
97 | + 'communities_more_recent' => _('More recent communities from network'), | |
98 | + 'communities_more_active' => _('More active communities from network'), | |
99 | + 'communities_more_popular' => _('More popular communities from network'), | |
100 | + 'enterprises_more_recent' => _('More recent enterprises from network'), | |
101 | + 'enterprises_more_active' => _('More active enterprises from network'), | |
102 | + 'enterprises_more_popular' => _('More popular enterprises from network'), | |
103 | + 'products_more_recent' => _('Highlights'), | |
104 | + }[asset.to_s + '_' + filter].to_s | |
105 | + end | |
106 | + | |
89 | 107 | end | ... | ... |
app/models/article.rb
... | ... | @@ -10,6 +10,12 @@ class Article < ActiveRecord::Base |
10 | 10 | :filename => 1, |
11 | 11 | } |
12 | 12 | |
13 | + SEARCH_FILTERS = %w[ | |
14 | + more_recent | |
15 | + more_popular | |
16 | + more_comments | |
17 | + ] | |
18 | + | |
13 | 19 | track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? } |
14 | 20 | |
15 | 21 | # xss_terminate plugin can't sanitize array fields |
... | ... | @@ -198,20 +204,12 @@ class Article < ActiveRecord::Base |
198 | 204 | named_scope :public, |
199 | 205 | :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ] |
200 | 206 | |
201 | - named_scope :more_recent, | |
202 | - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND | |
203 | - ((articles.type != ?) OR articles.type is NULL)", | |
204 | - true, true, true, true, 'RssFeed' | |
205 | - ], | |
206 | - :order => 'articles.published_at desc, articles.id desc' | |
207 | - | |
208 | 207 | # retrives the most commented articles, sorted by the comment count (largest |
209 | 208 | # first) |
210 | 209 | def self.most_commented(limit) |
211 | 210 | paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) |
212 | 211 | end |
213 | 212 | |
214 | - named_scope :more_popular, :order => 'hits DESC' | |
215 | 213 | named_scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"] |
216 | 214 | |
217 | 215 | def self.recent(limit = nil, extra_conditions = {}, pagination = true) |
... | ... | @@ -418,8 +416,8 @@ class Article < ActiveRecord::Base |
418 | 416 | named_scope :images, :conditions => { :is_image => true } |
419 | 417 | named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] |
420 | 418 | |
419 | + named_scope :more_popular, :order => 'hits DESC' | |
421 | 420 | named_scope :more_comments, :order => "comments_count DESC" |
422 | - named_scope :more_views, :order => "hits DESC" | |
423 | 421 | named_scope :more_recent, :order => "created_at DESC" |
424 | 422 | |
425 | 423 | def self.display_filter(user, profile) |
... | ... | @@ -608,7 +606,7 @@ class Article < ActiveRecord::Base |
608 | 606 | |
609 | 607 | end |
610 | 608 | |
611 | - def more_views_label | |
609 | + def more_popular_label | |
612 | 610 | amount = self.hits |
613 | 611 | { |
614 | 612 | 0 => _('no views'), | ... | ... |
app/models/organization.rb
app/models/person.rb
app/models/product.rb
app/models/profile.rb
test/unit/article_test.rb
... | ... | @@ -1480,8 +1480,8 @@ class ArticleTest < ActiveSupport::TestCase |
1480 | 1480 | assert_respond_to Article, :more_comments |
1481 | 1481 | end |
1482 | 1482 | |
1483 | - should 'respond to more views' do | |
1484 | - assert_respond_to Article, :more_views | |
1483 | + should 'respond to more popular' do | |
1484 | + assert_respond_to Article, :more_popular | |
1485 | 1485 | end |
1486 | 1486 | |
1487 | 1487 | should "return the more recent label" do |
... | ... | @@ -1510,19 +1510,19 @@ class ArticleTest < ActiveSupport::TestCase |
1510 | 1510 | should "return no views if profile has 0 views" do |
1511 | 1511 | a = Article.new |
1512 | 1512 | assert_equal 0, a.hits |
1513 | - assert_equal "no views", a.more_views_label | |
1513 | + assert_equal "no views", a.more_popular_label | |
1514 | 1514 | end |
1515 | 1515 | |
1516 | 1516 | should "return 1 view on label if the content has 1 view" do |
1517 | 1517 | a = Article.new(:hits => 1) |
1518 | 1518 | assert_equal 1, a.hits |
1519 | - assert_equal "one view", a.more_views_label | |
1519 | + assert_equal "one view", a.more_popular_label | |
1520 | 1520 | end |
1521 | 1521 | |
1522 | 1522 | should "return number of views on label if the content has more than one view" do |
1523 | 1523 | a = Article.new(:hits => 4) |
1524 | 1524 | assert_equal 4, a.hits |
1525 | - assert_equal "4 views", a.more_views_label | |
1525 | + assert_equal "4 views", a.more_popular_label | |
1526 | 1526 | end |
1527 | 1527 | |
1528 | 1528 | should 'return only text articles' do | ... | ... |