Added buttons for revert and undo to the log detail page

This commit is contained in:
Jan Böhmer 2023-05-15 00:16:49 +02:00
parent b62fd602f2
commit 49b6a42791
5 changed files with 111 additions and 1 deletions

View file

@ -1,3 +1,48 @@
{% macro undo_buttons(entry, target_element) %}
{# @var entry \App\Entity\LogSystem\ElementEditedLogEntry|\App\Entity\LogSystem\ElementDeletedLogEntry entry #}
{% set disabled = not is_granted('revert_element', entry.targetClass) %}
{% if entry is instanceof('App\\Entity\\LogSystem\\CollectionElementDeleted')
or (entry is instanceof('App\\Entity\\LogSystem\\ElementDeletedLogEntry') and entry.hasOldDataInformation) %}
{% set icon = 'fa-trash-restore' %}
{% set title = 'log.undo.undelete'|trans %}
{% set title_short = 'log.undo.undelete.short'|trans %}
{% elseif entry is instanceof('App\\Entity\\LogSystem\\ElementCreatedLogEntry')
or (entry is instanceof('App\\Entity\\LogSystem\\ElementEditedLogEntry') and entry.hasOldDataInformation) %}
{% set icon = 'fa-undo' %}
{% set title = 'log.undo.undo'|trans %}
{% set title_short = 'log.undo.undo.short'|trans %}
{% endif %}
<form method="post" action="{{ path("log_undo") }}"
{{ stimulus_controller('elements/delete_btn') }} {{ stimulus_action('elements/delete_btn', "submit", "submit") }}
data-delete-title="{% trans %}log.undo.confirm_title{% endtrans %}"
data-delete-message="{% trans %}log.undo.confirm_message{% endtrans %}">
<input type="hidden" name="redirect_back" value="{{ app.request.requestUri }}">
<div class="btn-group btn-group-sm" role="group">
<button type="submit" class="btn btn-outline-secondary" name="undo" value="{{ entry.id }}" {% if disabled %}disabled{% endif %}>
<i class="fas fa-fw {{ icon }}" title="{{ title }}"></i> {{ title_short }}
</button>
<button type="submit" class="btn btn-outline-secondary" name="revert" value="{{ entry.id }}" {% if disabled %}disabled{% endif %}>
<i class="fas fa-fw fa-backward" title="{% trans %}log.undo.revert{% endtrans %}"></i> {{ 'log.undo.revert.short' | trans }}
</button>
{# View button #}
{% if target_element and ((attribute(entry, 'oldDataInformation') is defined and entry.oldDataInformation)
or entry is instanceof('App\\Entity\\LogSystem\\CollectionElementDeleted')) %}
<a class="btn btn-outline-secondary" href="{{ timetravel_url(target_element, entry.timestamp)}}"><i class="fas fa-fw fa-eye"></i>
{% trans %}log.view_version{% endtrans %}
</a>
{% endif %}
</div>
</form>
{% endmacro %}
{% macro comment_field(entry) %}
{# @var entry \App\Entity\Contracts\LogWithComment #}

View file

@ -1,6 +1,7 @@
{% extends "main_card.html.twig" %}
{% import "helper.twig" as helper %}
{% import "log_system/details/helper.macro.html.twig" as log_helper %}
{% block title %}
{% trans %}log.details.title{% endtrans %}:
@ -58,6 +59,22 @@
</table>
<div class="card-body">
<div class="row mb-2">
<div class="col-6">
{% if log_entry is instanceof('App\\Entity\\LogSystem\\CollectionElementDeleted')
or log_entry is instanceof('App\\Entity\\LogSystem\\ElementDeletedLogEntry')
or log_entry is instanceof('App\\Entity\\LogSystem\\ElementCreatedLogEntry')
or log_entry is instanceof('App\\Entity\\LogSystem\\ElementEditedLogEntry')
%}
{{ log_helper.undo_buttons(log_entry, target_element) }}
{% endif %}
</div>
<div class="col-6 text-end">
<button type="button" class="btn btn-sm btn-outline-danger">Delete Log entry</button>
</div>
</div>
{# This assignment is to improve autocomplete on the subpages, as PHPstorm ignores typehints for log_entry #}
{% set entry = log_entry %}
{% if log_entry is instanceof('App\\Entity\\LogSystem\\DatabaseUpdatedLogEntry') %}