Setup an open project plugin. Copy pasted over some of the code from the backlogs plugin to get a minimum pdf being rendered with prawn. Rigged it up to read in the config from new taskbord_card_configuration model. Just now only the page_size property is being used. This is a basic implementation of ticket 3501.
parent
e7448a4301
commit
6c228762ee
@ -0,0 +1,3 @@ |
||||
# Changelog |
||||
|
||||
* `#<ticket number>` Create plugin |
@ -1,4 +1,7 @@ |
||||
openproject-pdf_export |
||||
====================== |
||||
# OpenProject Pdf Export Plugin |
||||
|
||||
Exports work packages to PDF |
||||
FIXME Add description and check issue tracker link below |
||||
|
||||
## Issue Tracker |
||||
|
||||
https://www.openproject.org/projects/pdf-export/issues |
||||
|
@ -0,0 +1,15 @@ |
||||
|
||||
class PdfExportBaseController < ApplicationController |
||||
before_filter :load_default_config |
||||
before_filter :load_project |
||||
|
||||
def load_default_config |
||||
@default_config = TaskboardCardConfiguration.first |
||||
end |
||||
|
||||
def load_project |
||||
if params[:project_id] |
||||
@project = Project.find(params[:project_id]) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,5 @@ |
||||
|
||||
class PdfExportController < PdfExportBaseController |
||||
def index |
||||
end |
||||
end |
@ -0,0 +1,13 @@ |
||||
|
||||
class TaskboardCardsController < PdfExportBaseController |
||||
include OpenProject::PdfExport::TaskboardCard |
||||
|
||||
def index |
||||
work_packages = @project.work_packages |
||||
document = OpenProject::PdfExport::TaskboardCard::DocumentGenerator.new(@default_config, work_packages) |
||||
|
||||
respond_to do |format| |
||||
format.pdf { send_data(document.render, :disposition => 'attachment', :type => 'application/pdf') } |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,9 @@ |
||||
|
||||
class TaskboardCardConfiguration < ActiveRecord::Base |
||||
#Note: rows is YAML text which we'll parse into a hash |
||||
attr_accessible :identifier, :name, :rows, :per_page, :page_size |
||||
|
||||
def rows_hash |
||||
YAML::parse(rows) |
||||
end |
||||
end |
@ -0,0 +1,5 @@ |
||||
<div class='contextual'></div> |
||||
<h2> |
||||
Pdf Export Test |
||||
</h2> |
||||
<%= link_to @default_config.name, "taskboard_cards.pdf" %> |
@ -0,0 +1,11 @@ |
||||
|
||||
OpenProject::Application.routes.draw do |
||||
|
||||
scope "", as: "pdf_export" do |
||||
scope "projects/:project_id", as: 'project' do |
||||
resources :pdf_export, :controller => :pdf_export, :only => [:index, :show] |
||||
resources :taskboard_cards, :controller => :taskboard_cards, :only => [:index] |
||||
end |
||||
end |
||||
|
||||
end |
@ -0,0 +1,11 @@ |
||||
class CreateTaskboardCardConfiguration < ActiveRecord::Migration |
||||
def change |
||||
create_table :taskboard_card_configurations do |t| |
||||
t.string :identifier |
||||
t.string :name |
||||
t.text :rows |
||||
t.integer :per_page |
||||
t.string :page_size |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,15 @@ |
||||
class InsertDefaultTaskboardCardConfiguration < ActiveRecord::Migration |
||||
def up |
||||
TaskboardCardConfiguration.create!({ |
||||
identifier: "DEFAULT", |
||||
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\"" |
||||
}) |
||||
end |
||||
|
||||
def down |
||||
TaskboardCardConfiguration.delete_all |
||||
end |
||||
end |
@ -0,0 +1,5 @@ |
||||
module OpenProject |
||||
module PdfExport |
||||
require "open_project/pdf_export/engine" |
||||
end |
||||
end |
@ -0,0 +1,60 @@ |
||||
require 'prawn' |
||||
|
||||
module OpenProject::PdfExport::TaskboardCard |
||||
class DocumentGenerator |
||||
attr_reader :config |
||||
attr_reader :work_packages |
||||
attr_reader :pdf |
||||
|
||||
def initialize(config, work_packages) |
||||
@config = config |
||||
@work_packages = work_packages |
||||
|
||||
page_layout = :landscape |
||||
@pdf = Prawn::Document.new( |
||||
:page_layout => page_layout, |
||||
:left_margin => 0, |
||||
:right_margin => 0, |
||||
:top_margin => 0, |
||||
:bottom_margin => 0, |
||||
:page_size => config["page_size"]) |
||||
end |
||||
|
||||
def render |
||||
# TODO RS: Define pdf page defaults, sizes, borders etc... |
||||
# pdf.start_new_page |
||||
render_rows |
||||
|
||||
pdf.render |
||||
end |
||||
|
||||
def render_rows |
||||
# 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}) |
||||
|
||||
# TODO RS: Iterate over each row and render whatever specified |
||||
# work_packages.each_with_index do |wp, i| |
||||
# config.rows_hash.each do |key, value| |
||||
# render_row(wp, value) |
||||
# end |
||||
# end |
||||
end |
||||
|
||||
def render_row(work_package, row_hash) |
||||
row_hash.columns.each do |key, value| |
||||
render_column(value) |
||||
end |
||||
end |
||||
|
||||
def render_column(column_hash) |
||||
# Do actual pdf rendering |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,5 @@ |
||||
module OpenProject |
||||
module PdfExport |
||||
VERSION = "0.0.1" |
||||
end |
||||
end |
@ -0,0 +1 @@ |
||||
require 'open_project/pdf_export' |
@ -0,0 +1,20 @@ |
||||
# encoding: UTF-8 |
||||
$:.push File.expand_path("../lib", __FILE__) |
||||
|
||||
require 'open_project/pdf_export/version' |
||||
# Describe your gem and declare its dependencies: |
||||
Gem::Specification.new do |s| |
||||
s.name = "openproject-pdf_export" |
||||
s.version = OpenProject::PdfExport::VERSION |
||||
s.authors = "Finn GmbH" |
||||
s.email = "info@finn.de" |
||||
s.homepage = "https://www.openproject.org/projects/pdf-export" # TODO check this URL |
||||
s.summary = 'OpenProject Pdf Export' |
||||
s.description = "FIXME" |
||||
s.license = "FIXME" # e.g. "MIT" or "GPLv3" |
||||
|
||||
s.files = Dir["{app,config,db,lib}/**/*"] + %w(CHANGELOG.md README.md) |
||||
|
||||
s.add_dependency "rails", "~> 3.2.14" |
||||
s.add_dependency "openproject-plugins", "~> 1.0.5" |
||||
end |
Loading…
Reference in new issue