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

Introduce massaction mode for media gallery #1509

Merged
merged 31 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
afcefbc
Introduce massaction mod for media gallery
Nazar65 Jun 19, 2020
b56ac46
correct styles for checkbox component
Nazar65 Jun 19, 2020
21ef7b2
Correct border radius
Nazar65 Jun 19, 2020
bcc1d62
Improve slide panel gallery, fix mftf tests
Nazar65 Jun 19, 2020
a466964
Hide column from sort by component
Nazar65 Jun 20, 2020
d13f78b
Track selected items in checkbox component fix static tests
Nazar65 Jun 20, 2020
1cb1669
use single quotes
Nazar65 Jun 20, 2020
77d144f
Correct component configuration
Nazar65 Jun 20, 2020
2efa76f
Show count of selected items
Nazar65 Jun 22, 2020
b6012a9
Send request to delete selected item, rfactoring
Nazar65 Jun 22, 2020
79f2f0a
Typo fixes
Nazar65 Jun 22, 2020
af43e33
REfactor to better component dependency
Nazar65 Jun 22, 2020
e2bf315
Fix typo
Nazar65 Jun 22, 2020
abed1ce
fix statis tests
Nazar65 Jun 22, 2020
8b79c96
Activate mass action if at least one item selected, add cancel button
Nazar65 Jun 22, 2020
70a4b5b
Fix Mftf tests, correct typos
Nazar65 Jun 23, 2020
9cae153
Cover changes with mftf tests
Nazar65 Jun 23, 2020
c99d81a
fix typos
Nazar65 Jun 23, 2020
126926a
Merge branch '2.0-develop' of https://github.com/magento/adobe-stock-…
Nazar65 Jun 24, 2020
45f39a4
Remove checkbox component, use checkbox as part of image component
Nazar65 Jun 24, 2020
73ef8bc
Remove unused properties
Nazar65 Jun 24, 2020
bf11f6e
Add warning popup when there is no images selected for mass delete ac…
Nazar65 Jun 26, 2020
2b493fc
fix identation and typos
Nazar65 Jun 26, 2020
22aa8de
Merge branch '2.0-develop' into ASI-1488
lenaorobei Jun 26, 2020
f1a537a
Merge branch '2.0-develop' of https://github.com/magento/adobe-stock-…
Nazar65 Jun 30, 2020
d26103e
Display content usage information for multiple assets during multiple…
Nazar65 Jun 30, 2020
e7eeadb
Merge branch 'ASI-1488' of https://github.com/Nazar65/adobe-stock-int…
Nazar65 Jun 30, 2020
f9f507c
Move prefix generation of content usage to frontend
Nazar65 Jun 30, 2020
e549b8f
Refactoring fix mftf tests
Nazar65 Jun 30, 2020
adfedb7
Fix static tests
Nazar65 Jun 30, 2020
d9dc62a
fic static
Nazar65 Jun 30, 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
21 changes: 10 additions & 11 deletions AdobeStockImageAdminUi/Plugin/AddAdobeStockImageDetailsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,37 +87,36 @@ public function __construct(
*
* @param GetDetailsByAssetId $getImageDetailsByAssetId
* @param array $imageDetails
* @param int $assetId
* @param array $assetIds
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterExecute(
GetDetailsByAssetId $getImageDetailsByAssetId,
array $imageDetails,
int $assetId
array $assetIds
): array {
try {
$mediaGalleryIdFilter = $this->filterBuilder->setField(self::MEDIA_GALLERY_ID)
->setValue($assetId)
->create();
->setValue(implode(",", $assetIds))
->setConditionType('in')
->create();

$searchCriteria = $this->searchCriteriaBuilder
->addFilter($mediaGalleryIdFilter)
->setPageSize(1)
->create();

/** @var AssetSearchResultsInterface $result */
$result = $this->assetRepository->getList($searchCriteria);
$adobeStockInfo = [];
if ($result->getTotalCount() > 0) {
$item = $result->getItems();
/** @var AssetInterface $asset */
$asset = reset($item);
$adobeStockInfo = $this->loadAssetsInfo($asset);

foreach ($item as $asset) {
$imageDetails[$asset->getMediaGalleryId()]['adobe_stock'] = $this->loadAssetsInfo($asset);
}
}
$imageDetails['adobe_stock'] = $adobeStockInfo;
} catch (Exception $exception) {
$this->logger->critical($exception);
$imageDetails['adobe_stock'] = [];
}

return $imageDetails;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/
-->
<div class="adobe-stock-image-details image-details-section" if="$parent.image().adobe_stock.length">
<div class="adobe-stock-image-details image-details-section" if="$parent.image().adobe_stock">
<h3 data-bind="i18n: 'Adobe Stock'"></h3>
<div class="attributes">
<each args="$parent.image().adobe_stock">
Expand Down
24 changes: 15 additions & 9 deletions MediaGalleryUi/Controller/Adminhtml/Image/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public function execute()
{
/** @var Json $resultJson */
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$imageId = (int) $this->getRequest()->getParam('id');
$imageIds = $this->getRequest()->getParam('ids');

if ($imageId === 0) {
if (empty($imageIds) || !is_array($imageIds)) {
$responseContent = [
'success' => false,
'message' => __('Image ID is required.'),
'message' => __('Image Ids are required and must be of type array.'),
];
$resultJson->setHttpResponseCode(self::HTTP_BAD_REQUEST);
$resultJson->setData($responseContent);
Expand All @@ -99,14 +99,20 @@ public function execute()
}

try {
$assets = $this->getAssetsByIds->execute([$imageId]);
/** @var AssetInterface $asset */
$asset = current($assets);
$this->deleteImage->execute($asset);
$assets = $this->getAssetsByIds->execute($imageIds);
$this->deleteImage->execute($assets);
$responseCode = self::HTTP_OK;
$message = count($imageIds) > 1 ?
'assets have been' :
' asset "' . current($assets)->getTitle() . '" has been';
$responseContent = [
'success' => true,
'message' => __('You have successfully removed the image "%image"', ['image' => $asset->getTitle()]),
'message' => __(
'The %message successfully deleted',
[
'message' => $message
]
),
];
} catch (LocalizedException $exception) {
$responseCode = self::HTTP_BAD_REQUEST;
Expand All @@ -119,7 +125,7 @@ public function execute()
$responseCode = self::HTTP_INTERNAL_ERROR;
$responseContent = [
'success' => false,
'message' => __('An error occurred on attempt to save image.'),
'message' => __('An error occurred on attempt to delete image.'),
];
}

Expand Down
8 changes: 4 additions & 4 deletions MediaGalleryUi/Controller/Adminhtml/Image/Details.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public function execute()
{
/** @var Json $resultJson */
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$id = (int) $this->getRequest()->getParam('id');
$ids = $this->getRequest()->getParam('ids');

if ($id === 0) {
if (empty($ids) || !is_array($ids)) {
$responseContent = [
'success' => false,
'message' => __('Asset ID is required.'),
'message' => __('Assets Ids is required, and must be of type array.'),
];
$resultJson->setHttpResponseCode(self::HTTP_BAD_REQUEST);
$resultJson->setData($responseContent);
Expand All @@ -80,7 +80,7 @@ public function execute()
}

try {
$details = $this->getDetailsByAssetId->execute($id);
$details = $this->getDetailsByAssetId->execute($ids);

$responseCode = self::HTTP_OK;
$responseContent = [
Expand Down
6 changes: 2 additions & 4 deletions MediaGalleryUi/Model/AssetDetailsProvider/UsedIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,14 @@ private function getUsedIn(int $assetId): array
foreach ($contentIdentities as $contentIdentity) {
$entityId = $contentIdentity->getEntityId();
$type = $this->contentTypes[$contentIdentity->getEntityType()] ?? $contentIdentity->getEntityType();
$singleType = $this->contentTypes[$contentIdentity->getEntityType() . '_single'] ?? $type;

if (!isset($entityIds[$type])) {
$usedIn[$singleType] = 1;
$usedIn[$type] = 1;
} elseif ($entityIds[$type]['entity_id'] !== $entityId) {
if (isset($usedIn[$type])) {
$usedIn[$type] +=1;
} else {
$usedIn[$type] = $usedIn[$singleType]+1;
unset($usedIn[$singleType]);
$usedIn[$type] = $usedIn[$type]+1;
}
}
$entityIds[$type]['entity_id'] = $entityId;
Expand Down
28 changes: 19 additions & 9 deletions MediaGalleryUi/Model/DeleteImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,27 @@ public function __construct(
*
* @see \Magento\MediaGallery\Plugin\Wysiwyg\Images\Storage
*
* @param AssetInterface $asset
* @throws LocalizedException
* @param AssetInterface[] $assets
*/
public function execute(AssetInterface $asset): void
public function execute(array $assets): void
{
if ($this->isPathExcluded->execute($asset->getPath())) {
throw new LocalizedException(__('Could not delete image: destination directory is restricted.'));
}
$failedAssets = [];
foreach ($assets as $asset) {
if ($this->isPathExcluded->execute($asset->getPath())) {
$failedAssets[] = $asset->getPath();
}

$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$absolutePath = $mediaDirectory->getAbsolutePath($asset->getPath());
$this->imagesStorage->deleteFile($absolutePath);
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$absolutePath = $mediaDirectory->getAbsolutePath($asset->getPath());
$this->imagesStorage->deleteFile($absolutePath);
}
if (!empty($failedAssets)) {
throw new LocalizedException(
__(
'Could not delete "%image": destination directory is restricted.',
['image' => implode(",", $failedAssets)]
)
);
}
}
}
44 changes: 25 additions & 19 deletions MediaGalleryUi/Model/GetDetailsByAssetId.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GetDetailsByAssetId
/**
* @var GetAssetsByIdsInterface
*/
private $getAssetById;
private $getAssetsById;

/**
* @var StoreManagerInterface
Expand Down Expand Up @@ -63,36 +63,42 @@ public function __construct(
GetAssetsKeywordsInterface $getAssetKeywords
) {
$this->detailsProviderPool = $detailsProviderPool;
$this->getAssetById = $getAssetById;
$this->getAssetsById = $getAssetById;
$this->storeManager = $storeManager;
$this->sourceIconProvider = $sourceIconProvider;
$this->getAssetKeywords = $getAssetKeywords;
}

/**
* Get image details by asset ID
* Get image details by assets Ids
*
* @param int $assetId
* @param array $assetIds
* @throws LocalizedException
* @throws Exception
* @return array
*/
public function execute(int $assetId): array
public function execute(array $assetIds): array
{
$asset = current($this->getAssetById->execute([$assetId]));

return [
'image_url' => $this->getUrl($asset->getPath()),
'title' => $asset->getTitle(),
'path' => $asset->getPath(),
'description' => $asset->getDescription(),
'id' => $assetId,
'details' => $this->detailsProviderPool->execute($asset),
'size' => $asset->getSize(),
'tags' => $this->getKeywords($asset),
'source' => $asset->getSource() ? $this->sourceIconProvider->getSourceIconUrl($asset->getSource()) : null,
'content_type' => strtoupper(str_replace('image/', '', $asset->getContentType())),
];
$assets = $this->getAssetsById->execute($assetIds);

$details = [];
foreach ($assets as $asset) {
$details[$asset->getId()] = [
'image_url' => $this->getUrl($asset->getPath()),
'title' => $asset->getTitle(),
'path' => $asset->getPath(),
'description' => $asset->getDescription(),
'id' => $asset->getId(),
'details' => $this->detailsProviderPool->execute($asset),
'size' => $asset->getSize(),
'tags' => $this->getKeywords($asset),
'source' => $asset->getSource() ?
$this->sourceIconProvider->getSourceIconUrl($asset->getSource()) :
null,
'content_type' => strtoupper(str_replace('image/', '', $asset->getContentType())),
];
}
return $details;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminEnhancedMediaGalleryAssertImagesDeletedInBulkActionGroup">
<annotations>
<description>Asserts images has been deleted in mass action.</description>
</annotations>

<see userInput='The assets have been successfully deleted' stepKey="verifyDeleteImages"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminEnhancedMediaGalleryAssertMassActionModeDetailsActionGroup">
<annotations>
<description>Asserts that massaction mode can be enabled and disabled, verify massaction view after switch to massaction mode</description>
</annotations>
<arguments>
<argument name="imageName" type="string"/>
</arguments>
<click selector="{{AdminEnhancedMediaGalleryMassActionSection.massActionCheckbox(imageName)}}" stepKey="selectImageInGridToDelte"/>
<see selector="{{AdminEnhancedMediaGalleryMassActionSection.totalSelected}}" userInput="(1 Selected)" stepKey="verifySelectedCount"/>
<click selector="{{AdminEnhancedMediaGalleryMassActionSection.cancelMassActionMode}}" stepKey="cancelMassAction"/>
<dontSeeElement selector="{{AdminEnhancedMediaGalleryMassActionSection.totalSelected}}" stepKey="verifyTeminateMAssAction"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminEnhancedMediaGalleryEnableMassActionModeActionGroup">
<annotations>
<description>Activate massaction mode by click on Delete Selected..</description>
</annotations>

<click selector="{{AdminEnhancedMediaGalleryMassActionSection.deleteSelected}}" stepKey="clickOnMassActionButton"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminEnhancedMediaGalleryImageDeleteImagesInBulkActionGroup">
<annotations>
<description>Delete images in bulk using mass action mode.</description>
</annotations>
<arguments>
<argument name="imageName" type="string" defaultValue="magento"/>
</arguments>

<click selector="{{AdminEnhancedMediaGalleryMassActionSection.deleteSelected}}" stepKey="clickDeleteImages"/>
<waitForLoadingMaskToDisappear stepKey="waitForDeleteModal"/>
<click selector="{{AdminEnhancedMediaGalleryDeleteModalSection.confirmDelete}}" stepKey="confirmDelete"/>
<waitForLoadingMaskToDisappear stepKey="waitForDeletingProcces"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminEnhancedMediaGallerySelectImageForMassActionActionGroup">
<annotations>
<description>Select images in grid by clicking on mass action checkbox</description>
</annotations>
<arguments>
<argument name="imageName" type="string" defaultValue="magento"/>
</arguments>

<click selector="{{AdminEnhancedMediaGalleryMassActionSection.massActionCheckbox(imageName)}}" stepKey="selectImageInGridToDelte"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<arguments>
<argument name="imageName" type="string" defaultValue="magento"/>
</arguments>
<see userInput='You have successfully removed the image "{{imageName}}"' stepKey="verifyDeleteImage"/>
<see userInput='The asset "{{imageName}}" has been successfully deleted' stepKey="verifyDeleteImage"/>
<dontSeeElement selector="{{AdminEnhancedMediaGalleryImageActionsSection.imageInGrid(imageName)}}" stepKey="dontSeeImage"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminEnhancedMediaGalleryMassActionSection">
<element name="massActionCheckbox" type="button" selector="//input[@type='checkbox'][@data-ui-id ='{{imageName}}']" parameterized="true"/>
<element name="totalSelected" type="text" selector=".mediagallery-massaction-items-count > .selected_count_text"/>
<element name="cancelMassActionMode" type="button" selector="#cancel_massaction"/>
<element name="deleteSelected" type="button" selector="#delete_massaction"/>
</section>
</sections>
Loading