Skip to content

Commit

Permalink
Result panel refactoring (#80)
Browse files Browse the repository at this point in the history
* Result panel refactoring - add abstract class to override gridColumnConfig methods

* Result panel refactoring - add ID filter for preselected export
  • Loading branch information
dvesh3 authored Jan 29, 2020
1 parent eaa4170 commit 33036f4
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 56 deletions.
1 change: 1 addition & 0 deletions src/AdvancedObjectSearchBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function getJsPaths()
'/bundles/advancedobjectsearch/js/searchConfigPanel.js',
'/bundles/advancedobjectsearch/js/searchConfig/conditionPanelContainerBuilder.js',
'/bundles/advancedobjectsearch/js/searchConfig/conditionPanel.js',
'/bundles/advancedobjectsearch/js/searchConfig/resultAbstractPanel.js',
'/bundles/advancedobjectsearch/js/searchConfig/resultPanel.js',
'/bundles/advancedobjectsearch/js/searchConfig/resultExtension.js',
'/bundles/advancedobjectsearch/js/searchConfig/conditionAbstractPanel.js',
Expand Down
25 changes: 13 additions & 12 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function getBatchJobsAction(Request $request, Service $service)

//get ID list from ES Service
$data = json_decode($request->get("filter"), true);
$results = $service->doFilter($data['classId'], $data['conditions']['filters'], $data['conditions']['fulltextSearchTerm'], null, 9999);
$results = $service->doFilter($data['classId'], $data['conditions']['filters'] ?? [], $data['conditions']['fulltextSearchTerm'] ?? [], null, 9999);

$ids = $service->extractIdsFromResult($results);

Expand Down Expand Up @@ -219,20 +219,21 @@ public function getExportJobsAction(Request $request, Service $service) {
$request->setLocale($request->get("language"));
}

//get ID list from ES Service
$data = json_decode($request->get("filter"), true);

//TODO eventually add ID filter for preselected export
if (empty($ids = $request->get('ids', false))) {
$results = $service->doFilter(
$data['classId'],
$data['conditions']['filters'],
$data['conditions']['fulltextSearchTerm'],
0,
9999 // elastic search cannot export more results than 9999 in one request
);

$results = $service->doFilter(
$data['classId'],
$data['conditions']['filters'],
$data['conditions']['fulltextSearchTerm'],
0,
9999 // elastic search cannot export more results than 9999 in one request
);
//get ID list from ES Service
$ids = $service->extractIdsFromResult($results);
}

$ids = $service->extractIdsFromResult($results);
$jobs = array_chunk($ids, 20);

$fileHandle = uniqid("export-");
Expand Down Expand Up @@ -386,7 +387,7 @@ public function loadSearchAction(Request $request) {
$helperColumns = [];

foreach ($config["gridConfig"]["columns"] as &$column) {
if(!$column["isOperator"]) {
if(!($column["isOperator"] ?? false)) {
$fieldDefinition = $classDefinition->getFieldDefinition($column['key']);
if($fieldDefinition) {
$width = isset($column["layout"]["width"]) ? $column["layout"]["width"] : null;
Expand Down
49 changes: 49 additions & 0 deletions src/Resources/public/js/searchConfig/resultAbstractPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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.bundle.advancedObjectSearch.searchConfig.resultAbstractPanel");
pimcore.bundle.advancedObjectSearch.searchConfig.resultAbstractPanel = Class.create(pimcore.object.helpers.gridTabAbstract, {
systemColumns: ["id", "fullpath", "type", "subtype", "filename", "classname", "creationDate", "modificationDate"],
noBatchColumns: [],
batchAppendColumns: [],
batchRemoveColumns: [],
exportPrepareUrl: "/admin/bundle/advanced-object-search/admin/get-export-jobs",
batchPrepareUrl: "/admin/bundle/advanced-object-search/admin/get-batch-jobs",

getSaveDataCallback: null,
gridConfigData: {},

portletMode: false,

fieldObject: {},

getLayout: function (initialFilter) {
},

updateGrid: function (classId) {
},

createGrid: function (fromConfig, response, settings, save) {
}
});

/**
* https://github.com/pimcore/advanced-object-search/issues/64
* TODO pimcore.object.helpers.gridcolumnconfig for BC reasons, to be removed with next major version
*/
if (pimcore.object.helpers.gridcolumnconfig) {
pimcore.bundle.advancedObjectSearch.searchConfig.resultAbstractPanel.addMethods(pimcore.object.helpers.gridcolumnconfig);
} else {
pimcore.bundle.advancedObjectSearch.searchConfig.resultAbstractPanel.addMethods(pimcore.element.helpers.gridColumnConfig);
}
76 changes: 32 additions & 44 deletions src/Resources/public/js/searchConfig/resultPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,12 @@


pimcore.registerNS("pimcore.bundle.advancedObjectSearch.searchConfig.resultPanel");
pimcore.bundle.advancedObjectSearch.searchConfig.resultPanel = Class.create(pimcore.object.helpers.gridTabAbstract, {
systemColumns: ["id", "fullpath", "type", "subtype", "filename", "classname", "creationDate", "modificationDate"],
noBatchColumns: [],
batchAppendColumns: [],
batchRemoveColumns: [],
pimcore.bundle.advancedObjectSearch.searchConfig.resultPanel = Class.create(pimcore.bundle.advancedObjectSearch.searchConfig.resultAbstractPanel, {

getSaveDataCallback: null,
gridConfigData: {},

portletMode: false,

fieldObject: {},
initialize: function (getSaveDataCallback, gridConfigData, portletMode) {
this.getSaveDataCallback = getSaveDataCallback;
this.settings = {};
this.element = {};
this.gridPageSize = 25;

if (gridConfigData) {
Expand Down Expand Up @@ -260,26 +251,19 @@ pimcore.bundle.advancedObjectSearch.searchConfig.resultPanel = Class.create(pimc
});
plugins.push(this.cellEditing);

tbar = tbar.concat(['->', "-", {
text: t("export_csv"),
iconCls: "pimcore_icon_export",
handler: function () {

Ext.MessageBox.show({
title: t('warning'),
msg: t('csv_object_export_warning'),
buttons: Ext.Msg.OKCANCEL,
fn: function (btn) {
if (btn == 'ok') {
this.exportResultPrepare();
}
}.bind(this),
icon: Ext.MessageBox.WARNING
});
var exportButtons = this.getExportButtons();
var firstButton = exportButtons.pop();

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

}.bind(this)
}, "-", this.columnConfigButton
tbar = tbar.concat(['->', "-",
this.exportButton, "-",
this.columnConfigButton
]);

tbars = [{
Expand Down Expand Up @@ -460,7 +444,7 @@ pimcore.bundle.advancedObjectSearch.searchConfig.resultPanel = Class.create(pimc

},

exportResultPrepare: function () {
exportPrepare: function (settings, exportType) {
var jobs = [];

var fields = this.getGridConfig().columns;
Expand Down Expand Up @@ -494,9 +478,7 @@ pimcore.bundle.advancedObjectSearch.searchConfig.resultPanel = Class.create(pimc
var fieldKeys = Object.keys(fields);

if (rdata.success && rdata.jobs) {
var exportType = {};
exportType.downloadUrl = "/admin/object-helper/download-csv-file";
this.exportProcess(rdata.jobs, rdata.fileHandle, fieldKeys, true, {}, exportType);
this.exportProcess(rdata.jobs, rdata.fileHandle, fieldKeys, true, settings, exportType);
}

}.bind(this)
Expand Down Expand Up @@ -604,16 +586,22 @@ pimcore.bundle.advancedObjectSearch.searchConfig.resultPanel = Class.create(pimc
} else {
return this.gridConfigData;
}
}
},

});
getExportButtons: function () {
var buttons = [];
pimcore.globalmanager.get("pimcore.object.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));

/**
* https://github.com/pimcore/advanced-object-search/issues/64
* TODO pimcore.object.helpers.gridcolumnconfig for BC reasons, to be removed with next major version
*/
if (pimcore.object.helpers.gridcolumnconfig) {
pimcore.bundle.advancedObjectSearch.searchConfig.resultPanel.addMethods(pimcore.object.helpers.gridcolumnconfig);
} else {
pimcore.bundle.advancedObjectSearch.searchConfig.resultPanel.addMethods(pimcore.element.helpers.gridColumnConfig);
}
return buttons;
}
});

0 comments on commit 33036f4

Please sign in to comment.