mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Show last activity to elements on homepage.
This commit is contained in:
parent
31290c070a
commit
41074f70ed
3 changed files with 36 additions and 3 deletions
|
@ -42,7 +42,11 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\DataTables\LogDataTable;
|
||||||
use App\Services\GitVersionInfo;
|
use App\Services\GitVersionInfo;
|
||||||
|
use Omines\DataTablesBundle\DataTableFactory;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use const DIRECTORY_SEPARATOR;
|
use const DIRECTORY_SEPARATOR;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
|
@ -53,11 +57,13 @@ class HomepageController extends AbstractController
|
||||||
{
|
{
|
||||||
protected $cache;
|
protected $cache;
|
||||||
protected $kernel;
|
protected $kernel;
|
||||||
|
protected $dataTable;
|
||||||
|
|
||||||
public function __construct(CacheInterface $cache, KernelInterface $kernel)
|
public function __construct(CacheInterface $cache, KernelInterface $kernel, DataTableFactory $dataTable)
|
||||||
{
|
{
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
$this->kernel = $kernel;
|
$this->kernel = $kernel;
|
||||||
|
$this->dataTable = $dataTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBanner(): string
|
public function getBanner(): string
|
||||||
|
@ -78,12 +84,22 @@ class HomepageController extends AbstractController
|
||||||
* @param GitVersionInfo $versionInfo
|
* @param GitVersionInfo $versionInfo
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @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', [
|
return $this->render('homepage.html.twig', [
|
||||||
'banner' => $this->getBanner(),
|
'banner' => $this->getBanner(),
|
||||||
'git_branch' => $versionInfo->getGitBranchName(),
|
'git_branch' => $versionInfo->getGitBranchName(),
|
||||||
'git_commit' => $versionInfo->getGitCommitHash(),
|
'git_commit' => $versionInfo->getGitCommitHash(),
|
||||||
|
'datatable' => $table
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,9 @@ use App\Entity\Base\AbstractDBElement;
|
||||||
use App\Entity\Contracts\TimeTravelInterface;
|
use App\Entity\Contracts\TimeTravelInterface;
|
||||||
use App\Entity\LogSystem\AbstractLogEntry;
|
use App\Entity\LogSystem\AbstractLogEntry;
|
||||||
use App\Entity\LogSystem\CollectionElementDeleted;
|
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\Exceptions\EntityNotSupportedException;
|
||||||
use App\Services\ElementTypeNameGenerator;
|
use App\Services\ElementTypeNameGenerator;
|
||||||
use App\Services\EntityURLGenerator;
|
use App\Services\EntityURLGenerator;
|
||||||
|
@ -91,7 +94,7 @@ class LogDataTable implements DataTableTypeInterface
|
||||||
'filter_elements' => [],
|
'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
|
public function configure(DataTable $dataTable, array $options): void
|
||||||
|
@ -252,6 +255,13 @@ class LogDataTable implements DataTableTypeInterface
|
||||||
->from(AbstractLogEntry::class, 'log')
|
->from(AbstractLogEntry::class, 'log')
|
||||||
->leftJoin('log.user', 'user');
|
->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'])) {
|
if (!empty($options['filter_elements'])) {
|
||||||
foreach ($options['filter_elements'] as $element) {
|
foreach ($options['filter_elements'] as $element) {
|
||||||
/** @var AbstractDBElement $element */
|
/** @var AbstractDBElement $element */
|
||||||
|
|
|
@ -39,4 +39,11 @@
|
||||||
{% trans %} homepage.others {% endtrans %}
|
{% trans %} homepage.others {% endtrans %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card mt-3">
|
||||||
|
<div class="card-header"><i class="fas fa-fw fa-history"></i> {% trans %}homepage.last_activity{% endtrans %}</div>
|
||||||
|
<div class="card-body">
|
||||||
|
{% include "LogSystem/_log_table.html.twig" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue