Skip to content

Commit

Permalink
Merge pull request #375 from magento-vanilla/PR
Browse files Browse the repository at this point in the history
[Vanilla] Bugsfixes + Ui Grid improvements
  • Loading branch information
guz-anton committed Jun 24, 2015
2 parents 163044a + 873a2a0 commit 5712d36
Show file tree
Hide file tree
Showing 64 changed files with 2,544 additions and 682 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getAfterElementHtml()
'id' => 'add_category_button',
'label' => $newCategoryCaption,
'title' => $newCategoryCaption,
'onclick' => 'jQuery("#new-category").trigger("openModal")',
'onclick' => 'jQuery("#new-category").modal("openModal")',
'disabled' => $this->getDisabled(),
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ define([
$('#new_category_name, #new_category_parent-suggest').val('');
$suggest.val('');
clearParentCategory();
widget.element.trigger('closeModal');
$(widget.element).modal('closeModal');
} else {
$('#new_category_messages').html(data.messages);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,84 @@
*/
namespace Magento\Cms\Test\Unit\Ui\Component\Listing\Column;

use Magento\Cms\Ui\Component\Listing\Column\PageActions;

class PageActionsTest extends \PHPUnit_Framework_TestCase
{
public function testPrepareItemsByPageId()
{
$pageId = 1;
// Create Mocks and SUT
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
/** @var \PHPUnit_Framework_MockObject_MockObject $urlBuilderMock */
$urlBuilderMock = $this->getMockBuilder('Magento\Framework\UrlInterface')
->disableOriginalConstructor()
->getMock();
$inputUrl = 'href/url/for/edit/action';

/** @var \Magento\Cms\Ui\Component\Listing\Column\PageActions $model */
$model = $objectManager->getObject(
'Magento\Cms\Ui\Component\Listing\Column\PageActions',
[
'urlBuilder' => $urlBuilderMock,
'url' => $inputUrl
]
);

// Define test input and expectations
$items = ['data' => ['items' => [['page_id' => 1]]]];
$fullUrl = 'full-url-including-base.com/href/url/for/edit/action';
$name = 'item_name';

$editArray = [
'href' => $fullUrl,
'label' => __('Edit'),
'hidden' => true
$items = [
'data' => [
'items' => [
[
'page_id' => $pageId
]
]
]
];
$name = 'item_name';
$expectedItems = [
[
'page_id' => 1,
$name => ['edit' => $editArray]
'page_id' => $pageId,
$name => [
'edit' => [
'href' => 'test/url/edit',
'label' => __('Edit'),
],
'delete' => [
'href' => 'test/url/delete',
'label' => __('Delete'),
'confirm' => [
'title' => __('Delete "${ $.$data.title }"'),
'message' => __('Are you sure you wan\'t to delete a "${ $.$data.title }" record?')
],
]
],
]
];

// Configure mocks and object data
$urlBuilderMock->expects($this->once())
$urlBuilderMock->expects($this->any())
->method('getUrl')
->with($inputUrl, ['page_id' => 1])
->willReturn($fullUrl);
->willReturnMap(
[
[
PageActions::CMS_URL_PATH_EDIT,
[
'page_id' => $pageId
],
'test/url/edit',
],
[
PageActions::CMS_URL_PATH_DELETE,
[
'page_id' => $pageId
],
'test/url/delete',
],
]
);

$model->setName($name);
$model->prepareDataSource($items);
// Run test
$this->assertEquals(
$expectedItems,
$items['data']['items']
);
$this->assertEquals($expectedItems, $items['data']['items']);
}
}
39 changes: 36 additions & 3 deletions app/code/Magento/Cms/Ui/Component/Listing/Column/BlockActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class BlockActions extends Column
/**
* Url path
*/
const URL_PATH = 'cms/block/edit';
const URL_PATH_EDIT = 'cms/block/edit';
const URL_PATH_DELETE = 'cms/block/delete';
const URL_PATH_DETAILS = 'cms/block/details';

/**
* @var UrlInterface
Expand All @@ -45,6 +47,10 @@ public function __construct(
parent::__construct($context, $uiComponentFactory, $components, $data);
}

/**
* @param array $items
* @return array
*/
/**
* Prepare Data Source
*
Expand All @@ -58,8 +64,35 @@ public function prepareDataSource(array & $dataSource)
if (isset($item['block_id'])) {
$item[$this->getData('name')] = [
'edit' => [
'href' => $this->urlBuilder->getUrl(static::URL_PATH, ['block_id' => $item['block_id']]),
'label' => __('Edit'),
'href' => $this->urlBuilder->getUrl(
static::URL_PATH_EDIT,
[
'block_id' => $item['block_id']
]
),
'label' => __('Edit')
],
'details' => [
'href' => $this->urlBuilder->getUrl(
static::URL_PATH_DETAILS,
[
'block_id' => $item['block_id']
]
),
'label' => __('Details')
],
'delete' => [
'href' => $this->urlBuilder->getUrl(
static::URL_PATH_DELETE,
[
'block_id' => $item['block_id']
]
),
'label' => __('Delete'),
'confirm' => [
'title' => __('Delete "${ $.$data.title }"'),
'message' => __('Are you sure you wan\'t to delete a "${ $.$data.title }" record?')
]
]
];
}
Expand Down
30 changes: 16 additions & 14 deletions app/code/Magento/Cms/Ui/Component/Listing/Column/PageActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,33 @@
class PageActions extends Column
{
/** Url path */
const CMS_URL_PATH = 'cms/page/edit';
const CMS_URL_PATH_EDIT = 'cms/page/edit';
const CMS_URL_PATH_DELETE = 'cms/page/delete';

/** @var UrlBuilder */
protected $actionUrlBuilder;

/** @var UrlInterface */
protected $urlBuilder;

/** @var string */
private $url;


/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param UrlBuilder $actionUrlBuilder
* @param UrlInterface $urlBuilder
* @param array $components
* @param array $data
* @param string $url
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlBuilder $actionUrlBuilder,
UrlInterface $urlBuilder,
array $components = [],
array $data = [],
$url = self::CMS_URL_PATH
array $data = []
) {
$this->urlBuilder = $urlBuilder;
$this->actionUrlBuilder = $actionUrlBuilder;
$this->url = $url;
parent::__construct($context, $uiComponentFactory, $components, $data);
}

Expand All @@ -63,15 +57,23 @@ public function prepareDataSource(array & $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
$name = $this->getData('name');
if (isset($item['page_id'])) {
$item[$this->getData('name')]['edit'] = [
'href' => $this->urlBuilder->getUrl($this->url, ['page_id' => $item['page_id']]),
'label' => __('Edit'),
'hidden' => true
$item[$name]['edit'] = [
'href' => $this->urlBuilder->getUrl(self::CMS_URL_PATH_EDIT, ['page_id' => $item['page_id']]),
'label' => __('Edit')
];
$item[$name]['delete'] = [
'href' => $this->urlBuilder->getUrl(self::CMS_URL_PATH_DELETE, ['page_id' => $item['page_id']]),
'label' => __('Delete'),
'confirm' => [
'title' => __('Delete "${ $.$data.title }"'),
'message' => __('Are you sure you wan\'t to delete a "${ $.$data.title }" record?')
]
];
}
if (isset($item['identifier'])) {
$item[$this->getData('name')]['preview'] = [
$item[$name]['preview'] = [
'href' => $this->actionUrlBuilder->getUrl(
$item['identifier'],
isset($item['_first_store_id']) ? $item['_first_store_id'] : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<container name="columns_controls">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="columnsData" xsi:type="array">
<item name="provider" xsi:type="string">cms_block_listing.cms_block_listing.cms_block_columns</item>
</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/controls/columns</item>
<item name="displayArea" xsi:type="string">dataGridActions</item>
</item>
Expand Down Expand Up @@ -225,13 +228,17 @@
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="selectProvider" xsi:type="string">cms_block_listing.cms_block_listing.cms_block_columns.ids</item>
<item name="displayArea" xsi:type="string">bottom</item>
<item name="actions" xsi:type="array">
<item name="delete" xsi:type="array">
<item name="confirm" xsi:type="string" translate="true">Are you sure you want to perform this action?</item>
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="string">cms/block/massDelete</item>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete items</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
</item>
</item>
</item>
<item name="indexField" xsi:type="string">block_id</item>
Expand All @@ -245,6 +252,7 @@
<item name="provider" xsi:type="string">cms_block_listing.cms_block_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current.paging</item>
</item>
<item name="selectProvider" xsi:type="string">cms_block_listing.cms_block_listing.cms_block_columns.ids</item>
<item name="displayArea" xsi:type="string">bottom</item>
<item name="options" xsi:type="array">
<item name="20" xsi:type="array">
Expand Down Expand Up @@ -275,10 +283,14 @@
<columns name="cms_block_columns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">cms_block_listing.cms_block_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="controlVisibility" xsi:type="boolean">true</item>
<item name="actionField" xsi:type="string">actions</item>
<item name="clickAction" xsi:type="string">edit</item>
<item name="appendTo" xsi:type="string">cms_block_listing.cms_block_listing.listing_top.columns_controls</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">cms_block_listing.cms_block_listing.listing_top.bookmarks</item>
<item name="root" xsi:type="string">columns.${ $.index }</item>
Expand All @@ -294,14 +306,14 @@
</item>
<item name="config" xsi:type="array">
<item name="indexField" xsi:type="string">block_id</item>
<item name="appendTo" xsi:type="boolean">false</item>
<item name="controlVisibility" xsi:type="boolean">false</item>
</item>
</argument>
</column>
<column name="block_id">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/sortable</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
Expand All @@ -314,7 +326,7 @@
<column name="title">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/sortable</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
Expand All @@ -326,7 +338,7 @@
<column name="identifier">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/sortable</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/column</item>
</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
Expand Down Expand Up @@ -397,7 +409,9 @@
<column name="actions" class="Magento\Cms\Ui\Component\Listing\Column\BlockActions">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="draggable" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">actions</item>
<item name="indexField" xsi:type="string">block_id</item>
<item name="align" xsi:type="string">left</item>
<item name="label" xsi:type="string" translate="true">Action</item>
<item name="data_type" xsi:type="string">actions</item>
Expand Down
Loading

0 comments on commit 5712d36

Please sign in to comment.