Feature #6375 » 6375_add_last_updated_by_column_r16248.patch
| app/models/issue.rb | ||
|---|---|---|
|
@spent_hours = nil
|
||
|
@total_spent_hours = nil
|
||
|
@total_estimated_hours = nil
|
||
|
@last_updated_by = nil
|
||
|
base_reload(*args)
|
||
|
end
|
||
| ... | ... | |
|
@relations ||= IssueRelation::Relations.new(self, (relations_from + relations_to).sort)
|
||
|
end
|
||
|
def last_updated_by
|
||
|
if @last_updated_by
|
||
|
@last_updated_by
|
||
|
else
|
||
|
journal = self.journals.preload(:user).visible.last
|
||
|
journal.user if journal
|
||
|
end
|
||
|
end
|
||
|
# Preloads relations for a collection of issues
|
||
|
def self.load_relations(issues)
|
||
|
if issues.any?
|
||
| ... | ... | |
|
where(:ancestors => {:id => issues.map(&:id)})
|
||
|
end
|
||
|
# Preloads users who updated last a collection of issues
|
||
|
def self.load_visible_last_updated_by(issues)
|
||
|
if issues.any?
|
||
|
issue_ids = issues.map(&:id)
|
||
|
journals = Journal.joins(issue: :project).preload(:user).
|
||
|
where(:journalized_type => 'Issue', :journalized_id => issue_ids).
|
||
|
where(Journal.visible_notes_condition(User.current, :skip_pre_condition => true)).to_a
|
||
|
issues.each do |issue|
|
||
|
journal = journals.select{|journal| journal.journalized_id == issue.id}
|
||
|
issue.instance_variable_set "@last_updated_by", (journal.empty? ? '' : journal.last.user)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
# Finds an issue relation given its id.
|
||
|
def find_relation(relation_id)
|
||
|
IssueRelation.where("issue_to_id = ? OR issue_from_id = ?", id, id).find(relation_id)
|
||
| app/models/issue_query.rb | ||
|---|---|---|
|
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio", :groupable => true),
|
||
|
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
|
||
|
QueryColumn.new(:closed_on, :sortable => "#{Issue.table_name}.closed_on", :default_order => 'desc'),
|
||
|
QueryColumn.new(:last_updated_by, :sortable => lambda {User.fields_for_order_statement("last_journal_user")}),
|
||
|
QueryColumn.new(:relations, :caption => :label_related_issues),
|
||
|
QueryColumn.new(:description, :inline => false)
|
||
|
]
|
||
| ... | ... | |
|
if has_column?(:total_spent_hours)
|
||
|
Issue.load_visible_total_spent_hours(issues)
|
||
|
end
|
||
|
if has_column?(:last_updated_by)
|
||
|
Issue.load_visible_last_updated_by(issues)
|
||
|
end
|
||
|
if has_column?(:relations)
|
||
|
Issue.load_visible_relations(issues)
|
||
|
end
|
||
| ... | ... | |
|
if order_options.include?('users')
|
||
|
joins << "LEFT OUTER JOIN #{User.table_name} ON #{User.table_name}.id = #{queried_table_name}.assigned_to_id"
|
||
|
end
|
||
|
if order_options.include?('last_journal_user')
|
||
|
joins << "LEFT OUTER JOIN #{Journal.table_name} ON #{Journal.table_name}.id = (SELECT MAX(#{Journal.table_name}.id) FROM #{Journal.table_name}" +
|
||
|
" WHERE #{Journal.table_name}.journalized_type='Issue' AND #{Journal.table_name}.journalized_id=#{Issue.table_name}.id AND #{Journal.visible_notes_condition(User.current, :skip_pre_condition => true)})" +
|
||
|
" LEFT OUTER JOIN #{User.table_name} last_journal_user ON last_journal_user.id = #{Journal.table_name}.user_id";
|
||
|
end
|
||
|
if order_options.include?('versions')
|
||
|
joins << "LEFT OUTER JOIN #{Version.table_name} ON #{Version.table_name}.id = #{queried_table_name}.fixed_version_id"
|
||
|
end
|
||
| public/stylesheets/application.css | ||
|---|---|---|
|
tr.project.idnt-9 td.name {padding-left: 12.5em;}
|
||
|
tr.issue { text-align: center; white-space: nowrap; }
|
||
|
tr.issue td.subject, tr.issue td.category, td.assigned_to, tr.issue td.string, tr.issue td.text, tr.issue td.list, tr.issue td.relations, tr.issue td.parent { white-space: normal; }
|
||
|
tr.issue td.subject, tr.issue td.category, td.assigned_to, td.last_updated_by, tr.issue td.string, tr.issue td.text, tr.issue td.list, tr.issue td.relations, tr.issue td.parent { white-space: normal; }
|
||
|
tr.issue td.relations { text-align: left; }
|
||
|
tr.issue td.done_ratio table.progress { margin-left:auto; margin-right: auto;}
|
||
|
tr.issue td.relations span {white-space: nowrap;}
|
||
| test/unit/query_test.rb | ||
|---|---|---|
|
query = IssueQuery.new(:name => '_')
|
||
|
filter_name = "updated_by"
|
||
|
assert_include filter_name, query.available_filters.keys
|
||
|
|
||
|
query.filters = {filter_name => {:operator => '=', :values => ['me']}}
|
||
|
assert_equal [2], find_issues_with_query(query).map(&:id).sort
|
||
|
end
|
||
| ... | ... | |
|
assert_not_nil issues.first.instance_variable_get("@spent_hours")
|
||
|
end
|
||
|
def test_query_should_preload_last_updated_by
|
||
|
q = IssueQuery.new(:name => '_', :column_names => [:subject, :last_updated_by])
|
||
|
assert q.has_column?(:last_updated_by)
|
||
|
issues = q.issues
|
||
|
assert_not_nil issues.first.instance_variable_get("@last_updated_by")
|
||
|
end
|
||
|
def test_query_with_last_updated_by_column
|
||
|
q = IssueQuery.new(:name => '_', :column_names => [:subject, :last_updated_by])
|
||
|
q.filters = {"project_id" => {:operator => '=', :values => [1]}}
|
||
|
assert_equal ["User", "String", "String", "User", "String", "String", "String"], q.issues.map { |i| i.last_updated_by.class.name}
|
||
|
assert_equal ["John Smith", "", "", "John Smith", "", "", ""], q.issues.map { |i| i.last_updated_by.to_s }
|
||
|
end
|
||
|
def test_groupable_columns_should_include_custom_fields
|
||
|
q = IssueQuery.new
|
||
|
column = q.groupable_columns.detect {|c| c.name == :cf_1}
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def test_sortable_columns_should_sort_last_updated_by_according_to_user_format_setting
|
||
|
with_settings :user_format => 'lastname_comma_firstname' do
|
||
|
q = IssueQuery.new
|
||
|
q.sort_criteria = [['last_updated_by', 'desc']]
|
||
|
assert q.sortable_columns.has_key?('last_updated_by')
|
||
|
assert_equal %w(last_journal_user.lastname last_journal_user.firstname last_journal_user.id), q.sortable_columns['last_updated_by']
|
||
|
end
|
||
|
end
|
||
|
def test_sortable_columns_should_include_custom_field
|
||
|
q = IssueQuery.new
|
||
|
assert q.sortable_columns['cf_1']
|
||