-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from DivanteLtd/issue/12-basic-clipboard-view
basic-clipboard-view
- Loading branch information
Showing
10 changed files
with
774 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* @category pimcore5-clipboard | ||
* @date 22/02/2018 | ||
* @author Korneliusz Kirsz <kkirsz@divante.pl> | ||
* @copyright Copyright (c) 2018 DIVANTE (http://divante.pl) | ||
*/ | ||
|
||
namespace Divante\ClipboardBundle\Controller; | ||
|
||
use Divante\ClipboardBundle\Service\ClipboardService; | ||
use Pimcore\Bundle\AdminBundle\Controller\Admin\DataObjectController as AdminDataObjectController; | ||
use Pimcore\Logger; | ||
use Pimcore\Model\DataObject; | ||
use Pimcore\Model\Element; | ||
use Pimcore\Tool; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
/** | ||
* Class DataObjectController | ||
* @package Divante\ClipboardBundle\Controller | ||
* @Route("/admin/object") | ||
*/ | ||
class DataObjectController extends AdminDataObjectController | ||
{ | ||
/** | ||
* @param Request $request | ||
* @param ClipboardService $clipboardService | ||
* @return JsonResponse | ||
* @Route("/get-clipboard") | ||
*/ | ||
public function getClipboardAction(Request $request, ClipboardService $clipboardService) | ||
{ | ||
$object = DataObject::getById(intval($request->get('id'))); | ||
if ($object->isAllowed('view')) { | ||
$objectData = []; | ||
|
||
$objectData['general'] = []; | ||
$objectData['idPath'] = Element\Service::getIdPath($object); | ||
$allowedKeys = ['o_published', 'o_key', 'o_id', 'o_type', 'o_path', 'o_modificationDate', | ||
'o_creationDate', 'o_userOwner', 'o_userModification']; | ||
foreach (get_object_vars($object) as $key => $value) { | ||
if (strstr($key, 'o_') && in_array($key, $allowedKeys)) { | ||
$objectData['general'][$key] = $value; | ||
} | ||
} | ||
$objectData['general']['fullpath'] = $object->getRealFullPath(); | ||
|
||
$objectData['general']['o_locked'] = $object->isLocked(); | ||
|
||
$objectData['properties'] = Element\Service::minimizePropertiesForEditmode($object->getProperties()); | ||
$objectData['userPermissions'] = $object->getUserPermissions(); | ||
$objectData['classes'] = $this->prepareChildClasses($clipboardService->getClasses()); | ||
|
||
// grid-config | ||
$configFile = PIMCORE_CONFIGURATION_DIRECTORY . '/object/grid/' | ||
. $object->getId() . '-user_' . $this->getAdminUser()->getId() . '.psf'; | ||
if (is_file($configFile)) { | ||
$gridConfig = Tool\Serialize::unserialize(file_get_contents($configFile)); | ||
if ($gridConfig) { | ||
$selectedClassId = $gridConfig['classId']; | ||
|
||
foreach ($objectData['classes'] as $class) { | ||
if ($class['id'] == $selectedClassId) { | ||
$objectData['selectedClass'] = $selectedClassId; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $this->adminJson($objectData); | ||
} else { | ||
Logger::debug('prevented getting folder id [ ' . $object->getId() . ' ] because of missing permissions'); | ||
|
||
return $this->adminJson(['success' => false, 'message' => 'missing_permission']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* @category pimcore5-clipboard | ||
* @date 22/02/2018 | ||
* @author Korneliusz Kirsz <kkirsz@divante.pl> | ||
* @copyright Copyright (c) 2018 DIVANTE (http://divante.pl) | ||
*/ | ||
|
||
namespace Divante\ClipboardBundle\Controller; | ||
|
||
use Divante\ClipboardBundle\Service\ClipboardService; | ||
use Pimcore\Bundle\AdminBundle\Controller\Admin\DataObjectHelperController as AdminDataObjectHelperController; | ||
use Pimcore\Model\DataObject; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
/** | ||
* Class DataObjectHelperController | ||
* @package Divante\ClipboardBundle\Controller | ||
* @Route("/admin/object-helper") | ||
*/ | ||
class DataObjectHelperController extends AdminDataObjectHelperController | ||
{ | ||
/** | ||
* @param Request $request | ||
* @param ClipboardService $clipboardService | ||
* @return JsonResponse | ||
* @Route("/get-clipboard-batch-jobs") | ||
*/ | ||
public function getClipboardBatchJobsAction(Request $request, ClipboardService $clipboardService) | ||
{ | ||
if ($request->get('language')) { | ||
$request->setLocale($request->get('language')); | ||
} | ||
|
||
$folder = DataObject::getById($request->get('folderId')); | ||
$class = DataObject\ClassDefinition::getById($request->get('classId')); | ||
|
||
$conditionFilters = "(o_path = ? OR o_path LIKE '" | ||
. str_replace('//', '/', $folder->getRealFullPath() . '/') | ||
. "%')"; | ||
$conditionFilters = [$conditionFilters]; | ||
|
||
if ($request->get('filter')) { | ||
$conditionFilters[] = DataObject\Service::getFilterCondition($request->get('filter'), $class); | ||
} | ||
if ($request->get('condition')) { | ||
$conditionFilters[] = ' (' . $request->get('condition') . ')'; | ||
} | ||
|
||
$objectIds = $clipboardService->getObjectIds(); | ||
if (empty($objectIds)) { | ||
$objectIds[] = 0; | ||
} | ||
|
||
$conditionFilters[] = 'o_id IN (' . implode(', ', $objectIds) . ')'; | ||
|
||
$className = $class->getName(); | ||
$listClass = '\\Pimcore\\Model\\DataObject\\' . ucfirst($className) . '\\Listing'; | ||
$list = new $listClass(); | ||
$list->setCondition(implode(' AND ', $conditionFilters), [$folder->getRealFullPath()]); | ||
$list->setOrder('ASC'); | ||
$list->setOrderKey('o_id'); | ||
|
||
if ($request->get('objecttype')) { | ||
$list->setObjectTypes([$request->get('objecttype')]); | ||
} | ||
|
||
$jobs = $list->loadIdList(); | ||
|
||
return $this->adminJson(['success' => true, 'jobs' => $jobs]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* @category pimcore5-clipboard | ||
* @date 22/02/2018 | ||
* @author Korneliusz Kirsz <kkirsz@divante.pl> | ||
* @copyright Copyright (c) 2018 DIVANTE (http://divante.pl) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Divante\ClipboardBundle\EventListener; | ||
|
||
use Divante\ClipboardBundle\Service\ClipboardService; | ||
use Pimcore\Event\AdminEvents; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\EventDispatcher\GenericEvent; | ||
|
||
/** | ||
* Class AdminListener | ||
* @package Divante\ClipboardBundle\EventListener | ||
*/ | ||
class AdminListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var ClipboardService | ||
*/ | ||
protected $service; | ||
|
||
/** | ||
* AdminListener constructor. | ||
* @param ClipboardService $service | ||
*/ | ||
public function __construct(ClipboardService $service) | ||
{ | ||
$this->service = $service; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
AdminEvents::OBJECT_LIST_BEFORE_LIST_LOAD => 'onBeforeListLoad', | ||
]; | ||
} | ||
|
||
/** | ||
* @param GenericEvent $event | ||
*/ | ||
public function onBeforeListLoad(GenericEvent $event) | ||
{ | ||
$context = $event->getArgument('context'); | ||
if (empty($context['clipboard'])) { | ||
return; | ||
} | ||
|
||
$objectIds = $this->service->getObjectIds(); | ||
if (empty($objectIds)) { | ||
$objectIds[] = 0; | ||
} | ||
|
||
/** @var \Pimcore\Model\Listing\AbstractListing $list */ | ||
$list = $event->getArgument('list'); | ||
$cond = $list->getCondition() . ' AND o_id IN (' . implode(', ', $objectIds) . ')'; | ||
$list->setCondition($cond); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
pimcore.registerNS("pimcore.plugin.DivanteClipboardBundle.Clipboard"); | ||
|
||
pimcore.plugin.DivanteClipboardBundle.Clipboard = Class.create(pimcore.object.abstract, { | ||
|
||
id: 1, | ||
type: "folder", | ||
managerKey: "clipboard", | ||
|
||
initialize: function () { | ||
this.options = undefined; | ||
this.getData(); | ||
}, | ||
|
||
getData: function () { | ||
var options = this.options || {}; | ||
Ext.Ajax.request({ | ||
url: "/admin/object/get-clipboard", | ||
params: {id: this.id}, | ||
ignoreErrors: options.ignoreNotFoundError, | ||
success: this.getDataComplete.bind(this), | ||
failure: function () { | ||
pimcore.globalmanager.remove(this.managerKey); | ||
}.bind(this) | ||
}); | ||
}, | ||
|
||
getDataComplete: function (response) { | ||
try { | ||
this.data = Ext.decode(response.responseText); | ||
this.search = new pimcore.plugin.DivanteClipboardBundle.Search(this, "folder"); | ||
this.addTab(); | ||
} catch (e) { | ||
console.log(e); | ||
this.closeObject(); | ||
} | ||
}, | ||
|
||
addTab: function () { | ||
|
||
var tabTitle = this.data.general.o_key; | ||
if (this.id == 1) { | ||
tabTitle = t("divante_clipboard"); | ||
} | ||
|
||
this.tabPanel = Ext.getCmp("pimcore_panel_tabs"); | ||
var tabId = this.managerKey; | ||
|
||
this.tab = new Ext.Panel({ | ||
id: tabId, | ||
title: tabTitle, | ||
closable: true, | ||
layout: "border", | ||
items: [this.getTabPanel()], | ||
iconCls: "pimcore_icon_export", | ||
object: this | ||
}); | ||
|
||
// remove this instance when the panel is closed | ||
this.tab.on("destroy", function () { | ||
pimcore.globalmanager.remove(this.managerKey); | ||
}.bind(this)); | ||
|
||
this.tab.on("activate", function () { | ||
this.tab.updateLayout(); | ||
pimcore.layout.refresh(); | ||
}.bind(this)); | ||
|
||
this.tab.on("afterrender", function (tabId) { | ||
this.tabPanel.setActiveItem(tabId); | ||
// load selected class if available | ||
if (this.data["selectedClass"]) { | ||
this.search.setClass(this.data["selectedClass"]); | ||
} | ||
}.bind(this, tabId)); | ||
|
||
this.tabPanel.add(this.tab); | ||
|
||
// recalculate the layout | ||
pimcore.layout.refresh(); | ||
}, | ||
|
||
getTabPanel: function () { | ||
|
||
var items = []; | ||
|
||
var search = this.search.getLayout(); | ||
if (search) { | ||
items.push(search); | ||
} | ||
|
||
this.tabbar = new Ext.TabPanel({ | ||
tabPosition: "top", | ||
region: "center", | ||
deferredRender: true, | ||
enableTabScroll: true, | ||
border: false, | ||
items: items, | ||
activeTab: 0 | ||
}); | ||
|
||
return this.tabbar; | ||
}, | ||
|
||
closeObject: function () { | ||
try { | ||
var panel = Ext.getCmp(this.managerKey); | ||
if (panel) { | ||
panel.close(); | ||
} else { | ||
console.log("to close element not found, doing nothing."); | ||
} | ||
|
||
pimcore.globalmanager.remove(this.managerKey); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}, | ||
|
||
activate: function () { | ||
var tabId = this.managerKey; | ||
var tabPanel = Ext.getCmp("pimcore_panel_tabs"); | ||
tabPanel.setActiveItem(tabId); | ||
} | ||
}); |
Oops, something went wrong.