Monkey patching WorkPackage model to have extra display properties.

This doesn't feel nice, but I really didn't want to put model specific methods inside the element classes. Tried to put this code in an initializer but it complains about acts_as_journalized, I'm guessing something to do with the ordering of the includes.
pull/6827/head
Richard 11 years ago
parent 349a938167
commit da9f03be30
  1. 7
      lib/open_project/pdf_export/export_card/document_generator.rb
  2. 5
      lib/open_project/pdf_export/export_card/model_display/work_package_display.rb

@ -36,6 +36,8 @@ module OpenProject::PdfExport::ExportCard
attr_reader :paper_height
def initialize(config, work_packages)
patch_models
defaults = { page_size: "A4" }
@config = config
@ -93,5 +95,10 @@ module OpenProject::PdfExport::ExportCard
end
end
end
def patch_models
# Note: Can't seem to patch the models when initializing for reasons which I don't understand
WorkPackage.send(:include, WorkPackageDisplay)
end
end
end

@ -0,0 +1,5 @@
module WorkPackageDisplay
def display_id
"#{(kind.is_standard) ? "" : "#{kind.name}"} ##{id}"
end
end
Loading…
Cancel
Save