Project

General

Profile

Feature #37973 » enable_to_display_watchers_count_on_issues_list.patch

Takenori TAKAKI, 2023-05-19 07:13

View differences:

app/models/issue.rb
end
end
def watchers_count
@watchers_count ||= self.watchers.count(:id)
end
# Preloads relations for a collection of issues
def self.load_relations(issues)
if issues.any?
app/models/issue_query.rb
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
QueryColumn.new(:fixed_version, :sortable => lambda {Version.fields_for_order_statement},
:groupable => true),
QueryColumn.new(
:watchers_count,
:sortable =>
lambda do
"COALESCE((SELECT COUNT(user_id) FROM #{Watcher.table_name}" \
" WHERE #{Watcher.table_name}.watchable_type = 'Issue'" \
" AND #{Watcher.table_name}.watchable_id = #{Issue.table_name}.id), 0)"
end,
:default_order => 'desc'),
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date", :groupable => true),
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours",
app/views/watchers/_set_watcher.js.erb
<% selector = ".#{watcher_css(watched)}" %>
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(watched, user) %>")});
$('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => watched.first})) %>');
var back_url = $('input[name="back_url"]').val() || '';
if (back_url.length > 0) {
window.location.href = back_url;
} else {
<% selector = ".#{watcher_css(watched)}" %>
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(watched, user) %>")});
$('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => watched.first})) %>');
}
app/views/watchers/create.js.erb
render(:partial => 'watchers/new',
:locals => {:watchables => @watchables, :users => @users})) %>');
<% if @watchables.size == 1 %>
<%= render(:partial => 'watchers/set_watcher',
:locals => {:watched => @watchables, :user => User.current}) %>
<% end %>
<%= render(:partial => 'watchers/set_watcher',
:locals => {:watched => @watchables, :user => User.current}) %>
config/locales/en.yml
field_parent_title: Parent page
field_editable: Editable
field_watcher: Watcher
field_watchers_count: Watchers count
field_content: Content
field_group_by: Group results by
field_sharing: Sharing
config/locales/ja.yml
field_parent_title: 親ページ
field_editable: 編集可能
field_watcher: ウォッチャー
field_watchers_count: ウォッチ数
field_content: 内容
field_group_by: グループ条件
field_sharing: 共有
test/functional/issues_controller_test.rb
assert_equal hours.sort.reverse, hours
end
def test_index_sort_by_watchers_count
Watcher.delete_all
User.find([2, 3]).each do |user|
Watcher.create!(:user => user, :watchable => Issue.find(1))
end
Watcher.create!(:user => User.find(2), :watchable => Issue.find(2))
get(:index, :params => {:sort => 'watchers_count:desc'})
assert_response :success
assert_equal [2, 1, 0], issues_in_list.map {|issue| issue.watchers_count}.first(3)
end
def test_index_sort_by_user_custom_field
cf = IssueCustomField.
create!(
test/unit/issue_test.rb
r = Issue.like('issue today')
assert_include Issue.find(7), r
end
def test_watchers_count
issue = Issue.generate!
User.find([2, 3]).each do |user|
Watcher.create!(:user => user, :watchable => issue)
end
assert_equal 2, issue.watchers_count
end
end
(4-4/4)