clarity-h2020 / docker-drupal

Drupal 8 Project for implememting the CLARTIY CSIS Platform.
https://csis.myclimateservice.eu
GNU Lesser General Public License v3.0
3 stars 0 forks source link

Report Generation #20

Closed p-a-s-c-a-l closed 5 years ago

p-a-s-c-a-l commented 6 years ago

Generate PDFs out of a Drupal Page either using a special Drupal Module (if available) or use some external libraries like Jasper Reports and fetch the study data from the REST API.

Important: All information needed to generate a report should reside in the Group Type "Study".

fgeyer16 commented 6 years ago

There are three modules for Drupal 8 which allow creating pdf from content:

  1. Entity print
  2. Printable
  3. PrinterFriendly From a first view I think 1 or 3 are more flexible than 2 so that we can create nice reports. For the definitive decision we will have to wait until the Study design in Drupal is fixed
patrickkaleta commented 6 years ago

I had a look at those three modules @fgeyer16 suggested:

  1. Entity print:

    • supports multiple PDF engines (worked best with tecnickcom/tcpdf)
    • works with Views
    • doesn't include the map component, so we would have to take a screenshot of that and include in the View
  2. Printable:

    • doesn't work with Views, supposed to work with all Content types and Groups, but the "generate-pdf button" doesn't appear for every content type. No documentation available, so no idea how to fix this
  3. Printfriendly:

    • only Pro version (40$/year) promises to work with dynamic content (Angular/React)
    • Drupal module only works for content types (no Groups or Views!) on two display modes (Teaser & Full page)

I would suggest using Entity print and include all dynamic content (like the map compoment) as screenshots. Alternatively I will have a look at athenapdf (https://github.com/arachnys/athenapdf), which is a pdf service that should work as a Docker image.

p-a-s-c-a-l commented 5 years ago

@patrickkaleta @fgeyer16

Report generation has now high priority as it's "show-stopper" feature for CSIS v1 and can be implemented even if no additional data (e.g. from impact calculation) is yet available.

Imho the following step are required:

fgeyer16 commented 5 years ago

I added fields to the summary view mode of GL-Step and Study group. So for now all Content of type "Report Image" which is related to a Step or a Study is shown on the Summary tabs. The content type "Report Image" has for now two types: Maps and tables and is the content which will be generated by the "include in report Button" ( #46 ). The images will be sorted by maps and Table in on the summary tab. The comment to an image can be added/edited on the summary tab.

p-a-s-c-a-l commented 5 years ago

@fgeyer16

Thanks! Some minor issues:

grafik

p-a-s-c-a-l commented 5 years ago

@fgeyer16 EVA: Report summary Images - EVA Study summary What is it supposed to show? A 'final' report including the information from all steps? The view aggregates the GL-steps, right? But only the introduction (taxonomy) is shown. Anyway, the summary Tab of the Study is not the reight place for the final report, see 2)

What we still need is 1) 'Include in Report Button'. It seems that there is 'something' available in the csis_helper_module, but without further information, I cannot proceed. 2) A 'final' report that includes the general study report (context + data package + map) plus all GL-Step report. This tab should probably be shown after the 'last EU-GL Step" 3) A possibility to print the final report

p-a-s-c-a-l commented 5 years ago

I've installed entity print, but the result is not what I've expected.

That's the Assess Risk & Impact Summary Page including report images from MCDA:

grafik

And that's what entity print generates:

grafik

I've set permission on almost any entities rendered in the summary view (e.g. EU-GL: Use all print engines: Authenticated user) but that didn't help.

@patrickkaleta @fgeyer16

According to the module description no separate PDF Engine is required for Drupal 8. However the documentation says that Dompdf has to be installed (not clear if this required for Drupal 7 or 8) as opposed to the Module description which requires wkhtmltopdf for Drupal 7. I tried to install Dompdf, but it failed with the following error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: phenx/php-svg-lib[v0.3.2, v0.2].
    - Can only install one of: phenx/php-svg-lib[v0.2, v0.3.2].
    - Can only install one of: phenx/php-svg-lib[v0.2, v0.3.2].
    - dompdf/dompdf v0.8.0 requires phenx/php-svg-lib 0.2.* -> satisfiable by phenx/php-svg-lib[v0.2].
    - Installation request for dompdf/dompdf 0.8.0 -> satisfiable by dompdf/dompdf[v0.8.0].
    - Installation request for phenx/php-svg-lib (locked at v0.3.2) -> satisfiable by phenx/php-svg-lib[v0.3.2].

Installation failed, reverting ./composer.json to its original content.

But as PDF generation as such works, I'm not sure if using another (?) PDF engine would solve the problem.

patrickkaleta commented 5 years ago

@p-a-s-c-a-l regarding the "Include in Report Button" we first tried to solve this with a custom field "snapshot", which turned out to be too complex. So, instead we now have a token field (created via Display Suite), which creates the "Include in Report Button" and can be set on the display of any content type (currently done for the React mount with js).

