Skip to content

Commit

Permalink
Merge pull request #24 from LeCreator/task/adjust-react-app
Browse files Browse the repository at this point in the history
Add changes and options for  manage export definition
  • Loading branch information
daniellienert authored Nov 30, 2021
2 parents ff6242b + fd66b00 commit 67fefc6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException;
use Neos\Utility\MediaTypes ;
use Neos\Flow\Annotations as Flow;
use PunktDe\Form\Persistence\Domain\ExportDefinition\ExportDefinitionInterface;

class ExcelExporter implements FormDataExporterInterface
class SpreadSheetExporter implements FormDataExporterInterface
{

/**
Expand All @@ -39,6 +42,7 @@ public function setOptions(array $options): FormDataExporterInterface
return $this;
}


/**
* @param iterable $formDataItems
* @return void
Expand All @@ -51,7 +55,7 @@ public function compileAndSend(iterable $formDataItems): void
header('Cache-Control: max-age=0');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false); // required for certain browsers
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Type: ' . MediaTypes::getMediaTypeFromFilename($this->fileName));
header(
sprintf(
'Content-Disposition: attachment; filename="%s"',
Expand All @@ -61,18 +65,19 @@ public function compileAndSend(iterable $formDataItems): void
);
header("Content-Transfer-Encoding: binary");

$writer = IOFactory::createWriter($this->compileXLS($formDataItems), 'Xlsx');
$writer = IOFactory::createWriter($this->compileXLS($formDataItems), $this->options['writerType']);
$writer->save('php://output');
exit;
}


/**
* @throws Exception
* @throws WriterException
*/
public function compileAndSave(iterable $formDataItems, string $filePath): void
{
$writer = IOFactory::createWriter($this->compileXLS($formDataItems), 'Xlsx');
$writer = IOFactory::createWriter($this->compileXLS($formDataItems), $this->options['writerType']);
$writer->save($filePath);
}

Expand All @@ -84,9 +89,9 @@ protected function compileXLS(iterable $formDataItems) :Spreadsheet
$spreadsheet = new Spreadsheet();

$spreadsheet->getProperties()
->setCreator('creator')
->setTitle('title')
->setSubject('subject');
->setCreator($this->options['creator']??'')
->setTitle($this->options['title']??'');

$headerColumns = array_keys($formDataItems[0]);
array_unshift($formDataItems ,$headerColumns );

Expand Down
11 changes: 7 additions & 4 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ PunktDe:
className: PunktDe\Form\Persistence\Domain\Exporter\CsvExporter
options: [ ]
xlsx:
className: PunktDe\Form\Persistence\Domain\Exporter\ExcelExporter #phpofficeexporter
options: [ ]
#Writertype:
className: PunktDe\Form\Persistence\Domain\Exporter\SpreadSheetExporter
options:
writerType: 'Xlsx'
title: ''
creator: ''


processorChain:
# Flatten nested fields into an array with namespaces
Expand All @@ -37,7 +40,7 @@ PunktDe:
fieldKeyMapping:
class: 'PunktDe\Form\Persistence\Domain\Processors\FieldKeyMappingProcessor'

# Convert form values to a an exportable representation. Eg. Uploaded data to its filename
# Convert form values to an exportable representation. Eg. Uploaded data to its filename
valueFormatting:
class: 'PunktDe\Form\Persistence\Domain\Processors\ValueFormattingProcessor'

Expand Down
6 changes: 3 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ After the successful installation run `./flow doctrine:migrate` to initialize th

## Exclude form types from saving

Some form types are only fro structuring the form or to display static text and should not be available for export. These form types can now be excluded using extendable configuration:
Some form types are only for structuring the form or to display static text and should not be available for export. These form types can now be excluded using extendable configuration:

```yaml
PunktDe:
Expand Down Expand Up @@ -136,8 +136,8 @@ To trigger the export, the command `formPersistence:sendExport` needs to be call

### Download form data

A simple backend module is provided to download the form data as CSV. The form version specifies the used fields and their position.
With that it is taken care, that if the form changes over time, a separate CSV file with consistent headers and column position is generated.
A simple backend module is provided to download the form data as multiple formats like CSV,Excel and Html here`s a list of possible formats https://phpspreadsheet.readthedocs.io/en/latest/. The form version specifies the used fields and their position.
With that it is taken care, that if the form changes over time, a separate CSV or Excel file with consistent headers and column position is generated.

![Backend Module](Documentation/BackendModule.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ prototype(PunktDe.Form.Persistence:Backend.ExportDefinition.Index) < prototype(N
exportDefinitionEditorApp = Neos.Fusion:ResourceUri {
path = 'resource://PunktDe.Form.Persistence/Public/ExportDefinitionEditorApp/build/static/js/main.js'
}
exporterTypes =${Json.stringify(Array.keys(Configuration.setting('PunktDe.Form.Persistence.exporter')))}


renderer = afx`

<div class="neos-content neos-container-fluid">
<div class="neos-module-container">
<div id="app" data-api-formdata={apiEndpoint.formData} data-api-exportdefinition={apiEndpoint.exportDefinition}></div>
<div id="app" data-api-formdata={apiEndpoint.formData} data-api-exportdefinition={apiEndpoint.exportDefinition} data-exporter-types={props.exporterTypes}></div>
</div>
<div class="neos-footer">
<a class="neos-button neos-button-primary" title="Export definitions" href={props.backToFormDataLink}>Back to Form data export</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const ExportDefinitionEditor = ({ reset, definitionIdentifier, apiFormData, apiE
label: item.exporter,
value: item.exporter
};
}), 'label') : [{ label: 'csv', value: 'csv' }],
}), 'label') : [{ label: 'csv', value: 'csv' }, { label: 'excel', value: 'excel' }],
lines: Object.keys(exportDefinitionData?.definition || {}).map((item, index) => {
return {
id: `id-${index}`,
Expand Down

0 comments on commit 67fefc6

Please sign in to comment.