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

Admin Indexing Queue Feature #1070

Merged
merged 12 commits into from
Nov 28, 2018
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

class Algolia_Algoliasearch_Block_Adminhtml_IndexingQueue extends Mage_Adminhtml_Block_Widget_Grid_Container
{
/**
* Initialize Grid Container
*/
public function __construct()
{
$this->_blockGroup = 'algoliasearch';
$this->_controller = 'adminhtml_indexingqueue';

parent::__construct();

$this->_removeButton('add');
$this->_addButton('clear_queue', array(
'label' => Mage::helper('algoliasearch')->__('Clear Queue'),
'onclick' => "if (confirm('Are you sure you want to clear the queue? This operation cannot be reverted.')) {
location.href='" . $this->getUrl('*/*/clear') . "' };",
'class' => 'cancel',
));
}

/**
* Get header text.
*
* @return string
*/
public function getHeaderText()
{
return Mage::helper('algoliasearch')->__('Algolia Search - Indexing Queue');
}

/**
* Set custom Algolia icon class.
*
* @return string
*/
public function getHeaderCssClass()
{
return 'icon-head algoliasearch-head-icon';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

class Algolia_Algoliasearch_Block_Adminhtml_IndexingQueue_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
/**
* Internal constructor.
*/
public function __construct()
{
parent::__construct();

$this->_objectId = 'job_id';
$this->_blockGroup = 'algoliasearch';
$this->_controller = 'adminhtml_indexingqueue';

$this->_removeButton('save');
$this->_removeButton('reset');
$this->_removeButton('delete');
}

/**
* Get header text.
*
* @return string
*/
public function getHeaderText()
{
return Mage::helper('algoliasearch')->__('Algolia Search - Indexing Queue Job #%s',
Mage::registry('algoliasearch_current_job')->getJobId());
}

/**
* Set custom Algolia icon class.
*
* @return string
*/
public function getHeaderCssClass()
{
return 'icon-head algoliasearch-head-icon';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

class Algolia_Algoliasearch_Block_Adminhtml_IndexingQueue_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
/**
* @return Algolia_Algoliasearch_Block_Adminhtml_IndexingQueue_Edit_Form
*/
protected function _prepareForm()
{
$model = Mage::registry('algoliasearch_current_job');

$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/updatePost'),
'method' => 'post',
));

$fieldset = $form->addFieldset('base_fieldset', array());
$readOnlyStyle = 'border: 0; background: none;';

$fieldset->addField('job_id', 'text', array(
'name' => 'job_id',
'label' => Mage::helper('algoliasearch')->__('Job ID'),
'title' => Mage::helper('algoliasearch')->__('Job ID'),
'readonly' => true,
'style' => $readOnlyStyle,
));

$fieldset->addField('created', 'text', array(
'name' => 'created',
'label' => Mage::helper('algoliasearch')->__('Created'),
'title' => Mage::helper('algoliasearch')->__('Created'),
'readonly' => true,
'style' => $readOnlyStyle,
));

$fieldset->addField('status', 'text', array(
'name' => 'status',
'label' => Mage::helper('algoliasearch')->__('Status'),
'title' => Mage::helper('algoliasearch')->__('Status'),
'readonly' => true,
'style' => $readOnlyStyle,
));

$fieldset->addField('pid', 'text', array(
'name' => 'pid',
'label' => Mage::helper('algoliasearch')->__('PID'),
'title' => Mage::helper('algoliasearch')->__('PID'),
'readonly' => true,
'style' => $readOnlyStyle,
));

$fieldset->addField('class', 'text', array(
'name' => 'class',
'label' => Mage::helper('algoliasearch')->__('Class'),
'title' => Mage::helper('algoliasearch')->__('Class'),
'readonly' => true,
'style' => $readOnlyStyle,
));

$fieldset->addField('method', 'text', array(
'name' => 'method',
'label' => Mage::helper('algoliasearch')->__('Method'),
'title' => Mage::helper('algoliasearch')->__('Method'),
'readonly' => true,
'style' => $readOnlyStyle,
));

$fieldset->addField('data', 'textarea', array(
'name' => 'data',
'label' => Mage::helper('algoliasearch')->__('Data'),
'title' => Mage::helper('algoliasearch')->__('Data'),
'readonly' => true,
));

$fieldset->addField('max_retries', 'text', array(
'name' => 'max_retries',
'label' => Mage::helper('algoliasearch')->__('Max Retries'),
'title' => Mage::helper('algoliasearch')->__('Max Retries'),
'readonly' => true,
'style' => $readOnlyStyle,
));

$fieldset->addField('retries', 'text', array(
'name' => 'retries',
'label' => Mage::helper('algoliasearch')->__('Retries'),
'title' => Mage::helper('algoliasearch')->__('Retries'),
'readonly' => true,
'style' => $readOnlyStyle,
));

$fieldset->addField('data_size', 'text', array(
'name' => 'data_size',
'label' => Mage::helper('algoliasearch')->__('Data Size'),
'title' => Mage::helper('algoliasearch')->__('Data Size'),
'readonly' => true,
'style' => $readOnlyStyle,
));

$fieldset->addField('error_log', 'textarea', array(
'name' => 'error_log',
'label' => Mage::helper('algoliasearch')->__('Error Log'),
'title' => Mage::helper('algoliasearch')->__('Error Log'),
'readonly' => true,
));


$form->setValues($model->getData());
$form->addValues(array(
'status' => $model->getStatusLabel()
));
$form->setUseContainer(true);

$this->setForm($form);

return parent::_prepareForm();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

class Algolia_Algoliasearch_Block_Adminhtml_IndexingQueue_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
/**
* Initialize Grid Properties
*
*/
public function __construct()
{
parent::__construct();
$this->setId('job_id');
$this->setDefaultSort('job_id');
$this->setDefaultDir('desc');
}

/**
* Prepare Search Report collection for grid
*
* @return Mage_Adminhtml_Block_Report_Search_Grid
*/
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('algoliasearch/job_collection');
$this->setCollection($collection);

return parent::_prepareCollection();
}

/**
* Prepare Grid columns
*
* @return Mage_Adminhtml_Block_Report_Search_Grid
*/
protected function _prepareColumns()
{
$this->addColumn('job_id', array(
'header' => Mage::helper('algoliasearch')->__('Job ID'),
'width' => '50px',
'filter' => false,
'index' => 'job_id',
'type' => 'number'
));

$this->addColumn('created', array(
'header' => Mage::helper('algoliasearch')->__('Created'),
'index' => 'created',
'type' => 'datetime',
));

$this->addColumn('status', array(
'header' => Mage::helper('algoliasearch')->__('Status'),
'index' => 'status',
'getter' => 'getStatusLabel',
'filter' => false,
));

$this->addColumn('method', array(
'header' => Mage::helper('algoliasearch')->__('Method'),
'index' => 'method',
'type' => 'options',
'options' => Mage::getModel('algoliasearch/source_jobMethods')->getMethods(),
));

$this->addColumn('data', array(
'header' => Mage::helper('algoliasearch')->__('Data'),
'index' => 'data',
'renderer' => 'Algolia_Algoliasearch_Block_Adminhtml_IndexingQueue_Grid_Renderer_Json'
));

$this->addColumn('max_retries', array(
'header' => Mage::helper('algoliasearch')->__('Max Retries'),
'width' => '40px',
'filter' => false,
'index' => 'max_retries',
'type' => 'number'
));

$this->addColumn('retries', array(
'header' => Mage::helper('algoliasearch')->__('Retries'),
'width' => '40px',
'filter' => false,
'index' => 'retries',
'type' => 'number'
));

bsuravech marked this conversation as resolved.
Show resolved Hide resolved
return parent::_prepareColumns();
}

/**
* Retrieve Row Click callback URL
*
* @return string
*/
public function getRowUrl($row)
{
return $this->getUrl('*/*/view', array('id' => $row->getJobId()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class Algolia_Algoliasearch_Block_Adminhtml_IndexingQueue_Grid_Renderer_Json extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
/**
* @param Varien_Object $row
* @return string
*/
public function render(Varien_Object $row)
{
$html = '';
if ($json = $row->getData('data')) {
$json = json_decode($json, true);

foreach ($json as $var => $value) {
$html .= $var . ': ' . (is_array($value) ? implode(',', $value) : $value) . '<br/>';
}
}
return $html;
}
}
Loading