Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/xlsx export #5038

Merged
merged 9 commits into from Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,6 +14,9 @@

namespace Pimcore\Bundle\AdminBundle\Controller\Admin\DataObject;

use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Bundle\AdminBundle\Helper\GridHelperService;
use Pimcore\Config;
Expand Down Expand Up @@ -1848,6 +1851,37 @@ public function downloadCsvFileAction(Request $request)
}
}

/**
* @Route("/download-xlsx-file", methods={"GET"})
*
* @param Request $request
*
* @return BinaryFileResponse
*/
public function downloadXlsxFileAction(Request $request)
{
$fileHandle = \Pimcore\File::getValidFilename($request->get('fileHandle'));
$csvFile = $this->getCsvFile($fileHandle);
if (file_exists($csvFile)) {
$csvReader = new Csv();
$csvReader->setDelimiter(';');
$csvReader->setEnclosure('""');
$csvReader->setSheetIndex(0);

$spreadsheet = $csvReader->load($csvFile);
$writer = new Xlsx($spreadsheet);
$xlsxFilename = PIMCORE_SYSTEM_TEMP_DIRECTORY. "/" .$fileHandle. ".xlsx";
$writer->save($xlsxFilename);

$response = new BinaryFileResponse($xlsxFilename);
$response->headers->set('Content-Type', 'application/xlsx');
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'export.xlsx');
$response->deleteFileAfterSend(true);

return $response;
}
}

