mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-22 09:53:35 +02:00
Added buttons for revert and undo to the log detail page
This commit is contained in:
parent
b62fd602f2
commit
49b6a42791
5 changed files with 111 additions and 1 deletions
|
@ -104,15 +104,19 @@ class LogController extends AbstractController
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function logDetails(Request $request, AbstractLogEntry $logEntry, LogEntryExtraFormatter $logEntryExtraFormatter,
|
public function logDetails(Request $request, AbstractLogEntry $logEntry, LogEntryExtraFormatter $logEntryExtraFormatter,
|
||||||
LogLevelHelper $logLevelHelper, LogTargetHelper $logTargetHelper): Response
|
LogLevelHelper $logLevelHelper, LogTargetHelper $logTargetHelper, EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('read', $logEntry);
|
$this->denyAccessUnlessGranted('read', $logEntry);
|
||||||
|
|
||||||
$extra_html = $logEntryExtraFormatter->format($logEntry);
|
$extra_html = $logEntryExtraFormatter->format($logEntry);
|
||||||
$target_html = $logTargetHelper->formatTarget($logEntry);
|
$target_html = $logTargetHelper->formatTarget($logEntry);
|
||||||
|
|
||||||
|
$repo = $entityManager->getRepository(AbstractLogEntry::class);
|
||||||
|
$target_element = $repo->getTargetElement($logEntry);
|
||||||
|
|
||||||
return $this->render('log_system/details/log_details.html.twig', [
|
return $this->render('log_system/details/log_details.html.twig', [
|
||||||
'log_entry' => $logEntry,
|
'log_entry' => $logEntry,
|
||||||
|
'target_element' => $target_element,
|
||||||
'extra_html' => $extra_html,
|
'extra_html' => $extra_html,
|
||||||
'target_html' => $target_html,
|
'target_html' => $target_html,
|
||||||
'log_level_helper' => $logLevelHelper,
|
'log_level_helper' => $logLevelHelper,
|
||||||
|
|
|
@ -71,6 +71,8 @@ final class EntityExtension extends AbstractExtension
|
||||||
new TwigFunction('entity_type', [$this, 'getEntityType']),
|
new TwigFunction('entity_type', [$this, 'getEntityType']),
|
||||||
/* Returns the URL to the given entity */
|
/* Returns the URL to the given entity */
|
||||||
new TwigFunction('entity_url', [$this, 'generateEntityURL']),
|
new TwigFunction('entity_url', [$this, 'generateEntityURL']),
|
||||||
|
/* Returns the URL to the given entity in timetravel mode */
|
||||||
|
new TwigFunction('timetravel_url', [$this->entityURLGenerator, 'timetravelURL']),
|
||||||
/* Generates a JSON array of the given tree */
|
/* Generates a JSON array of the given tree */
|
||||||
new TwigFunction('tree_data', [$this, 'treeData']),
|
new TwigFunction('tree_data', [$this, 'treeData']),
|
||||||
|
|
||||||
|
|
|
@ -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) %}
|
{% macro comment_field(entry) %}
|
||||||
{# @var entry \App\Entity\Contracts\LogWithComment #}
|
{# @var entry \App\Entity\Contracts\LogWithComment #}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{% extends "main_card.html.twig" %}
|
{% extends "main_card.html.twig" %}
|
||||||
|
|
||||||
{% import "helper.twig" as helper %}
|
{% import "helper.twig" as helper %}
|
||||||
|
{% import "log_system/details/helper.macro.html.twig" as log_helper %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans %}log.details.title{% endtrans %}:
|
{% trans %}log.details.title{% endtrans %}:
|
||||||
|
@ -58,6 +59,22 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="card-body">
|
<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 #}
|
{# This assignment is to improve autocomplete on the subpages, as PHPstorm ignores typehints for log_entry #}
|
||||||
{% set entry = log_entry %}
|
{% set entry = log_entry %}
|
||||||
{% if log_entry is instanceof('App\\Entity\\LogSystem\\DatabaseUpdatedLogEntry') %}
|
{% if log_entry is instanceof('App\\Entity\\LogSystem\\DatabaseUpdatedLogEntry') %}
|
||||||
|
|
|
@ -11361,5 +11361,47 @@ Element 3</target>
|
||||||
<target>Diff</target>
|
<target>Diff</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="OB_fVDI" name="log.undo.undo.short">
|
||||||
|
<segment>
|
||||||
|
<source>log.undo.undo.short</source>
|
||||||
|
<target>Undo</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="AvoT6DL" name="log.undo.revert.short">
|
||||||
|
<segment>
|
||||||
|
<source>log.undo.revert.short</source>
|
||||||
|
<target>Revert to this timestamp</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="YdXQd2_" name="log.view_version">
|
||||||
|
<segment>
|
||||||
|
<source>log.view_version</source>
|
||||||
|
<target>View version</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="l47W4kt" name="log.undo.undelete.short">
|
||||||
|
<segment>
|
||||||
|
<source>log.undo.undelete.short</source>
|
||||||
|
<target>Undelete</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="PDJYeqj" name="log.element_edited.changed_fields.id">
|
||||||
|
<segment>
|
||||||
|
<source>log.element_edited.changed_fields.id</source>
|
||||||
|
<target>ID</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="cQTNNI7" name="log.element_edited.changed_fields.id_owner">
|
||||||
|
<segment>
|
||||||
|
<source>log.element_edited.changed_fields.id_owner</source>
|
||||||
|
<target>Owner</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="h1eBlp8" name="log.element_edited.changed_fields.parent_id">
|
||||||
|
<segment>
|
||||||
|
<source>log.element_edited.changed_fields.parent_id</source>
|
||||||
|
<target>Parent</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue