add-ever-assigned-to_r2823.patch

Chris Grieger, 2009-07-19 12:35

Download (3.66 KB)

View differences:

app/models/query.rb (working copy)
160 160
                           "due_date" => { :type => :date, :order => 12 },
161 161
                           "estimated_hours" => { :type => :integer, :order => 13 },
162 162
                           "done_ratio" =>  { :type => :integer, :order => 14 }}
163
    
163
                              
164 164
    user_values = []
165 165
    user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
166 166
    if project
......
171 171
    end
172 172
    @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
173 173
    @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
174
    
174
    @available_filters["ever_assigned_to_id"] = { :type => :list, :order => 4, :values => user_values } unless user_values.empty?
175 175
    if User.current.logged?
176 176
      @available_filters["watcher_id"] = { :type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]] }
177 177
    end
......
348 348
      operator = operator_for(field)
349 349
      
350 350
      # "me" value subsitution
351
      if %w(assigned_to_id author_id watcher_id).include?(field)
351
      #if %w(assigned_to_id author_id watcher_id).include?(field)
352
      if %w(assigned_to_id author_id).include?(field) or %w(ever_assigned_to_id author_id).include?(field)
352 353
        v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me")
353 354
      end
354 355
      
355 356
      sql = ''
357
      has_double_field = false
358

  
356 359
      if field =~ /^cf_(\d+)$/
357 360
        # custom field
358 361
        db_table = CustomValue.table_name
......
365 368
        db_field = 'user_id'
366 369
        sql << "#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND "
367 370
        sql << sql_for_field(field, '=', v, db_table, db_field) + ')'
371
      elsif field == "ever_assigned_to_id"
372
		  db_table = JournalDetail.table_name
373
			db_field = 'old_value'
374
			db_field2 = 'value'
375
			is_custom_filter = true
376
			has_double_field = true
377
	   	sql << "#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} INNER 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' )"
368 378
      else
369 379
        # regular field
370 380
        db_table = Issue.table_name
......
385 395
    sql = ''
386 396
    case operator
387 397
    when "="
398
      sql << "(" if has_double_field
388 399
      sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
400
      sql << " OR #{db_table}.#{db_field2} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))" if has_double_field
389 401
    when "!"
390 402
      sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
391 403
    when "!*"
config/locales/en.yml (working copy)
161 161
  field_description: Description
162 162
  field_summary: Summary
163 163
  field_is_required: Required
164
  field_ever_assigned_to: Ever assigned to
164 165
  field_firstname: Firstname
165 166
  field_lastname: Lastname
166 167
  field_mail: Email