summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/queries_helper.rb2
-rw-r--r--app/models/issue.rb26
-rw-r--r--app/models/issue_query.rb6
-rw-r--r--app/views/issues/_list.html.erb7
-rw-r--r--app/views/issues/index.html.erb1
-rw-r--r--app/views/timelog/_list.html.erb7
-rw-r--r--config/locales/en.yml1
-rw-r--r--lib/redmine/export/pdf/issues_pdf_helper.rb11
-rw-r--r--public/stylesheets/application.css4
-rw-r--r--test/functional/issues_controller_test.rb37
-rw-r--r--test/unit/query_test.rb11
11 files changed, 104 insertions, 9 deletions
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 458fb70fd..c356ca0d4 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -185,6 +185,8 @@ module QueriesHelper
value ? (value.visible? ? link_to_issue(value, :subject => false) : "##{value.id}") : ''
when :description
item.description? ? content_tag('div', textilizable(item, :description), :class => "wiki") : ''
+ when :last_notes
+ item.last_notes.present? ? content_tag('div', textilizable(item, :last_notes), :class => "wiki") : ''
when :done_ratio
progress_bar(value)
when :relations
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 19fef95b5..c80920ca5 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -246,6 +246,7 @@ class Issue < ActiveRecord::Base
@total_spent_hours = nil
@total_estimated_hours = nil
@last_updated_by = nil
+ @last_notes = nil
base_reload(*args)
end
@@ -1078,6 +1079,15 @@ class Issue < ActiveRecord::Base
end
end
+ def last_notes
+ if @last_notes
+ @last_notes
+ else
+ notes = self.journals.visible.where.not(notes: '').to_a
+ notes.last.notes unless notes.empty?
+ end
+ end
+
# Preloads relations for a collection of issues
def self.load_relations(issues)
if issues.any?
@@ -1158,6 +1168,22 @@ class Issue < ActiveRecord::Base
end
end
+ # Preloads visible last notes for a collection of issues
+ def self.load_visible_last_notes(issues, user=User.current)
+ if issues.any?
+ issue_ids = issues.map(&:id)
+
+ notes = Journal.joins(issue: :project).where.not(notes: '').
+ where(Journal.visible_notes_condition(User.current, :skip_pre_condition => true)).
+ where(:issues => {:id => issue_ids}).order("#{Journal.table_name}.id ASC").to_a
+
+ issues.each do |issue|
+ note = notes.select{|note| note.journalized_id == issue.id}
+ issue.instance_variable_set "@last_notes", (note.empty? ? '' : note.last.notes)
+ 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)
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index 88b51f593..7f399f469 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -45,7 +45,8 @@ class IssueQuery < Query
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)
+ QueryColumn.new(:description, :inline => false),
+ QueryColumn.new(:last_notes, :caption => :label_last_notes, :inline => false)
]
def initialize(attributes=nil, *args)
@@ -305,6 +306,9 @@ class IssueQuery < Query
if has_column?(:relations)
Issue.load_visible_relations(issues)
end
+ if has_column?(:last_notes)
+ Issue.load_visible_last_notes(issues)
+ end
issues
rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message)
diff --git a/app/views/issues/_list.html.erb b/app/views/issues/_list.html.erb
index 7e34fca24..3ae5e7023 100644
--- a/app/views/issues/_list.html.erb
+++ b/app/views/issues/_list.html.erb
@@ -33,7 +33,12 @@
<% @query.block_columns.each do |column|
if (text = column_content(column, issue)) && text.present? -%>
<tr class="<%= current_cycle %>">
- <td colspan="<%= @query.inline_columns.size + 1 %>" class="<%= column.css_classes %>"><%= text %></td>
+ <td colspan="<%= @query.inline_columns.size + 1 %>" class="<%= column.css_classes %>">
+ <% if query.block_columns.count > 1 %>
+ <span><%= column.caption %></span>
+ <% end %>
+ <%= text %>
+ </td>
</tr>
<% end -%>
<% end -%>
diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb
index 3d456aad1..80210814e 100644
--- a/app/views/issues/index.html.erb
+++ b/app/views/issues/index.html.erb
@@ -37,6 +37,7 @@
</p>
<p>
<label><%= check_box_tag 'c[]', 'description', @query.has_column?(:description) %> <%= l(:field_description) %></label>
+ <label><%= check_box_tag 'c[]', 'last_notes', @query.has_column?(:last_notes) %> <%= l(:label_last_notes) %></label>
</p>
<% if @issue_count > Setting.issues_export_limit.to_i %>
<p class="icon icon-warning">
diff --git a/app/views/timelog/_list.html.erb b/app/views/timelog/_list.html.erb
index 0fb72aeb4..b39eb5cc3 100644
--- a/app/views/timelog/_list.html.erb
+++ b/app/views/timelog/_list.html.erb
@@ -50,7 +50,12 @@
<% @query.block_columns.each do |column|
if (text = column_content(column, issue)) && text.present? -%>
<tr class="<%= current_cycle %>">
- <td colspan="<%= @query.inline_columns.size + 1 %>" class="<%= column.css_classes %>"><%= text %></td>
+ <td colspan="<%= @query.inline_columns.size + 1 %>" class="<%= column.css_classes %>">
+ <% if query.block_columns.count > 1 %>
+ <span><%= column.caption %></span>
+ <% end %>
+ <%= text %>
+ </td>
</tr>
<% end -%>
<% end -%>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index eb3d7cf37..2d9260fb5 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1014,6 +1014,7 @@ en:
label_font_default: Default font
label_font_monospace: Monospaced font
label_font_proportional: Proportional font
+ label_last_notes: Last notes
button_login: Login
button_submit: Submit
diff --git a/lib/redmine/export/pdf/issues_pdf_helper.rb b/lib/redmine/export/pdf/issues_pdf_helper.rb
index 4c0b935da..cf8a79d3c 100644
--- a/lib/redmine/export/pdf/issues_pdf_helper.rb
+++ b/lib/redmine/export/pdf/issues_pdf_helper.rb
@@ -278,8 +278,8 @@ module Redmine
table_width = col_width.inject(0, :+)
end
- # use full width if the description is displayed
- if table_width > 0 && query.has_column?(:description)
+ # use full width if the description or last_notes are displayed
+ if table_width > 0 && (query.has_column?(:description) || query.has_column?(:last_notes))
col_width = col_width.map {|w| w * (page_width - right_margin - left_margin) / table_width}
table_width = col_width.inject(0, :+)
end
@@ -339,6 +339,13 @@ module Redmine
pdf.RDMwriteHTMLCell(0, 5, 10, '', issue.description.to_s, issue.attachments, "LRBT")
pdf.set_auto_page_break(false)
end
+
+ if query.has_column?(:last_notes) && issue.last_notes.present?
+ pdf.set_x(10)
+ pdf.set_auto_page_break(true, bottom_margin)
+ pdf.RDMwriteHTMLCell(0, 5, 10, '', issue.last_notes.to_s, [], "LRBT")
+ pdf.set_auto_page_break(false)
+ end
end
if issues.size == Setting.issues_export_limit.to_i
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 6c2ffed30..7754fc565 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -258,8 +258,8 @@ tr.issue td.subject, tr.issue td.category, td.assigned_to, td.last_updated_by, t
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;}
-table.issues td.description {color:#777; font-size:90%; padding:4px 4px 4px 24px; text-align:left; white-space:normal;}
-table.issues td.description pre {white-space:normal;}
+table.issues td.description, table.issues td.last_notes {color:#777; font-size:90%; padding:4px 4px 4px 24px; text-align:left; white-space:normal;}
+table.issues td.description pre, table.issues td.last_notes pre {white-space:normal;}
tr.issue.idnt td.subject {background: url(../images/bullet_arrow_right.png) no-repeat 0 50%;}
tr.issue.idnt-1 td.subject {padding-left: 24px; background-position: 8px 50%;}
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 6aa6a0623..63ac34fdd 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -971,6 +971,43 @@ class IssuesControllerTest < Redmine::ControllerTest
assert_equal 'application/pdf', response.content_type
end
+ def test_index_with_last_notes_column
+ get :index, :set_filter => 1, :c => %w(subject last_notes)
+
+ assert_response :success
+ assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject
+
+ assert_select 'td.last_notes[colspan="3"]', :text => 'Some notes with Redmine links: #2, r2.'
+ assert_select 'td.last_notes[colspan="3"]', :text => 'A comment with inline image: and a reference to #1 and r2.'
+
+ get :index, :set_filter => 1, :c => %w(subject last_notes), :format => 'pdf'
+ assert_response :success
+ assert_equal 'application/pdf', response.content_type
+ end
+
+ def test_index_with_last_notes_column_should_display_private_notes_with_permission_only
+ journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
+ @request.session[:user_id] = 2
+
+ get :index, :set_filter => 1, :c => %w(subject last_notes)
+ assert_response :success
+ assert_select 'td.last_notes[colspan="3"]', :text => 'Privates notes'
+
+ Role.find(1).remove_permission! :view_private_notes
+
+ get :index, :set_filter => 1, :c => %w(subject last_notes)
+ assert_response :success
+ assert_select 'td.last_notes[colspan="3"]', :text => 'A comment with inline image: and a reference to #1 and r2.'
+ end
+
+ def test_index_with_description_and_last_notes_columns_should_display_column_name
+ get :index, :set_filter => 1, :c => %w(subject last_notes description)
+ assert_response :success
+
+ assert_select 'td.last_notes[colspan="3"] span', :text => 'Last notes'
+ assert_select 'td.description[colspan="3"] span', :text => 'Description'
+ end
+
def test_index_with_parent_column
Issue.delete_all
parent = Issue.generate!
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 77340e1ca..5a3283900 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -1302,10 +1302,10 @@ class QueryTest < ActiveSupport::TestCase
def test_inline_and_block_columns
q = IssueQuery.new
- q.column_names = ['subject', 'description', 'tracker']
+ q.column_names = ['subject', 'description', 'tracker', 'last_notes']
assert_equal [:id, :subject, :tracker], q.inline_columns.map(&:name)
- assert_equal [:description], q.block_columns.map(&:name)
+ assert_equal [:description, :last_notes], q.block_columns.map(&:name)
end
def test_custom_field_columns_should_be_inline
@@ -1335,6 +1335,13 @@ class QueryTest < ActiveSupport::TestCase
end
end
+ def test_query_should_preload_last_notes
+ q = IssueQuery.new(:name => '_', :column_names => [:subject, :last_notes])
+ assert q.has_column?(:last_notes)
+ issues = q.issues
+ assert_not_nil issues.first.instance_variable_get("@last_notes")
+ end
+
def test_groupable_columns_should_include_custom_fields
q = IssueQuery.new
column = q.groupable_columns.detect {|c| c.name == :cf_1}