Skip to content

Commit

Permalink
add export options
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien committed Oct 7, 2022
1 parent 9dc7872 commit 0eeeabe
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ public function render()
}
```

You can define two parameters to configure your export : orientation (portrait or landscape) and format (a4, a3, a2, ...)

Example :
```php
public function render()
{
return $this->twig("widget/pasta_widget.html.twig", [
"data" => $data,
"exportable" => [
"orientation" => "landscape",
"format" => "a3"
],
]);
}
```


## Widget configuration

Expand Down
6 changes: 6 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ function initializeExportWidget() {
if (event.target.classList.contains('lle-dashboard-widget-export')) {
const widget = document.getElementById(event.target.dataset.export);
const widgetTitle = event.target.dataset.exportName;
let orientation = event.target.dataset.exportOrientation ?? 'portrait';
let format = event.target.dataset.exportFormat ?? 'a4';

html2pdf()
.set({
Expand All @@ -269,6 +271,10 @@ function initializeExportWidget() {
},
html2canvas: {
scale: 2
},
jsPDF: {
orientation,
format
}
})
.from(widget)
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/public/dashboard/app.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/Resources/views/widget/includes/_buttons.html.twig
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{% block widget_export_button %}
{% if exportable is not defined or (exportable is defined and exportable) %}
{% if exportable is not defined or (exportable is defined and exportable != false) %}
<span
class="lle-dashboard-widget-export far fa-file show-hover"
data-export="widget_{{ widget.id }}"
data-export-name="{{ widget.title|default(widget.name|trans) }}"
{% if exportable is defined and exportable.orientation is defined %}data-export-orientation="{{ exportable.orientation }}"{% endif %}
{% if exportable is defined and exportable.format is defined %}data-export-format="{{ exportable.format }}"{% endif %}
title="{{ 'widget.pdf_export'|trans(domain='LleDashboardBundle') }}">
</span>
{% endif %}
Expand Down

0 comments on commit 0eeeabe

Please sign in to comment.