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-28567: As an editor I want to be able to restore archived Content version #201

Merged
merged 1 commit into from
Dec 18, 2017
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(function (global, doc) {
const FORM_ARCHIVED_VERSION_RESTORE = 'form[name="archived_version_restore"]';
const restoreArchivedVersion = (event) => {
const versionRestoreForm = doc.querySelector(FORM_ARCHIVED_VERSION_RESTORE);
const contentId = event.currentTarget.dataset.contentId;
const versionNo = event.currentTarget.dataset.versionNo;
const languageCode = event.currentTarget.dataset.languageCode;
const contentInfoInput = versionRestoreForm.querySelector('input[name="archived_version_restore[content_info]"]');
const versionInfoContentInfoInput = versionRestoreForm.querySelector('input[name="archived_version_restore[version_info][content_info]"]');
const versionInfoVersionNoInput = versionRestoreForm.querySelector('input[name="archived_version_restore[version_info][version_no]"]');
const languageInput = versionRestoreForm.querySelector('#archived_version_restore_language_' + languageCode);

event.preventDefault();

contentInfoInput.value = contentId;
versionInfoContentInfoInput.value = contentId;
versionInfoVersionNoInput.value = versionNo;
languageInput.setAttribute('checked', true);

versionRestoreForm.submit();
};

[...doc.querySelectorAll('.ez-btn--restore-archived-version')].forEach(button => button.addEventListener('click', restoreArchivedVersion, false));
})(window, document);
1 change: 1 addition & 0 deletions src/bundle/Resources/views/content/locationview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
'bundles/ezplatformadminui/js/scripts/admin.location.visibility.js'
'bundles/ezplatformadminui/js/scripts/admin.location.update.js'
'bundles/ezplatformadminui/js/scripts/admin.location.add.translation.js'
'bundles/ezplatformadminui/js/scripts/admin.location.version.restore_archived.js'
'bundles/ezplatformadminui/js/scripts/udw/move.js'
'bundles/ezplatformadminui/js/scripts/udw/copy.js'
'bundles/ezplatformadminui/js/scripts/udw/swap.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% trans_default_domain 'locationview' %}
{% import _self as tab %}
{% form_theme form_archived_version_restore '@EzPlatformAdminUi/parts/form/flat_widgets.html.twig' %}

{% if draft_versions is not empty %}
<section>
Expand Down Expand Up @@ -34,7 +35,7 @@
{{ form_start(form_version_remove_archived, {'action': path('ezplatform.version.remove')}) }}
{% include '@EzPlatformAdminUi/parts/table_header.html.twig' with { headerText: 'tab.versions.archived_versions'|trans()|desc('Archived versions'), tools: tab.table_header_tools(form_version_remove_archived) } %}
{% if archived_versions is not empty %}
{{ include('@EzPlatformAdminUi/content/tab/versions/table.html.twig', { 'versions': archived_versions, 'form': form_version_remove_archived }) }}
{{ include('@EzPlatformAdminUi/content/tab/versions/table.html.twig', { 'versions': archived_versions, 'form': form_version_remove_archived, 'is_archived': true, 'form_archived_version_restore': form_archived_version_restore }) }}
{% else %}
<p>
{{ 'tab.versions.no_permission'|trans()|desc('You don\'t have access to view the content item\'s versions') }}
Expand All @@ -44,6 +45,10 @@
</section>
{% endif %}

{{ form_start(form_archived_version_restore, {'action': path('ezplatform.content.edit')}) }}
{{ form_widget(form_archived_version_restore.language, {'attr': {'hidden': 'hidden'}}) }}
{{ form_end(form_archived_version_restore) }}

{% macro table_header_tools(form) %}
<button class="btn btn-danger btn--trigger" data-click="#{{ form.remove.vars.id }}">
<svg class="ez-icon ez-icon-trash">
Expand Down
12 changes: 11 additions & 1 deletion src/bundle/Resources/views/content/tab/versions/table.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% trans_default_domain 'locationview' %}
{% set is_draft = is_draft is defined and is_draft %}
{% set is_archived = is_archived is defined and is_archived %}

<table class="table">
<thead>
Expand All @@ -12,7 +13,7 @@
<th>{{ 'tab.versions.table.contributor'|trans()|desc('Contributor') }}</th>
<th>{{ 'tab.versions.table.created'|trans()|desc('Created') }}</th>
<th>{{ 'tab.versions.table.last_saved'|trans()|desc('Last saved') }}</th>
{% if is_draft %}
{% if is_draft or is_archived %}
<th></th>
{% endif %}
</tr>
Expand Down Expand Up @@ -52,6 +53,15 @@
</a>
</td>
{% endif %}
{% if is_archived %}
<td>
<button class="btn btn-icon ez-btn--restore-archived-version" data-content-id="{{ version.contentInfo.id }}" data-version-no="{{ version.versionNo }}" data-language-code="{{ version.initialLanguageCode }}">
<svg class="ez-icon ez-icon-edit">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#archive-restore"></use>
</svg>
</button>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
Expand Down
6 changes: 6 additions & 0 deletions src/lib/Tab/LocationView/VersionsTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Draft\ContentEditData;
use EzSystems\EzPlatformAdminUi\Form\Data\Version\VersionRemoveData;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Tab\AbstractTab;
Expand Down Expand Up @@ -98,13 +99,18 @@ public function renderView(array $parameters): string
$archivedVersions,
false
);
$archivedVersionRestoreForm = $this->formFactory->contentEdit(
new ContentEditData($contentInfo),
'archived_version_restore'
);

$viewParameters = [
'published_versions' => $versionsDataset->getPublishedVersions(),
'draft_versions' => $draftVersions,
'archived_versions' => $archivedVersions,
'form_version_remove_draft' => $removeVersionDraftForm->createView(),
'form_version_remove_archived' => $removeVersionArchivedForm->createView(),
'form_archived_version_restore' => $archivedVersionRestoreForm->createView(),
];

return $this->twig->render(
Expand Down