Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF-export by work packages query (backend only) #12312

Merged
merged 71 commits into from
May 25, 2023

Conversation

as-op
Copy link
Contributor

@as-op as-op commented Mar 21, 2023

* overview table
* work package details

* batching removed (for now)
* attachments table removed, export inlined images in description instead
@lindenthal
Copy link
Member

Hi @as-op,

Thanks a lot for issuing this preview. Very helpful.
I just played around with it and I think I found out that the "Export with description" leads to an error as soon as one work package contains a description.

Best
Niels

@as-op
Copy link
Contributor Author

as-op commented Mar 22, 2023

Hi @lindenthal, wow you are fast. :D It is fixed now. Best, Andrej

as-op added 24 commits March 23, 2023 12:17
…nto the "non-dangling header before page break" check
@as-op as-op changed the title wip: pdf-export by work packages query WIP: pdf-export by work packages query May 17, 2023
@as-op as-op changed the title WIP: pdf-export by work packages query PDF-export by work packages query (backend only) May 23, 2023
@as-op as-op marked this pull request as ready for review May 23, 2023 08:19
Copy link
Contributor

@klaustopher klaustopher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, with inline comments, I am trying to follow https://github.com/erikthedeveloper/code-review-emoji-guide. So everything that is not a 🔧 does not require attention from my point of view.

Code is straight forward and does what it's supposed to. PDF looks nice and seems to follow the requirements written in the ticket (for the portions where it is supposed to).

Personally, I am not the hugest fan of splitting code into seperate modules that require to be included together. This feels like it is splitting code up to follow a metric like ClassLength or AbcSize, but by requiring a developer to keep 6 files in mind/open to figure out where each method is coming from. So there is some potential to refactor this. I left some inline ideas how this might be done in the future. FWIW in this PR we are mostly following the existing structure and just extending it. In the chat with @as-op, they mentioned that there will be future refactorings, i.e. the styles will be loaded from YAML Content out of the DB in the future. Maybe there is some potential to do a first refactoring and instead of loading the styles as a bunch of included methods, have a PDFExportStyle class, that can be instantiated with the DB Content, extracts the data and then the xxx_style methods will be replaced by accessing that object.

📌 Also, the whole code is untested. In the past we have used the pdf-reader gem to write RSpec tests, that open the generated PDF and at least check that certain content we are expecting is rendered correctly. Right now it feels like it's mostly tested by visual inspection.

✅ approve from my side

Gemfile Show resolved Hide resolved
app/models/work_package/pdf_export/common.rb Outdated Show resolved Hide resolved
begin
draw_node(root, pdf_root_options(@styles.page), true)
rescue StandardError => e
Rails.logger.error "Failed to draw markdown pdf: #{e}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ I guess this is for development only? Or is this the common error reporting behavior we are using? Write to the error log and then have the customer send us that log for investigation? Maybe a question to @ulferts or @oliverguenther

Copy link
Contributor Author

@as-op as-op May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really for development. My intention was to avoid that a PDF export with thousands of work packages would fail as whole if one description or long text field would somehow cause an error. E.g. when prawn can't fit a user inserted table on a page at all.
I should probably at least reduce the scope and catch Prawn::Errors::CannotFit only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up: I did reduce the scope.

Copy link
Member

@oliverguenther oliverguenther May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's a background job, ideally it would report that to the job status so it becomes visible to the user in here: https://github.com/opf/openproject/blob/dev/app/workers/exports/export_job.rb#L118

Maybe keep that in mind as an implementation ticket to ensure errors get reported to the export modal, so this can get merged.

app/models/work_package/pdf_export/overview_table.rb Outdated Show resolved Hide resolved
app/models/work_package/pdf_export/overview_table.rb Outdated Show resolved Hide resolved
@as-op
Copy link
Contributor Author

as-op commented May 24, 2023

📌 Also, the whole code is untested. In the past we have used the pdf-reader gem to write RSpec tests, that open the generated PDF and at least check that certain content we are expecting is rendered correctly. Right now it feels like it's mostly tested by visual inspection.

100% agreement. I'm not going to use the excuse that it was not tested before 😀, but the better explanation that pdf-reader tests are so dependent on the content structure - even for just text existence tests, so I wanted to wait until the specification settled.
For the used/shared code with md-to-pdf there are already tests.

@oliverguenther oliverguenther merged commit 831c35c into dev May 25, 2023
11 checks passed
@oliverguenther oliverguenther deleted the feature/46226-pdf-export-of-work-plans branch May 25, 2023 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants