diff --git a/src/Controller/HomepageController.php b/src/Controller/HomepageController.php index 3edb4485..33314d78 100644 --- a/src/Controller/HomepageController.php +++ b/src/Controller/HomepageController.php @@ -42,7 +42,11 @@ declare(strict_types=1); namespace App\Controller; +use App\DataTables\LogDataTable; use App\Services\GitVersionInfo; +use Omines\DataTablesBundle\DataTableFactory; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use const DIRECTORY_SEPARATOR; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpKernel\KernelInterface; @@ -53,11 +57,13 @@ class HomepageController extends AbstractController { protected $cache; protected $kernel; + protected $dataTable; - public function __construct(CacheInterface $cache, KernelInterface $kernel) + public function __construct(CacheInterface $cache, KernelInterface $kernel, DataTableFactory $dataTable) { $this->cache = $cache; $this->kernel = $kernel; + $this->dataTable = $dataTable; } public function getBanner(): string @@ -78,12 +84,22 @@ class HomepageController extends AbstractController * @param GitVersionInfo $versionInfo * @return \Symfony\Component\HttpFoundation\Response */ - public function homepage(GitVersionInfo $versionInfo): \Symfony\Component\HttpFoundation\Response + public function homepage(Request $request, GitVersionInfo $versionInfo): Response { + $table = $this->dataTable->createFromType(LogDataTable::class, [ + 'mode' => 'last_activity' + ], ['pageLength' => 10]) + ->handleRequest($request); + + if ($table->isCallback()) { + return $table->getResponse(); + } + return $this->render('homepage.html.twig', [ 'banner' => $this->getBanner(), 'git_branch' => $versionInfo->getGitBranchName(), 'git_commit' => $versionInfo->getGitCommitHash(), + 'datatable' => $table ]); } } diff --git a/src/DataTables/LogDataTable.php b/src/DataTables/LogDataTable.php index 8aff2994..01babc82 100644 --- a/src/DataTables/LogDataTable.php +++ b/src/DataTables/LogDataTable.php @@ -51,6 +51,9 @@ use App\Entity\Base\AbstractDBElement; use App\Entity\Contracts\TimeTravelInterface; use App\Entity\LogSystem\AbstractLogEntry; use App\Entity\LogSystem\CollectionElementDeleted; +use App\Entity\LogSystem\ElementCreatedLogEntry; +use App\Entity\LogSystem\ElementDeletedLogEntry; +use App\Entity\LogSystem\ElementEditedLogEntry; use App\Exceptions\EntityNotSupportedException; use App\Services\ElementTypeNameGenerator; use App\Services\EntityURLGenerator; @@ -91,7 +94,7 @@ class LogDataTable implements DataTableTypeInterface 'filter_elements' => [], ]); - $optionsResolver->setAllowedValues('mode', ['system_log', 'element_history']); + $optionsResolver->setAllowedValues('mode', ['system_log', 'element_history', 'last_activity']); } public function configure(DataTable $dataTable, array $options): void @@ -252,6 +255,13 @@ class LogDataTable implements DataTableTypeInterface ->from(AbstractLogEntry::class, 'log') ->leftJoin('log.user', 'user'); + if ($options['mode'] === 'last_activity') { + $builder->where('log INSTANCE OF ' . ElementCreatedLogEntry::class) + ->orWhere('log INSTANCE OF ' . ElementDeletedLogEntry::class) + ->orWhere('log INSTANCE OF ' . ElementEditedLogEntry::class) + ->orWhere('log INSTANCE OF ' . CollectionElementDeleted::class); + } + if (!empty($options['filter_elements'])) { foreach ($options['filter_elements'] as $element) { /** @var AbstractDBElement $element */ diff --git a/templates/homepage.html.twig b/templates/homepage.html.twig index 4aee4dd4..b39e162d 100644 --- a/templates/homepage.html.twig +++ b/templates/homepage.html.twig @@ -39,4 +39,11 @@ {% trans %} homepage.others {% endtrans %} + +
+
{% trans %}homepage.last_activity{% endtrans %}
+
+ {% include "LogSystem/_log_table.html.twig" %} +
+
{% endblock %} \ No newline at end of file