pruning empty rows before calculating row sizes.

pull/6827/head
Richard 11 years ago
parent bc2cafa68e
commit a1cf452aa7
  1. 12
      lib/open_project/pdf_export/taskboard_card/card_element.rb
  2. 17
      lib/open_project/pdf_export/taskboard_card/row_element.rb

@ -6,15 +6,15 @@ module OpenProject::PdfExport::TaskboardCard
@rows_config = rows_config
@work_package = work_package
@row_elements = []
@rows = @rows_config["rows"]
# Simpler to remove empty rows before calculating the row sizes
RowElement.prune_empty_rows(@rows, work_package)
# Initialize row elements
# TODO: It would be useful at this point to remove empty rows which do not need to be rendered if empty.
# This would fit better at column drawing time but by then it's too late because the heights have already
# been assigned.
heights = assign_row_heights
current_y_offset = 0
@rows_config["rows"].each_with_index do |(key, value), i|
@rows.each_with_index do |(key, value), i|
current_y_offset += heights[i - 1] if i > 0
row_orientation = {
y_offset: @orientation[:height] - current_y_offset,
@ -30,7 +30,7 @@ module OpenProject::PdfExport::TaskboardCard
def assign_row_heights
# Assign initial heights
available = @orientation[:height]
c = @rows_config["rows"].count
c = @rows.count
assigned_heights = Array.new(c){available/c}
min_heights = min_row_heights(c)

@ -10,7 +10,7 @@ module OpenProject::PdfExport::TaskboardCard
# Initialise column elements
x_offset = 0
columns_config.each_with_index do |key, value|
columns_config.each do |key, value|
width = col_width(value)
column_orientation = @orientation.clone
column_orientation[:x_offset] = x_offset
@ -36,5 +36,20 @@ module OpenProject::PdfExport::TaskboardCard
c.draw
end
end
def self.prune_empty_rows(rows, wp)
rows.each_with_index do |(rk, rv), i|
ck, cv = rv["columns"].first
if is_empty_column(ck, cv, wp)
rows.delete(rk)
end
end
end
def self.is_empty_column(property_name, column, wp)
value = wp.send(property_name) if wp.respond_to?(property_name) else ""
value = value.to_s if !value.is_a?(String)
!column["render_if_empty"] && value.empty?
end
end
end
Loading…
Cancel
Save