Skip to content

Commit

Permalink
EZP-29408: As an editor I want to delete a content item with an image…
Browse files Browse the repository at this point in the history
… asset field (#591)

* EZP-29408: As an editor I want to delete a content item with an image asset field

* EZP-29408: As an editor I want to delete a content item with an image asset field

* EZP-29408: Updated modals design

* EZP-29408: changed when form options are build + CR fixes

* fixup! EZP-29408: changed when form options are build + CR fixes

* fixup! EZP-29408: changed when form options are build + CR fixes
  • Loading branch information
ViniTou authored and Łukasz Serwatka committed Sep 28, 2018
1 parent 57eaab8 commit 578226c
Show file tree
Hide file tree
Showing 21 changed files with 816 additions and 18 deletions.
32 changes: 31 additions & 1 deletion src/bundle/Controller/ContentViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace EzSystems\EzPlatformAdminUiBundle\Controller;

use eZ\Publish\API\Repository\BookmarkService;
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\LanguageService;
use eZ\Publish\API\Repository\Values\Content\Location;
Expand All @@ -20,9 +21,12 @@
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationCopySubtreeData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationMoveData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashWithAssetData;
use EzSystems\EzPlatformAdminUi\Form\Data\User\UserDeleteData;
use EzSystems\EzPlatformAdminUi\Form\Data\User\UserEditData;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Specification\Content\ContentHaveAssetRelation;
use EzSystems\EzPlatformAdminUi\Specification\Content\ContentHaveUniqueRelation;
use EzSystems\EzPlatformAdminUi\Specification\ContentIsUser;
use EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ContentViewParameterSupplier as SubitemsContentViewParameterSupplier;
use EzSystems\EzPlatformAdminUi\UI\Service\PathService;
Expand Down Expand Up @@ -69,6 +73,9 @@ class ContentViewController extends Controller
/** @var int */
private $defaultCustomUrlPaginationLimit;

/** @var \eZ\Publish\API\Repository\ContentService */
private $contentService;

/**
* @param \eZ\Publish\API\Repository\ContentTypeService $contentTypeService
* @param \eZ\Publish\API\Repository\LanguageService $languageService
Expand All @@ -77,6 +84,7 @@ class ContentViewController extends Controller
* @param \EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ContentViewParameterSupplier $subitemsContentViewParameterSupplier
* @param \eZ\Publish\API\Repository\UserService $userService
* @param \eZ\Publish\API\Repository\BookmarkService $bookmarkService
* @param \eZ\Publish\API\Repository\ContentService $contentService
* @param int $defaultDraftPaginationLimit
* @param array $siteAccessLanguages
* @param int $defaultRolePaginationLimit
Expand All @@ -92,6 +100,7 @@ public function __construct(
SubitemsContentViewParameterSupplier $subitemsContentViewParameterSupplier,
UserService $userService,
BookmarkService $bookmarkService,
ContentService $contentService,
int $defaultDraftPaginationLimit,
array $siteAccessLanguages,
int $defaultRolePaginationLimit,
Expand All @@ -112,6 +121,7 @@ public function __construct(
$this->defaultPolicyPaginationLimit = $defaultPolicyPaginationLimit;
$this->defaultSystemUrlPaginationLimit = $defaultSystemUrlPaginationLimit;
$this->defaultCustomUrlPaginationLimit = $defaultCustomUrlPaginationLimit;
$this->contentService = $contentService;
}

/**
Expand Down Expand Up @@ -230,7 +240,27 @@ private function supplyContentActionForms(ContentView $view): void
'form_location_copy_subtree' => $locationCopySubtreeType->createView(),
]);

if ((new ContentIsUser($this->userService))->isSatisfiedBy($content)) {
$contentHaveAssetRelation = new ContentHaveAssetRelation($this->contentService);
if ($contentHaveAssetRelation
->and(new ContentHaveUniqueRelation($this->contentService))
->isSatisfiedBy($content)
) {
$trashWithAssetType = $this->formFactory->trashLocationWithAsset(
new LocationTrashWithAssetData($location)
);

$view->addParameters([
'form_location_trash_with_single_asset' => $trashWithAssetType->createView(),
]);
} elseif ($contentHaveAssetRelation->isSatisfiedBy($content)) {
$locationTrashType = $this->formFactory->trashLocation(
new LocationTrashData($location)
);

$view->addParameters([
'form_location_trash_with_asset' => $locationTrashType->createView(),
]);
} elseif ((new ContentIsUser($this->userService))->isSatisfiedBy($content)) {
$userDeleteType = $this->formFactory->deleteUser(
new UserDeleteData($content->contentInfo)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUiBundle\Controller\Location;

use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\TrashService;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashWithAssetData;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Form\SubmitHandler;
use EzSystems\EzPlatformAdminUi\Form\Type\Location\LocationTrashWithAssetType;
use EzSystems\EzPlatformAdminUiBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class TrashLocationWithAssetController extends Controller
{
/** @var \EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory */
private $formFactory;

/** @var \EzSystems\EzPlatformAdminUi\Form\SubmitHandler */
private $submitHandler;

/** @var \eZ\Publish\API\Repository\LocationService */
private $locationService;

/** @var \eZ\Publish\API\Repository\ContentService */
private $contentService;

/** @var \eZ\Publish\API\Repository\TrashService */
private $trashService;

/**
* @param \EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory $formFactory
* @param \EzSystems\EzPlatformAdminUi\Form\SubmitHandler $submitHandler
* @param \eZ\Publish\API\Repository\LocationService $locationService
* @param \eZ\Publish\API\Repository\ContentService $contentService
* @param \eZ\Publish\API\Repository\TrashService $trashService
*/
public function __construct(
FormFactory $formFactory,
SubmitHandler $submitHandler,
LocationService $locationService,
ContentService $contentService,
TrashService $trashService
) {
$this->formFactory = $formFactory;
$this->submitHandler = $submitHandler;
$this->trashService = $trashService;
$this->locationService = $locationService;
$this->contentService = $contentService;
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
public function trashAction(Request $request): Response
{
$form = $this->formFactory->trashLocationWithAsset(
new LocationTrashWithAssetData()
);
$form->handleRequest($request);

if ($form->isSubmitted()) {
$result = $this->submitHandler->handle($form, function (LocationTrashWithAssetData $data) {
$location = $data->getLocation();
$parentLocation = $this->locationService->loadLocation($location->parentLocationId);
if ($data->getTrashAssets() === LocationTrashWithAssetType::RADIO_SELECT_TRASH_WITH_ASSETS) {
$content = $this->contentService->loadContentByContentInfo($location->contentInfo);
$relations = $this->contentService->loadRelations($content->versionInfo);
$imageLocation = $this->locationService->loadLocation($relations[0]->destinationContentInfo->mainLocationId);
$this->trashService->trash($imageLocation);
}

$this->trashService->trash($location);

return $this->redirectToLocation($parentLocation);
});

if ($result instanceof Response) {
return $result;
}
}

return $this->redirect($this->generateUrl('ezplatform.trash.list'));
}
}
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ ezplatform.location.copy_subtree:
defaults:
_controller: 'EzPlatformAdminUiBundle:Location:copySubtree'

ezplatform.location.trash_with_asset:
path: /location/trash-with-asset
methods: ['POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:Location\TrashLocationWithAsset:trash'

# LocationView / Translation tab

ezplatform.translation.add:
Expand Down
1 change: 0 additions & 1 deletion src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ services:

EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory: ~


EzSystems\EzPlatformAdminUi\Notification\FlashBagNotificationHandler: ~

EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface: '@EzSystems\EzPlatformAdminUi\Notification\FlashBagNotificationHandler'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function (global, doc) {
const toggleForms = [...doc.querySelectorAll('.ez-toggle-btn-state-radio')];

toggleForms.forEach((toggleForm) => {
const radioInputs = [...toggleForm.querySelectorAll('input[type="radio"]')];
const toggleButtonState = () => {
const button = doc.querySelector(toggleForm.dataset.toggleButtonId);
const oneIsSelected = radioInputs.some(el => el.checked);

if (oneIsSelected) {
button['removeAttribute']('disabled', true);
}
};

radioInputs.forEach(radioInput => radioInput.addEventListener('change', toggleButtonState, false));
});
})(window, document);
19 changes: 14 additions & 5 deletions src/bundle/Resources/public/scss/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,27 @@
}
}

.ez-modal--trash-with-asset {
.modal-footer {
.btn-secondary {
background-color: $ez-color-base-medium;
border-color: $ez-color-base-medium;

&:hover {
background-color: $ez-color-base-medium-hover;
border-color: $ez-color-base-medium-hover;
}
}
}
}

.ez-content-view,
.ez-trash-list-view {
.ez-modal--send-to-trash {
.modal-footer {
.form-check-inline {
margin-right: 0;

.btn {
font-size: 1rem;
padding-bottom: .5rem;
}

.btn-danger {
margin-right: 0;
}
Expand Down
6 changes: 6 additions & 0 deletions src/bundle/Resources/public/scss/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ form:not(.form-inline) {
color: $ez-color-danger;
}
}

.ez-trash-with-asset-checkbox-list {
.form-check-input {
position: absolute;
}
}
47 changes: 47 additions & 0 deletions src/bundle/Resources/public/scss/_modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,50 @@
}
}
}

.ez-modal--trash-with-asset {
.modal-dialog {
max-width: calculateRem(800px);
}

.modal-header {
background: $ez-color-base-pale;
border-bottom: none;

.modal-title {
font-size: calculateRem(24px);
}

.close {
margin-top: calculateRem(-9px);
}
}

.modal-body {
padding: calculateRem(32px);
background-color: $ez-ground-base-medium;
border-radius: 0 0 calculateRem(4px) calculateRem(4px);

.ez-modal-body__main {
margin-bottom: calculateRem(24px);

.ez-modal-body__main-content {
margin-bottom: 0;
}
}

.ez-table-header,
.ez-table__draft-conflict {
margin-bottom: 0;
}

.form-check {
margin-bottom: 0;
margin-left: calculateRem(50px);
}
}

.modal-footer {
justify-content: center;
}
}
10 changes: 10 additions & 0 deletions src/bundle/Resources/translations/forms.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,21 @@
<target state="new">Move</target>
<note>key: location_move.move</note>
</trans-unit>
<trans-unit id="4b7b2b4de853db0d1fb1851e07f3ccc51e5713fc" resname="location_trash_form.default_trash">
<source>Delete only %content_name% (%content_type%)</source>
<target state="new">Delete only %content_name% (%content_type%)</target>
<note>key: location_trash_form.default_trash</note>
</trans-unit>
<trans-unit id="796f8196b2bc086fe788e6689a6189c79b8e047e" resname="location_trash_form.trash">
<source>Send to Trash</source>
<target state="new">Send to Trash</target>
<note>key: location_trash_form.trash</note>
</trans-unit>
<trans-unit id="2598fe0050f38f3c02014a404ed14aee248e27d1" resname="location_trash_form.trash_with_asset">
<source>Delete %content_name% (%content_type%) and its related image assets</source>
<target state="new">Delete %content_name% (%content_type%) and its related image assets</target>
<note>key: location_trash_form.trash_with_asset</note>
</trans-unit>
<trans-unit id="f86cd366867d370b0706e250355f605e2b783229" resname="policies_delete_form.delete">
<source>Delete policies</source>
<target state="new">Delete policies</target>
Expand Down
25 changes: 25 additions & 0 deletions src/bundle/Resources/translations/messages.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,31 @@
<target state="new">Are you sure you want to send this content item to trash?</target>
<note>key: trash.modal.message</note>
</trans-unit>
<trans-unit id="bd97a738137e75de44544db1104bab3a46222791" resname="trash_asset.modal.message_body">
<source>If you wish to delete this(/these) asset(s) too, first make sure they are not used by other content. You can check these content going to the asset(s) and looking at their content relations in the Relation tab.</source>
<target state="new">If you wish to delete this(/these) asset(s) too, first make sure they are not used by other content. You can check these content going to the asset(s) and looking at their content relations in the Relation tab.</target>
<note>key: trash_asset.modal.message_body</note>
</trans-unit>
<trans-unit id="17c7abad79d72d771a25b064e0de38b72fc6c926" resname="trash_asset.modal.message_header">
<source>You are about to delete a content that has one or several asset(s) field(s) used by other content items. These assets will remain available in system.</source>
<target state="new">You are about to delete a content that has one or several asset(s) field(s) used by other content items. These assets will remain available in system.</target>
<note>key: trash_asset.modal.message_header</note>
</trans-unit>
<trans-unit id="0d57f9b91203aa4d9920e63d793b8e62c0bb242c" resname="trash_asset_single.modal.header">
<source>Deleting content</source>
<target state="new">Deleting content</target>
<note>key: trash_asset_single.modal.header</note>
</trans-unit>
<trans-unit id="e81a14f38ebe272cb11ef90e2948a8c6602307ca" resname="trash_asset_single.modal.message">
<source>You have the option to delete %content_name% (%content_type%) only or to also delete the assets it is using. Make your choice:</source>
<target state="new">You have the option to delete %content_name% (%content_type%) only or to also delete the assets it is using. Make your choice:</target>
<note>key: trash_asset_single.modal.message</note>
</trans-unit>
<trans-unit id="ff537a1e092270edf7497dc13ce051cdb458958b" resname="trash_asset_single.modal.message_main">
<source>You are about to delete a content with one or several asset(s) field(s).</source>
<target state="new">You are about to delete a content with one or several asset(s) field(s).</target>
<note>key: trash_asset_single.modal.message_main</note>
</trans-unit>
</body>
</file>
</xliff>
12 changes: 12 additions & 0 deletions src/bundle/Resources/views/content/locationview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@
{% if form_user_delete is defined %}
{% include '@ezdesign/content/modal_user_delete.html.twig' with {'form': form_user_delete} only %}
{% endif %}
{% if form_location_trash_with_asset is defined %}
{% include '@ezdesign/content/modal_location_trash_with_asset.html.twig' with {
'form': form_location_trash_with_asset
} only %}
{% endif %}
{% if form_location_trash_with_single_asset is defined %}
{% include '@ezdesign/content/modal_location_trash_with_single_asset.html.twig' with {
'form': form_location_trash_with_single_asset,
'content_name': content.name,
'content_type': contentType.name
} only %}
{% endif %}
{{ form(form_location_copy, {'action': path('ezplatform.location.copy')}) }}
{{ form(form_location_move, {'action': path('ezplatform.location.move')}) }}
{{ form(form_location_copy_subtree, {'action': path('ezplatform.location.copy_subtree')}) }}
Expand Down
Loading

0 comments on commit 578226c

Please sign in to comment.