remove trailing white-spaces from app/models/query.rb.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6465 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-08-20 03:38:29 +00:00
parent 2de3dca044
commit 3605a18137
1 changed files with 17 additions and 17 deletions

View File

@ -157,7 +157,7 @@ class Query < ActiveRecord::Base
:include => :project :include => :project
} }
} }
def initialize(attributes = nil) def initialize(attributes = nil)
super attributes super attributes
self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} } self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
@ -172,9 +172,9 @@ class Query < ActiveRecord::Base
filters.each_key do |field| filters.each_key do |field|
if values_for(field) if values_for(field)
case type_for(field) case type_for(field)
when :integer when :integer
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) } errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
when :float when :float
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d*)?$/) } errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d*)?$/) }
when :date, :date_past when :date, :date_past
case operator_for(field) case operator_for(field)
@ -185,7 +185,7 @@ class Query < ActiveRecord::Base
end end
end end
end end
errors.add label_for(field), :blank unless errors.add label_for(field), :blank unless
# filter requires one or more values # filter requires one or more values
(values_for(field) and !values_for(field).first.blank?) or (values_for(field) and !values_for(field).first.blank?) or
@ -193,7 +193,7 @@ class Query < ActiveRecord::Base
["o", "c", "!*", "*", "t", "w"].include? operator_for(field) ["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
end if filters end if filters
end end
# Returns true if the query is visible to +user+ or the current user. # Returns true if the query is visible to +user+ or the current user.
def visible?(user=User.current) def visible?(user=User.current)
(project.nil? || user.allowed_to?(:view_issues, project)) && (self.is_public? || self.user_id == user.id) (project.nil? || user.allowed_to?(:view_issues, project)) && (self.is_public? || self.user_id == user.id)
@ -242,12 +242,12 @@ class Query < ActiveRecord::Base
end end
end end
users = principals.select {|p| p.is_a?(User)} users = principals.select {|p| p.is_a?(User)}
assigned_to_values = [] assigned_to_values = []
assigned_to_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged? assigned_to_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
assigned_to_values += (Setting.issue_group_assignment? ? principals : users).collect{|s| [s.name, s.id.to_s] } assigned_to_values += (Setting.issue_group_assignment? ? principals : users).collect{|s| [s.name, s.id.to_s] }
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => assigned_to_values } unless assigned_to_values.empty? @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => assigned_to_values } unless assigned_to_values.empty?
author_values = [] author_values = []
author_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged? author_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
author_values += users.collect{|s| [s.name, s.id.to_s] } author_values += users.collect{|s| [s.name, s.id.to_s] }
@ -324,7 +324,7 @@ class Query < ActiveRecord::Base
def has_filter?(field) def has_filter?(field)
filters and filters[field] filters and filters[field]
end end
def type_for(field) def type_for(field)
available_filters[field][:type] if available_filters.has_key?(field) available_filters[field][:type] if available_filters.has_key?(field)
end end
@ -336,7 +336,7 @@ class Query < ActiveRecord::Base
def values_for(field) def values_for(field)
has_filter?(field) ? filters[field][:values] : nil has_filter?(field) ? filters[field][:values] : nil
end end
def value_for(field, index=0) def value_for(field, index=0)
(values_for(field) || [])[index] (values_for(field) || [])[index]
end end
@ -349,7 +349,7 @@ class Query < ActiveRecord::Base
def available_columns def available_columns
return @available_columns if @available_columns return @available_columns if @available_columns
@available_columns = Query.available_columns @available_columns = Query.available_columns
@available_columns += (project ? @available_columns += (project ?
project.all_issue_custom_fields : project.all_issue_custom_fields :
IssueCustomField.find(:all) IssueCustomField.find(:all)
).collect {|cf| QueryCustomFieldColumn.new(cf) } ).collect {|cf| QueryCustomFieldColumn.new(cf) }
@ -577,13 +577,13 @@ class Query < ActiveRecord::Base
rescue ::ActiveRecord::StatementInvalid => e rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message) raise StatementInvalid.new(e.message)
end end
def sql_for_watcher_id_field(field, operator, value) def sql_for_watcher_id_field(field, operator, value)
db_table = Watcher.table_name db_table = Watcher.table_name
"#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND " + "#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND " +
sql_for_field(field, '=', value, db_table, 'user_id') + ')' sql_for_field(field, '=', value, db_table, 'user_id') + ')'
end end
def sql_for_member_of_group_field(field, operator, value) def sql_for_member_of_group_field(field, operator, value)
if operator == '*' # Any group if operator == '*' # Any group
groups = Group.all groups = Group.all
@ -605,7 +605,7 @@ class Query < ActiveRecord::Base
'(' + sql_for_field("assigned_to_id", operator, members_of_groups, Issue.table_name, "assigned_to_id", false) + ')' '(' + sql_for_field("assigned_to_id", operator, members_of_groups, Issue.table_name, "assigned_to_id", false) + ')'
end end
def sql_for_assigned_to_role_field(field, operator, value) def sql_for_assigned_to_role_field(field, operator, value)
if operator == "*" # Any Role if operator == "*" # Any Role
roles = Role.givable roles = Role.givable
@ -629,14 +629,14 @@ class Query < ActiveRecord::Base
end end
private private
def sql_for_custom_field(field, operator, value, custom_field_id) def sql_for_custom_field(field, operator, value, custom_field_id)
db_table = CustomValue.table_name db_table = CustomValue.table_name
db_field = 'value' db_field = 'value'
"#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{custom_field_id} WHERE " + "#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{custom_field_id} WHERE " +
sql_for_field(field, operator, value, db_table, db_field, true) + ')' sql_for_field(field, operator, value, db_table, db_field, true) + ')'
end end
# Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+ # Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+
def sql_for_field(field, operator, value, db_table, db_field, is_custom_filter=false) def sql_for_field(field, operator, value, db_table, db_field, is_custom_filter=false)
sql = '' sql = ''
@ -760,7 +760,7 @@ class Query < ActiveRecord::Base
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name }) @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
end end
end end
# Returns a SQL clause for a date or datetime field. # Returns a SQL clause for a date or datetime field.
def date_clause(table, field, from, to) def date_clause(table, field, from, to)
s = [] s = []
@ -772,7 +772,7 @@ class Query < ActiveRecord::Base
end end
s.join(' AND ') s.join(' AND ')
end end
# Returns a SQL clause for a date or datetime field using relative dates. # Returns a SQL clause for a date or datetime field using relative dates.
def relative_date_clause(table, field, days_from, days_to) def relative_date_clause(table, field, days_from, days_to)
date_clause(table, field, (days_from ? Date.today + days_from : nil), (days_to ? Date.today + days_to : nil)) date_clause(table, field, (days_from ? Date.today + days_from : nil), (days_to ? Date.today + days_to : nil))