Altered config so that property id is column name.

pull/6827/head
Richard 11 years ago
parent fb87caa903
commit 35cf6fad26
  1. 2
      app/models/taskboard_card_configuration.rb
  2. 2
      db/migrate/20140113141913_insert_default_taskboard_card_configuration.rb
  3. 79
      lib/open_project/pdf_export/taskboard_card/document_generator.rb

@ -4,6 +4,6 @@ class TaskboardCardConfiguration < ActiveRecord::Base
attr_accessible :identifier, :name, :rows, :per_page, :page_size
def rows_hash
YAML::parse(rows)
YAML::load(rows)
end
end

@ -5,7 +5,7 @@ class InsertDefaultTaskboardCardConfiguration < ActiveRecord::Migration
name: "Default",
per_page: 1,
page_size: "A4",
rows: "rows:\n row1:\n has_border: false\n columns:\n column1:\n has_label: false\n property: \"id\"\n font_size: \"15\""
rows: "rows:\n row1:\n has_border: false\n columns:\n id:\n has_label: false\n font_size: \"15\""
})
end

@ -5,6 +5,7 @@ module OpenProject::PdfExport::TaskboardCard
attr_reader :config
attr_reader :work_packages
attr_reader :pdf
attr_reader :current_position
def initialize(config, work_packages)
defaults = { page_size: "A4" }
@ -27,38 +28,80 @@ module OpenProject::PdfExport::TaskboardCard
def render
# TODO RS: Define pdf page defaults, sizes, borders etc...
# pdf.start_new_page
render_rows
render_cards
pdf.render
end
def render_rows
def render_cards
# TESTING: RENDER FIRST WORK PACKAGE
wp = work_packages.first
work_package_identification = "#{wp.type.name} ##{wp.id}"
offset = [0, pdf.bounds.height]
box = pdf.text_box(work_package_identification,
{:height => 20,
:at => offset,
:size => 20,
:padding_bottom => 5})
render_rows(work_packages.first)
# TODO RS: Iterate over each row and render whatever specified
# TODO: Removed for testing convenience
# Iterate over all work packages
# work_packages.each_with_index do |wp, i|
# config.rows_hash.each do |key, value|
# render_row(wp, value)
# end
# render_rows wp
# end
end
def render_rows(work_package)
@current_position = {
y_offset: pdf.bounds.height,
x_offset: 0
}
config.rows_hash["rows"].each do |key, value|
render_row(work_package, value)
adjust_current_position(value)
end
end
def render_row(work_package, row_hash)
row_hash.columns.each do |key, value|
render_column(value)
row_hash["columns"].each do |key, value|
render_column(work_package, key, value)
end
end
def render_column(column_hash)
# Do actual pdf rendering
def render_column(work_package, property_name, column_hash)
column = ColumnElement.new(pdf, work_package, property_name, column_hash)
column.draw(current_position)
end
def adjust_current_position(row_config)
# The current position needs to be manipulated based on the minimun lines, font size and
# priority of the column. This will need to take into consideration all of the rows at once
# to decide on which ones get prioritised, and so will need something a lot more clever
# than just adjusting it inline like this.
current_position[:y_offset] -= (pdf.bounds.height * 0.05)
end
end
class ColumnElement
def initialize(pdf, work_package, property_name, config)
@pdf = pdf
@work_package = work_package
@property_name = property_name
@config = config
end
def draw(position)
# Get value from model
has_label = @config['has_label']
value = @work_package.send(@property_name) if @work_package.respond_to?(@property_name)
value = value.to_s
text = ""
text = text + "#{@property_name}:- " if has_label
text = text + value
# Draw on pdf
offset = [0, position[:y_offset]]
box = @pdf.text_box(text,
{:height => 20,
:at => offset,
:size => 20,
:padding_bottom => 5})
end
end
end
Loading…
Cancel
Save