Skip to content

Commit

Permalink
Merge pull request #218 from dkarlovi/feature/export-from-grid
Browse files Browse the repository at this point in the history
feature: add support to start an export from the folder search grid
  • Loading branch information
dpfaffenbauer authored Aug 26, 2019
2 parents 9dde214 + cdebbe5 commit 602ddf7
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function load(array $configs, ContainerBuilder $container)
$config['pimcore_admin']['js']['process_manager_import'] = '/bundles/datadefinitions/pimcore/js/process_manager/import_definitions.js';
$config['pimcore_admin']['js']['process_manager_export'] = '/bundles/datadefinitions/pimcore/js/process_manager/export_definitions.js';
$config['pimcore_admin']['js']['process_manager_export_contextmenu'] = '/bundles/datadefinitions/pimcore/js/process_manager/export_contextmenu.js';
$config['pimcore_admin']['js']['process_manager_export_search'] = '/bundles/datadefinitions/pimcore/js/process_manager/export_search.js';
$loader->load('process_manager.yml');
}

Expand Down
60 changes: 57 additions & 3 deletions src/DataDefinitionsBundle/Fetcher/ObjectsFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ private function getClassListing(ExportDefinitionInterface $definition, $params)
{
$class = $definition->getClass();
$classDefinition = ClassDefinition::getByName($class);
$obj = null;

if (!$classDefinition instanceof ClassDefinition) {
throw new \InvalidArgumentException(sprintf('Class not found %s', $class));
}
Expand All @@ -59,16 +57,72 @@ private function getClassListing(ExportDefinitionInterface $definition, $params)
$list = new $classList;
$list->setUnpublished($definition->isFetchUnpublished());

$rootNode = null;
$conditionFilters = [];
if (isset($params['root'])) {
$rootNode = Concrete::getById($params['root']);

if (null !== $rootNode) {
$list->addConditionParam('o_path LIKE :path', ['path' => $rootNode->getFullPath().'%']);
$quotedPath = $list->quote($rootNode->getRealFullPath());
$quotedWildcardPath = $list->quote(str_replace('//', '/', $rootNode->getRealFullPath() . '/') . '%');
$conditionFilters[] = '(o_path = ' . $quotedPath . ' OR o_path LIKE ' . $quotedWildcardPath . ')';
}
}

if ($params['query']) {
$query = $this->filterQueryParam($params['query']);
if (!empty($query)) {
$conditionFilters[] = 'oo_id IN (SELECT id FROM search_backend_data WHERE MATCH (`data`,`properties`) AGAINST (' . $list->quote($query) . ' IN BOOLEAN MODE))';
}
}

if ($params['only_direct_children'] == 'true' && null !== $rootNode) {
$conditionFilters[] = 'o_parentId = ' . $rootNode->getId();
}

if ($params['condition']) {
$conditionFilters[] = '(' . $params['condition'] . ')';
}
if ($params['ids']) {
$quotedIds = [];
foreach ($params['ids'] as $id) {
$quotedIds[] = $list->quote($id);
}
if (!empty($quotedIds)) {
$conditionFilters[] = 'oo_id IN (' . implode(',', $quotedIds) . ')';
}
}

$list->setCondition(implode(' AND ', $conditionFilters));

return $list;
}

/**
* @param string $query
*
* @return string
*/
protected function filterQueryParam(string $query)
{
if ($query == '*') {
$query = '';
}

$query = str_replace('%', '*', $query);
$query = str_replace('@', '#', $query);
$query = preg_replace("@([^ ])\-@", '$1 ', $query);

$query = str_replace(['<', '>', '(', ')', '~'], ' ', $query);

// it is not allowed to have * behind another *
$query = preg_replace('#[*]+#', '*', $query);

// no boolean operators at the end of the query
$query = rtrim($query, '+- ');

return $query;
}
}

class_alias(ObjectsFetcher::class, 'ImportDefinitionsBundle\Fetcher\ObjectsFetcher');
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
namespace Wvision\Bundle\DataDefinitionsBundle\Form\Type\ProcessManager;

