Project

General

Profile

Patch #5535 ยป Ability_to_use_nobody_in_Assigned_to_field_filter.patch

Vitaly Klimov, 2010-07-09 09:34

View differences:

app/models/query.rb Wed Jul 07 11:40:28 MSD 2010
184 184
    
185 185
    user_values = []
186 186
    user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
187
    user_values << ["<< #{l(:label_nobody)} >>", "nobody"]
187 188
    if project
188 189
      user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] }
189 190
    else
......
430 431
        # regular field
431 432
        db_table = Issue.table_name
432 433
        db_field = field
434
        if field == 'assigned_to_id' && operator == "=" && v.delete('nobody')
435
	        operator = v.empty? ? "!*" : "=nobody" 
436
				end
433 437
        sql << '(' + sql_for_field(field, operator, v, db_table, db_field) + ')'
434 438
      end
435 439
      filters_clauses << sql
......
508 512
  def sql_for_field(field, operator, value, db_table, db_field, is_custom_filter=false)
509 513
    sql = ''
510 514
    case operator
511
    when "="
515
    when "=", "=nobody"
512 516
      sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
517
	    sql = "(#{db_table}.#{db_field} IS NULL OR " + sql + ")" if operator == "=nobody"
513 518
    when "!"
514 519
      sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
515 520
    when "!*"
    (1-1/1)