add-ever-assigned-to.patch

Grzegorz Kulewski, 2009-07-05 16:42

Download (2.81 KB)

View differences:

app/models/query.rb 2009-07-05 03:12:46.000000000 +0200
163 163
      user_values += User.current.projects.collect(&:users).flatten.uniq.sort.collect{|s| [s.name, s.id.to_s] }
164 164
    end
165 165
    @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
166
    @available_filters["ever_assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
166 167
    @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
167 168
  
168 169
    if project
......
297 298
            
298 299
      sql = ''
299 300
      is_custom_filter = false
301
      has_double_field = false
300 302
      if field =~ /^cf_(\d+)$/
301 303
        # custom field
302 304
        db_table = CustomValue.table_name
303 305
        db_field = 'value'
304 306
        is_custom_filter = true
305 307
        sql << "#{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=#{$1} WHERE "
308
      elsif field == "ever_assigned_to_id"
309
        db_table = JournalDetail.table_name
310
	db_field = 'old_value'
311
	db_field2 = 'value'
312
	is_custom_filter = true
313
	has_double_field = true
314
      	sql << "#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{Journal.table_name} ON #{Journal.table_name}.journalized_type='Issue' AND #{Journal.table_name}.journalized_id=#{Issue.table_name}.id LEFT OUTER JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id=#{Journal.table_name}.id AND #{JournalDetail.table_name}.prop_key='assigned_to_id' WHERE "
306 315
      else
307 316
        # regular field
308 317
        db_table = Issue.table_name
......
311 320
      end
312 321
      
313 322
      # "me" value subsitution
314
      if %w(assigned_to_id author_id).include?(field)
323
      if %w(assigned_to_id author_id).include?(field) or %w(ever_assigned_to_id author_id).include?(field)
315 324
        v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me")
316 325
      end
317 326
      
318 327
      case operator_for field
319 328
      when "="
329
      	sql << "(" if has_double_field
320 330
        sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
331
	sql << " OR #{db_table}.#{db_field2} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))" if has_double_field
321 332
      when "!"
322 333
        sql = sql + "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
323 334
      when "!*"