Adds an option for displaying the issue description on the issue list (#3447).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10948 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
43fb321195
commit
8201761e77
|
@ -371,12 +371,16 @@ module IssuesHelper
|
|||
def issues_to_csv(issues, project, query, options={})
|
||||
decimal_separator = l(:general_csv_decimal_separator)
|
||||
encoding = l(:general_csv_encoding)
|
||||
columns = (options[:columns] == 'all' ? query.available_columns : query.columns)
|
||||
columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
|
||||
if options[:description]
|
||||
if description = query.available_columns.detect {|q| q.name == :description}
|
||||
columns << description
|
||||
end
|
||||
end
|
||||
|
||||
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
|
||||
# csv header fields
|
||||
csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } +
|
||||
(options[:description] ? [Redmine::CodesetUtil.from_utf8(l(:field_description), encoding)] : [])
|
||||
csv << [ "#" ] + columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) }
|
||||
|
||||
# csv lines
|
||||
issues.each do |issue|
|
||||
|
@ -398,8 +402,7 @@ module IssuesHelper
|
|||
end
|
||||
s.to_s
|
||||
end
|
||||
csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) } +
|
||||
(options[:description] ? [Redmine::CodesetUtil.from_utf8(issue.description, encoding)] : [])
|
||||
csv << [ issue.id.to_s ] + col_values.collect {|c| Redmine::CodesetUtil.from_utf8(c.to_s, encoding) }
|
||||
end
|
||||
end
|
||||
export
|
||||
|
|
|
@ -50,6 +50,14 @@ module QueriesHelper
|
|||
end
|
||||
end
|
||||
|
||||
def available_block_columns_tags(query)
|
||||
tags = ''.html_safe
|
||||
query.available_block_columns.each do |column|
|
||||
tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline')
|
||||
end
|
||||
tags
|
||||
end
|
||||
|
||||
def column_header(column)
|
||||
column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
|
||||
:default_order => column.default_order) :
|
||||
|
@ -70,6 +78,8 @@ module QueriesHelper
|
|||
when 'String'
|
||||
if column.name == :subject
|
||||
link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
|
||||
elsif column.name == :description
|
||||
issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
|
||||
else
|
||||
h(value)
|
||||
end
|
||||
|
|
|
@ -27,6 +27,7 @@ class QueryColumn
|
|||
self.groupable = name.to_s
|
||||
end
|
||||
self.default_order = options[:default_order]
|
||||
@inline = options.key?(:inline) ? options[:inline] : true
|
||||
@caption_key = options[:caption] || "field_#{name}"
|
||||
end
|
||||
|
||||
|
@ -43,6 +44,10 @@ class QueryColumn
|
|||
@sortable.is_a?(Proc) ? @sortable.call : @sortable
|
||||
end
|
||||
|
||||
def inline?
|
||||
@inline
|
||||
end
|
||||
|
||||
def value(issue)
|
||||
issue.send name
|
||||
end
|
||||
|
@ -58,6 +63,7 @@ class QueryCustomFieldColumn < QueryColumn
|
|||
self.name = "cf_#{custom_field.id}".to_sym
|
||||
self.sortable = custom_field.order_statement || false
|
||||
self.groupable = custom_field.group_statement || false
|
||||
@inline = true
|
||||
@cf = custom_field
|
||||
end
|
||||
|
||||
|
@ -153,7 +159,8 @@ class Query < ActiveRecord::Base
|
|||
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
|
||||
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(:relations, :caption => :label_related_issues)
|
||||
QueryColumn.new(:relations, :caption => :label_related_issues),
|
||||
QueryColumn.new(:description, :inline => false)
|
||||
]
|
||||
cattr_reader :available_columns
|
||||
|
||||
|
@ -506,6 +513,22 @@ class Query < ActiveRecord::Base
|
|||
end.compact
|
||||
end
|
||||
|
||||
def inline_columns
|
||||
columns.select(&:inline?)
|
||||
end
|
||||
|
||||
def block_columns
|
||||
columns.reject(&:inline?)
|
||||
end
|
||||
|
||||
def available_inline_columns
|
||||
available_columns.select(&:inline?)
|
||||
end
|
||||
|
||||
def available_block_columns
|
||||
available_columns.reject(&:inline?)
|
||||
end
|
||||
|
||||
def default_columns_names
|
||||
@default_columns_names ||= begin
|
||||
default_columns = Setting.issue_list_default_columns.map(&:to_sym)
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}" %>
|
||||
</th>
|
||||
<%= sort_header_tag('id', :caption => '#', :default_order => 'desc') %>
|
||||
<% query.columns.each do |column| %>
|
||||
<% query.inline_columns.each do |column| %>
|
||||
<%= column_header(column) %>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
@ -21,7 +21,7 @@
|
|||
<% if @query.grouped? && (group = @query.group_by_column.value(issue)) != previous_group %>
|
||||
<% reset_cycle %>
|
||||
<tr class="group open">
|
||||
<td colspan="<%= query.columns.size + 2 %>">
|
||||
<td colspan="<%= query.inline_columns.size + 2 %>">
|
||||
<span class="expander" onclick="toggleRowGroup(this);"> </span>
|
||||
<%= group.blank? ? l(:label_none) : column_content(@query.group_by_column, issue) %> <span class="count"><%= @issue_count_by_group[group] %></span>
|
||||
<%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}",
|
||||
|
@ -33,8 +33,15 @@
|
|||
<tr id="issue-<%= issue.id %>" class="hascontextmenu <%= cycle('odd', 'even') %> <%= issue.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
|
||||
<td class="checkbox hide-when-print"><%= check_box_tag("ids[]", issue.id, false, :id => nil) %></td>
|
||||
<td class="id"><%= link_to issue.id, issue_path(issue) %></td>
|
||||
<%= raw query.columns.map {|column| "<td class=\"#{column.css_classes}\">#{column_content(column, issue)}</td>"}.join %>
|
||||
<%= raw query.inline_columns.map {|column| "<td class=\"#{column.css_classes}\">#{column_content(column, issue)}</td>"}.join %>
|
||||
</tr>
|
||||
<% @query.block_columns.each do |column|
|
||||
if (text = column_content(column, issue)) && text.present? -%>
|
||||
<tr class="<%= current_cycle %>">
|
||||
<td colspan="<%= @query.inline_columns.size + 2 %>" class="<%= column.css_classes %>"><%= text %></td>
|
||||
</tr>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -34,6 +34,10 @@
|
|||
@query.group_by)
|
||||
) %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><%= l(:button_show) %></td>
|
||||
<td><%= available_block_columns_tags(@query) %></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
@ -73,7 +77,7 @@
|
|||
<label><%= radio_button_tag 'columns', 'all' %> <%= l(:description_all_columns) %></label>
|
||||
</p>
|
||||
<p>
|
||||
<label><%= check_box_tag 'description', '1' %> <%= l(:field_description) %></label>
|
||||
<label><%= check_box_tag 'description', '1', @query.has_column?(:description) %> <%= l(:field_description) %></label>
|
||||
</p>
|
||||
<p class="buttons">
|
||||
<%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<%= label_tag "available_columns", l(:description_available_columns) %>
|
||||
<br />
|
||||
<%= select_tag 'available_columns',
|
||||
options_for_select((query.available_columns - query.columns).collect {|column| [column.caption, column.name]}),
|
||||
options_for_select((query.available_inline_columns - query.columns).collect {|column| [column.caption, column.name]}),
|
||||
:multiple => true, :size => 10, :style => "width:150px",
|
||||
:ondblclick => "moveOptions(this.form.available_columns, this.form.selected_columns);" %>
|
||||
</td>
|
||||
|
@ -18,7 +18,7 @@
|
|||
<%= label_tag "selected_columns", l(:description_selected_columns) %>
|
||||
<br />
|
||||
<%= select_tag((defined?(tag_name) ? tag_name : 'c[]'),
|
||||
options_for_select(query.columns.collect {|column| [column.caption, column.name]}),
|
||||
options_for_select(query.inline_columns.collect {|column| [column.caption, column.name]}),
|
||||
:id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px",
|
||||
:ondblclick => "moveOptions(this.form.selected_columns, this.form.available_columns);") %>
|
||||
</td>
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
<p><label for="query_group_by"><%= l(:field_group_by) %></label>
|
||||
<%= select 'query', 'group_by', @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, :include_blank => true %></p>
|
||||
|
||||
<p><label><%= l(:button_show) %></label>
|
||||
<%= available_block_columns_tags(@query) %></p>
|
||||
</div>
|
||||
|
||||
<fieldset id="filters"><legend><%= l(:label_filter_plural) %></legend>
|
||||
|
|
|
@ -403,6 +403,9 @@ class TCPDF
|
|||
Error("Incorrect orientation: #{orientation}")
|
||||
end
|
||||
|
||||
@fw = @w_pt/@k
|
||||
@fh = @h_pt/@k
|
||||
|
||||
@cur_orientation = @def_orientation
|
||||
@w = @w_pt/@k
|
||||
@h = @h_pt/@k
|
||||
|
@ -3615,9 +3618,9 @@ class TCPDF
|
|||
restspace = GetPageHeight() - GetY() - GetBreakMargin();
|
||||
|
||||
writeHTML(html, true, fill); # write html text
|
||||
SetX(x)
|
||||
|
||||
currentY = GetY();
|
||||
|
||||
@auto_page_break = false;
|
||||
# check if a new page has been created
|
||||
if (@page > pagenum)
|
||||
|
@ -3625,11 +3628,13 @@ class TCPDF
|
|||
currentpage = @page;
|
||||
@page = pagenum;
|
||||
SetY(GetPageHeight() - restspace - GetBreakMargin());
|
||||
SetX(x)
|
||||
Cell(w, restspace - 1, "", b, 0, 'L', 0);
|
||||
b = b2;
|
||||
@page += 1;
|
||||
while @page < currentpage
|
||||
SetY(@t_margin); # put cursor at the beginning of text
|
||||
SetX(x)
|
||||
Cell(w, @page_break_trigger - @t_margin, "", b, 0, 'L', 0);
|
||||
@page += 1;
|
||||
end
|
||||
|
@ -3638,10 +3643,12 @@ class TCPDF
|
|||
end
|
||||
# design a cell around the text on last page
|
||||
SetY(@t_margin); # put cursor at the beginning of text
|
||||
SetX(x)
|
||||
Cell(w, currentY - @t_margin, "", b, 0, 'L', 0);
|
||||
else
|
||||
SetY(y); # put cursor at the beginning of text
|
||||
# design a cell around the text
|
||||
SetX(x)
|
||||
Cell(w, [h, (currentY - y)].max, "", border, 0, 'L', 0);
|
||||
end
|
||||
@auto_page_break = true;
|
||||
|
|
|
@ -34,12 +34,12 @@ module Redmine
|
|||
include Redmine::I18n
|
||||
attr_accessor :footer_date
|
||||
|
||||
def initialize(lang)
|
||||
def initialize(lang, orientation='P')
|
||||
@@k_path_cache = Rails.root.join('tmp', 'pdf')
|
||||
FileUtils.mkdir_p @@k_path_cache unless File::exist?(@@k_path_cache)
|
||||
set_language_if_valid lang
|
||||
pdf_encoding = l(:general_pdf_encoding).upcase
|
||||
super('P', 'mm', 'A4', (pdf_encoding == 'UTF-8'), pdf_encoding)
|
||||
super(orientation, 'mm', 'A4', (pdf_encoding == 'UTF-8'), pdf_encoding)
|
||||
case current_language.to_s.downcase
|
||||
when 'vi'
|
||||
@font_for_content = 'DejaVuSans'
|
||||
|
@ -236,7 +236,7 @@ module Redmine
|
|||
|
||||
# fetch row values
|
||||
def fetch_row_values(issue, query, level)
|
||||
query.columns.collect do |column|
|
||||
query.inline_columns.collect do |column|
|
||||
s = if column.is_a?(QueryCustomFieldColumn)
|
||||
cv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id}
|
||||
show_value(cv)
|
||||
|
@ -263,10 +263,10 @@ module Redmine
|
|||
# by captions
|
||||
pdf.SetFontStyle('B',8)
|
||||
col_padding = pdf.GetStringWidth('OO')
|
||||
col_width_min = query.columns.map {|v| pdf.GetStringWidth(v.caption) + col_padding}
|
||||
col_width_min = query.inline_columns.map {|v| pdf.GetStringWidth(v.caption) + col_padding}
|
||||
col_width_max = Array.new(col_width_min)
|
||||
col_width_avg = Array.new(col_width_min)
|
||||
word_width_max = query.columns.map {|c|
|
||||
word_width_max = query.inline_columns.map {|c|
|
||||
n = 10
|
||||
c.caption.split.each {|w|
|
||||
x = pdf.GetStringWidth(w) + col_padding
|
||||
|
@ -370,13 +370,13 @@ module Redmine
|
|||
# render it background to find the max height used
|
||||
base_x = pdf.GetX
|
||||
base_y = pdf.GetY
|
||||
max_height = issues_to_pdf_write_cells(pdf, query.columns, col_width, row_height, true)
|
||||
max_height = issues_to_pdf_write_cells(pdf, query.inline_columns, col_width, row_height, true)
|
||||
pdf.Rect(base_x, base_y, table_width + col_id_width, max_height, 'FD');
|
||||
pdf.SetXY(base_x, base_y);
|
||||
|
||||
# write the cells on page
|
||||
pdf.RDMCell(col_id_width, row_height, "#", "T", 0, 'C', 1)
|
||||
issues_to_pdf_write_cells(pdf, query.columns, col_width, row_height, true)
|
||||
issues_to_pdf_write_cells(pdf, query.inline_columns, col_width, row_height, true)
|
||||
issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
|
||||
pdf.SetY(base_y + max_height);
|
||||
|
||||
|
@ -387,7 +387,7 @@ module Redmine
|
|||
|
||||
# Returns a PDF string of a list of issues
|
||||
def issues_to_pdf(issues, project, query)
|
||||
pdf = ITCPDF.new(current_language)
|
||||
pdf = ITCPDF.new(current_language, "L")
|
||||
title = query.new_record? ? l(:label_issue_plural) : query.name
|
||||
title = "#{project} - #{title}" if project
|
||||
pdf.SetTitle(title)
|
||||
|
@ -407,11 +407,17 @@ module Redmine
|
|||
# column widths
|
||||
table_width = page_width - right_margin - 10 # fixed left margin
|
||||
col_width = []
|
||||
unless query.columns.empty?
|
||||
unless query.inline_columns.empty?
|
||||
col_width = calc_col_width(issues, query, table_width - col_id_width, pdf)
|
||||
table_width = col_width.inject(0) {|s,v| s += v}
|
||||
end
|
||||
|
||||
# use full width if the description is displayed
|
||||
if table_width > 0 && query.has_column?(:description)
|
||||
col_width = col_width.map {|w| w = w * (page_width - right_margin - 10 - col_id_width) / table_width}
|
||||
table_width = col_width.inject(0) {|s,v| s += v}
|
||||
end
|
||||
|
||||
# title
|
||||
pdf.SetFontStyle('B',11)
|
||||
pdf.RDMCell(190,10, title)
|
||||
|
@ -454,6 +460,13 @@ module Redmine
|
|||
issues_to_pdf_write_cells(pdf, col_values, col_width, row_height)
|
||||
issues_to_pdf_draw_borders(pdf, base_x, base_y, base_y + max_height, col_id_width, col_width)
|
||||
pdf.SetY(base_y + max_height);
|
||||
|
||||
if query.has_column?(:description) && issue.description?
|
||||
pdf.SetX(10)
|
||||
pdf.SetAutoPageBreak(true, 20)
|
||||
pdf.RDMwriteHTMLCell(0, 5, 10, 0, issue.description.to_s, issue.attachments, "LRBT")
|
||||
pdf.SetAutoPageBreak(false)
|
||||
end
|
||||
end
|
||||
|
||||
if issues.size == Setting.issues_export_limit.to_i
|
||||
|
|
|
@ -149,6 +149,8 @@ tr.issue td.subject, tr.issue td.category, td.assigned_to, tr.issue td.string, t
|
|||
tr.issue td.subject, 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;}
|
||||
|
||||
tr.issue.idnt td.subject a {background: url(../images/bullet_arrow_right.png) no-repeat 0 50%; padding-left: 16px;}
|
||||
tr.issue.idnt-1 td.subject {padding-left: 0.5em;}
|
||||
|
|
|
@ -418,7 +418,7 @@ class IssuesControllerTest < ActionController::TestCase
|
|||
assert_equal 'text/csv; header=present', @response.content_type
|
||||
assert @response.body.starts_with?("#,")
|
||||
lines = @response.body.chomp.split("\n")
|
||||
assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
|
||||
assert_equal assigns(:query).available_inline_columns.size + 1, lines[0].split(',').size
|
||||
end
|
||||
|
||||
def test_index_csv_with_multi_column_field
|
||||
|
@ -825,6 +825,17 @@ class IssuesControllerTest < ActionController::TestCase
|
|||
assert_equal 'application/pdf', response.content_type
|
||||
end
|
||||
|
||||
def test_index_with_description_column
|
||||
get :index, :set_filter => 1, :c => %w(subject description)
|
||||
|
||||
assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject
|
||||
assert_select 'td.description[colspan=3]', :text => 'Unable to print recipes'
|
||||
|
||||
get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf'
|
||||
assert_response :success
|
||||
assert_equal 'application/pdf', response.content_type
|
||||
end
|
||||
|
||||
def test_index_send_html_if_query_is_invalid
|
||||
get :index, :f => ['start_date'], :op => {:start_date => '='}
|
||||
assert_equal 'text/html', @response.content_type
|
||||
|
|
|
@ -737,7 +737,9 @@ class QueryTest < ActiveSupport::TestCase
|
|||
|
||||
def test_default_columns
|
||||
q = Query.new
|
||||
assert !q.columns.empty?
|
||||
assert q.columns.any?
|
||||
assert q.inline_columns.any?
|
||||
assert q.block_columns.empty?
|
||||
end
|
||||
|
||||
def test_set_column_names
|
||||
|
@ -748,6 +750,21 @@ class QueryTest < ActiveSupport::TestCase
|
|||
assert q.has_column?(c)
|
||||
end
|
||||
|
||||
def test_inline_and_block_columns
|
||||
q = Query.new
|
||||
q.column_names = ['subject', 'description', 'tracker']
|
||||
|
||||
assert_equal [:subject, :tracker], q.inline_columns.map(&:name)
|
||||
assert_equal [:description], q.block_columns.map(&:name)
|
||||
end
|
||||
|
||||
def test_custom_field_columns_should_be_inline
|
||||
q = Query.new
|
||||
columns = q.available_columns.select {|column| column.is_a? QueryCustomFieldColumn}
|
||||
assert columns.any?
|
||||
assert_nil columns.detect {|column| !column.inline?}
|
||||
end
|
||||
|
||||
def test_query_should_preload_spent_hours
|
||||
q = Query.new(:name => '_', :column_names => [:subject, :spent_hours])
|
||||
assert q.has_column?(:spent_hours)
|
||||
|
|
Loading…
Reference in New Issue