mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-22 18:03:37 +02:00
Added history tab to admin pages.
This commit is contained in:
parent
0c2af9e968
commit
f9bb2d57e9
3 changed files with 38 additions and 3 deletions
|
@ -42,6 +42,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Controller\AdminPages;
|
namespace App\Controller\AdminPages;
|
||||||
|
|
||||||
|
use App\DataTables\LogDataTable;
|
||||||
use App\Entity\Base\AbstractNamedDBElement;
|
use App\Entity\Base\AbstractNamedDBElement;
|
||||||
use App\Entity\Base\AbstractStructuralDBElement;
|
use App\Entity\Base\AbstractStructuralDBElement;
|
||||||
use App\Entity\UserSystem\User;
|
use App\Entity\UserSystem\User;
|
||||||
|
@ -53,9 +54,12 @@ use App\Services\Attachments\AttachmentSubmitHandler;
|
||||||
use App\Services\EntityExporter;
|
use App\Services\EntityExporter;
|
||||||
use App\Services\EntityImporter;
|
use App\Services\EntityImporter;
|
||||||
use App\Services\LogSystem\EventCommentHelper;
|
use App\Services\LogSystem\EventCommentHelper;
|
||||||
|
use App\Services\LogSystem\HistoryHelper;
|
||||||
|
use App\Services\LogSystem\TimeTravel;
|
||||||
use App\Services\StructuralElementRecursionHelper;
|
use App\Services\StructuralElementRecursionHelper;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use Omines\DataTablesBundle\DataTableFactory;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
|
@ -80,9 +84,14 @@ abstract class BaseAdminController extends AbstractController
|
||||||
protected $attachmentSubmitHandler;
|
protected $attachmentSubmitHandler;
|
||||||
protected $commentHelper;
|
protected $commentHelper;
|
||||||
|
|
||||||
|
protected $historyHelper;
|
||||||
|
protected $timeTravel;
|
||||||
|
protected $dataTableFactory;
|
||||||
|
|
||||||
public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder,
|
public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder,
|
||||||
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler,
|
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler,
|
||||||
EventCommentHelper $commentHelper)
|
EventCommentHelper $commentHelper, HistoryHelper $historyHelper, TimeTravel $timeTravel,
|
||||||
|
DataTableFactory $dataTableFactory)
|
||||||
{
|
{
|
||||||
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
|
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
|
||||||
throw new InvalidArgumentException('You have to override the $entity_class, $form_class, $route_base and $twig_template value in your subclasss!');
|
throw new InvalidArgumentException('You have to override the $entity_class, $form_class, $route_base and $twig_template value in your subclasss!');
|
||||||
|
@ -97,6 +106,9 @@ abstract class BaseAdminController extends AbstractController
|
||||||
$this->attachmentHelper = $attachmentHelper;
|
$this->attachmentHelper = $attachmentHelper;
|
||||||
$this->attachmentSubmitHandler = $attachmentSubmitHandler;
|
$this->attachmentSubmitHandler = $attachmentSubmitHandler;
|
||||||
$this->commentHelper = $commentHelper;
|
$this->commentHelper = $commentHelper;
|
||||||
|
$this->historyHelper = $historyHelper;
|
||||||
|
$this->timeTravel = $timeTravel;
|
||||||
|
$this->dataTableFactory = $dataTableFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,6 +116,17 @@ abstract class BaseAdminController extends AbstractController
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('read', $entity);
|
$this->denyAccessUnlessGranted('read', $entity);
|
||||||
|
|
||||||
|
|
||||||
|
$table = $this->dataTableFactory->createFromType(LogDataTable::class, [
|
||||||
|
'filter_elements' => $this->historyHelper->getAssociatedElements($entity),
|
||||||
|
'mode' => 'element_history'
|
||||||
|
], ['pageLength' => 10])
|
||||||
|
->handleRequest($request);
|
||||||
|
|
||||||
|
if ($table->isCallback()) {
|
||||||
|
return $table->getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
$form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]);
|
$form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]);
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
@ -153,6 +176,7 @@ abstract class BaseAdminController extends AbstractController
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'attachment_helper' => $this->attachmentHelper,
|
'attachment_helper' => $this->attachmentHelper,
|
||||||
'route_base' => $this->route_base,
|
'route_base' => $this->route_base,
|
||||||
|
'datatable' => $table
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
namespace App\Services\LogSystem;
|
namespace App\Services\LogSystem;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||||
use App\Entity\Base\AbstractDBElement;
|
use App\Entity\Base\AbstractDBElement;
|
||||||
use App\Entity\Parts\Part;
|
use App\Entity\Parts\Part;
|
||||||
|
|
||||||
|
@ -40,10 +41,13 @@ class HistoryHelper
|
||||||
public function getAssociatedElements(AbstractDBElement $element): array
|
public function getAssociatedElements(AbstractDBElement $element): array
|
||||||
{
|
{
|
||||||
$array = [$element];
|
$array = [$element];
|
||||||
|
if ($element instanceof AttachmentContainingDBElement) {
|
||||||
|
$array = array_merge($array, $element->getAttachments()->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
if ($element instanceof Part) {
|
if ($element instanceof Part) {
|
||||||
$array = array_merge(
|
$array = array_merge(
|
||||||
$array,
|
$array,
|
||||||
$element->getAttachments()->toArray(),
|
|
||||||
$element->getPartLots()->toArray(),
|
$element->getPartLots()->toArray(),
|
||||||
$element->getOrderdetails()->toArray()
|
$element->getOrderdetails()->toArray()
|
||||||
);
|
);
|
||||||
|
|
|
@ -45,6 +45,9 @@
|
||||||
<ul class="nav nav-tabs mt-2">
|
<ul class="nav nav-tabs mt-2">
|
||||||
<li class="nav-item"><a class="link-anchor active nav-link" data-toggle="tab" href="#home">{% trans %}standard.label{% endtrans %}</a></li>
|
<li class="nav-item"><a class="link-anchor active nav-link" data-toggle="tab" href="#home">{% trans %}standard.label{% endtrans %}</a></li>
|
||||||
<li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#info">{% trans %}infos.label{% endtrans %}</a></li>
|
<li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#info">{% trans %}infos.label{% endtrans %}</a></li>
|
||||||
|
{% if datatable is defined and datatable is not null %}
|
||||||
|
<li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#history">{% trans %}history.label{% endtrans %}</a></li>
|
||||||
|
{% endif %}
|
||||||
{% if entity.id %}
|
{% if entity.id %}
|
||||||
<li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#export">{% trans %}export.label{% endtrans %}</a> </li>
|
<li class="nav-item"><a data-toggle="tab" class="link-anchor nav-link" href="#export">{% trans %}export.label{% endtrans %}</a> </li>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -128,7 +131,11 @@
|
||||||
{% include "AdminPages/_info.html.twig" %}
|
{% include "AdminPages/_info.html.twig" %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if datatable is defined and datatable is not null %}
|
||||||
|
<div id="history" class="tab-pane fade">
|
||||||
|
{% include "LogSystem/_log_table.html.twig" %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if entity.id %}
|
{% if entity.id %}
|
||||||
<div id="export" class="tab-pane fade">
|
<div id="export" class="tab-pane fade">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue