Feature #38568 » enable_to_display_file_count_and_total_file_size_on_issues_list.patch
| app/helpers/queries_helper.rb | ||
|---|---|---|
| 277 | 277 |
link_to_if(value > 0, format_hours(value), project_time_entries_path(item.project, :issue_id => "~#{item.id}"))
|
| 278 | 278 |
when :attachments |
| 279 | 279 |
value.to_a.map {|a| format_object(a)}.join(" ").html_safe
|
| 280 |
when :attachments_filesize |
|
| 281 |
value == 0 ? '' : number_to_human_size(value) |
|
| 280 | 282 |
else |
| 281 | 283 |
format_object(value) |
| 282 | 284 |
end |
| app/models/issue.rb | ||
|---|---|---|
| 1188 | 1188 |
@watchers_count ||= self.watchers.count(:id) |
| 1189 | 1189 |
end |
| 1190 | 1190 | |
| 1191 |
def attachments_count |
|
| 1192 |
@attachments_count ||= self.attachments.count(:id) |
|
| 1193 |
end |
|
| 1194 | ||
| 1195 |
def attachments_filesize |
|
| 1196 |
@attachments_filesize ||= self.attachments.sum(:filesize) |
|
| 1197 |
end |
|
| 1198 | ||
| 1191 | 1199 |
# Preloads relations for a collection of issues |
| 1192 | 1200 |
def self.load_relations(issues) |
| 1193 | 1201 |
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 |
:attachments_count, |
|
| 59 |
:sortable => |
|
| 60 |
lambda do |
|
| 61 |
"COALESCE((SELECT COUNT(author_id) FROM #{Attachment.table_name}" \
|
|
| 62 |
" WHERE #{Attachment.table_name}.container_type = 'Issue'" \
|
|
| 63 |
" AND #{Attachment.table_name}.container_id = #{Issue.table_name}.id), 0)"
|
|
| 64 |
end, |
|
| 65 |
:default_order => 'desc'), |
|
| 66 |
QueryColumn.new( |
|
| 67 |
:attachments_filesize, |
|
| 68 |
:sortable => |
|
| 69 |
lambda do |
|
| 70 |
"COALESCE((SELECT SUM(filesize) FROM #{Attachment.table_name}" \
|
|
| 71 |
" WHERE #{Attachment.table_name}.container_type = 'Issue'" \
|
|
| 72 |
" AND #{Attachment.table_name}.container_id = #{Issue.table_name}.id), 0)"
|
|
| 73 |
end, |
|
| 74 |
:default_order => 'desc'), |
|
| 57 | 75 |
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date", :groupable => true),
|
| 58 | 76 |
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
|
| 59 | 77 |
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_attachments_count: Files count |
|
| 374 |
field_attachments_filesize: Total file size |
|
| 373 | 375 |
field_content: Content |
| 374 | 376 |
field_group_by: Group results by |
| 375 | 377 |
field_sharing: Sharing |
| config/locales/ja.yml | ||
|---|---|---|
| 329 | 329 |
field_editable: 編集可能 |
| 330 | 330 |
field_watcher: ウォッチャー |
| 331 | 331 |
field_watchers_count: ウォッチ数 |
| 332 |
field_attachments_count: 添付ファイル数 |
|
| 333 |
field_attachments_filesize: 添付ファイル合計サイズ |
|
| 332 | 334 |
field_content: 内容 |
| 333 | 335 |
field_group_by: グループ条件 |
| 334 | 336 |
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_attachments_count_and_filesize |
|
| 1392 |
user = User.find(2) |
|
| 1393 |
file = uploaded_test_file("testfile.txt", "text/plain")
|
|
| 1394 |
Attachment.delete_all |
|
| 1395 |
2.times.each do |
|
| 1396 |
a = Attachment.new(:container => Issue.find(1), :file => file, :author => user) |
|
| 1397 |
a.filesize = 0.5.megabyte |
|
| 1398 |
a.save! |
|
| 1399 |
end |
|
| 1400 |
a = Attachment.new(:container => Issue.find(2), :file => file, :author => user) |
|
| 1401 |
a.filesize = 2.megabyte |
|
| 1402 |
a.save! |
|
| 1403 |
# sort by attachments count |
|
| 1404 |
get(:index, :params => {:sort => 'attachments_count:desc'})
|
|
| 1405 |
assert_response :success |
|
| 1406 |
assert_equal [2, 1, 0], issues_in_list.map {|issue| issue.attachments_count}.first(3)
|
|
| 1407 |
# sort by attachments filesize |
|
| 1408 |
get(:index, :params => {:sort => 'attachments_filesize:desc'})
|
|
| 1409 |
assert_response :success |
|
| 1410 |
assert_equal [2.megabyte, 1.megabyte, 0], issues_in_list.map {|issue| issue.attachments_filesize}.first(3)
|
|
| 1411 |
end |
|
| 1412 | ||
| 1391 | 1413 |
def test_index_sort_by_user_custom_field |
| 1392 | 1414 |
cf = IssueCustomField. |
| 1393 | 1415 |
create!( |
| test/unit/issue_test.rb | ||
|---|---|---|
| 3532 | 3532 |
end |
| 3533 | 3533 |
assert_equal 2, issue.watchers_count |
| 3534 | 3534 |
end |
| 3535 | ||
| 3536 |
def test_attachments_count_and_filesize |
|
| 3537 |
issue = Issue.generate! |
|
| 3538 |
user = User.find(2) |
|
| 3539 |
attachments_filesize = 2.times.collect do |
|
| 3540 |
a = Attachment.new(:container => issue, |
|
| 3541 |
:file => uploaded_test_file("testfile.txt", "text/plain"),
|
|
| 3542 |
:author => user) |
|
| 3543 |
a.save! && a |
|
| 3544 |
end.sum{ |a| a.filesize }
|
|
| 3545 |
assert_equal 2, issue.attachments_count |
|
| 3546 |
assert_equal attachments_filesize, issue.attachments_filesize |
|
| 3547 |
end |
|
| 3535 | 3548 |
end |
- « Previous
- 1
- 2
- Next »