Project

General

Profile

Patch #1765 ยป backport_of_r1576_to_07branch.patch

Mischa The Evil, 2008-08-11 16:15

View differences:

app/models/query.rb (working copy)
166 166
    @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
167 167
  
168 168
    if project
169
      # project specific filters      
170
      @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
171
      @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
169
      # project specific filters
170
      unless @project.issue_categories.empty?
171
        @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
172
      end
173
      unless @project.versions.empty?
174
        @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
175
      end
172 176
      unless @project.active_children.empty?
173 177
        @available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
174 178
      end
175
      @project.all_custom_fields.select(&:is_filter?).each do |field|
176
        case field.field_format
177
        when "text"
178
          options = { :type => :text, :order => 20 }
179
        when "list"
180
          options = { :type => :list_optional, :values => field.possible_values, :order => 20}
181
        when "date"
182
          options = { :type => :date, :order => 20 }
183
        when "bool"
184
          options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
185
        else
186
          options = { :type => :string, :order => 20 }
187
        end          
188
        @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
189
      end
190
      # remove category filter if no category defined
191
      @available_filters.delete "category_id" if @available_filters["category_id"][:values].empty?
179
      add_custom_fields_filters(@project.all_custom_fields)
180
    else
181
      # global filters for cross project issue list
182
      add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
192 183
    end
193 184
    @available_filters
194 185
  end
......
366 357
    
367 358
    (project_clauses + filters_clauses).join(' AND ')
368 359
  end
360
  
361
  private
362
  
363
  def add_custom_fields_filters(custom_fields)
364
    @available_filters ||= {}
365
    
366
    custom_fields.select(&:is_filter?).each do |field|
367
      case field.field_format
368
      when "text"
369
        options = { :type => :text, :order => 20 }
370
      when "list"
371
        options = { :type => :list_optional, :values => field.possible_values, :order => 20}
372
      when "date"
373
        options = { :type => :date, :order => 20 }
374
      when "bool"
375
        options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
376
      else
377
        options = { :type => :string, :order => 20 }
378
      end
379
      @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
380
    end
381
  end
369 382
end
test/fixtures/custom_fields.yml (working copy)
30 30
  min_length: 0
31 31
  regexp: ""
32 32
  is_for_all: false
33
  is_filter: true
33 34
  type: ProjectCustomField
34 35
  max_length: 0
35 36
  possible_values: Stable|Beta|Alpha|Planning
test/unit/query_test.rb (working copy)
19 19

  
20 20
class QueryTest < Test::Unit::TestCase
21 21
  fixtures :projects, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries
22

  
22
  
23
  def test_custom_fields_for_all_projects_should_be_available_in_global_queries
24
    query = Query.new(:project => nil, :name => '_')
25
    assert query.available_filters.has_key?('cf_1')
26
    assert !query.available_filters.has_key?('cf_3')
27
  end
28
  
23 29
  def test_query_with_multiple_custom_fields
24 30
    query = Query.find(1)
25 31
    assert query.valid?
    (1-1/1)