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

Report Generation #20

Closed
p-a-s-c-a-l opened this issue Sep 10, 2018 · 18 comments
Closed

Report Generation #20

p-a-s-c-a-l opened this issue Sep 10, 2018 · 18 comments
Assignees
Labels
BB: Report Generation Report Generation Building Block enhancement New feature or request SHOWSTOPPER Feature or bug, that, if not addressed, renders the CSIS essentially useless

Comments

@p-a-s-c-a-l
Copy link
Member

p-a-s-c-a-l commented Sep 10, 2018

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".

@p-a-s-c-a-l p-a-s-c-a-l added the enhancement New feature or request label Sep 10, 2018
@p-a-s-c-a-l p-a-s-c-a-l added this to the CSIS Bootstrapping milestone Sep 10, 2018
@p-a-s-c-a-l p-a-s-c-a-l changed the title Report Genration Report Generation Sep 10, 2018
@fgeyer16
Copy link

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
Copy link
Contributor

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
Copy link
Member Author

@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:

  • define a structure for report content at the level of Gl-Step and Study Group Type. For static content, we could introduce an additional boolean flag includeInReport.
  • Add the "Include in report" buttons to each GL-Step page to flag "static" content (e.g. data package resource descriptions, taxonomy terms like GL-Step description, ...) for inclusion in the report
  • Add the "Include in report" buttons for "dynamic" content (like tables and maps) that are embedded as external apps and that display content that is not available in the Drupal Backend (e.g. displayed maps layers are obtained from external WMS).
    • for CSIS v2: add the "Include in report" button in each embedded React/iFrame Apps (e.g. Scenario Analysis separately. These components will have to use the JSON API to patch their report content into the GL-Step entity. ()
    • for CSIS v1: extend ReactMount and iFrame Content Types by an "Include in report" button that uses html2canvas to create a screenshot of the whole embedded app (e.g. map with all layers as shown on the screen) and stores it in the GL-Step.
  • create views for the different summary pages that contain the report-related properties (like the screenshots of the apps) of the Gl-Step. This corresponds to the summary tabs on the level of the distinct steps, e.g. Analyse Vulnerability Summary
  • create a view for the complete study that aggregates the different step views. Question: Does this correspond to Study Summary tab or do we need another top-level "Report" tab?
  • add PDF Export functionality as discussed here

@fgeyer16
Copy link

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
Copy link
Member Author

p-a-s-c-a-l commented Feb 22, 2019

@fgeyer16

Thanks! Some minor issues:

  • Report Images are shown in the GL-Step View, e.g. here fixed
  • Report Images in summary are not visible for demo user

grafik

@p-a-s-c-a-l
Copy link
Member Author

@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
Copy link
Member Author

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
Copy link
Contributor

@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
Copy link
Member Author

@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
Copy link
Contributor

@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
Copy link

@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
Copy link
Member Author

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

@patrickkaleta
Copy link
Contributor

@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:

  • composer require h4cc/wkhtmltopdf-amd64
  • composer require mikehaertl/phpwkhtmltopdf

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
Copy link
Member Author

@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
Copy link
Member Author

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

grafik

@p-a-s-c-a-l
Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Member Author

Basic Report Generation Functionality implemented.

T4.5 Scenario Analysis, Decision Support and Report Generation automation moved this from In progress to Done Jul 1, 2019
@p-a-s-c-a-l p-a-s-c-a-l added this to Backlog: High Priority in T1.3 Climate Services Co-creation via automation Oct 28, 2019
@p-a-s-c-a-l p-a-s-c-a-l moved this from Backlog: High Priority to Done in T1.3 Climate Services Co-creation Oct 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BB: Report Generation Report Generation Building Block enhancement New feature or request SHOWSTOPPER Feature or bug, that, if not addressed, renders the CSIS essentially useless
Projects
No open projects
Development

No branches or pull requests

4 participants