In the csis-helpers Module that button could then trigger the generation of the screenshot and create a Report image entity via JSON:API + then link that created Report image to the corresponding Group (this is already done, since it wasn't much work).

It seems like you already managed to create the screenshot and post the Report image in your Scenario analysis app. I can now try to extract the necessary code from there and add it to the csis-helpers Module.

p-a-s-c-a-l commented 5 years ago

@patrickkaleta Thanks. The relevant JavaScript code for taking the screenshots is available here. However, I use the AngularJS framework and it's $http and $resource services. So this cannot be used 1:1 in 'plain' JavaScript. The general program flow is: 1) GET gl-step entity and extract report images array from relationships (this is necessary since PATCH does overwrite the complete array and does not add new entities) 2) POST new file (binary PNG) and get the uuid 3) POST new report_image from template assign file uuid from 2) to relationships and get uuid of report image entity 4) PATCH gl-step entity, sending as payload a simple template + the array retrieved in 1) with pushed report image uuid retrieved in 3)

Any idea what's wrong with the entity print module? I've tested it only in my local instance. I can make it available on CSIS.

patrickkaleta commented 5 years ago

@p-a-s-c-a-l thanks for the instructions!

Regarding the entity print module, I will have a look at it in my local instance as well (check which PDF engine works best) and talk to the guy responsible for setting up entity print in a different Drupal 8 project. On the CSIS module-page I can already see that the entity print module is available, it only needs to be installed (activated), so I don't think you need to do anything at the moment.

fgeyer16 commented 5 years ago

@p-a-s-c-a-l The difference between screen and pdf comes from Drupals view modes system. Entity print takes the default view mode while on screen the summary view mode is shown. How ever entity print provides a PDF view mode which has to be activated on Manage Display on the Dafault view mode:

Bildschirmfoto von »2019-03-14 20-12-14«

Then you can arrange the fields on the PDF view mode. To copy an existing view mode first set Layout for Gl-step to none Bildschirmfoto von »2019-03-14 20-16-29« and then clone the layout of the view mode Bildschirmfoto von »2019-03-14 20-19-58«

According to the module description no separate PDF Engine is required for Drupal 8. However the documentation says that Dompdf has to be installed (not clear if this required for Drupal 7 or 8)

I installed entity print on my localsystem and dompdf was installed automatically by composer with its dependencies without an error Bildschirmfoto von »2019-03-14 19-53-17«

I think composer was confused when you tried to install it a second time. From the log it looks like as if you (or composer) tried to get dompdf 0.8.0 while dompdf 0.8.3 was already installed So composer could not resolve dependencies.

p-a-s-c-a-l commented 5 years ago

Thanks, I'll give it a try. Regarding dompdf, you'r right, it's automatically installed. :-)

patrickkaleta commented 5 years ago

@p-a-s-c-a-l , @fgeyer16 I can confirm that dompdf is installed automatically, but for me that engine doesn't work. When trying to generate the pdf I get an error saying that it's unable to load the css and/or images (even though I can access the respective URLs via Browser).

Installing TCPDF (v1) via "composer require tecnickcom/tcpdf ~6" worked fine and a pdf is generated. But I noticed that it has some problems when the format of the images is set to "Responsive image". In that case no image is printed onto the pdf. Using "Image" as the format works. responsive-image-formatter


Installing PHP Wkhtmltopdf worked with Composer:

Binary location has to be set to "/app/vendor/bin/wkhtmltopdf-amd64". But after trying to fix other error messages regarding shared libraries libxrender.so.1 and libfontconfig.so.1, I only managed to successfully destroy my local instance of the CSIS :(

p-a-s-c-a-l commented 5 years ago

@fgeyer16 @patrickkaleta

I've created the PDF View for Assess Risk and Impact Summary and PDF creation works without the need to install additional modules:5.Assess.Risk.and.Impact.pdf

grafik

The PDF doesn't look very nice yet, but I think this can be improved by configuring additional PDF Views, e.g. for Taxonomy Terms and Report Images. There also a possibility to style PDF with custom CSS. BTW @DenoBeno what about the availability Alejandro for developing some CSS styles for the CSIS in general?

p-a-s-c-a-l commented 5 years ago

Display of Data Package could be improved in Study/Summary, the identifier shouldn't be shown so prominently. This is related to https://github.com/clarity-h2020/docker-drupal/issues/52#issuecomment-473805313

grafik

p-a-s-c-a-l commented 5 years ago

Minor Issue: Scenario Analysis Report images are only relevant in RA/IA step, so the report image category "scenario analysis" should not be should be shown in the other Summary Views. @fgeyer16 any idea how this could be easily resolved?

grafik

patrickkaleta commented 5 years ago

Display of Data Package could be improved in Study/Summary, the identifier shouldn't be shown so prominently. This is related to #52 (comment)

I altered the corresponding display to show the title and below that the identifier (in a less prominent way). study-summary-view

p-a-s-c-a-l commented 5 years ago

Basic Report Generation Functionality implemented.