Skip to content

Commit 43731ae

Browse files
committed
Add rendersections plugin
1 parent f5d6dc8 commit 43731ae

File tree

18 files changed

+658
-0
lines changed

18 files changed

+658
-0
lines changed

plugins/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
!projectnumber
1515
!webhooks
1616
!renderfindings
17+
!rendersections
1718
!excalidraw
1819
!markdownexport

plugins/package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/rendersections/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
static

plugins/rendersections/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
```

plugins/rendersections/__init__.py

Whitespace-only changes.

plugins/rendersections/apps.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from sysreptor.plugins import PluginConfig
2+
3+
4+
class RenderSectionsPluginConfig(PluginConfig):
5+
"""
6+
This plugin lets you choose sections of a PDF to render.
7+
You might need to update your design to propertly support and customize this plugin.
8+
For more information see the README.md file in the plugin's directory.
9+
"""
10+
11+
plugin_id = 'ebfbb193-c108-4b80-bd6a-a97a86ba9c8f'
12+
professional_only = True
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Nuxt dev/build outputs
2+
.output
3+
.data
4+
.nuxt
5+
.nitro
6+
.cache
7+
dist
8+
9+
# Node dependencies
10+
node_modules
11+
12+
# Logs
13+
logs
14+
*.log
15+
16+
# Misc
17+
.DS_Store
18+
.fleet
19+
.idea
20+
21+
# Local env files
22+
.env
23+
.env.*
24+
!.env.example
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @ts-check
2+
import withNuxt from './.nuxt/eslint.config.mjs'
3+
4+
export default withNuxt(
5+
// Your custom configs here
6+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
export default defineNuxtConfig({
3+
extends: [
4+
'@sysreptor/plugin-base-layer',
5+
],
6+
7+
appConfig: {
8+
pluginId: 'ebfbb193-c108-4b80-bd6a-a97a86ba9c8f',
9+
},
10+
11+
nitro: {
12+
output: {
13+
publicDir: '../static/'
14+
}
15+
},
16+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@sysreptor/plugin-rendersections-frontend",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "nuxt dev",
7+
"generate": "nuxt generate",
8+
"postinstall": "nuxt prepare"
9+
},
10+
"dependencies": {
11+
"@sysreptor/plugin-base-layer": "../../../packages/plugin-base-layer",
12+
"@sysreptor/nuxt-base-layer": "../../../packages/nuxt-base-layer",
13+
14+
"nuxt": "*",
15+
"vuetify": "*",
16+
"pinia": "*"
17+
},
18+
"overrides": {
19+
"vue": "latest"
20+
}
21+
}

0 commit comments

Comments
 (0)