|
| 1 | +# Render Sections Plugins |
| 2 | + |
| 3 | +This plugin allows you to create selectable sections to render to a PDF without rendering the whole report. |
| 4 | +It is possible to render multiple sections in one PDF and to render each section to a separate PDF. |
| 5 | + |
| 6 | +The plugin is closely related to the `renderfindings` plugin (it is based on the original code), but extends it to support choosing arbitrary parts of your report. |
| 7 | + |
| 8 | + |
| 9 | +## Configuration |
| 10 | + |
| 11 | +``` |
| 12 | +ENABLED_PLUGINS="rendersections" |
| 13 | +``` |
| 14 | + |
| 15 | +You will need to update your design to support this plugin, as it relies on the `data-sysreptor-rendersections` attribute and an accompanying `id`. |
| 16 | +This attribute takes one of the following values: |
| 17 | + |
| 18 | +* `choosable`: The element can be chosen to be included or excluded from the PDF |
| 19 | +* `related`: The element will only be included in the PDF, if one of the related sections is included. This is based on the attribute `data-sysreptor-rendersections-relatedids`, which takes a `,` separated list of section IDs. |
| 20 | + |
| 21 | +Compared to the `renderfindings` plugin, this works also on non-top-level elements and only affects elements with the attribute `data-sysreptor-rendersections`. |
| 22 | + |
| 23 | +How rendering works: |
| 24 | + |
| 25 | +* Select one or multiple sections to render |
| 26 | + * When getting the list of possible sections, the report HTML is fully rendered once and all items with the attribute `data-sysreptor-rendersections` and an `id` set are listed. |
| 27 | + * The name for each section that is used in the list can be overriden by setting the attribute `data-sysreptor-rendersections-name`. By default it is the element's `id`. |
| 28 | + * Since the report is fully rendered, you can also dynamically create elements with the attribute `data-sysreptor-rendersections` (e.g. on each of the findings, or on attachments). |
| 29 | +* Render the selected findings and all sections to HTML using the project's design |
| 30 | + * The entire report is rendered to HTML with all findings/sections (this is a difference to `renderfindings`, which only includes the selected findings and therefore might have issues with graphs and references that would not be included in the report). |
| 31 | + * The variable `data.isPluginRenderFindings` is set to `true`. Use this variable to customize rendering. (This attribute name is kept for backwards compatibility) |
| 32 | +* Remove non-selected sections from the HTML |
| 33 | + * Get all elements containing `data-sysreptor-rendersections`. |
| 34 | + * Remove all of these elements whose `id` is not in the list of selected sections and where there are no related findings included. |
| 35 | +* Render post-processed HTML to PDF |
| 36 | + |
| 37 | + |
| 38 | +## Limitations |
| 39 | +* Different counter values than in the full report e.g. heading numbers, figures, tables, pages, etc. |
| 40 | + |
| 41 | + |
| 42 | +## Examples |
| 43 | + |
| 44 | +### Make Findings Choosable |
| 45 | +```html |
| 46 | +<section> |
| 47 | + <h1>Finding List</h1> |
| 48 | + <div v-for="finding in findings" |
| 49 | + :id="finding.id" |
| 50 | + data-sysreptor-rendersections="choosable" |
| 51 | + :data-sysreptor-rendersections-name="finding.title" |
| 52 | + > |
| 53 | + |
| 54 | + <h2>{{ finding.title }}</h2> |
| 55 | + ... |
| 56 | + </div> |
| 57 | +</section> |
| 58 | +``` |
| 59 | + |
| 60 | +### Related Sections |
| 61 | +```html |
| 62 | +<section> |
| 63 | + <h1>Finding List</h1> |
| 64 | + <div v-for="finding in findings" |
| 65 | + :id="finding.id" |
| 66 | + data-sysreptor-rendersections="choosable" |
| 67 | + :data-sysreptor-rendersections-name="finding.title" |
| 68 | + > |
| 69 | + |
| 70 | + <h2>{{ finding.title }}</h2> |
| 71 | + ... |
| 72 | + </div> |
| 73 | +</section> |
| 74 | + |
| 75 | +<!-- When using "related" then you don't need to set an id on the element itself, and since it's not shown as selectable in the list, a name is also not necessary --> |
| 76 | +<section |
| 77 | + data-sysreptor-rendersections="related" |
| 78 | + :data-sysreptor-rendersections-relatedids="findings.map(x => x.id).join(',')" |
| 79 | +> |
| 80 | + <h1>Finding Related</h1> |
| 81 | + ... |
| 82 | +</section> |
| 83 | +``` |
0 commit comments