From 8201761e7732faa3933899653de5951dcbd6b27c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 6 Dec 2012 17:48:19 +0000 Subject: [PATCH] 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 --- app/helpers/issues_helper.rb | 13 ++++++---- app/helpers/queries_helper.rb | 10 ++++++++ app/models/query.rb | 25 +++++++++++++++++- app/views/issues/_list.html.erb | 13 +++++++--- app/views/issues/index.html.erb | 6 ++++- app/views/queries/_columns.html.erb | 4 +-- app/views/queries/_form.html.erb | 3 +++ lib/plugins/rfpdf/lib/tcpdf.rb | 9 ++++++- lib/redmine/export/pdf.rb | 31 ++++++++++++++++------- public/stylesheets/application.css | 2 ++ test/functional/issues_controller_test.rb | 13 +++++++++- test/unit/query_test.rb | 19 +++++++++++++- 12 files changed, 124 insertions(+), 24 deletions(-) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 7f70f6255..5073571f6 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -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 diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 6ea879a35..6b9c0962d 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -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 diff --git a/app/models/query.rb b/app/models/query.rb index 409095434..a4c9a53ed 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -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) diff --git a/app/views/issues/_list.html.erb b/app/views/issues/_list.html.erb index 0eda312ed..f3e8cae2c 100644 --- a/app/views/issues/_list.html.erb +++ b/app/views/issues/_list.html.erb @@ -10,7 +10,7 @@ :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}" %> <%= sort_header_tag('id', :caption => '#', :default_order => 'desc') %> - <% query.columns.each do |column| %> + <% query.inline_columns.each do |column| %> <%= column_header(column) %> <% end %> @@ -21,7 +21,7 @@ <% if @query.grouped? && (group = @query.group_by_column.value(issue)) != previous_group %> <% reset_cycle %> - +   <%= group.blank? ? l(:label_none) : column_content(@query.group_by_column, issue) %> <%= @issue_count_by_group[group] %> <%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}", @@ -33,8 +33,15 @@ "> <%= check_box_tag("ids[]", issue.id, false, :id => nil) %> <%= link_to issue.id, issue_path(issue) %> - <%= raw query.columns.map {|column| "#{column_content(column, issue)}"}.join %> + <%= raw query.inline_columns.map {|column| "#{column_content(column, issue)}"}.join %> + <% @query.block_columns.each do |column| + if (text = column_content(column, issue)) && text.present? -%> + + <%= text %> + + <% end -%> + <% end -%> <% end -%> diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index d7679d65a..864c7d554 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -34,6 +34,10 @@ @query.group_by) ) %> + + <%= l(:button_show) %> + <%= available_block_columns_tags(@query) %> + @@ -73,7 +77,7 @@

- +

<%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %> diff --git a/app/views/queries/_columns.html.erb b/app/views/queries/_columns.html.erb index 5e665fd75..78d3c5703 100644 --- a/app/views/queries/_columns.html.erb +++ b/app/views/queries/_columns.html.erb @@ -4,7 +4,7 @@ <%= label_tag "available_columns", l(:description_available_columns) %>
<%= 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);" %> @@ -18,7 +18,7 @@ <%= label_tag "selected_columns", l(:description_selected_columns) %>
<%= 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);") %> diff --git a/app/views/queries/_form.html.erb b/app/views/queries/_form.html.erb index 0e75d9418..32f6aab27 100644 --- a/app/views/queries/_form.html.erb +++ b/app/views/queries/_form.html.erb @@ -21,6 +21,9 @@

<%= select 'query', 'group_by', @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, :include_blank => true %>

+ +

+<%= available_block_columns_tags(@query) %>

<%= l(:label_filter_plural) %> diff --git a/lib/plugins/rfpdf/lib/tcpdf.rb b/lib/plugins/rfpdf/lib/tcpdf.rb index 5c15b1aa7..62d07cd03 100755 --- a/lib/plugins/rfpdf/lib/tcpdf.rb +++ b/lib/plugins/rfpdf/lib/tcpdf.rb @@ -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; diff --git a/lib/redmine/export/pdf.rb b/lib/redmine/export/pdf.rb index cd1f33a2d..0000ddeba 100644 --- a/lib/redmine/export/pdf.rb +++ b/lib/redmine/export/pdf.rb @@ -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 diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 9a8c2ed7a..20e49f9c3 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -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;} diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 4a69019a9..e0d11d7ef 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -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 diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index c6f506347..6b1dda1e0 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -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)