use ProcessManagerBundle\Form\Type\AbstractStartupFormType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

Expand All @@ -28,7 +30,22 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->add('root', TextType::class, [
'required' => false
]);
])
->add('query', TextType::class, [
'required' => false
])
->add('only_direct_children', CheckboxType::class, [
'required' => false
])
->add('condition', TextType::class, [
'required' => false
])
->add('ids', CollectionType::class, [
'allow_add' => true,
'entry_type' => TextType::class,
'required' => false
])
;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ pimcore.plugin.datadefinitions.export.context_menu = Class.create(pimcore.plugin
rootProperty: 'data'
}
},
sorters: [{
property: 'name',
direction: 'ASC'
}],
sortRoot: 'data',
autoLoad: true,
listeners: {
load: function(store, executables, successful) {
if (!successful) {
return;
}

refresh: function(store) {
var exportMenu = [];
executables.forEach(function (executable) {
store.each(function (executable) {
exportMenu.push({
text: executable.get('name'),
iconCls: "pimcore_icon_object pimcore_icon_overlay_add",
Expand All @@ -53,7 +54,7 @@ pimcore.plugin.datadefinitions.export.context_menu = Class.create(pimcore.plugin
tree.add([
{ xtype: 'menuseparator' },
{
text: t("importdefinitions_processmanager_export_from_here"),
text: t("data_definitions_processmanager_export_from_here"),
iconCls: "pimcore_icon_object pimcore_icon_overlay_download",
menu: exportMenu
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* Data Definitions.
*
* LICENSE
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2019 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
*/

pimcore.object.search = Class.create(pimcore.object.search, {
createGrid: function ($super, fromConfig, response, settings, save) {
if (!Ext.ClassManager.get('Executable')) {
Ext.define('Executable', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
]
});
}

this.exportFromHere = new Ext.SplitButton({
text: t('data_definitions_processmanager_export_from_here'),
iconCls: "pimcore_icon_object pimcore_icon_overlay_add",
menu: []
});

var $this = this;
Ext.create('Ext.data.Store', {
model: 'Executable',
proxy: {
type: 'ajax',
url: '/admin/process_manager/executables/list-by-type',
extraParams: {
type: 'exportdefinition'
},
reader: {
type: 'json',
rootProperty: 'data'
}
},
sorters: [{
property: 'name',
direction: 'ASC'
}],
sortRoot: 'data',
autoLoad: true,
listeners: {
refresh: function(store) {
var exportMenu = [];
store.each(function (executable) {
exportMenu.push({
text: executable.get('name'),
iconCls: "pimcore_icon_object pimcore_icon_overlay_add",
handler: $this.exportObjects.bind($this, executable)
});
});

if (exportMenu) {
$this.exportFromHere.down("menu").add(exportMenu);
}
}
}
});

$super(fromConfig, response, settings, save);
this.grid.down("toolbar").add([
"-",
this.exportFromHere,
"-"
]);
},

exportObjects: function (executable, menuItem) {
var selected = this.grid.getSelectionModel().getSelection(), ids = [];
if (selected) {
ids = selected.map(function (item) {
return item.id;
});
}

Ext.Ajax.request({
url: '/admin/process_manager/executables/run',
params: {
id: executable.id,
startupConfig: Ext.encode({
root: this.object.id,
query: this.searchField.getValue(),
only_direct_children: this.checkboxOnlyDirectChildren.getValue(),
condition: this.sqlEditor.getValue(),
ids: ids,
}),
csrfToken: pimcore.settings['csrfToken']
},
method: 'POST',
success: function (result) {
result = Ext.decode(result.responseText);

if (result.success) {
Ext.Msg.alert(t('success'), t('processmanager_executable_started'));
} else {
Ext.Msg.alert(t('error'), result.message);
}
}.bind(this)
});
}
});

0 comments on commit 602ddf7

Please sign in to comment.