Skip to content

Commit

Permalink
EZP-28567: As an editor I want to be able to restore archived Content…
Browse files Browse the repository at this point in the history
… version (#201)
  • Loading branch information
webhdx authored and Łukasz Serwatka committed Dec 18, 2017
1 parent 2129c48 commit 2d5a48c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
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 @@ -91,6 +91,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,6 +1,7 @@
{% 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 @@ -41,7 +42,7 @@
}) }}
{% 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 @@ -51,6 +52,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) %}
{% set modal_data_target = 'delete-versions-modal' %}
<button id="delete-translations-{{ form.remove.vars.id }}" type="button" class="btn btn-danger" disabled data-toggle="modal"
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,6 +1,7 @@
{% 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 @@ -13,7 +14,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 @@ -53,6 +54,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

0 comments on commit 2d5a48c

Please sign in to comment.