add-ever-assigned-to_r2823.patch

Proper version of the patch - Chris Grieger, 2009-07-19 14:48

Download (4.48 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 ever_assigned_to_id).include?(field)# or %w(ever_assigned_to_id author_id).include?(field)
352 352
        v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me")
353 353
      end
354 354
      
......
359 359
        db_field = 'value'
360 360
        is_custom_filter = true
361 361
        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 "
362
        sql << sql_for_field(field, operator, v, db_table, db_field, true) + ')'
362
        sql << sql_for_field(field, operator, v, db_table, db_field,'',false, is_custom_filter) + ')'
363 363
      elsif field == 'watcher_id'
364 364
        db_table = Watcher.table_name
365 365
        db_field = 'user_id'
366 366
        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 367
        sql << sql_for_field(field, '=', v, db_table, db_field) + ')'
368
      elsif field == "ever_assigned_to_id"
369
		  db_table = JournalDetail.table_name
370
			db_field = 'old_value'
371
			db_field2 = 'value'
372
			is_custom_filter = true
373
      has_double_field = true
374
	   	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' WHERE "
375
      sql << sql_for_field(field, '=', v, db_table, db_field,db_field2,has_double_field,is_custom_filter) + ')'
368 376
      else
369 377
        # regular field
370 378
        db_table = Issue.table_name
......
381 389
  private
382 390
  
383 391
  # Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+
384
  def sql_for_field(field, operator, value, db_table, db_field, is_custom_filter=false)
392
  def sql_for_field(field, operator, value, db_table, db_field,db_field2='',has_double_field=false, is_custom_filter=false)
385 393
    sql = ''
386 394
    case operator
387 395
    when "="
396
      sql << "(" if has_double_field
388 397
      sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
398
       sql << " OR #{db_table}.#{db_field2} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" if has_double_field
389 399
    when "!"
390 400
      sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
391 401
    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