Project

General

Profile

Feature #20081 » 0001-Filter-issues-after-project-status.patch

Marius BĂLTEANU, 2018-10-28 16:38

View differences:

app/models/issue_query.rb
165 165
        :values => lambda { subproject_values }
166 166
    end
167 167

  
168
    add_available_filter("project.status",
169
      :type => :list,
170
      :name => l(:label_attribute_of_project, :name => l(:field_status)),
171
      :values => lambda { project_statuses_values }
172
    ) if project.nil? || !project.leaf?
173

  
168 174
    add_custom_fields_filters(issue_custom_fields)
169 175
    add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version
170 176

  
......
577 583
    "(#{sql})"
578 584
  end
579 585

  
586
  def sql_for_project_status_field(field, operator, value, options={})
587
    sql_for_field(field, operator, value, Project.table_name, "status")
588
  end
589

  
580 590
  def find_assigned_to_id_filter_values(values)
581 591
    Principal.visible.where(:id => values).map {|p| [p.name, p.id.to_s]}
582 592
  end
app/models/project.rb
24 24
  STATUS_CLOSED     = 5
25 25
  STATUS_ARCHIVED   = 9
26 26

  
27
  LABEL_BY_STATUS = {
28
    1 => l(:project_status_active),
29
    5 => l(:project_status_closed),
30
    9 => l(:project_status_archived),
31
  }
32

  
27 33
  # Maximum length for project identifiers
28 34
  IDENTIFIER_MAX_LENGTH = 100
29 35

  
app/models/query.rb
579 579
    end
580 580
  end
581 581

  
582
  # Returns a scope of project statuses that are available as columns or filters
583
  def project_statuses_values
584
    project_statuses =  Project::LABEL_BY_STATUS
585
    # Remove archived status from filters
586
    project_statuses.delete(9)
587
    project_statuses.stringify_keys.invert.to_a
588
  end
589

  
582 590
  # Adds available filters
583 591
  def initialize_available_filters
584 592
    # implemented by sub-classes
test/functional/issues_controller_test.rb
264 264
    assert_equal [3, 5], issues_in_list.map(&:project_id).uniq.sort
265 265
  end
266 266

  
267
  def test_index_with_project_status_filter
268
    project = Project.find(2)
269
    project.close
270
    project.save
271

  
272
    get :index, :params => {
273
        :set_filter => 1,
274
        :f => ['project.status'],
275
        :op => {'project.status' => '='},
276
        :v => {'project.status' => ['1']}
277
      }
278

  
279
    assert_response :success
280

  
281
    issues = issues_in_list.map(&:id).uniq.sort
282
    assert_include 1, issues
283
    assert_not_include 4, issues
284
  end
285

  
267 286
  def test_index_with_query
268 287
    get :index, :params => {
269 288
        :project_id => 1,
test/helpers/queries_helper_test.rb
75 75
    with_locale 'en' do
76 76
      options = filters_options_for_select(IssueQuery.new)
77 77
      assert_select_in options, 'optgroup[label=?]', 'Project', 1
78
      assert_select_in options, 'optgroup[label=?] > option', 'Project', 2
78
      assert_select_in options, 'optgroup[label=?] > option', 'Project', 3
79 79
      assert_select_in options, 'optgroup > option[value=?]', "project.cf_#{cf1.id}", :text => "Project's Foo"
80 80
    end
81 81
  end
test/unit/query_test.rb
2199 2199

  
2200 2200
    assert_equal ['1','2','3','4','5','6'], query.available_filters['status_id'][:values].map(&:second)
2201 2201
  end
2202

  
2203
  def test_project_status_filter_should_be_available_in_global_queries
2204
    query = IssueQuery.new(:project => nil, :name => '_')
2205
    assert query.available_filters.has_key?('project.status')
2206
  end
2207

  
2208
  def test_project_status_filter_should_be_available_when_project_has_subprojects
2209
    query = IssueQuery.new(:project => Project.find(1), :name => '_')
2210
    assert query.available_filters.has_key?('project.status')
2211
  end
2212

  
2213
  def test_project_status_filter_should_not_be_available_when_project_is_leaf
2214
    query = IssueQuery.new(:project => Project.find(2), :name => '_')
2215
    assert !query.available_filters.has_key?('project.status')
2216
  end
2217

  
2218
  def test_project_statuses_values_should_return_only_active_and_closed_statuses
2219
    query = IssueQuery.new(:project => nil, :name => '_')
2220
    project_status_filter = query.available_filters['project.status']
2221
    assert_not_nil project_status_filter
2222

  
2223
    assert_equal [["active", "1"], ["closed", "5"]], project_status_filter[:values]
2224
  end
2202 2225
end
(2-2/3)