Commit b9a0b4d3e38dc31550135c3b26023f5d7d9fd855
1 parent
1e4f68ac
Exists in
master
and in
28 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,6 +8,7 @@ class SearchController < PublicController | ||
| 8 | before_filter :load_category | 8 | before_filter :load_category |
| 9 | before_filter :load_search_assets | 9 | before_filter :load_search_assets |
| 10 | before_filter :load_query | 10 | before_filter :load_query |
| 11 | + before_filter :load_filter | ||
| 11 | 12 | ||
| 12 | # Backwards compatibility with old URLs | 13 | # Backwards compatibility with old URLs |
| 13 | def redirect_asset_param | 14 | def redirect_asset_param |
| @@ -145,8 +146,6 @@ class SearchController < PublicController | @@ -145,8 +146,6 @@ class SearchController < PublicController | ||
| 145 | @order ||= [@asset] | 146 | @order ||= [@asset] |
| 146 | params[:display] ||= 'list' | 147 | params[:display] ||= 'list' |
| 147 | @searches ||= {} | 148 | @searches ||= {} |
| 148 | - @filter = filter | ||
| 149 | - @filter_title = filter_description(@asset, @filter) | ||
| 150 | 149 | ||
| 151 | @query = params[:query] || '' | 150 | @query = params[:query] || '' |
| 152 | @empty_query = @category.nil? && @query.blank? | 151 | @empty_query = @category.nil? && @query.blank? |
| @@ -166,42 +165,13 @@ class SearchController < PublicController | @@ -166,42 +165,13 @@ class SearchController < PublicController | ||
| 166 | end | 165 | end |
| 167 | end | 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 | def load_search_assets | 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 | render_not_found | 170 | render_not_found |
| 201 | return | 171 | return |
| 202 | end | 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 | @searching = {} | 175 | @searching = {} |
| 206 | @titles = {} | 176 | @titles = {} |
| 207 | @enabled_searches.each do |key, name| | 177 | @enabled_searches.each do |key, name| |
| @@ -211,6 +181,14 @@ class SearchController < PublicController | @@ -211,6 +181,14 @@ class SearchController < PublicController | ||
| 211 | @names = @titles if @names.nil? | 181 | @names = @titles if @names.nil? |
| 212 | end | 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 | def limit | 192 | def limit |
| 215 | if map_search? | 193 | if map_search? |
| 216 | MAP_SEARCH_LIMIT | 194 | MAP_SEARCH_LIMIT |
| @@ -226,7 +204,7 @@ class SearchController < PublicController | @@ -226,7 +204,7 @@ class SearchController < PublicController | ||
| 226 | end | 204 | end |
| 227 | 205 | ||
| 228 | def paginate_options(page = params[:page]) | 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 | { :per_page => limit, :page => page } | 208 | { :per_page => limit, :page => page } |
| 231 | end | 209 | end |
| 232 | 210 |
app/helpers/search_helper.rb
| @@ -5,7 +5,7 @@ module SearchHelper | @@ -5,7 +5,7 @@ module SearchHelper | ||
| 5 | BLOCKS_SEARCH_LIMIT = 24 | 5 | BLOCKS_SEARCH_LIMIT = 24 |
| 6 | MULTIPLE_SEARCH_LIMIT = 8 | 6 | MULTIPLE_SEARCH_LIMIT = 8 |
| 7 | 7 | ||
| 8 | - Searches = ActiveSupport::OrderedHash[ | 8 | + SEARCHES = ActiveSupport::OrderedHash[ |
| 9 | :articles, _('Contents'), | 9 | :articles, _('Contents'), |
| 10 | :enterprises, _('Enterprises'), | 10 | :enterprises, _('Enterprises'), |
| 11 | :people, _('People'), | 11 | :people, _('People'), |
| @@ -22,7 +22,7 @@ module SearchHelper | @@ -22,7 +22,7 @@ module SearchHelper | ||
| 22 | end | 22 | end |
| 23 | 23 | ||
| 24 | def map_search? | 24 | def map_search? |
| 25 | - !multiple_search? and params[:display] == 'map' | 25 | + !multiple_search? && params[:display] == 'map' |
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | def asset_class(asset) | 28 | def asset_class(asset) |
| @@ -86,4 +86,22 @@ module SearchHelper | @@ -86,4 +86,22 @@ module SearchHelper | ||
| 86 | end | 86 | end |
| 87 | end | 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 | end | 107 | end |
app/models/article.rb
| @@ -10,6 +10,12 @@ class Article < ActiveRecord::Base | @@ -10,6 +10,12 @@ class Article < ActiveRecord::Base | ||
| 10 | :filename => 1, | 10 | :filename => 1, |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | + SEARCH_FILTERS = %w[ | ||
| 14 | + more_recent | ||
| 15 | + more_popular | ||
| 16 | + more_comments | ||
| 17 | + ] | ||
| 18 | + | ||
| 13 | track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? } | 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 | # xss_terminate plugin can't sanitize array fields | 21 | # xss_terminate plugin can't sanitize array fields |
| @@ -198,20 +204,12 @@ class Article < ActiveRecord::Base | @@ -198,20 +204,12 @@ class Article < ActiveRecord::Base | ||
| 198 | named_scope :public, | 204 | named_scope :public, |
| 199 | :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ] | 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 | # retrives the most commented articles, sorted by the comment count (largest | 207 | # retrives the most commented articles, sorted by the comment count (largest |
| 209 | # first) | 208 | # first) |
| 210 | def self.most_commented(limit) | 209 | def self.most_commented(limit) |
| 211 | paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) | 210 | paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) |
| 212 | end | 211 | end |
| 213 | 212 | ||
| 214 | - named_scope :more_popular, :order => 'hits DESC' | ||
| 215 | named_scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"] | 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 | def self.recent(limit = nil, extra_conditions = {}, pagination = true) | 215 | def self.recent(limit = nil, extra_conditions = {}, pagination = true) |
| @@ -418,8 +416,8 @@ class Article < ActiveRecord::Base | @@ -418,8 +416,8 @@ class Article < ActiveRecord::Base | ||
| 418 | named_scope :images, :conditions => { :is_image => true } | 416 | named_scope :images, :conditions => { :is_image => true } |
| 419 | named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] | 417 | named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] |
| 420 | 418 | ||
| 419 | + named_scope :more_popular, :order => 'hits DESC' | ||
| 421 | named_scope :more_comments, :order => "comments_count DESC" | 420 | named_scope :more_comments, :order => "comments_count DESC" |
| 422 | - named_scope :more_views, :order => "hits DESC" | ||
| 423 | named_scope :more_recent, :order => "created_at DESC" | 421 | named_scope :more_recent, :order => "created_at DESC" |
| 424 | 422 | ||
| 425 | def self.display_filter(user, profile) | 423 | def self.display_filter(user, profile) |
| @@ -608,7 +606,7 @@ class Article < ActiveRecord::Base | @@ -608,7 +606,7 @@ class Article < ActiveRecord::Base | ||
| 608 | 606 | ||
| 609 | end | 607 | end |
| 610 | 608 | ||
| 611 | - def more_views_label | 609 | + def more_popular_label |
| 612 | amount = self.hits | 610 | amount = self.hits |
| 613 | { | 611 | { |
| 614 | 0 => _('no views'), | 612 | 0 => _('no views'), |
app/models/organization.rb
| 1 | # Represents any organization of the system | 1 | # Represents any organization of the system |
| 2 | class Organization < Profile | 2 | class Organization < Profile |
| 3 | 3 | ||
| 4 | + SEARCH_FILTERS += %w[ | ||
| 5 | + more_popular | ||
| 6 | + more_active | ||
| 7 | + ] | ||
| 8 | + | ||
| 4 | settings_items :closed, :type => :boolean, :default => false | 9 | settings_items :closed, :type => :boolean, :default => false |
| 5 | def closed? | 10 | def closed? |
| 6 | closed | 11 | closed |
app/models/person.rb
| 1 | # A person is the profile of an user holding all relationships with the rest of the system | 1 | # A person is the profile of an user holding all relationships with the rest of the system |
| 2 | class Person < Profile | 2 | class Person < Profile |
| 3 | 3 | ||
| 4 | + SEARCH_FILTERS += %w[ | ||
| 5 | + more_popular | ||
| 6 | + more_active | ||
| 7 | + ] | ||
| 8 | + | ||
| 4 | def self.type_name | 9 | def self.type_name |
| 5 | _('Person') | 10 | _('Person') |
| 6 | end | 11 | end |
app/models/product.rb
| @@ -5,6 +5,10 @@ class Product < ActiveRecord::Base | @@ -5,6 +5,10 @@ class Product < ActiveRecord::Base | ||
| 5 | :description => 1, | 5 | :description => 1, |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | + SEARCH_FILTERS = %w[ | ||
| 9 | + more_recent | ||
| 10 | + ] | ||
| 11 | + | ||
| 8 | belongs_to :enterprise | 12 | belongs_to :enterprise |
| 9 | has_one :region, :through => :enterprise | 13 | has_one :region, :through => :enterprise |
| 10 | validates_presence_of :enterprise | 14 | validates_presence_of :enterprise |
app/models/profile.rb
| @@ -9,6 +9,10 @@ class Profile < ActiveRecord::Base | @@ -9,6 +9,10 @@ class Profile < ActiveRecord::Base | ||
| 9 | :nickname => 2, | 9 | :nickname => 2, |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | + SEARCH_FILTERS = %w[ | ||
| 13 | + more_recent | ||
| 14 | + ] | ||
| 15 | + | ||
| 12 | module Roles | 16 | module Roles |
| 13 | def self.admin(env_id) | 17 | def self.admin(env_id) |
| 14 | find_role('admin', env_id) | 18 | find_role('admin', env_id) |
test/unit/article_test.rb
| @@ -1480,8 +1480,8 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1480,8 +1480,8 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 1480 | assert_respond_to Article, :more_comments | 1480 | assert_respond_to Article, :more_comments |
| 1481 | end | 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 | end | 1485 | end |
| 1486 | 1486 | ||
| 1487 | should "return the more recent label" do | 1487 | should "return the more recent label" do |
| @@ -1510,19 +1510,19 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1510,19 +1510,19 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 1510 | should "return no views if profile has 0 views" do | 1510 | should "return no views if profile has 0 views" do |
| 1511 | a = Article.new | 1511 | a = Article.new |
| 1512 | assert_equal 0, a.hits | 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 | end | 1514 | end |
| 1515 | 1515 | ||
| 1516 | should "return 1 view on label if the content has 1 view" do | 1516 | should "return 1 view on label if the content has 1 view" do |
| 1517 | a = Article.new(:hits => 1) | 1517 | a = Article.new(:hits => 1) |
| 1518 | assert_equal 1, a.hits | 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 | end | 1520 | end |
| 1521 | 1521 | ||
| 1522 | should "return number of views on label if the content has more than one view" do | 1522 | should "return number of views on label if the content has more than one view" do |
| 1523 | a = Article.new(:hits => 4) | 1523 | a = Article.new(:hits => 4) |
| 1524 | assert_equal 4, a.hits | 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 | end | 1526 | end |
| 1527 | 1527 | ||
| 1528 | should 'return only text articles' do | 1528 | should 'return only text articles' do |