From 84eae3219272c0b13a7bfeb4d478120b7bbed393 Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Fri, 29 May 2020 17:55:13 +0300 Subject: [PATCH 01/13] Add related content information to the delete asset warning --- .../RelatedContentCount.php | 48 +++++++++++++++++++ MediaGalleryUi/etc/adminhtml/di.xml | 1 + .../adminhtml/web/js/action/deleteImage.js | 15 +++++- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 MediaGalleryUi/Model/FilterParametersProvider/RelatedContentCount.php diff --git a/MediaGalleryUi/Model/FilterParametersProvider/RelatedContentCount.php b/MediaGalleryUi/Model/FilterParametersProvider/RelatedContentCount.php new file mode 100644 index 000000000000..b11f8672c39a --- /dev/null +++ b/MediaGalleryUi/Model/FilterParametersProvider/RelatedContentCount.php @@ -0,0 +1,48 @@ +connection = $connection; + } + + /** + * @inheritdoc + */ + public function apply(Select $select, SearchCriteriaInterface $searchCriteria): void + { + $select->joinLeft( + ['mca' => $this->connection->getTableName(self::MEDIA_CONTENT_ASSET_TABLE_NAME)], + 'mca.asset_id = main_table.id', + ['related_content_count' => 'COUNT(mca.asset_id)'] + )->group('main_table.id'); + } +} diff --git a/MediaGalleryUi/etc/adminhtml/di.xml b/MediaGalleryUi/etc/adminhtml/di.xml index bd26420b3a67..a87346bfb3c9 100644 --- a/MediaGalleryUi/etc/adminhtml/di.xml +++ b/MediaGalleryUi/etc/adminhtml/di.xml @@ -15,6 +15,7 @@ Magento\MediaGalleryUi\Model\FilterParametersProvider\Directory + Magento\MediaGalleryUi\Model\FilterParametersProvider\RelatedContentCount diff --git a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js index 8d2713515236..125e574a046a 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js +++ b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js @@ -20,7 +20,7 @@ define([ * @param {String} deleteUrl */ deleteImageAction: function (record, deleteUrl) { - var baseContent = $.mage.__('Are you sure you want to delete "%s" image?'), + var baseContent = this.getContentMessage(record.path, record.related_content_count), title = $.mage.__('Delete image'), cancelText = $.mage.__('Cancel'), deleteImageText = $.mage.__('Delete Image'), @@ -29,7 +29,7 @@ define([ confirmation({ title: title, modalClass: 'media-gallery-delete-image-action', - content: baseContent.replace('%s', record.path), + content: baseContent, buttons: [ { text: cancelText, @@ -58,6 +58,17 @@ define([ }); }, + /** + * Returns content + * + * @param {string} recordPath + * @param {string} recordRelatedContentCount + * @return string + */ + getContentMessage: function(recordPath, recordRelatedContentCount) { + return $.mage.__('This image is used in '+ recordRelatedContentCount +' page. Are you sure you want to delete "' + recordPath + '" image?'); + }, + /** * Delete image * From e7889e5a577a4af7eb10e2033b999b4fd16dd1f4 Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Sat, 30 May 2020 15:01:51 +0300 Subject: [PATCH 02/13] corrected message text --- MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js index 125e574a046a..eedb69eaffdc 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js +++ b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js @@ -66,7 +66,7 @@ define([ * @return string */ getContentMessage: function(recordPath, recordRelatedContentCount) { - return $.mage.__('This image is used in '+ recordRelatedContentCount +' page. Are you sure you want to delete "' + recordPath + '" image?'); + return $.mage.__('This image is used in '+ recordRelatedContentCount +' page(s). Are you sure you want to delete "' + recordPath + '" image?'); }, /** From 3b0cd3c25b1fe2f411ec5163382fd71eb19f9296 Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Mon, 1 Jun 2020 10:56:15 +0300 Subject: [PATCH 03/13] changed message for delete confirmation --- .../RelatedContentCount.php | 48 ------------------- .../Ui/Component/Listing/Provider.php | 48 +++++++++++++++++-- MediaGalleryUi/etc/adminhtml/di.xml | 1 - .../adminhtml/web/js/action/deleteImage.js | 36 +++++++++++--- 4 files changed, 73 insertions(+), 60 deletions(-) delete mode 100644 MediaGalleryUi/Model/FilterParametersProvider/RelatedContentCount.php diff --git a/MediaGalleryUi/Model/FilterParametersProvider/RelatedContentCount.php b/MediaGalleryUi/Model/FilterParametersProvider/RelatedContentCount.php deleted file mode 100644 index b11f8672c39a..000000000000 --- a/MediaGalleryUi/Model/FilterParametersProvider/RelatedContentCount.php +++ /dev/null @@ -1,48 +0,0 @@ -connection = $connection; - } - - /** - * @inheritdoc - */ - public function apply(Select $select, SearchCriteriaInterface $searchCriteria): void - { - $select->joinLeft( - ['mca' => $this->connection->getTableName(self::MEDIA_CONTENT_ASSET_TABLE_NAME)], - 'mca.asset_id = main_table.id', - ['related_content_count' => 'COUNT(mca.asset_id)'] - )->group('main_table.id'); - } -} diff --git a/MediaGalleryUi/Ui/Component/Listing/Provider.php b/MediaGalleryUi/Ui/Component/Listing/Provider.php index d1ba5bb67282..05e7091d6e3f 100644 --- a/MediaGalleryUi/Ui/Component/Listing/Provider.php +++ b/MediaGalleryUi/Ui/Component/Listing/Provider.php @@ -6,15 +6,19 @@ namespace Magento\MediaGalleryUi\Ui\Component\Listing; +use Exception; use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy; use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory; use Magento\Framework\Event\ManagerInterface as EventManager; +use Magento\Framework\Exception\IntegrationException; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult; use Magento\MediaGalleryApi\Api\Data\AssetInterface; use Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterface; use Magento\MediaGalleryApi\Api\Data\KeywordInterface; +use Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface; use Magento\MediaGalleryApi\Api\GetAssetsKeywordsInterface; +use Magento\MediaGalleryUi\Model\AssetDetailsProvider\UsedIn; use Psr\Log\LoggerInterface as Logger; class Provider extends SearchResult @@ -23,6 +27,14 @@ class Provider extends SearchResult * @var GetAssetsKeywordsInterface */ private $getAssetKeywords; + /** + * @var GetAssetsByIdsInterface + */ + private $getAssetsByIds; + /** + * @var UsedIn + */ + private $usedIn; /** * @param EntityFactory $entityFactory @@ -30,6 +42,8 @@ class Provider extends SearchResult * @param FetchStrategy $fetchStrategy * @param EventManager $eventManager * @param GetAssetsKeywordsInterface $getAssetKeywords + * @param GetAssetsByIdsInterface $getAssetsByIds + * @param UsedIn $usedIn * @param string $mainTable * @param null|string $resourceModel * @param null|string $identifierName @@ -42,6 +56,8 @@ public function __construct( FetchStrategy $fetchStrategy, EventManager $eventManager, GetAssetsKeywordsInterface $getAssetKeywords, + GetAssetsByIdsInterface $getAssetsByIds, + UsedIn $usedIn, $mainTable = 'media_gallery_asset', $resourceModel = null, $identifierName = null, @@ -58,6 +74,8 @@ public function __construct( $connectionName ); $this->getAssetKeywords = $getAssetKeywords; + $this->getAssetsByIds = $getAssetsByIds; + $this->usedIn = $usedIn; } /** @@ -77,12 +95,32 @@ public function getData() /** @var AssetInterface $asset */ foreach ($data as $key => $asset) { - $data[$key]['thumbnail_url'] = $asset['path']; - $data[$key]['content_type'] = strtoupper(str_replace('image/', '', $asset['content_type'])); - $data[$key]['preview_url'] = $asset['path']; - $data[$key]['keywords'] = isset($keywords[$asset['id']]) ? implode(",", $keywords[$asset['id']]) : ''; - $data[$key]['source'] = empty($asset['source']) ? 'Local' : $asset['source']; + try { + $data[$key]['thumbnail_url'] = $asset['path']; + $data[$key]['content_type'] = strtoupper(str_replace('image/', '', $asset['content_type'])); + $data[$key]['preview_url'] = $asset['path']; + $data[$key]['keywords'] = isset($keywords[$asset['id']]) ? implode(",", $keywords[$asset['id']]) : ''; + $data[$key]['source'] = empty($asset['source']) ? 'Local' : $asset['source']; + $data[$key]['related_content'] = $this->getRelatedContent($asset['id']); + } catch (Exception $exception) { + $this->_logger->error($exception->getMessage()); + } } return $data; } + + /** + * Returns information about related content + * + * @param int $assetId + * @return array + * @throws LocalizedException + * @throws IntegrationException + */ + private function getRelatedContent(int $assetId): array + { + $assetItem = $this->getAssetsByIds->execute([$assetId]); + + return isset($assetItem[0]) ? $this->usedIn->execute($assetItem[0]) : []; + } } diff --git a/MediaGalleryUi/etc/adminhtml/di.xml b/MediaGalleryUi/etc/adminhtml/di.xml index a87346bfb3c9..bd26420b3a67 100644 --- a/MediaGalleryUi/etc/adminhtml/di.xml +++ b/MediaGalleryUi/etc/adminhtml/di.xml @@ -15,7 +15,6 @@ Magento\MediaGalleryUi\Model\FilterParametersProvider\Directory - Magento\MediaGalleryUi\Model\FilterParametersProvider\RelatedContentCount diff --git a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js index eedb69eaffdc..f9eb53b150a5 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js +++ b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js @@ -20,7 +20,7 @@ define([ * @param {String} deleteUrl */ deleteImageAction: function (record, deleteUrl) { - var baseContent = this.getContentMessage(record.path, record.related_content_count), + var baseContent = this.getContentMessage(record['path'], record['related_content']), title = $.mage.__('Delete image'), cancelText = $.mage.__('Cancel'), deleteImageText = $.mage.__('Delete Image'), @@ -61,12 +61,36 @@ define([ /** * Returns content * - * @param {string} recordPath - * @param {string} recordRelatedContentCount - * @return string + * @param {String} recordPath + * @param {Object} recordRelatedContent + * @return String */ - getContentMessage: function(recordPath, recordRelatedContentCount) { - return $.mage.__('This image is used in '+ recordRelatedContentCount +' page(s). Are you sure you want to delete "' + recordPath + '" image?'); + getContentMessage: function (recordPath, recordRelatedContentCount) { + return $.mage.__(this.getRecordRelatedContentHtml(recordRelatedContentCount.value) + + '. Are you sure you want to delete "' + recordPath + '" image?'); + }, + + /** + * Get information about image use + * + * @param {Object|String} value + * @return {String} + */ + getRecordRelatedContentHtml: function (value) { + var usedIn = 'This image is used in '; + + if (_.isObject(value) && !_.isEmpty(value)) { + _.each(value, function (numberOfTimeUsed, moduleName) { + usedIn += numberOfTimeUsed + ' ' + moduleName + ' '; + }); + + return usedIn; + } else { + + return 'This image is not used anywhere'; + } + + return value; }, /** From 3a1c9d1e18deb916e700f9be7fcb84d70f2bad65 Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopov Date: Mon, 1 Jun 2020 11:01:58 +0300 Subject: [PATCH 04/13] Update Provider.php --- MediaGalleryUi/Ui/Component/Listing/Provider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MediaGalleryUi/Ui/Component/Listing/Provider.php b/MediaGalleryUi/Ui/Component/Listing/Provider.php index 05e7091d6e3f..3cb0423c3e61 100644 --- a/MediaGalleryUi/Ui/Component/Listing/Provider.php +++ b/MediaGalleryUi/Ui/Component/Listing/Provider.php @@ -27,10 +27,12 @@ class Provider extends SearchResult * @var GetAssetsKeywordsInterface */ private $getAssetKeywords; + /** * @var GetAssetsByIdsInterface */ private $getAssetsByIds; + /** * @var UsedIn */ From 41a0c4a7f44552c8e5470022fd9286fa81d15959 Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Mon, 1 Jun 2020 13:55:53 +0300 Subject: [PATCH 05/13] corrected static test --- MediaGalleryUi/Ui/Component/Listing/Provider.php | 3 ++- MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/MediaGalleryUi/Ui/Component/Listing/Provider.php b/MediaGalleryUi/Ui/Component/Listing/Provider.php index 05e7091d6e3f..af21ea860a5c 100644 --- a/MediaGalleryUi/Ui/Component/Listing/Provider.php +++ b/MediaGalleryUi/Ui/Component/Listing/Provider.php @@ -49,6 +49,7 @@ class Provider extends SearchResult * @param null|string $identifierName * @param null|string $connectionName * @throws LocalizedException + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( EntityFactory $entityFactory, @@ -101,7 +102,7 @@ public function getData() $data[$key]['preview_url'] = $asset['path']; $data[$key]['keywords'] = isset($keywords[$asset['id']]) ? implode(",", $keywords[$asset['id']]) : ''; $data[$key]['source'] = empty($asset['source']) ? 'Local' : $asset['source']; - $data[$key]['related_content'] = $this->getRelatedContent($asset['id']); + $data[$key]['relatedContent'] = $this->getRelatedContent($asset['id']); } catch (Exception $exception) { $this->_logger->error($exception->getMessage()); } diff --git a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js index f9eb53b150a5..f6f8a81a6cfb 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js +++ b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js @@ -20,7 +20,7 @@ define([ * @param {String} deleteUrl */ deleteImageAction: function (record, deleteUrl) { - var baseContent = this.getContentMessage(record['path'], record['related_content']), + var baseContent = this.getContentMessage(record.path, record.relatedContent), title = $.mage.__('Delete image'), cancelText = $.mage.__('Cancel'), deleteImageText = $.mage.__('Delete Image'), @@ -65,8 +65,8 @@ define([ * @param {Object} recordRelatedContent * @return String */ - getContentMessage: function (recordPath, recordRelatedContentCount) { - return $.mage.__(this.getRecordRelatedContentHtml(recordRelatedContentCount.value) + + getContentMessage: function (recordPath, recordRelatedContent) { + return $.mage.__(this.getRecordRelatedContentHtml(recordRelatedContent.value) + '. Are you sure you want to delete "' + recordPath + '" image?'); }, From 18fecea4ebb057efe70df2c3a4d4e0cbaa50640e Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Tue, 9 Jun 2020 15:39:48 +0300 Subject: [PATCH 06/13] processing of additional information for the removal process has been replaced to endpoint using --- .../Ui/Component/Listing/Provider.php | 50 ++--------------- .../adminhtml/web/js/action/deleteImage.js | 43 ++------------ .../web/js/grid/columns/image/actions.js | 56 ++++++++++++++++++- 3 files changed, 63 insertions(+), 86 deletions(-) diff --git a/MediaGalleryUi/Ui/Component/Listing/Provider.php b/MediaGalleryUi/Ui/Component/Listing/Provider.php index 8e4f4d9a5b81..3ecfd87c738b 100644 --- a/MediaGalleryUi/Ui/Component/Listing/Provider.php +++ b/MediaGalleryUi/Ui/Component/Listing/Provider.php @@ -6,19 +6,15 @@ namespace Magento\MediaGalleryUi\Ui\Component\Listing; -use Exception; use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy; use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory; use Magento\Framework\Event\ManagerInterface as EventManager; -use Magento\Framework\Exception\IntegrationException; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult; use Magento\MediaGalleryApi\Api\Data\AssetInterface; use Magento\MediaGalleryApi\Api\Data\AssetKeywordsInterface; use Magento\MediaGalleryApi\Api\Data\KeywordInterface; -use Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface; use Magento\MediaGalleryApi\Api\GetAssetsKeywordsInterface; -use Magento\MediaGalleryUi\Model\AssetDetailsProvider\UsedIn; use Psr\Log\LoggerInterface as Logger; class Provider extends SearchResult @@ -27,16 +23,6 @@ class Provider extends SearchResult * @var GetAssetsKeywordsInterface */ private $getAssetKeywords; - - /** - * @var GetAssetsByIdsInterface - */ - private $getAssetsByIds; - - /** - * @var UsedIn - */ - private $usedIn; /** * @param EntityFactory $entityFactory @@ -44,8 +30,6 @@ class Provider extends SearchResult * @param FetchStrategy $fetchStrategy * @param EventManager $eventManager * @param GetAssetsKeywordsInterface $getAssetKeywords - * @param GetAssetsByIdsInterface $getAssetsByIds - * @param UsedIn $usedIn * @param string $mainTable * @param null|string $resourceModel * @param null|string $identifierName @@ -59,8 +43,6 @@ public function __construct( FetchStrategy $fetchStrategy, EventManager $eventManager, GetAssetsKeywordsInterface $getAssetKeywords, - GetAssetsByIdsInterface $getAssetsByIds, - UsedIn $usedIn, $mainTable = 'media_gallery_asset', $resourceModel = null, $identifierName = null, @@ -77,8 +59,6 @@ public function __construct( $connectionName ); $this->getAssetKeywords = $getAssetKeywords; - $this->getAssetsByIds = $getAssetsByIds; - $this->usedIn = $usedIn; } /** @@ -98,32 +78,12 @@ public function getData() /** @var AssetInterface $asset */ foreach ($data as $key => $asset) { - try { - $data[$key]['thumbnail_url'] = $asset['path']; - $data[$key]['content_type'] = strtoupper(str_replace('image/', '', $asset['content_type'])); - $data[$key]['preview_url'] = $asset['path']; - $data[$key]['keywords'] = isset($keywords[$asset['id']]) ? implode(",", $keywords[$asset['id']]) : ''; - $data[$key]['source'] = empty($asset['source']) ? 'Local' : $asset['source']; - $data[$key]['relatedContent'] = $this->getRelatedContent($asset['id']); - } catch (Exception $exception) { - $this->_logger->error($exception->getMessage()); - } + $data[$key]['thumbnail_url'] = $asset['path']; + $data[$key]['content_type'] = strtoupper(str_replace('image/', '', $asset['content_type'])); + $data[$key]['preview_url'] = $asset['path']; + $data[$key]['keywords'] = isset($keywords[$asset['id']]) ? implode(",", $keywords[$asset['id']]) : ''; + $data[$key]['source'] = empty($asset['source']) ? 'Local' : $asset['source']; } return $data; } - - /** - * Returns information about related content - * - * @param int $assetId - * @return array - * @throws LocalizedException - * @throws IntegrationException - */ - private function getRelatedContent(int $assetId): array - { - $assetItem = $this->getAssetsByIds->execute([$assetId]); - - return isset($assetItem[0]) ? $this->usedIn->execute($assetItem[0]) : []; - } } diff --git a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js index f6f8a81a6cfb..2e726c6fae15 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js +++ b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js @@ -18,10 +18,10 @@ define([ * * @param {Object} record * @param {String} deleteUrl + * @param {String} confirmationContent */ - deleteImageAction: function (record, deleteUrl) { - var baseContent = this.getContentMessage(record.path, record.relatedContent), - title = $.mage.__('Delete image'), + deleteImageAction: function (record, deleteUrl, confirmationContent) { + var title = $.mage.__('Delete image'), cancelText = $.mage.__('Cancel'), deleteImageText = $.mage.__('Delete Image'), deleteImageCallback = this.deleteImage.bind(this); @@ -29,7 +29,7 @@ define([ confirmation({ title: title, modalClass: 'media-gallery-delete-image-action', - content: baseContent, + content: confirmationContent, buttons: [ { text: cancelText, @@ -58,41 +58,6 @@ define([ }); }, - /** - * Returns content - * - * @param {String} recordPath - * @param {Object} recordRelatedContent - * @return String - */ - getContentMessage: function (recordPath, recordRelatedContent) { - return $.mage.__(this.getRecordRelatedContentHtml(recordRelatedContent.value) + - '. Are you sure you want to delete "' + recordPath + '" image?'); - }, - - /** - * Get information about image use - * - * @param {Object|String} value - * @return {String} - */ - getRecordRelatedContentHtml: function (value) { - var usedIn = 'This image is used in '; - - if (_.isObject(value) && !_.isEmpty(value)) { - _.each(value, function (numberOfTimeUsed, moduleName) { - usedIn += numberOfTimeUsed + ' ' + moduleName + ' '; - }); - - return usedIn; - } else { - - return 'This image is not used anywhere'; - } - - return value; - }, - /** * Delete image * diff --git a/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js b/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js index 4a980115400b..d88afa9b6169 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js +++ b/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js @@ -7,8 +7,9 @@ define([ 'underscore', 'uiComponent', 'Magento_MediaGalleryUi/js/action/deleteImage', + 'Magento_MediaGalleryUi/js/action/getDetails', 'Magento_MediaGalleryUi/js/grid/columns/image/insertImageAction' -], function ($, _, Component, deleteImage, image) { +], function ($, _, Component, deleteImage, getDetails, image) { 'use strict'; return Component.extend({ @@ -70,7 +71,58 @@ define([ * @param {Object} record */ deleteImageAction: function (record) { - deleteImage.deleteImageAction(record, this.imageModel().deleteImageUrl); + var imageDetailsUrl = this.imageModel().imageDetailsurl, + deleteImageUrl = this.imageModel().deleteImageUrl, + defaultConfirmationContent = $.mage.__('Are you sure you want to delete "' + record.path + '" image?'); + + getDetails(imageDetailsUrl, record.id).then(function(imageDetails) { + var confirmationContent = this.getConfirmationContentByImageDetails(imageDetails) + .concat(defaultConfirmationContent); + deleteImage.deleteImageAction(record, deleteImageUrl, confirmationContent); + }.bind(this)).fail(function () { + deleteImage.deleteImageAction(record, deleteImageUrl, defaultConfirmationContent); + }); + }, + + /** + * Returns confirmation content with information about related content + * + * @param {Object} imageDetails + * @return String + */ + getConfirmationContentByImageDetails: function (imageDetails) { + var details = imageDetails.details; + + if(_.isObject(details) && !_.isUndefined(details['6'])) { + var detailValue = details['6'].value; + + return $.mage.__(this.getRecordRelatedContentHtml(detailValue)); + } + + return ''; + }, + + /** + * Get information about image use + * + * @param {Object|String} value + * @return {String} + */ + getRecordRelatedContentHtml: function (value) { + var usedIn = 'This image is used in '; + + if (_.isObject(value) && !_.isEmpty(value)) { + _.each(value, function (numberOfTimeUsed, moduleName) { + usedIn += numberOfTimeUsed + ' ' + moduleName + ' '; + }); + + return usedIn + '. '; + } else { + + return 'This image is not used anywhere. '; + } + + return value; }, /** From 1ac1e12ceb2e419ca6a20c432a3238d9b662f41a Mon Sep 17 00:00:00 2001 From: Vitaliy Prokopov Date: Wed, 10 Jun 2020 19:23:56 +0300 Subject: [PATCH 07/13] Update MediaGalleryUi/Ui/Component/Listing/Provider.php Co-authored-by: Gabriel da Gama --- MediaGalleryUi/Ui/Component/Listing/Provider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/MediaGalleryUi/Ui/Component/Listing/Provider.php b/MediaGalleryUi/Ui/Component/Listing/Provider.php index 3ecfd87c738b..d1ba5bb67282 100644 --- a/MediaGalleryUi/Ui/Component/Listing/Provider.php +++ b/MediaGalleryUi/Ui/Component/Listing/Provider.php @@ -35,7 +35,6 @@ class Provider extends SearchResult * @param null|string $identifierName * @param null|string $connectionName * @throws LocalizedException - * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( EntityFactory $entityFactory, From 7243241147f0e5731694269d9e93601ef52066fa Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Wed, 10 Jun 2020 19:50:47 +0300 Subject: [PATCH 08/13] apply code review recommendations --- .../web/js/grid/columns/image/actions.js | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js b/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js index d88afa9b6169..e64fa9da1ace 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js +++ b/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js @@ -52,7 +52,7 @@ define([ initEvents: function () { $(this.imageModel().addSelectedBtnSelector).click(function () { image.insertImage( - this.imageModel().getSelected(), + this.imageModel().getSelected(), { onInsertUrl: this.imageModel().onInsertUrl, storeId: this.imageModel().storeId @@ -71,16 +71,21 @@ define([ * @param {Object} record */ deleteImageAction: function (record) { - var imageDetailsUrl = this.imageModel().imageDetailsurl, + var imageDetailsUrl = this.mediaGalleryImageDetails().imageDetailsUrl, deleteImageUrl = this.imageModel().deleteImageUrl, - defaultConfirmationContent = $.mage.__('Are you sure you want to delete "' + record.path + '" image?'); - - getDetails(imageDetailsUrl, record.id).then(function(imageDetails) { - var confirmationContent = this.getConfirmationContentByImageDetails(imageDetails) - .concat(defaultConfirmationContent); + confirmationContent = $.mage.__('%1 Are you sure you want to delete "%2" image?') + .replace('%2', record.path); + + getDetails(imageDetailsUrl, record.id) + .then(function (imageDetails) { + confirmationContent = confirmationContent.replace( + '%1', + this.getConfirmationContentByImageDetails(imageDetails) + ); + }.bind(this)).fail(function () { + confirmationContent = confirmationContent.replace('%1', ""); + }).always(function () { deleteImage.deleteImageAction(record, deleteImageUrl, confirmationContent); - }.bind(this)).fail(function () { - deleteImage.deleteImageAction(record, deleteImageUrl, defaultConfirmationContent); }); }, @@ -93,10 +98,10 @@ define([ getConfirmationContentByImageDetails: function (imageDetails) { var details = imageDetails.details; - if(_.isObject(details) && !_.isUndefined(details['6'])) { + if (_.isObject(details) && !_.isUndefined(details['6'])) { var detailValue = details['6'].value; - return $.mage.__(this.getRecordRelatedContentHtml(detailValue)); + return this.getRecordRelatedContentMessage(detailValue); } return ''; @@ -108,21 +113,18 @@ define([ * @param {Object|String} value * @return {String} */ - getRecordRelatedContentHtml: function (value) { - var usedIn = 'This image is used in '; - + getRecordRelatedContentMessage: function (value) { + var usedInMessage = $.mage.__('This image is used in %s.'), + usedIn = ''; if (_.isObject(value) && !_.isEmpty(value)) { _.each(value, function (numberOfTimeUsed, moduleName) { - usedIn += numberOfTimeUsed + ' ' + moduleName + ' '; + usedIn += numberOfTimeUsed + ' ' + moduleName + ', '; }); + usedIn = usedIn.replace(/,\s*$/, ""); - return usedIn + '. '; - } else { - - return 'This image is not used anywhere. '; + return usedInMessage.replace('%s', usedIn); } - - return value; + return ''; }, /** From fa88116a3257fa6d5926984fd51a0b44cfc0deb9 Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Wed, 10 Jun 2020 21:08:06 +0300 Subject: [PATCH 09/13] fixed failed static test --- .../adminhtml/web/js/grid/columns/image/actions.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js b/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js index e64fa9da1ace..85718f169ba1 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js +++ b/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js @@ -83,7 +83,7 @@ define([ this.getConfirmationContentByImageDetails(imageDetails) ); }.bind(this)).fail(function () { - confirmationContent = confirmationContent.replace('%1', ""); + confirmationContent = confirmationContent.replace('%1', ''); }).always(function () { deleteImage.deleteImageAction(record, deleteImageUrl, confirmationContent); }); @@ -99,9 +99,7 @@ define([ var details = imageDetails.details; if (_.isObject(details) && !_.isUndefined(details['6'])) { - var detailValue = details['6'].value; - - return this.getRecordRelatedContentMessage(detailValue); + return this.getRecordRelatedContentMessage(details['6'].value); } return ''; @@ -116,14 +114,16 @@ define([ getRecordRelatedContentMessage: function (value) { var usedInMessage = $.mage.__('This image is used in %s.'), usedIn = ''; + if (_.isObject(value) && !_.isEmpty(value)) { _.each(value, function (numberOfTimeUsed, moduleName) { usedIn += numberOfTimeUsed + ' ' + moduleName + ', '; }); - usedIn = usedIn.replace(/,\s*$/, ""); + usedIn = usedIn.replace(/,\s*$/, ''); - return usedInMessage.replace('%s', usedIn); + return usedInMessage.replace('%s', usedIn); } + return ''; }, From 05443d7aa4fc7afedca8fc3f0ab65bf688de4c0b Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Thu, 11 Jun 2020 19:54:44 +0300 Subject: [PATCH 10/13] fixed confirmation message for deleting ffrom detail window --- .../deleteImageWithDetailConfirmation.js | 77 +++++++++++++++++++ .../web/js/grid/columns/image/actions.js | 59 +------------- .../adminhtml/web/js/image/image-actions.js | 13 +++- 3 files changed, 90 insertions(+), 59 deletions(-) create mode 100644 MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js diff --git a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js new file mode 100644 index 000000000000..e00603f3467a --- /dev/null +++ b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js @@ -0,0 +1,77 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +define([ + 'jquery', + 'Magento_MediaGalleryUi/js/action/getDetails', + 'Magento_MediaGalleryUi/js/action/deleteImage' +], function ($, getDetails, deleteImage) { + 'use strict'; + + return { + + /** + * Returns confirmation content with information about related content + * + * @param {Object} imageDetails + * @return String + */ + getConfirmationContentByImageDetails: function (imageDetails) { + var details = imageDetails.details; + + if (_.isObject(details) && !_.isUndefined(details['6'])) { + return this.getRecordRelatedContentMessage(details['6'].value); + } + + return ''; + }, + + /** + * Get information about image use + * + * @param {Object|String} value + * @return {String} + */ + getRecordRelatedContentMessage: function (value) { + var usedInMessage = $.mage.__('This image is used in %s.'), + usedIn = ''; + + if (_.isObject(value) && !_.isEmpty(value)) { + _.each(value, function (numberOfTimeUsed, moduleName) { + usedIn += numberOfTimeUsed + ' ' + moduleName + ', '; + }); + usedIn = usedIn.replace(/,\s*$/, ''); + + return usedInMessage.replace('%s', usedIn); + } + + return ''; + }, + + /** + * Get information about image use + * + * @param {Object} record + * @param {String} imageDetailsUrl + * @param {String} deleteImageUrl + * @return {String} + */ + deleteImageAction: function (record, imageDetailsUrl, deleteImageUrl) { + var confirmationContent = $.mage.__('%1 Are you sure you want to delete "%2" image?') + .replace('%2', record.path); + + getDetails(imageDetailsUrl, record.id) + .then(function (imageDetails) { + confirmationContent = confirmationContent.replace( + '%1', + this.getConfirmationContentByImageDetails(imageDetails) + ); + }.bind(this)).fail(function () { + confirmationContent = confirmationContent.replace('%1', ''); + }).always(function () { + deleteImage.deleteImageAction(record, deleteImageUrl, confirmationContent); + }); + } + } +}); diff --git a/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js b/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js index 85718f169ba1..d629e30bceab 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js +++ b/MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js @@ -6,10 +6,9 @@ define([ 'jquery', 'underscore', 'uiComponent', - 'Magento_MediaGalleryUi/js/action/deleteImage', - 'Magento_MediaGalleryUi/js/action/getDetails', + 'Magento_MediaGalleryUi/js/action/deleteImageWithDetailConfirmation', 'Magento_MediaGalleryUi/js/grid/columns/image/insertImageAction' -], function ($, _, Component, deleteImage, getDetails, image) { +], function ($, _, Component, deleteImageWithDetailConfirmation, image) { 'use strict'; return Component.extend({ @@ -72,59 +71,9 @@ define([ */ deleteImageAction: function (record) { var imageDetailsUrl = this.mediaGalleryImageDetails().imageDetailsUrl, - deleteImageUrl = this.imageModel().deleteImageUrl, - confirmationContent = $.mage.__('%1 Are you sure you want to delete "%2" image?') - .replace('%2', record.path); + deleteImageUrl = this.imageModel().deleteImageUrl; - getDetails(imageDetailsUrl, record.id) - .then(function (imageDetails) { - confirmationContent = confirmationContent.replace( - '%1', - this.getConfirmationContentByImageDetails(imageDetails) - ); - }.bind(this)).fail(function () { - confirmationContent = confirmationContent.replace('%1', ''); - }).always(function () { - deleteImage.deleteImageAction(record, deleteImageUrl, confirmationContent); - }); - }, - - /** - * Returns confirmation content with information about related content - * - * @param {Object} imageDetails - * @return String - */ - getConfirmationContentByImageDetails: function (imageDetails) { - var details = imageDetails.details; - - if (_.isObject(details) && !_.isUndefined(details['6'])) { - return this.getRecordRelatedContentMessage(details['6'].value); - } - - return ''; - }, - - /** - * Get information about image use - * - * @param {Object|String} value - * @return {String} - */ - getRecordRelatedContentMessage: function (value) { - var usedInMessage = $.mage.__('This image is used in %s.'), - usedIn = ''; - - if (_.isObject(value) && !_.isEmpty(value)) { - _.each(value, function (numberOfTimeUsed, moduleName) { - usedIn += numberOfTimeUsed + ' ' + moduleName + ', '; - }); - usedIn = usedIn.replace(/,\s*$/, ''); - - return usedInMessage.replace('%s', usedIn); - } - - return ''; + deleteImageWithDetailConfirmation.deleteImageAction(record, imageDetailsUrl, deleteImageUrl); }, /** diff --git a/MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js b/MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js index 32d674d83201..e8bd48107dce 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js +++ b/MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js @@ -7,18 +7,20 @@ define([ 'jquery', 'underscore', 'uiElement', - 'Magento_MediaGalleryUi/js/action/deleteImage', + 'Magento_MediaGalleryUi/js/action/deleteImageWithDetailConfirmation', 'Magento_MediaGalleryUi/js/grid/columns/image/insertImageAction' -], function ($, _, Element, deleteImage, addSelected) { +], function ($, _, Element, deleteImageWithDetailConfirmation, addSelected) { 'use strict'; return Element.extend({ defaults: { modalSelector: '', modalWindowSelector: '', + mediaGalleryImageDetailsName: 'mediaGalleryImageDetails', template: 'Magento_MediaGalleryUi/image/actions', modules: { - imageModel: '${ $.imageModelName }' + imageModel: '${ $.imageModelName }', + mediaGalleryImageDetails: '${ $.mediaGalleryImageDetailsName }' } }, @@ -52,7 +54,10 @@ define([ * Delete image action */ deleteImageAction: function () { - deleteImage.deleteImageAction(this.imageModel().getSelected(), this.imageModel().deleteImageUrl); + var imageDetailsUrl = this.mediaGalleryImageDetails().imageDetailsUrl, + deleteImageUrl = this.imageModel().deleteImageUrl; + + deleteImageWithDetailConfirmation.deleteImageAction(this.imageModel().getSelected(), imageDetailsUrl, deleteImageUrl); }, /** From 48d3a3eecb5810bc22c839857637676dcaf84a24 Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Thu, 11 Jun 2020 21:12:32 +0300 Subject: [PATCH 11/13] fixed code style --- .../web/js/action/deleteImageWithDetailConfirmation.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js index e00603f3467a..007496126055 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js +++ b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js @@ -33,7 +33,7 @@ define([ * @param {Object|String} value * @return {String} */ - getRecordRelatedContentMessage: function (value) { + getRecordRelatedContentMessage: function (value) { var usedInMessage = $.mage.__('This image is used in %s.'), usedIn = ''; @@ -55,7 +55,6 @@ define([ * @param {Object} record * @param {String} imageDetailsUrl * @param {String} deleteImageUrl - * @return {String} */ deleteImageAction: function (record, imageDetailsUrl, deleteImageUrl) { var confirmationContent = $.mage.__('%1 Are you sure you want to delete "%2" image?') From 728ccbbd1afaf35deeba8c750df49a3b1626a969 Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Fri, 12 Jun 2020 14:28:05 +0300 Subject: [PATCH 12/13] fixed eslint errors --- .../deleteImageWithDetailConfirmation.js | 53 ++++++++++--------- .../adminhtml/web/js/image/image-actions.js | 6 ++- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js index 007496126055..edbb6adde07a 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js +++ b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js @@ -4,13 +4,38 @@ */ define([ 'jquery', + 'underscore', 'Magento_MediaGalleryUi/js/action/getDetails', 'Magento_MediaGalleryUi/js/action/deleteImage' -], function ($, getDetails, deleteImage) { +], function ($, _, getDetails, deleteImage) { 'use strict'; return { + /** + * Get information about image use + * + * @param {Object} record + * @param {String} imageDetailsUrl + * @param {String} deleteImageUrl + */ + deleteImageAction: function (record, imageDetailsUrl, deleteImageUrl) { + var confirmationContent = $.mage.__('%1 Are you sure you want to delete "%2" image?') + .replace('%2', record.path); + + getDetails(imageDetailsUrl, record.id) + .then(function (imageDetails) { + confirmationContent = confirmationContent.replace( + '%1', + this.getConfirmationContentByImageDetails(imageDetails) + ); + }.bind(this)).fail(function () { + confirmationContent = confirmationContent.replace('%1', ''); + }).always(function () { + deleteImage.deleteImageAction(record, deleteImageUrl, confirmationContent); + }); + }, + /** * Returns confirmation content with information about related content * @@ -48,29 +73,5 @@ define([ return ''; }, - - /** - * Get information about image use - * - * @param {Object} record - * @param {String} imageDetailsUrl - * @param {String} deleteImageUrl - */ - deleteImageAction: function (record, imageDetailsUrl, deleteImageUrl) { - var confirmationContent = $.mage.__('%1 Are you sure you want to delete "%2" image?') - .replace('%2', record.path); - - getDetails(imageDetailsUrl, record.id) - .then(function (imageDetails) { - confirmationContent = confirmationContent.replace( - '%1', - this.getConfirmationContentByImageDetails(imageDetails) - ); - }.bind(this)).fail(function () { - confirmationContent = confirmationContent.replace('%1', ''); - }).always(function () { - deleteImage.deleteImageAction(record, deleteImageUrl, confirmationContent); - }); - } - } + }; }); diff --git a/MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js b/MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js index e8bd48107dce..67354b175ae5 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js +++ b/MediaGalleryUi/view/adminhtml/web/js/image/image-actions.js @@ -57,7 +57,11 @@ define([ var imageDetailsUrl = this.mediaGalleryImageDetails().imageDetailsUrl, deleteImageUrl = this.imageModel().deleteImageUrl; - deleteImageWithDetailConfirmation.deleteImageAction(this.imageModel().getSelected(), imageDetailsUrl, deleteImageUrl); + deleteImageWithDetailConfirmation.deleteImageAction( + this.imageModel().getSelected(), + imageDetailsUrl, + deleteImageUrl + ); }, /** From 5b1feebd83d7720e9f33ce452290fc85537ff634 Mon Sep 17 00:00:00 2001 From: "v.prokopov" Date: Fri, 12 Jun 2020 15:02:41 +0300 Subject: [PATCH 13/13] removed extra char --- .../web/js/action/deleteImageWithDetailConfirmation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js index edbb6adde07a..e399f5ae4180 100644 --- a/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js +++ b/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js @@ -72,6 +72,6 @@ define([ } return ''; - }, + } }; });