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

feat: New Print Format Builder #14134

Merged
merged 43 commits into from Oct 25, 2021

Conversation

netchampfaris
Copy link
Contributor

@netchampfaris netchampfaris commented Sep 7, 2021

Refactor of Print Format Builder has been long overdue. This PR tries to fix the culmination of all the frustrations I have had with the current PFB.

Features

  • Better drag-n-drop implementation
  • Inline section and field labels editing
  • Intuitive table column editing
  • Custom page margins
  • Custom font
  • Page breaks after sections
  • Uses weasyprint as the PDF renderer

Why weasyprint?

wkhtmltopdf uses a really old version of WebKit which doesn't even support standard flexbox implementation. This is the primary reason why I decided to look for an alternative. wkhtmltopdf's status page basically says that there is no promise that it will be updated to the latest WebKit engine.

However, weasyprint does not only fix the flexbox problem, it implements standard W3C CSS specifications, which means there is a standard feature to add page numbers in a PDF rather than a JS hack. Not only this, there is whole bunch of standard CSS features that allow you to customize a PDF. This was an exciting discovery.

Demo

The new Print Format Builder works alongside the current one with a feature flag in the Print Format document. So it does not break existing formats and is opt-in for now.

Show GIF

new-print-format-builder-2

Installation

weasyprint is a pure python package but it depends on a few libraries. Follow the installation instructions at weasyprint installation page

For macOS users, simple run:

brew install pango libffi

ToDo

  • Fix print preview in form
  • Letterhead editing
  • Handle custom formats, for e.g., template for Sales Taxes and Charges

no-docs

- Print Format Builder Beta page
- Add margin fields in Print Format
- Using vuedraggable for drag and drop
- Show selection dialog if Print Format not selected
- Field component
- Common store
- Edit Field label inline
- Configure table columns
- Edit Custom HTML
- Preview
- /printpreview route to preview HTML template
- show "Not Saved" when dirty
- Toggle Preview only when format is saved
- save a new format on first load
@codecov
Copy link

codecov bot commented Sep 7, 2021

Codecov Report

Merging #14134 (c1053be) into develop (ff27f80) will increase coverage by 0.56%.
The diff coverage is 20.87%.

@@             Coverage Diff             @@
##           develop   #14134      +/-   ##
===========================================
+ Coverage    49.72%   50.28%   +0.56%     
===========================================
  Files          744      747       +3     
  Lines        65023    65367     +344     
  Branches      5435     5460      +25     
===========================================
+ Hits         32332    32872     +540     
+ Misses       28720    28603     -117     
+ Partials      3971     3892      -79     
Flag Coverage Δ
server 56.77% <19.66%> (-0.06%) ⬇️
ui-tests 38.34% <75.00%> (+1.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

- Letterhead editing
- Edit Header and Footer
- Margin Text
- PrintFormatGenerator class handles generation of HTML and PDF and repeating of Header/Footer
- Simplify /printpreview
- Separate renderer files for each fieldtype
@stale
Copy link

stale bot commented Sep 23, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed within 3 days if no further activity occurs, but it only takes a comment to keep a contribution alive :) Also, even if it is closed, you can always reopen the PR when you're ready. Thank you for contributing.

@stale stale bot added the inactive label Sep 23, 2021
@stale stale bot closed this Sep 26, 2021
- Image resize and align
@stale stale bot removed the inactive label Oct 4, 2021
@surajshetty3416
Copy link
Member

surajshetty3416 commented Oct 4, 2021

@netchampfaris What's the update on this? Is this ready for QA testing for basic/core functionalities?

@surajshetty3416 surajshetty3416 added the resolve-conflicts There seems to be conflict due to changes in current branch. Please resolve it to get your PR merged label Oct 6, 2021
Copy link
Member

@surajshetty3416 surajshetty3416 left a comment

Choose a reason for hiding this comment

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

@netchampfaris Nice enhancements overall 👍

Noticed a few things that can be fixed.

  • Screenshot 2021-10-21 at 6 43 32 PM
    These icons are confusing because in form view it signifies "Print" and "Refresh"… most people will not try to click on these for “Preview” and “Reset". Suggestion: Add text to the button

  • Screenshot 2021-10-21 at 6 42 54 PM
    Background color of controls are not the same

  • Screenshot 2021-10-21 at 6 40 55 PM
    This!!

  • Editing User New Print Format
    Changing these options should update the preview in real-time (at least for HTML preview). The preview feature shines while tweaking such variables. (We can skip this if this requires major changes or if there are performance concerns)

@surajshetty3416
Copy link
Member

surajshetty3416 commented Oct 21, 2021

Fair enough but I think we should add barebones docs. Test cases could be deferred but, I have a feeling there should be some basic ones for the weasyprint APIs at this stage. Although, if you don't see the need for them, idm as long as they get added in the near future 😛

Let's skip the documentation for now (to avoid docs for namesake). I have created a backlog to ensure the documentation and tests are added by next month.

@surajshetty3416
Copy link
Member

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Oct 22, 2021

update

✅ Branch has been successfully updated

@surajshetty3416
Copy link
Member

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Oct 22, 2021

update

✅ Branch has been successfully updated

- CSS variables in svg don't work in PDF
- styling is done via external css now to make it work in form as well as PDF
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants