Feature #6375 » add_column_last_updated_by_v2.patch
app/models/issue.rb | ||
---|---|---|
244 | 244 |
@spent_hours = nil |
245 | 245 |
@total_spent_hours = nil |
246 | 246 |
@total_estimated_hours = nil |
247 |
@last_updated_by = nil |
|
247 | 248 |
base_reload(*args) |
248 | 249 |
end |
249 | 250 | |
... | ... | |
1027 | 1028 |
@relations ||= IssueRelation::Relations.new(self, (relations_from + relations_to).sort) |
1028 | 1029 |
end |
1029 | 1030 | |
1031 |
def last_updated_by |
|
1032 |
@last_updated_by |
|
1033 |
end |
|
1034 | ||
1030 | 1035 |
# Preloads relations for a collection of issues |
1031 | 1036 |
def self.load_relations(issues) |
1032 | 1037 |
if issues.any? |
... | ... | |
1081 | 1086 |
end |
1082 | 1087 |
end |
1083 | 1088 | |
1089 |
# Preloads users who updated last a collection of issues |
|
1090 |
def self.load_last_updated_by(issues) |
|
1091 |
if issues.any? |
|
1092 |
journals_user = {} |
|
1093 |
issues_last_journal = Journal.joins(:issue).preload(:user). |
|
1094 |
where('issues.updated_on = journals.created_on'). |
|
1095 |
where(:journalized_id => issues.map(&:id)) |
|
1096 | ||
1097 |
issues_last_journal.each do |journal| |
|
1098 |
journals_user[journal.journalized_id] = journal.user |
|
1099 |
end |
|
1100 | ||
1101 |
issues.each do |issue| |
|
1102 |
issue.instance_variable_set "@last_updated_by", (journals_user[issue.id] || nil) |
|
1103 |
end |
|
1104 |
end |
|
1105 |
end |
|
1106 | ||
1084 | 1107 |
# Finds an issue relation given its id. |
1085 | 1108 |
def find_relation(relation_id) |
1086 | 1109 |
IssueRelation.where("issue_to_id = ? OR issue_from_id = ?", id, id).find(relation_id) |
... | ... | |
1400 | 1423 |
end |
1401 | 1424 |
Project.where(condition).having_trackers |
1402 | 1425 |
end |
1403 |
|
|
1426 | ||
1404 | 1427 |
# Returns a scope of trackers that user can assign the issue to |
1405 | 1428 |
def allowed_target_trackers(user=User.current) |
1406 | 1429 |
self.class.allowed_target_trackers(project, user, tracker_id_was) |
app/models/issue_query.rb | ||
---|---|---|
31 | 31 |
QueryColumn.new(:author, :sortable => lambda {User.fields_for_order_statement("authors")}, :groupable => true), |
32 | 32 |
QueryColumn.new(:assigned_to, :sortable => lambda {User.fields_for_order_statement}, :groupable => true), |
33 | 33 |
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'), |
34 |
QueryColumn.new(:last_updated_by, :sortable => false), |
|
34 | 35 |
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true), |
35 | 36 |
QueryColumn.new(:fixed_version, :sortable => lambda {Version.fields_for_order_statement}, :groupable => true), |
36 | 37 |
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"), |
... | ... | |
328 | 329 |
if has_column?(:total_spent_hours) |
329 | 330 |
Issue.load_visible_total_spent_hours(issues) |
330 | 331 |
end |
332 |
if has_column?(:last_updated_by) |
|
333 |
Issue.load_last_updated_by(issues) |
|
334 |
end |
|
331 | 335 |
if has_column?(:relations) |
332 | 336 |
Issue.load_visible_relations(issues) |
333 | 337 |
end |
public/stylesheets/application.css | ||
---|---|---|
190 | 190 |
tr.project.idnt-9 td.name {padding-left: 12.5em;} |
191 | 191 | |
192 | 192 |
tr.issue { text-align: center; white-space: nowrap; } |
193 |
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; } |
|
193 |
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; }
|
|
194 | 194 |
tr.issue td.relations { text-align: left; } |
195 | 195 |
tr.issue td.done_ratio table.progress { margin-left:auto; margin-right: auto;} |
196 | 196 |
tr.issue td.relations span {white-space: nowrap;} |
test/unit/query_test.rb | ||
---|---|---|
1117 | 1117 |
assert_not_nil issues.first.instance_variable_get("@spent_hours") |
1118 | 1118 |
end |
1119 | 1119 | |
1120 |
def test_query_should_preload_last_updated_by |
|
1121 |
q = IssueQuery.new(:name => '_', :column_names => [:subject, :last_updated_by]) |
|
1122 |
assert q.has_column?(:last_updated_by) |
|
1123 |
issues = q.issues |
|
1124 |
assert_not_nil issues.first.instance_variable_get("@last_updated_by") |
|
1125 |
end |
|
1126 | ||
1127 |
def test_query_with_last_updated_by_column |
|
1128 |
q = IssueQuery.new(:name => '_', :column_names => [:subject, :last_updated_by]) |
|
1129 |
q.filters = {"project_id" => {:operator => '=', :values => [1]}} |
|
1130 | ||
1131 |
assert_equal ["User", "User", "User", "NilClass", "NilClass", "NilClass", "NilClass"], q.issues.map { |i| i.last_updated_by.class.name} |
|
1132 |
assert_equal ["John Smith", "John Smith", "Dave Lopper", "", "", "", ""], q.issues.map { |i| i.last_updated_by.to_s } |
|
1133 |
end |
|
1134 | ||
1120 | 1135 |
def test_groupable_columns_should_include_custom_fields |
1121 | 1136 |
q = IssueQuery.new |
1122 | 1137 |
column = q.groupable_columns.detect {|c| c.name == :cf_1} |