Skip to content

Commit

Permalink
Added save and display of logged events in dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed Jun 30, 2023
1 parent 3fc027e commit c2b0c30
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion assets/styles/desktop/dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ main
ul
{
// Liste détaillée.
height: 10rem;
padding: 0.25rem;
overflow: auto;
max-height: 13rem;

li
{
Expand Down
9 changes: 9 additions & 0 deletions src/Controller/ActionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace App\Controller;

use App\Entity\User;
use App\Entity\Event;
use App\Entity\Server;
use App\Service\ServerManager;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -220,6 +221,14 @@ public function action(Request $request): Response
}
}

// On enregistre l'action réalisée dans les événements journalisés.
$event = new Event();
$event->setServer($server);
$event->setDate(new \DateTime());
$event->setAction($action);

$this->entityManager->getRepository(Event::class)->save($event, true);

// On envoie par la suite la réponse au client.
return new Response(
$this->translator->trans("global.action_success"),
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace App\Controller;

use App\Entity\User;
use App\Entity\Event;
use App\Entity\Server;
use App\Service\ServerManager;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -47,6 +48,7 @@ public function index(Request $request): Response
// l'action de l'utilisateur.
/** @var User */
$user = $this->getUser();
$cacheId = intval($request->getSession()->get("serverId", 0));
$serverId = intval($request->request->get("id", 0));
$repository = $this->entityManager->getRepository(Server::class);

Expand Down Expand Up @@ -130,7 +132,7 @@ public function index(Request $request): Response
return $this->render("dashboard.html.twig", [

// Récupération de l'historique des actions et commandes.
"dashboard_logs" => [],
"dashboard_logs" => $this->entityManager->getRepository(Event::class)->findBy(["server" => $cacheId], ["id" => "DESC"], 3),

// Liste des serveurs depuis la base de données.
"dashboard_servers" => $repository->findBy(["client" => $user->getId()])
Expand Down
10 changes: 5 additions & 5 deletions src/Entity/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Contact
private ?int $id = null;

#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $timestamp = null;
private ?\DateTimeInterface $date = null;

#[ORM\Column(length: 100)]
#[Assert\Email]
Expand Down Expand Up @@ -47,14 +47,14 @@ public function getId(): ?int
return $this->id;
}

public function getTimestamp(): ?\DateTimeInterface
public function getDate(): ?\DateTimeInterface
{
return $this->timestamp;
return $this->date;
}

public function setTimestamp(\DateTimeInterface $timestamp): self
public function setDate(\DateTimeInterface $date): self
{
$this->timestamp = $timestamp;
$this->date = $date;

return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions templates/dashboard.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@
{% for logs in dashboard_logs %}
<li>
{# Icône représentative de la tâche #}
<i class="bi bi-check-square-fill" data-type="{{ logs["action_type"] }}"></i>
<i class="bi bi-check-square-fill" data-type="{{ logs.action }}"></i>

{# Heure de l'actionnement #}
<span>{{ logs["timestamp"]|date("H:m:s (d/m)") }}</span>
<span>{{ logs.date|date("H:m:s (d/m)") }}</span>

{# Titre de l'action #}
<em>{{ t("global_" ~ logs["action_type"] ~ "_title")|trans|default(logs["action_type"]|capitalize) }}</em>
<em>{{ t("global." ~ logs.action)|trans|default(logs.action|capitalize) }}</em>
</li>
{% endfor %}
</ul>
Expand Down

0 comments on commit c2b0c30

Please sign in to comment.