/**
* @param $field
*
Expand Down
31 changes: 11 additions & 20 deletions bundles/AdminBundle/Resources/public/js/pimcore/helpers.js
Expand Up @@ -2573,7 +2573,6 @@ pimcore.helpers.requestNicePathData = function (source, targets, config, fieldCo
});
};


pimcore.helpers.getNicePathHandlerStore = function (store, config, gridView, responseData) {
config = config || {};
Ext.applyIf(config, {
Expand Down Expand Up @@ -2612,14 +2611,13 @@ pimcore.helpers.getNicePathHandlerStore = function (store, config, gridView, res
gridView.updateLayout();
};

pimcore.helpers.csvExportWarning = function (callback) {

pimcore.helpers.exportWarning = function (type, callback) {
var iconComponent = new Ext.Component({
cls: "x-message-box-warning x-dlg-icon"
});

var textContainer = Ext.Component({
html: t('csv_object_export_warning')
html: type.warningText
});

var promptContainer = new Ext.container.Container({
Expand Down Expand Up @@ -2656,31 +2654,23 @@ pimcore.helpers.csvExportWarning = function (callback) {
]
});

var delimiter = new Ext.form.TextField({
fieldLabel: t('delimiter'),
name: 'delimiter',
maxLength: 1,
labelWidth: 200,
value: ';'
});
var formPanelItems = [];
formPanelItems.push(objectSettingsContainer);

exportSettingsContainer = type.getExportSettingsContainer();

var csvSettingsContainer = new Ext.form.FieldSet({
title: t('csv_settings'),
items: [
delimiter
]
});
if(exportSettingsContainer) {
formPanelItems.push(exportSettingsContainer);
}

var formPanel = new Ext.form.FormPanel({
bodyStyle: 'padding:10px',
items: [objectSettingsContainer, csvSettingsContainer]
items: formPanelItems
});


var window = new Ext.Window({
modal: true,
title: t('export_csv'),
title: type.text,
width: 600,
height: 450,
bodyStyle: "padding: 10px;",
Expand All @@ -2703,6 +2693,7 @@ pimcore.helpers.csvExportWarning = function (callback) {
}
]
});

window.show();
};

Expand Down
Expand Up @@ -314,6 +314,25 @@ pimcore.object.search = Class.create(pimcore.object.helpers.gridTabAbstract, {
}
});

this.searchAndMoveButton = new Ext.Button({
text: t("search_and_move"),
iconCls: "pimcore_icon_search pimcore_icon_overlay_go",
handler: pimcore.helpers.searchAndMove.bind(this, this.object.id,
function () {
this.store.reload();
}.bind(this), "object")
});

var exportButtons = this.getExportButtons();
var firstButton = exportButtons.pop();

this.exportButton = new Ext.SplitButton({
text: firstButton.text,
iconCls: firstButton.iconCls,
handler: firstButton.handler,
menu: exportButtons,
});

var hideSaveColumnConfig = !fromConfig || save;

this.saveColumnConfigButton = new Ext.Button({
Expand Down Expand Up @@ -364,22 +383,14 @@ pimcore.object.search = Class.create(pimcore.object.helpers.gridTabAbstract, {
}
},
cls: 'pimcore_object_grid_panel',
tbar: [this.searchField, "-", this.languageInfo, "-", this.toolbarFilterInfo, this.clearFilterButton, "->", this.checkboxOnlyDirectChildren, "-", this.sqlEditor, this.sqlButton, "-", {
text: t("search_and_move"),
iconCls: "pimcore_icon_search pimcore_icon_overlay_go",
handler: pimcore.helpers.searchAndMove.bind(this, this.object.id,
function () {
this.store.reload();
}.bind(this), "object")
}, "-", {
text: t("export_csv"),
iconCls: "pimcore_icon_export",
handler: function () {
pimcore.helpers.csvExportWarning(function(settings) {
this.exportPrepare(settings);
}.bind(this));
}.bind(this)
}, "-",
tbar: [this.searchField, "-",
this.languageInfo, "-",
this.toolbarFilterInfo,
this.clearFilterButton, "->",
this.checkboxOnlyDirectChildren, "-",
this.sqlEditor, this.sqlButton, "-",
this.searchAndMoveButton, "-",
this.exportButton, "-",
this.columnConfigButton,
this.saveColumnConfigButton
]
Expand Down Expand Up @@ -436,6 +447,23 @@ pimcore.object.search = Class.create(pimcore.object.helpers.gridTabAbstract, {
}
},

getExportButtons: function () {
var buttons = [];
pimcore.globalmanager.get("pimcore.gridexport").forEach(function (exportType) {
buttons.push({
text: t(exportType.text),
iconCls: exportType.icon || "pimcore_icon_export",
handler: function () {
pimcore.helpers.exportWarning(exportType, function (settings) {
this.exportPrepare(settings, exportType);
}.bind(this));
}.bind(this),
})
}.bind(this));

return buttons;
},

getGridConfig: function ($super) {
var config = $super();
config.onlyDirectChildren = this.onlyDirectChildren;
Expand Down
@@ -0,0 +1,25 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/

pimcore.registerNS("pimcore.gridexport.abstract");
pimcore.gridexport.abstract = Class.create({
name: t('export'),
text: t('export'),
warningText: t('object_export_warning'),
downloadUrl: null,
getExportSettingsContainer: function () {
return null;
}
});

pimcore.globalmanager.add("pimcore.gridexport", []);
@@ -0,0 +1,36 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/

pimcore.registerNS("pimcore.gridexport.csv");
pimcore.gridexport.csv = Class.create(pimcore.gridexport.abstract, {
name: "csv",
text: t("export_csv"),
warningText: t('csv_object_export_warning'),
downloadUrl: "/admin/object-helper/download-csv-file",
getExportSettingsContainer: function () {
return new Ext.form.FieldSet({
title: t('csv_settings'),
items: [
new Ext.form.TextField({
fieldLabel: t('delimiter'),
name: 'delimiter',
maxLength: 1,
labelWidth: 200,
value: ';'
})
]
});
}
});

pimcore.globalmanager.get("pimcore.gridexport").push(new pimcore.gridexport.csv())
@@ -0,0 +1,24 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/

pimcore.registerNS("pimcore.gridexport.xlsx");
pimcore.gridexport.xlsx = Class.create(pimcore.gridexport.abstract, {
name: "xlsx",
text: t("export_xlsx"),
downloadUrl: "/admin/object-helper/download-xlsx-file",
getExportSettingsContainer: function () {
return null;
}
});

pimcore.globalmanager.get("pimcore.gridexport").push(new pimcore.gridexport.xlsx())