Skip to content

#1390 Add related content information to the delete asset warning #1401

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

Merged
merged 21 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
84eae32
Add related content information to the delete asset warning
ProkopovVitaliy May 29, 2020
e7889e5
corrected message text
ProkopovVitaliy May 30, 2020
f17ecca
Merge branch '2.0.0-stabilization' into #1390
ProkopovVitaliy May 30, 2020
3b0cd3c
changed message for delete confirmation
ProkopovVitaliy Jun 1, 2020
eedc6ab
Merge branch '#1390' of github.com:ProkopovVitaliy/adobe-stock-integr…
ProkopovVitaliy Jun 1, 2020
ee31084
Merge branch '2.0.0-stabilization' into #1390
ProkopovVitaliy Jun 1, 2020
3a1c9d1
Update Provider.php
ProkopovVitaliy Jun 1, 2020
41a0c4a
corrected static test
ProkopovVitaliy Jun 1, 2020
ff3dd10
Merge branch '#1390' of github.com:ProkopovVitaliy/adobe-stock-integr…
ProkopovVitaliy Jun 1, 2020
18fecea
processing of additional information for the removal process has been…
ProkopovVitaliy Jun 9, 2020
2d7b00f
Merge branch '2.0-develop' into #1390
ProkopovVitaliy Jun 9, 2020
1ac1e12
Update MediaGalleryUi/Ui/Component/Listing/Provider.php
ProkopovVitaliy Jun 10, 2020
7243241
apply code review recommendations
ProkopovVitaliy Jun 10, 2020
b94408d
Merge branch '2.0-develop' into #1390
ProkopovVitaliy Jun 10, 2020
fa88116
fixed failed static test
ProkopovVitaliy Jun 10, 2020
167d92e
Merge branch '#1390' of github.com:ProkopovVitaliy/adobe-stock-integr…
ProkopovVitaliy Jun 10, 2020
05443d7
fixed confirmation message for deleting ffrom detail window
ProkopovVitaliy Jun 11, 2020
48d3a3e
fixed code style
ProkopovVitaliy Jun 11, 2020
c7e80a4
Merge branch '2.0-develop' into #1390
ProkopovVitaliy Jun 11, 2020
728ccbb
fixed eslint errors
ProkopovVitaliy Jun 12, 2020
5b1feeb
removed extra char
ProkopovVitaliy Jun 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions MediaGalleryUi/Ui/Component/Listing/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,25 +27,40 @@ class Provider extends SearchResult
* @var GetAssetsKeywordsInterface
*/
private $getAssetKeywords;

/**
* @var GetAssetsByIdsInterface
*/
private $getAssetsByIds;

/**
* @var UsedIn
*/
private $usedIn;

/**
* @param EntityFactory $entityFactory
* @param Logger $logger
* @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
* @param null|string $connectionName
* @throws LocalizedException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
EntityFactory $entityFactory,
Logger $logger,
FetchStrategy $fetchStrategy,
EventManager $eventManager,
GetAssetsKeywordsInterface $getAssetKeywords,
GetAssetsByIdsInterface $getAssetsByIds,
UsedIn $usedIn,
$mainTable = 'media_gallery_asset',
$resourceModel = null,
$identifierName = null,
Expand All @@ -58,6 +77,8 @@ public function __construct(
$connectionName
);
$this->getAssetKeywords = $getAssetKeywords;
$this->getAssetsByIds = $getAssetsByIds;
$this->usedIn = $usedIn;
}

/**
Expand All @@ -77,12 +98,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]['relatedContent'] = $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]) : [];
}
}
39 changes: 37 additions & 2 deletions MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.relatedContent),
title = $.mage.__('Delete image'),
cancelText = $.mage.__('Cancel'),
deleteImageText = $.mage.__('Delete Image'),
Expand All @@ -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,
Expand Down Expand Up @@ -58,6 +58,41 @@ 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
*
Expand Down