-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Admin Grid for Queue Archive
- Loading branch information
1 parent
2618116
commit b7c5dff
Showing
11 changed files
with
782 additions
and
0 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,69 @@ | ||
<?php | ||
|
||
namespace Algolia\AlgoliaSearch\Block\Adminhtml\QueueArchive; | ||
|
||
use Magento\Backend\Block\Widget\Button; | ||
use Magento\Framework\Registry; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Framework\View\Element\Template\Context; | ||
|
||
class View extends Template | ||
{ | ||
/** @var Registry */ | ||
protected $coreRegistry; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Registry $coreRegistry | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Registry $coreRegistry, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
|
||
$this->coreRegistry = $coreRegistry; | ||
} | ||
|
||
/** @inheritdoc */ | ||
protected function _prepareLayout() | ||
{ | ||
/** @var Button $button */ | ||
$button = $this->getLayout()->createBlock(Button::class); | ||
$button->setData( | ||
[ | ||
'label' => __('Back'), | ||
'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')', | ||
'class' => 'back', | ||
] | ||
); | ||
|
||
$this->getToolbar()->setChild('back_button', $button); | ||
|
||
return parent::_prepareLayout(); | ||
} | ||
|
||
/** @return \Algolia\AlgoliaSearch\Model\QueueArchive */ | ||
public function getCurrentJob() | ||
{ | ||
return $this->coreRegistry->registry('current_job'); | ||
} | ||
|
||
/** @return string */ | ||
public function getBackUrl() | ||
{ | ||
return $this->getUrl('*/*/index'); | ||
} | ||
|
||
/** | ||
* Return toolbar block instance | ||
* | ||
* @return bool|\Magento\Framework\View\Element\Template | ||
*/ | ||
public function getToolbar() | ||
{ | ||
return $this->getLayout()->getBlock('page.actions.toolbar'); | ||
} | ||
} |
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,75 @@ | ||
<?php | ||
|
||
namespace Algolia\AlgoliaSearch\Controller\Adminhtml\QueueArchive; | ||
|
||
use Algolia\AlgoliaSearch\Model\QueueArchiveFactory; | ||
use Algolia\AlgoliaSearch\Model\ResourceModel\QueueArchive as QueueArchiveResourceModel; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\Registry; | ||
use Magento\Indexer\Model\IndexerFactory; | ||
|
||
abstract class AbstractAction extends \Magento\Backend\App\Action | ||
{ | ||
/** @var Registry */ | ||
protected $coreRegistry; | ||
|
||
/** @var \Algolia\AlgoliaSearch\Model\QueueArchiveFactory */ | ||
protected $queueArchiveFactory; | ||
|
||
/** @var QueueArchiveResourceModel */ | ||
protected $queueArchiveResourceModel; | ||
|
||
/** @var IndexerFactory */ | ||
protected $indexerFactory; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Registry $coreRegistry | ||
* @param QueueArchiveFactory $queueArchiveFactory | ||
* @param QueueArchiveResourceModel $queueArchiveResourceModel | ||
* @param IndexerFactory $indexerFactory | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Registry $coreRegistry, | ||
QueueArchiveFactory $queueArchiveFactory, | ||
QueueArchiveResourceModel $queueArchiveResourceModel, | ||
IndexerFactory $indexerFactory | ||
) { | ||
parent::__construct($context); | ||
|
||
$this->coreRegistry = $coreRegistry; | ||
$this->queueArchiveFactory = $queueArchiveFactory; | ||
$this->queueArchiveResourceModel = $queueArchiveResourceModel; | ||
$this->indexerFactory = $indexerFactory; | ||
} | ||
|
||
/** @return bool */ | ||
protected function _isAllowed() | ||
{ | ||
return $this->_authorization->isAllowed('Algolia_AlgoliaSearch::manage'); | ||
} | ||
|
||
/** @return \Algolia\AlgoliaSearch\Model\QueueArchive */ | ||
protected function initJob() | ||
{ | ||
$jobId = (int) $this->getRequest()->getParam('id'); | ||
|
||
// We must have an id | ||
if (!$jobId) { | ||
return null; | ||
} | ||
|
||
/** @var \Algolia\AlgoliaSearch\Model\QueueArchive $model */ | ||
$model = $this->queueArchiveFactory->create(); | ||
$this->queueArchiveResourceModel->load($model, $jobId); | ||
if (!$model->getId()) { | ||
return null; | ||
} | ||
|
||
// Register model to use later in blocks | ||
$this->coreRegistry->register('current_job', $model); | ||
|
||
return $model; | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Algolia\AlgoliaSearch\Controller\Adminhtml\QueueArchive; | ||
|
||
use Magento\Framework\Controller\ResultFactory; | ||
|
||
class Index extends \Magento\Backend\App\Action | ||
{ | ||
/** @return \Magento\Framework\View\Result\Page */ | ||
public function execute() | ||
{ | ||
$breadMain = __('Algolia | Queue Archives'); | ||
|
||
/** @var \Magento\Framework\View\Result\Page $resultPage */ | ||
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); | ||
$resultPage->setActiveMenu('Algolia_AlgoliaSearch::manage'); | ||
$resultPage->getConfig()->getTitle()->prepend($breadMain); | ||
|
||
return $resultPage; | ||
} | ||
} |
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,91 @@ | ||
<?php | ||
namespace Algolia\AlgoliaSearch\Controller\Adminhtml\Queuearchive; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Ui\Component\MassAction\Filter; | ||
use Algolia\AlgoliaSearch\Model\ResourceModel\QueueArchive\CollectionFactory; | ||
use Algolia\AlgoliaSearch\Model\QueueArchive; | ||
|
||
class MassDelete extends Action | ||
{ | ||
/** | ||
* @var CollectionFactory | ||
*/ | ||
protected $collectionFactory; | ||
/** | ||
* @var Filter | ||
*/ | ||
protected $filter; | ||
|
||
/** | ||
* @var QueueArchive | ||
*/ | ||
protected $queueArchive; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Filter $filter | ||
* @param CollectionFactory $collectionFactory | ||
* @param QueueArchive $queueArchive | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Filter $filter, | ||
CollectionFactory $collectionFactory, | ||
QueueArchive $queueArchive | ||
) { | ||
$this->filter = $filter; | ||
$this->collectionFactory = $collectionFactory; | ||
$this->queueArchive = $queueArchive; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
$jobData = $this->collectionFactory->create(); | ||
|
||
foreach ($jobData as $value){ | ||
$templateId[] = $value['id']; | ||
} | ||
$parameterData = $this->getRequest()->getParams('id'); | ||
$selectedAppsid = $this->getRequest()->getParams('id'); | ||
|
||
if(array_key_exists("selected", $parameterData)){ | ||
$selectedAppsid = $parameterData['selected']; | ||
} | ||
if(array_key_exists("excluded", $parameterData)) { | ||
if ($parameterData['excluded'] == 'false') { | ||
$selectedAppsid = $templateId; | ||
} else { | ||
$selectedAppsid = array_diff($templateId, $parameterData['excluded']); | ||
} | ||
} | ||
$collection = $this->collectionFactory->create(); | ||
$collection->addFieldToFilter('archive_id', ['in' => $selectedAppsid]); | ||
$delete = 0; | ||
$model = []; | ||
foreach ($collection as $item){ | ||
$this->deleteById($item->getId()); | ||
$delete++; | ||
} | ||
$this->messageManager->addSuccess(__('A total of %1 records have been deleted.', $delete)); | ||
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); | ||
return $resultRedirect->setPath('*/*/'); | ||
} | ||
|
||
/** | ||
* [deleteById description] | ||
* $param [type] $id [description] | ||
* $return [type] [description] | ||
*/ | ||
public function deleteById($id){ | ||
$item = $this->queueArchive->load($id); | ||
$item->delete(); | ||
return; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace Algolia\AlgoliaSearch\Controller\Adminhtml\QueueArchive; | ||
|
||
use Magento\Backend\Model\View\Result\Page; | ||
use Magento\Backend\Model\View\Result\Redirect; | ||
use Magento\Framework\Controller\ResultFactory; | ||
|
||
class View extends AbstractAction | ||
{ | ||
/** @return Page */ | ||
public function execute() | ||
{ | ||
$job = $this->initJob(); | ||
if (is_null($job)) { | ||
$this->messageManager->addErrorMessage(__('This job does not exists.')); | ||
/** @var Redirect $resultRedirect */ | ||
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); | ||
|
||
return $resultRedirect->setPath('*/*/'); | ||
} | ||
|
||
/** @var Page $resultPage */ | ||
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); | ||
|
||
$breadcrumbTitle = __('View Queue Archive'); | ||
$resultPage | ||
->setActiveMenu('Algolia_AlgoliaSearch::manage') | ||
->addBreadcrumb(__('Queue Archive'), __('Queue Archive')) | ||
->addBreadcrumb($breadcrumbTitle, $breadcrumbTitle); | ||
|
||
$resultPage->getConfig()->getTitle()->prepend(__('Queue Archive')); | ||
$resultPage->getConfig()->getTitle()->prepend(__('View Queue Archive #%1', $job->getId())); | ||
|
||
return $resultPage; | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
namespace Algolia\AlgoliaSearch\Ui\Component\Listing\Column; | ||
|
||
use Magento\Framework\UrlInterface; | ||
use Magento\Framework\View\Element\UiComponent\ContextInterface; | ||
use Magento\Framework\View\Element\UiComponentFactory; | ||
use Magento\Ui\Component\Listing\Columns\Column; | ||
|
||
class QueueArchive extends Column | ||
{ | ||
public const URL_PATH_VIEW = 'algolia_algoliasearch/queuearchive/view'; | ||
|
||
/** @var UrlInterface */ | ||
protected $urlBuilder; | ||
|
||
/** | ||
* @param ContextInterface $context | ||
* @param UiComponentFactory $uiComponentFactory | ||
* @param UrlInterface $urlBuilder | ||
* @param array $components | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
ContextInterface $context, | ||
UiComponentFactory $uiComponentFactory, | ||
UrlInterface $urlBuilder, | ||
array $components = [], | ||
array $data = [] | ||
) { | ||
$this->urlBuilder = $urlBuilder; | ||
|
||
parent::__construct($context, $uiComponentFactory, $components, $data); | ||
} | ||
|
||
/** | ||
* @param array $dataSource | ||
* | ||
* @return array | ||
*/ | ||
public function prepareDataSource(array $dataSource) | ||
{ | ||
if (isset($dataSource['data']['items'])) { | ||
foreach ($dataSource['data']['items'] as &$item) { | ||
$item[$this->getData('name')] = [ | ||
'view' => [ | ||
'href' => $this->urlBuilder->getUrl( | ||
static::URL_PATH_VIEW, | ||
[ | ||
'id' => $item['archive_id'], | ||
] | ||
), | ||
'label' => __('View'), | ||
], | ||
]; | ||
} | ||
} | ||
|
||
return $dataSource; | ||
} | ||
} |
Oops, something went wrong.