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

Use browser's native printing dialog when exporting summaries to PDF #3998

Merged
merged 1 commit into from
Jun 11, 2018

Conversation

skateman
Copy link
Member

@skateman skateman commented May 28, 2018

Our current implementation of exporting to PDF does not support JavaScript execution, i.e. all the Angular/React components are not visible. As I converted the quadicons and @martinpovolny did the same with textual summaries it is necessary to do something about it. So here are the options I've found:

  • Rendering the components on the server-side (headless browser or just some NodeJS magic) would require major changes on the appliance and it would consume a lot of resources.

  • Rendering the components on the client-side and passing it to the server would be the easiest to do, but it might expose us to some new security issues. We can't assume that the components are all rendered on the given page where the user clicks on the Export to PDF button. Also the new components don't have support for inline base64 encoded images .

  • Rendering the components on the client-side and using the browser's native PDF printing feature seemed pretty easy. There are some CSS features that aren't fully supported (headers/footers) by the browser, but if they aren't really necessary, this solution is to simplest to implement.

I looked into all of these and chose the last one to be implemented. The existing PDF exporting buttons are now opening a new window and return a HTML with a reduced set of assets and a piece of JavaScript code that's responsible for opening the printing dialog and closing the window after the printing is finished/cancelled.

Instead of the header on each page I added a <h1> with the entity name and the creation date that was in the footer is now on the bottom of the summary.

However, this solution is not ideal, we are appending a lot of custom styling to the page that's maintained by us and it's highly unstable. IMO these stylings should be included in patternfly somehow as @media @print rules. /cc @LHinson

RFE BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1588072
Related issue: #4113

@miq-bot add_reviewer @martinpovolny
@miq-bot add_reviewer @epwinchell
@miq-bot add_label gaprindashvili/no, enhancement

@miq-bot
Copy link
Member

miq-bot commented May 29, 2018

This pull request is not mergeable. Please rebase and repush.

@skateman skateman force-pushed the pdf-summaries branch 2 times, most recently from e2ca0c8 to f46fd13 Compare May 29, 2018 08:42
@skateman skateman changed the title [WIP] Use browser's native printing dialog when exporting summaries to PDF Use browser's native printing dialog when exporting summaries to PDF May 29, 2018
@miq-bot miq-bot removed the wip label May 29, 2018
Copy link
Contributor

@epwinchell epwinchell left a comment

Choose a reason for hiding this comment

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

Tested. Looks good

@martinpovolny
Copy link
Member

martinpovolny commented May 30, 2018

ping @dclarizio.

This is the approach that allows us not to use Prince for some printing. We can use it to gradularly replace the printing.

Also this allows us to enable printing in ManageIQ (not CF).

@skateman : I thing you should replace ApplicationHelper::Button::Pdf with ApplicationHelper::Button::Basic (actually with no value). To have the printing enabled w/o Prince installed.

@skateman
Copy link
Member Author

@martinpovolny in general I would like to replace the button's icon and text to be more descriptive. What do you think about a printer icon and the text Print or export to PDF?

@dclarizio dclarizio self-assigned this May 30, 2018
@dclarizio
Copy link

ping @dclarizio

I'll try to test this today to see how it "feels" :)

@dclarizio
Copy link

@skateman I tried to test this, but don't see the PDF download button on the summary screens:

image

Perhaps this is still using the check for Prince being installed (which I don't have) to decide whether or not to show the button? If so, need to remove that check, but only for the summary screen buttons as we will still use Prince for list view PDF downloads.

@skateman
Copy link
Member Author

skateman commented May 31, 2018

@dclarizio yup fixed, I also updated the icon and the tooltip to be more descriptive.
screenshot from 2018-05-31 14-22-42

@@ -29,11 +29,12 @@ class ApplicationHelper::Toolbar::DashboardSummaryToggleView < ApplicationHelper
button_group('summary_download', [
button(
:download_view,
'fa fa-file-pdf-o fa-lg',
N_('Download summary in PDF format'),
'fa fa-print fa-lg',
Copy link
Contributor

@epwinchell epwinchell May 31, 2018

Choose a reason for hiding this comment

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

@skateman Please change to "pficon pficon-print fa-lg"

Copy link
Member Author

Choose a reason for hiding this comment

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

@epwinchell fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

@skateman Thanks

@dclarizio
Copy link

Tested in FF and Chrome . . . works well, but in FF the window doesn't auto close and in Chrome you have to check the box to print background images. I think the Chrome setting should be documented.

@skateman please take a look at the codeclimate issue to see if it can be resolved, then we're ready to merge.

@dclarizio
Copy link

@martinpovolny can you review/approve?

@skateman skateman force-pushed the pdf-summaries branch 2 times, most recently from 25ceb26 to 35c0280 Compare June 6, 2018 15:17
@miq-bot
Copy link
Member

miq-bot commented Jun 8, 2018

Checked commit skateman@5303854 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
8 files checked, 1 offense detected

**

  • 💣 💥 🔥 🚒 - Linter/Haml - Linter::Haml STDERR:
warning: parser/current is loading parser/ruby23, which recognizes
warning: 2.3.6-compliant syntax, but you are running 2.3.3.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.

@martinpovolny martinpovolny merged commit 112735b into ManageIQ:master Jun 11, 2018
@martinpovolny martinpovolny added this to the Sprint 88 Ending Jun 18, 2018 milestone Jun 11, 2018
@skateman skateman deleted the pdf-summaries branch June 11, 2018 07:45
@himdel himdel mentioned this pull request Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants