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

EZP-29089: Usability bug when deleting containers #704

Merged
merged 1 commit into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 27 additions & 4 deletions src/bundle/Controller/ContentViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\LanguageService;
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
Expand All @@ -25,16 +26,19 @@
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\Location\LocationTrashContainerData;
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\Specification\Location\HasChildren;
use EzSystems\EzPlatformAdminUi\Specification\Location\IsContainer;
use EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ContentViewParameterSupplier as SubitemsContentViewParameterSupplier;
use EzSystems\EzPlatformAdminUi\UI\Service\PathService;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Form;

class ContentViewController extends Controller
{
Expand Down Expand Up @@ -80,6 +84,9 @@ class ContentViewController extends Controller
/** @var \eZ\Publish\API\Repository\ContentService */
private $contentService;

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

/**
* @param \eZ\Publish\API\Repository\ContentTypeService $contentTypeService
* @param \eZ\Publish\API\Repository\LanguageService $languageService
Expand All @@ -89,6 +96,7 @@ class ContentViewController extends Controller
* @param \eZ\Publish\API\Repository\UserService $userService
* @param \eZ\Publish\API\Repository\BookmarkService $bookmarkService
* @param \eZ\Publish\API\Repository\ContentService $contentService
* @param \eZ\Publish\API\Repository\LocationService $locationService
* @param int $defaultDraftPaginationLimit
* @param array $siteAccessLanguages
* @param int $defaultRolePaginationLimit
Expand All @@ -105,6 +113,7 @@ public function __construct(
UserService $userService,
BookmarkService $bookmarkService,
ContentService $contentService,
LocationService $locationService,
int $defaultDraftPaginationLimit,
array $siteAccessLanguages,
int $defaultRolePaginationLimit,
Expand All @@ -119,13 +128,14 @@ public function __construct(
$this->subitemsContentViewParameterSupplier = $subitemsContentViewParameterSupplier;
$this->userService = $userService;
$this->bookmarkService = $bookmarkService;
$this->contentService = $contentService;
$this->locationService = $locationService;
$this->defaultDraftPaginationLimit = $defaultDraftPaginationLimit;
$this->siteAccessLanguages = $siteAccessLanguages;
$this->defaultRolePaginationLimit = $defaultRolePaginationLimit;
$this->defaultPolicyPaginationLimit = $defaultPolicyPaginationLimit;
$this->defaultSystemUrlPaginationLimit = $defaultSystemUrlPaginationLimit;
$this->defaultCustomUrlPaginationLimit = $defaultCustomUrlPaginationLimit;
$this->contentService = $contentService;
}

/**
Expand Down Expand Up @@ -245,6 +255,7 @@ private function supplyContentActionForms(ContentView $view): void
]);

$contentHaveAssetRelation = new ContentHaveAssetRelation($this->contentService);

if ($contentHaveAssetRelation
->and(new ContentHaveUniqueRelation($this->contentService))
->isSatisfiedBy($content)
Expand Down Expand Up @@ -291,6 +302,18 @@ private function supplyContentActionForms(ContentView $view): void
'form_content_edit' => $contentEditType->createView(),
]);
}

$isContainer = new IsContainer($this->contentTypeService);
$hasChildren = new HasChildren($this->locationService);

if ($isContainer->and($hasChildren)->isSatisfiedBy($location)) {
$trashLocationContainerForm = $this->formFactory->trashContainerLocation(
new LocationTrashContainerData($location)
);
$view->addParameters([
'form_location_trash_container' => $trashLocationContainerForm->createView(),
]);
}
}

/**
Expand All @@ -299,14 +322,14 @@ private function supplyContentActionForms(ContentView $view): void
* @param \eZ\Publish\API\Repository\Values\Content\Language|null $language
* @param \eZ\Publish\API\Repository\Values\Content\Location|null $location
*
* @return \EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentEditData
* @return \Symfony\Component\Form\FormInterface
*/
private function createContentEditForm(
?ContentInfo $contentInfo = null,
?VersionInfo $versionInfo = null,
?Language $language = null,
?Location $location = null
): Form {
): FormInterface {
return $this->formFactory->contentEdit(
new ContentEditData($contentInfo, $versionInfo, $language, $location)
);
Expand Down
69 changes: 55 additions & 14 deletions src/bundle/Controller/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationCopySubtreeData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationMoveData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationSwapData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashContainerData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashData;
use EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationUpdateData;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
Expand Down Expand Up @@ -327,26 +328,38 @@ public function trashAction(Request $request): Response
$form = $this->formFactory->trashLocation(
new LocationTrashData()
);

$form->handleRequest($request);

if ($form->isSubmitted()) {
$result = $this->submitHandler->handle($form, function (LocationTrashData $data) {
$location = $data->getLocation();
$parentLocation = $this->locationService->loadLocation($location->parentLocationId);
$this->trashService->trash($location);
return $this->handleTrashLocationForm($data);
});

$this->notificationHandler->success(
$this->translator->trans(
/** @Desc("Location '%name%' moved to trash.") */
'location.trash.success',
['%name%' => $location->getContentInfo()->name],
'location'
)
);
if ($result instanceof Response) {
return $result;
}
}

return new RedirectResponse($this->generateUrl('_ezpublishLocation', [
'locationId' => $parentLocation->id,
]));
return $this->redirect($this->generateUrl('ezplatform.trash.list'));
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function trashContainerAction(Request $request): Response
{
$form = $this->formFactory->trashContainerLocation(
new LocationTrashContainerData()
);

$form->handleRequest($request);

if ($form->isSubmitted()) {
$result = $this->submitHandler->handle($form, function (LocationTrashContainerData $data) {
return $this->handleTrashLocationForm($data);
});

if ($result instanceof Response) {
Expand All @@ -357,6 +370,34 @@ public function trashAction(Request $request): Response
return $this->redirect($this->generateUrl('ezplatform.trash.list'));
}

/**
* @param \EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashData|\EzSystems\EzPlatformAdminUi\Form\Data\Location\LocationTrashContainerData $data
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
private function handleTrashLocationForm($data): RedirectResponse
{
$location = $data->getLocation();
$parentLocation = $this->locationService->loadLocation($location->parentLocationId);
$this->trashService->trash($location);

$this->notificationHandler->success(
$this->translator->trans(
/** @Desc("Location '%name%' moved to trash.") */
'location.trash.success',
['%name%' => $location->getContentInfo()->name],
'location'
)
);

return new RedirectResponse($this->generateUrl('_ezpublishLocation', [
'locationId' => $parentLocation->id,
]));
}

/**
* Handles removing locations assigned to content item based on submitted form.
*
Expand Down
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ ezplatform.location.trash:
defaults:
_controller: 'EzPlatformAdminUiBundle:Location:trash'

ezplatform.location.trash_container:
path: /location/trash_container
methods: ['POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:Location:trashContainer'

ezplatform.location.update:
path: /location/update
methods: ['POST']
Expand Down
18 changes: 18 additions & 0 deletions src/bundle/Resources/public/js/scripts/admin.trash.container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function (global, doc) {
const toggleForm = doc.querySelector('form[name="location_trash_container"]');
const hasAsset = toggleForm.dataset.hasAsset;
const hasUniqueAsset = toggleForm.dataset.hasUniqueAsset;

const openTrashImageAssetModal = (event) => {
if (!hasAsset && !hasUniqueAsset) {
return;
}

event.preventDefault();
ViniTou marked this conversation as resolved.
Show resolved Hide resolved

$('#trash-container-modal').modal('hide');
$('#trash-with-asset-modal').modal('show');
};

toggleForm.addEventListener('submit', openTrashImageAssetModal, false);
})(window, document);
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(function (global, doc) {
const toggleForms = doc.querySelectorAll('.ez-toggle-btn-state-checkbox');
const ALL_CHECKED = 'all-checked';
const ANY_CHECKED = 'any-checked';

const toggleButtonState = (button, validateCheckboxStatus) => {
let methodName = 'setAttribute';

if (validateCheckboxStatus()) {
methodName = 'removeAttribute';
}

button[methodName]('disabled', true);
};

toggleForms.forEach((toggleForm) => {
const checkboxInputs = [...toggleForm.querySelectorAll('input[type="checkbox"]')];
const button = doc.querySelector(toggleForm.dataset.toggleButtonId);
const toggleMode = toggleForm.dataset.toggleMode || ANY_CHECKED;
const validateCheckboxStatus = () =>
(checkboxInputs.some(el => el.checked) && ALL_CHECKED === toggleMode) ||
(checkboxInputs.every(el => el.checked) && ANY_CHECKED === toggleMode);

checkboxInputs.forEach(input =>
input.addEventListener('change', toggleButtonState.bind(input, button, validateCheckboxStatus), false)
);
});
})(window, document);
3 changes: 2 additions & 1 deletion src/bundle/Resources/public/scss/_modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@
}
}

.ez-modal--trash-with-asset {
.ez-modal--trash-with-asset,
.ez-modal--trash-container {
.modal-dialog {
max-width: calculateRem(800px);
}
Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/translations/forms.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@
<target state="new">Send to Trash</target>
<note>key: location_trash_form.trash</note>
</trans-unit>
<trans-unit id="f9887d04de58202b07207b1521880373c00c8201" resname="location_trash_form.trash_container">
<source>%children_count% content items under location %content_name%</source>
<target state="new">%children_count% content items under location %content_name%</target>
<note>key: location_trash_form.trash_container</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>
Expand Down
10 changes: 10 additions & 0 deletions src/bundle/Resources/translations/messages.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@
<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>
<trans-unit id="a70d984d62d43229009fefdbfdc740199ede75ca" resname="trash_container.modal.header">
<source>Deleting content</source>
<target state="new">Deleting content</target>
<note>key: trash_container.modal.header</note>
</trans-unit>
<trans-unit id="1e6a1d97cca01a288e47d2d14479274b90e6c6c1" resname="trash_container.modal.message_main">
<source>Deleting %content_name% will also delete its sub-items, under its location(s). To confirm, please check below</source>
<target state="new">Deleting %content_name% will also delete its sub-items, under its location(s). To confirm, please check below</target>
<note>key: trash_container.modal.message_main</note>
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/bundle/Resources/translations/validators.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<target state="new">Selected Location have assets that can't be removed.</target>
<note>key: ezplatform.trash.have_used_assets</note>
</trans-unit>
<trans-unit id="50f88ff616406e9f9474c6f78937aadb1303868e" resname="ezplatform.trash.location_has_no_children">
<source>Selected Location has no children locations.</source>
<target state="new">Selected Location has no children locations.</target>
<note>key: ezplatform.trash.location_has_no_children</note>
</trans-unit>
<trans-unit id="cf558f546b83d94f1272929f81c64bd33d2997bc" resname="js.error.address_not_found">
<source>Provided address does not exist</source>
<target state="new">Provided address does not exist</target>
Expand Down
10 changes: 9 additions & 1 deletion src/bundle/Resources/views/content/locationview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
{% endif %}
</div>
</div>
{% if form_location_trash is defined %}
{% if form_location_trash is defined and form_location_trash_container is not defined %}
{% include '@ezdesign/content/modal_location_trash.html.twig' with {'form': form_location_trash} only %}
{% endif %}
{% if form_user_delete is defined %}
Expand All @@ -114,6 +114,14 @@
{{ 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')}) }}
{% if form_location_trash_container is defined %}
{% include '@ezdesign/content/modal_location_trash_container.html.twig' with {
'form': form_location_trash_container,
'content_name': content.name,
'has_asset': form_location_trash_with_asset is defined,
'has_unique_asset': form_location_trash_with_single_asset is defined
} only %}
{% endif %}
</div>
</div>
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% form_theme form '@ezdesign/form_fields.html.twig' %}

<div class="modal fade ez-modal ez-modal--trash-container" id="trash-container-modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ 'trash_container.modal.header'|trans|desc('Deleting content') }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<svg class="ez-icon ez-icon--medium" aria-hidden="true">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#discard"></use>
</svg>
</button>
</div>
<div class="modal-body">
<p class="ez-modal-body__main">
{{ 'trash_container.modal.message_main'|trans({'%content_name%': content_name})|desc('Deleting %content_name% will also delete its sub-items, under its location(s). To confirm, please check below') }}
</p>
{{ form_start(form, {
'action': path('ezplatform.location.trash_container'),
'attr' : {
'class' : 'ez-toggle-btn-state-checkbox',
'data-toggle-button-id' : '#location_trash_container_trash',
'data-has-asset': has_asset,
'data-has-unique-asset': has_unique_asset
},
}) }}
{{ form_widget(form.trashContainer) }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-dark btn--no" data-dismiss="modal">
{{ 'trash.form.cancel'|trans|desc('Cancel') }}
</button>
{{ form_widget(form.trash, {
'attr': {
'class': 'btn-danger',
'disabled' : 'disabled'
}
}) }}
{{ form_end(form) }}
</div>
</div>
</div>
</div>

{% block javascripts %}
{% javascripts
'@EzPlatformAdminUiBundle/Resources/public/js/scripts/button.state.checkbox.toggle.js'
'@EzPlatformAdminUiBundle/Resources/public/js/scripts/admin.trash.container.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
Loading