:include => :project
}
}
-
+
def initialize(attributes = nil)
super attributes
self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
filters.each_key do |field|
if values_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+$/) }
- when :float
+ when :float
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d*)?$/) }
when :date, :date_past
case operator_for(field)
end
end
end
-
+
errors.add label_for(field), :blank unless
# filter requires one or more values
(values_for(field) and !values_for(field).first.blank?) or
["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
end if filters
end
-
+
# Returns true if the query is visible to +user+ or the current user.
def visible?(user=User.current)
(project.nil? || user.allowed_to?(:view_issues, project)) && (self.is_public? || self.user_id == user.id)
end
end
users = principals.select {|p| p.is_a?(User)}
-
+
assigned_to_values = []
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] }
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => assigned_to_values } unless assigned_to_values.empty?
-
+
author_values = []
author_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
author_values += users.collect{|s| [s.name, s.id.to_s] }
def has_filter?(field)
filters and filters[field]
end
-
+
def type_for(field)
available_filters[field][:type] if available_filters.has_key?(field)
end
def values_for(field)
has_filter?(field) ? filters[field][:values] : nil
end
-
+
def value_for(field, index=0)
(values_for(field) || [])[index]
end
def available_columns
return @available_columns if @available_columns
@available_columns = Query.available_columns
- @available_columns += (project ?
+ @available_columns += (project ?
project.all_issue_custom_fields :
IssueCustomField.find(:all)
).collect {|cf| QueryCustomFieldColumn.new(cf) }
rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message)
end
-
+
def sql_for_watcher_id_field(field, operator, value)
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 " +
sql_for_field(field, '=', value, db_table, 'user_id') + ')'
end
-
+
def sql_for_member_of_group_field(field, operator, value)
if operator == '*' # Any group
groups = Group.all
'(' + sql_for_field("assigned_to_id", operator, members_of_groups, Issue.table_name, "assigned_to_id", false) + ')'
end
-
+
def sql_for_assigned_to_role_field(field, operator, value)
if operator == "*" # Any Role
roles = Role.givable
end
private
-
+
def sql_for_custom_field(field, operator, value, custom_field_id)
db_table = CustomValue.table_name
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 " +
sql_for_field(field, operator, value, db_table, db_field, true) + ')'
end
-
+
# 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)
sql = ''
@available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
end
end
-
+
# Returns a SQL clause for a date or datetime field.
def date_clause(table, field, from, to)
s = []
end
s.join(' AND ')
end
-
+
# Returns a SQL clause for a date or datetime field using relative dates.
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))