##// END OF EJS Templates
remove trailing white-spaces from vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb...
Toshi MARUYAMA -
r9171:f800d2185e2f
parent child
Show More
@@ -1,16 +1,16
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -18,9 +18,9
18 module Redmine
18 module Redmine
19 module Acts
19 module Acts
20 module Searchable
20 module Searchable
21 def self.included(base)
21 def self.included(base)
22 base.extend ClassMethods
22 base.extend ClassMethods
23 end
23 end
24
24
25 module ClassMethods
25 module ClassMethods
26 # Options:
26 # Options:
@@ -31,7 +31,7 module Redmine
31 # * :permission - permission required to search the model (default to :view_"objects")
31 # * :permission - permission required to search the model (default to :view_"objects")
32 def acts_as_searchable(options = {})
32 def acts_as_searchable(options = {})
33 return if self.included_modules.include?(Redmine::Acts::Searchable::InstanceMethods)
33 return if self.included_modules.include?(Redmine::Acts::Searchable::InstanceMethods)
34
34
35 cattr_accessor :searchable_options
35 cattr_accessor :searchable_options
36 self.searchable_options = options
36 self.searchable_options = options
37
37
@@ -44,10 +44,10 module Redmine
44 searchable_options[:project_key] ||= "#{table_name}.project_id"
44 searchable_options[:project_key] ||= "#{table_name}.project_id"
45 searchable_options[:date_column] ||= "#{table_name}.created_on"
45 searchable_options[:date_column] ||= "#{table_name}.created_on"
46 searchable_options[:order_column] ||= searchable_options[:date_column]
46 searchable_options[:order_column] ||= searchable_options[:date_column]
47
47
48 # Should we search custom fields on this model ?
48 # Should we search custom fields on this model ?
49 searchable_options[:search_custom_fields] = !reflect_on_association(:custom_values).nil?
49 searchable_options[:search_custom_fields] = !reflect_on_association(:custom_values).nil?
50
50
51 send :include, Redmine::Acts::Searchable::InstanceMethods
51 send :include, Redmine::Acts::Searchable::InstanceMethods
52 end
52 end
53 end
53 end
@@ -71,21 +71,21 module Redmine
71 user = User.current
71 user = User.current
72 tokens = [] << tokens unless tokens.is_a?(Array)
72 tokens = [] << tokens unless tokens.is_a?(Array)
73 projects = [] << projects unless projects.nil? || projects.is_a?(Array)
73 projects = [] << projects unless projects.nil? || projects.is_a?(Array)
74
74
75 find_options = {:include => searchable_options[:include]}
75 find_options = {:include => searchable_options[:include]}
76 find_options[:order] = "#{searchable_options[:order_column]} " + (options[:before] ? 'DESC' : 'ASC')
76 find_options[:order] = "#{searchable_options[:order_column]} " + (options[:before] ? 'DESC' : 'ASC')
77
77
78 limit_options = {}
78 limit_options = {}
79 limit_options[:limit] = options[:limit] if options[:limit]
79 limit_options[:limit] = options[:limit] if options[:limit]
80 if options[:offset]
80 if options[:offset]
81 limit_options[:conditions] = "(#{searchable_options[:date_column]} " + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
81 limit_options[:conditions] = "(#{searchable_options[:date_column]} " + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')"
82 end
82 end
83
83
84 columns = searchable_options[:columns]
84 columns = searchable_options[:columns]
85 columns = columns[0..0] if options[:titles_only]
85 columns = columns[0..0] if options[:titles_only]
86
86
87 token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
87 token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
88
88
89 if !options[:titles_only] && searchable_options[:search_custom_fields]
89 if !options[:titles_only] && searchable_options[:search_custom_fields]
90 searchable_custom_field_ids = CustomField.find(:all,
90 searchable_custom_field_ids = CustomField.find(:all,
91 :select => 'id',
91 :select => 'id',
@@ -98,11 +98,11 module Redmine
98 token_clauses << custom_field_sql
98 token_clauses << custom_field_sql
99 end
99 end
100 end
100 end
101
101
102 sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
102 sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
103
103
104 find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
104 find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
105
105
106 scope = self
106 scope = self
107 project_conditions = []
107 project_conditions = []
108 if searchable_options.has_key?(:permission)
108 if searchable_options.has_key?(:permission)
@@ -116,7 +116,7 module Redmine
116 # TODO: use visible scope options instead
116 # TODO: use visible scope options instead
117 project_conditions << "#{searchable_options[:project_key]} IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
117 project_conditions << "#{searchable_options[:project_key]} IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
118 project_conditions = project_conditions.empty? ? nil : project_conditions.join(' AND ')
118 project_conditions = project_conditions.empty? ? nil : project_conditions.join(' AND ')
119
119
120 results = []
120 results = []
121 results_count = 0
121 results_count = 0
122
122
General Comments 0
You need to be logged in to leave comments. Login now