pull/6827/head
parent
35cf6fad26
commit
8ede393ea4
@ -0,0 +1,43 @@ |
||||
module OpenProject::PdfExport::TaskboardCard |
||||
class CardElement |
||||
def initialize(pdf, orientation, rows_config, work_package) |
||||
@pdf = pdf |
||||
@orientation = orientation |
||||
@rows_config = rows_config |
||||
@work_package = work_package |
||||
@row_elements = [] |
||||
|
||||
# Initialize row elements |
||||
row_y_offset = 0 |
||||
rows_config["rows"].each do |key, value| |
||||
# TODO: Intelligently configure the orientation of row elements |
||||
row_orientation = { |
||||
y_offset: @orientation[:height] - row_y_offset, |
||||
x_offset: 0, |
||||
width: 400, # TODO: Calculate |
||||
height: 40 # TODO: Calculate |
||||
} |
||||
row_y_offset += 40 # TODO: Calculate from text size, lines, priority, whatever |
||||
|
||||
@row_elements << RowElement.new(@pdf, row_orientation, value["columns"], @work_package) |
||||
end |
||||
end |
||||
|
||||
def draw |
||||
top_left = [@orientation[:x_offset], @orientation[:y_offset]] |
||||
bounds = @orientation.slice(:width, :height) |
||||
|
||||
@pdf.bounding_box(top_left, bounds) do |
||||
@pdf.stroke_color 'FF0000' |
||||
|
||||
# Draw rows |
||||
@row_elements.each do |row| |
||||
row.draw |
||||
end |
||||
|
||||
@pdf.stroke_bounds |
||||
end |
||||
|
||||
end |
||||
end |
||||
end |
@ -0,0 +1,31 @@ |
||||
module OpenProject::PdfExport::TaskboardCard |
||||
class ColumnElement |
||||
def initialize(pdf, property_name, config, orientation, work_package) |
||||
@pdf = pdf |
||||
@property_name = property_name |
||||
@config = config |
||||
@orientation = orientation |
||||
@work_package = work_package |
||||
end |
||||
|
||||
def draw |
||||
# 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 = [@orientation[:x_offset], @orientation[:y_offset]] |
||||
box = @pdf.text_box(text, |
||||
{:height => 20, |
||||
:at => offset, |
||||
:size => 20, |
||||
:padding_bottom => 5}) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,25 @@ |
||||
module OpenProject::PdfExport::TaskboardCard |
||||
class RowElement |
||||
def initialize(pdf, orientation, columns_config, work_package) |
||||
@pdf = pdf |
||||
@orientation = orientation |
||||
@columns_config = columns_config |
||||
@work_package = work_package |
||||
@column_elements = [] |
||||
|
||||
# Initialise column elements |
||||
columns_config.each do |key, value| |
||||
# TODO: Intelligently configure the orientation of column elements |
||||
column_orientation = @orientation |
||||
@column_elements << ColumnElement.new(@pdf, key, value, column_orientation, @work_package) |
||||
end |
||||
end |
||||
|
||||
def draw |
||||
# Draw columns |
||||
@column_elements.each do |c| |
||||
c.draw |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue