Project

General

Profile

Feature #23215 » filter_after_target_version_status_and_due_date_v2.patch

Marius BĂLTEANU, 2016-07-05 22:25

View differences:

app/helpers/queries_helper.rb
24 24
    ungrouped = []
25 25
    grouped = {}
26 26
    query.available_filters.map do |field, field_options|
27
      if [:tree, :relation].include?(field_options[:type]) 
27
      if [:tree, :relation].include?(field_options[:type])
28 28
        group = :label_relations
29 29
      elsif field =~ /^(.+)\./
30 30
        # association filters
31
        group = "field_#{$1}"
31
        group = "field_#{$1}".to_sym
32 32
      elsif %w(member_of_group assigned_to_role).include?(field)
33 33
        group = :field_assigned_to
34
      elsif %w(fixed_version_effective_date fixed_version_status).include?(field)
35
        group = :field_fixed_version
34 36
      elsif field_options[:type] == :date_past || field_options[:type] == :date
35 37
        group = :label_date
36 38
      end
......
41 43
      end
42 44
    end
43 45
    # Don't group dates if there's only one (eg. time entries filters)
44
    if grouped[:label_date].try(:size) == 1 
46
    if grouped[:label_date].try(:size) == 1
45 47
      ungrouped << grouped.delete(:label_date).first
46 48
    end
47 49
    s = options_for_select([[]] + ungrouped)
......
134 136
      column_value(column, issue, value)
135 137
    end
136 138
  end
137
  
139

  
138 140
  def column_value(column, issue, value)
139 141
    case column.name
140 142
    when :id
app/models/issue_query.rb
203 203
      :type => :list_optional,
204 204
      :values => Version.sort_by_status(versions).collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s, l("version_status_#{s.status}")] }
205 205

  
206
    add_available_filter "fixed_version_effective_date",
207
      :type => :date,
208
      :name => l(:label_attribute_of_fixed_version, :name => l(:field_effective_date))
209

  
210
    add_available_filter "fixed_version_status",
211
      :type => :list,
212
      :name => l(:label_attribute_of_fixed_version, :name => l(:field_status)),
213
      :values => Version::VERSION_STATUSES.map{|t| [t, t] }
214

  
206 215
    add_available_filter "category_id",
207 216
      :type => :list_optional,
208 217
      :values => categories.collect{|s| [s.name, s.id.to_s] }
......
463 472
    end
464 473
  end
465 474

  
475
  def sql_for_fixed_version_status_field(field, operator, value)
476
    where = sql_for_field(field, operator, value, Version.table_name, "status")
477
    version_ids = versions(:conditions => [where]).map(&:id)
478
    sql_for_field("fixed_version_id", "=", version_ids, Issue.table_name, "fixed_version_id")
479
  end
480

  
481
  def sql_for_fixed_version_effective_date_field(field, operator, value)
482
    where = sql_for_field(field, operator, value, Version.table_name, "effective_date")
483
    version_ids = versions(:conditions => [where]).map(&:id)
484
    sql_for_field("fixed_version_id", "=", version_ids, Issue.table_name, "fixed_version_id")
485
  end
486

  
466 487
  def sql_for_is_private_field(field, operator, value)
467 488
    op = (operator == "=" ? 'IN' : 'NOT IN')
468 489
    va = value.map {|v| v == '0' ? self.class.connection.quoted_false : self.class.connection.quoted_true}.uniq.join(',')
test/unit/query_test.rb
811 811
    assert_equal [2], find_issues_with_query(query).map(&:fixed_version_id).uniq.sort
812 812
  end
813 813

  
814
  def test_filter_on_fixed_version_effective_date
815
    query = IssueQuery.new(:name => '_')
816
    filter_name = "fixed_version_effective_date"
817
    assert_include filter_name, query.available_filters.keys
818
    query.filters = {filter_name => {:operator => '=', :values => [20.day.from_now.to_date.to_s(:db)]}}
819
    assert_equal [2], find_issues_with_query(query).map(&:fixed_version_id).uniq.sort
820

  
821
    query = IssueQuery.new(:name => '_')
822
    query.filters = {filter_name => {:operator => '>=', :values => [21.day.from_now.to_date.to_s(:db)]}}
823
    assert_equal [], find_issues_with_query(query).map(&:fixed_version_id).uniq.sort
824
  end
825

  
826
  def test_filter_on_fixed_version_status
827
    query = IssueQuery.new(:name => '_')
828
    filter_name = "fixed_version_status"
829
    assert_include filter_name, query.available_filters.keys
830
    query.filters = {filter_name => {:operator => '=', :values => ['closed']}}
831
    assert_equal [1], find_issues_with_query(query).map(&:fixed_version_id).uniq.sort
832
  end
833

  
814 834
  def test_filter_on_relations_with_a_specific_issue
815 835
    IssueRelation.delete_all
816 836
    IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(2))
......
943 963
  def test_filter_on_parent
944 964
    Issue.delete_all
945 965
    parent = Issue.generate_with_descendants!
946
    
966

  
947 967

  
948 968
    query = IssueQuery.new(:name => '_')
949 969
    query.filters = {"parent_id" => {:operator => '=', :values => [parent.id.to_s]}}
......
973 993
    parent = Issue.generate_with_descendants!
974 994
    child, leaf = parent.children.sort_by(&:id)
975 995
    grandchild = child.children.first
976
    
996

  
977 997

  
978 998
    query = IssueQuery.new(:name => '_')
979 999
    query.filters = {"child_id" => {:operator => '=', :values => [grandchild.id.to_s]}}
(3-3/5)