Feature #37973 » enable_to_display_watchers_count_on_issues_list.patch
| app/models/issue.rb | ||
|---|---|---|
| 1184 | 1184 |
end |
| 1185 | 1185 |
end |
| 1186 | 1186 | |
| 1187 |
def watchers_count |
|
| 1188 |
@watchers_count ||= self.watchers.count(:id) |
|
| 1189 |
end |
|
| 1190 | ||
| 1187 | 1191 |
# Preloads relations for a collection of issues |
| 1188 | 1192 |
def self.load_relations(issues) |
| 1189 | 1193 |
if issues.any? |
| app/models/issue_query.rb | ||
|---|---|---|
| 45 | 45 |
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
|
| 46 | 46 |
QueryColumn.new(:fixed_version, :sortable => lambda {Version.fields_for_order_statement},
|
| 47 | 47 |
:groupable => true), |
| 48 |
QueryColumn.new( |
|
| 49 |
:watchers_count, |
|
| 50 |
:sortable => |
|
| 51 |
lambda do |
|
| 52 |
"COALESCE((SELECT COUNT(user_id) FROM #{Watcher.table_name}" \
|
|
| 53 |
" WHERE #{Watcher.table_name}.watchable_type = 'Issue'" \
|
|
| 54 |
" AND #{Watcher.table_name}.watchable_id = #{Issue.table_name}.id), 0)"
|
|
| 55 |
end, |
|
| 56 |
:default_order => 'desc'), |
|
| 48 | 57 |
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date", :groupable => true),
|
| 49 | 58 |
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
|
| 50 | 59 |
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours",
|
| app/views/watchers/_set_watcher.js.erb | ||
|---|---|---|
| 1 |
<% selector = ".#{watcher_css(watched)}" %>
|
|
| 2 |
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(watched, user) %>")});
|
|
| 3 |
$('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => watched.first})) %>');
|
|
| 1 |
var back_url = $('input[name="back_url"]').val() || '';
|
|
| 2 |
if (back_url.length > 0) {
|
|
| 3 |
window.location.href = back_url; |
|
| 4 |
} else {
|
|
| 5 |
<% selector = ".#{watcher_css(watched)}" %>
|
|
| 6 |
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(watched, user) %>")});
|
|
| 7 |
$('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => watched.first})) %>');
|
|
| 8 |
} |
|
| app/views/watchers/create.js.erb | ||
|---|---|---|
| 3 | 3 |
render(:partial => 'watchers/new', |
| 4 | 4 |
:locals => {:watchables => @watchables, :users => @users})) %>');
|
| 5 | 5 | |
| 6 |
<% if @watchables.size == 1 %> |
|
| 7 |
<%= render(:partial => 'watchers/set_watcher', |
|
| 8 |
:locals => {:watched => @watchables, :user => User.current}) %>
|
|
| 9 |
<% end %> |
|
| 6 |
<%= render(:partial => 'watchers/set_watcher', |
|
| 7 |
:locals => {:watched => @watchables, :user => User.current}) %>
|
|
| config/locales/en.yml | ||
|---|---|---|
| 369 | 369 |
field_parent_title: Parent page |
| 370 | 370 |
field_editable: Editable |
| 371 | 371 |
field_watcher: Watcher |
| 372 |
field_watchers_count: Watchers count |
|
| 372 | 373 |
field_content: Content |
| 373 | 374 |
field_group_by: Group results by |
| 374 | 375 |
field_sharing: Sharing |
| config/locales/ja.yml | ||
|---|---|---|
| 328 | 328 |
field_parent_title: 親ページ |
| 329 | 329 |
field_editable: 編集可能 |
| 330 | 330 |
field_watcher: ウォッチャー |
| 331 |
field_watchers_count: ウォッチ数 |
|
| 331 | 332 |
field_content: 内容 |
| 332 | 333 |
field_group_by: グループ条件 |
| 333 | 334 |
field_sharing: 共有 |
| test/functional/issues_controller_test.rb | ||
|---|---|---|
| 1377 | 1377 |
assert_equal hours.sort.reverse, hours |
| 1378 | 1378 |
end |
| 1379 | 1379 | |
| 1380 |
def test_index_sort_by_watchers_count |
|
| 1381 |
Watcher.delete_all |
|
| 1382 |
User.find([2, 3]).each do |user| |
|
| 1383 |
Watcher.create!(:user => user, :watchable => Issue.find(1)) |
|
| 1384 |
end |
|
| 1385 |
Watcher.create!(:user => User.find(2), :watchable => Issue.find(2)) |
|
| 1386 |
get(:index, :params => {:sort => 'watchers_count:desc'})
|
|
| 1387 |
assert_response :success |
|
| 1388 |
assert_equal [2, 1, 0], issues_in_list.map {|issue| issue.watchers_count}.first(3)
|
|
| 1389 |
end |
|
| 1390 | ||
| 1380 | 1391 |
def test_index_sort_by_user_custom_field |
| 1381 | 1392 |
cf = IssueCustomField. |
| 1382 | 1393 |
create!( |
| test/unit/issue_test.rb | ||
|---|---|---|
| 3524 | 3524 |
r = Issue.like('issue today')
|
| 3525 | 3525 |
assert_include Issue.find(7), r |
| 3526 | 3526 |
end |
| 3527 | ||
| 3528 |
def test_watchers_count |
|
| 3529 |
issue = Issue.generate! |
|
| 3530 |
User.find([2, 3]).each do |user| |
|
| 3531 |
Watcher.create!(:user => user, :watchable => issue) |
|
| 3532 |
end |
|
| 3533 |
assert_equal 2, issue.watchers_count |
|
| 3534 |
end |
|
| 3527 | 3535 |
end |
- « Previous
- 1
- 2
- 3
- 4
- Next »