Project

General

Profile

Feature #38567 » enable_to_display_notes_count_on_issues_list.patch

Takenori TAKAKI, 2023-05-19 07:46

View differences:

app/models/issue.rb
1188 1188
    @watchers_count ||= self.watchers.count(:id)
1189 1189
  end
1190 1190

  
1191
  def notes_count
1192
    @notes_count ||= self.journals.where.not(notes: '').count(:id)
1193
  end
1194

  
1191 1195
  # Preloads relations for a collection of issues
1192 1196
  def self.load_relations(issues)
1193 1197
    if issues.any?
app/models/issue_query.rb
54 54
          " AND #{Watcher.table_name}.watchable_id = #{Issue.table_name}.id), 0)"
55 55
        end,
56 56
      :default_order => 'desc'),
57
    QueryColumn.new(
58
      :notes_count,
59
      :sortable =>
60
        lambda do
61
          "COALESCE((SELECT COUNT(user_id) FROM #{Journal.table_name}" \
62
          " WHERE #{Journal.table_name}.notes <> ''" \
63
          " AND #{Journal.table_name}.journalized_id = #{Issue.table_name}.id), 0)"
64
        end,
65
      :default_order => 'desc'),
57 66
    QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date", :groupable => true),
58 67
    QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
59 68
    QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours",
config/locales/en.yml
370 370
  field_editable: Editable
371 371
  field_watcher: Watcher
372 372
  field_watchers_count: Watchers count
373
  field_notes_count: Notes count
373 374
  field_content: Content
374 375
  field_group_by: Group results by
375 376
  field_sharing: Sharing
config/locales/ja.yml
329 329
  field_editable: 編集可能
330 330
  field_watcher: ウォッチャー
331 331
  field_watchers_count: ウォッチ数
332
  field_notes_count: コメント数
332 333
  field_content: 内容
333 334
  field_group_by: グループ条件
334 335
  field_sharing: 共有
test/functional/issues_controller_test.rb
1388 1388
    assert_equal [2, 1, 0], issues_in_list.map {|issue| issue.watchers_count}.first(3)
1389 1389
  end
1390 1390

  
1391
  def test_index_sort_by_notes_count
1392
    user = User.find(2)
1393
    Journal.delete_all
1394
    2.times.each do
1395
      Journal.generate!(journalized: Issue.find(1), user: user, notes: 'Some notes')
1396
    end
1397
    Journal.generate!(journalized: Issue.find(2), user: user, notes: 'Some notes')
1398
    get(:index, :params => {:sort => 'notes_count:desc'})
1399
    assert_response :success
1400
    assert_equal [2, 1, 0], issues_in_list.map {|issue| issue.notes_count}.first(3)
1401
  end
1402

  
1391 1403
  def test_index_sort_by_user_custom_field
1392 1404
    cf = IssueCustomField.
1393 1405
           create!(
test/unit/issue_test.rb
3532 3532
    end
3533 3533
    assert_equal 2, issue.watchers_count
3534 3534
  end
3535

  
3536
  def test_notes_count
3537
    issue = Issue.generate!
3538
    User.find([2, 3]).each do |user|
3539
      Journal.generate!(journalized: issue, user: user, notes: 'Some notes')
3540
    end
3541
    assert_equal 2, issue.notes_count
3542
  end
3535 3543
end
(1-1/2)