From 55330d0fce5cc627e93f95ecdccd1f58d9e8c034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20Cuculi=C4=87?= Date: Tue, 11 Jun 2024 17:29:45 +0200 Subject: [PATCH] Tests ExportModel with custom format options --- controllers/Locations.php | 4 +++- controllers/locations/_list_toolbar.htm | 5 ++++ .../locations/config_import_export.yaml | 18 ++++++++++++++ controllers/locations/export.htm | 24 +++++++++++++++++++ models/LocationExport.php | 17 +++++++++++++ models/locationexport/columns.yaml | 9 +++++++ 6 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 controllers/locations/config_import_export.yaml create mode 100644 controllers/locations/export.htm create mode 100644 models/LocationExport.php create mode 100644 models/locationexport/columns.yaml diff --git a/controllers/Locations.php b/controllers/Locations.php index 1391aed..859e4bf 100644 --- a/controllers/Locations.php +++ b/controllers/Locations.php @@ -11,12 +11,14 @@ class Locations extends Controller public $implement = [ \Backend\Behaviors\FormController::class, \Backend\Behaviors\ListController::class, - \Backend\Behaviors\RelationController::class + \Backend\Behaviors\RelationController::class, + \Backend\Behaviors\ImportExportController::class, ]; public $formConfig = 'config_form.yaml'; public $listConfig = 'config_list.yaml'; public $relationConfig = 'config_relation.yaml'; + public $importExportConfig = 'config_import_export.yaml'; public function __construct() { diff --git a/controllers/locations/_list_toolbar.htm b/controllers/locations/_list_toolbar.htm index 795722b..d16ab55 100644 --- a/controllers/locations/_list_toolbar.htm +++ b/controllers/locations/_list_toolbar.htm @@ -18,6 +18,11 @@ data-stripe-load-indicator> Delete selected + + Export Locations + diff --git a/controllers/locations/config_import_export.yaml b/controllers/locations/config_import_export.yaml new file mode 100644 index 0000000..be2fe43 --- /dev/null +++ b/controllers/locations/config_import_export.yaml @@ -0,0 +1,18 @@ +# =================================== +# Import/Export Behavior Config +# =================================== + +export: + #useList: false + fileName: locations.csv + title: 'Export Locations' + modelClass: October\Test\Models\LocationExport + list: $/october/test/models/locationexport/columns.yaml + redirect: october/test/locations + +defaultFormatOptions: + fileFormat: csv_custom + delimiter: ',' + enclosure: '"' + escape: '\' + encoding: 'utf-8' diff --git a/controllers/locations/export.htm b/controllers/locations/export.htm new file mode 100644 index 0000000..8171508 --- /dev/null +++ b/controllers/locations/export.htm @@ -0,0 +1,24 @@ + + + + + 'layout mw-750']); ?> +
+ exportRender(); ?> +
+
+
+ +
+
+ diff --git a/models/LocationExport.php b/models/LocationExport.php new file mode 100644 index 0000000..13e96c2 --- /dev/null +++ b/models/LocationExport.php @@ -0,0 +1,17 @@ +each(function($location) use ($columns) { + $location->addVisible($columns); + }); + + return $locations->toArray(); + } +} diff --git a/models/locationexport/columns.yaml b/models/locationexport/columns.yaml new file mode 100644 index 0000000..e5b7f1a --- /dev/null +++ b/models/locationexport/columns.yaml @@ -0,0 +1,9 @@ +# =================================== +# List Column Definitions +# =================================== + +columns: + is_enabled: Enabled + name: Address + city_name: City + country_name: Country