set admin V3 User

This commit is contained in:
jleroy2023
2024-11-19 15:58:28 +01:00
parent 2995c10d50
commit 1369fcab53
3 changed files with 120 additions and 1 deletions

View File

@@ -3,8 +3,10 @@
namespace App\Controller;
use App\Entity\Participant;
use App\Entity\Site;
use App\Entity\Ville;
use App\Repository\ParticipantRepository;
use App\Repository\SiteRepository;
use App\Repository\VilleRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -187,4 +189,40 @@ class AdminController extends AbstractController
$this->addFlash('success', 'Ville supprimée avec succès.');
return $this->redirectToRoute('app_adminCity');
}
//Gestion des sites
#[Route('/admin/site', name: 'app_adminSite')]
public function adminSite(SiteRepository $siteRepository): Response
{
return $this->render('admin/site.html.twig', [
'sites' => $siteRepository->findAll(),
'controller_name' => 'AdminController',
]);
}
#[Route('/admin/site/add', name: 'app_adminSiteAdd', methods: ['POST'])]
public function adminSiteAdd(Request $request, EntityManagerInterface $entityManager): Response
{
try {
// Récupérer les données envoyées par le formulaire
$nom = $request->request->get('nom');
// Vérifier que les champs ne sont pas vides
if (!$nom) {
return new Response('Tous les champs sont requis.', Response::HTTP_BAD_REQUEST);
}
// Créer une nouvelle entité City et définir ses propriétés
$site = new Site();
$site->setNom($nom);
// Enregistrer la ville dans la base de données
$entityManager->persist($site);
$entityManager->flush();
$this->addFlash('success', "Site ajouté !");
return $this->redirectToRoute('app_adminSite');
} catch(\Exception $e) {
$this->addFlash('error', "Erreur : " . $e->getMessage());
return $this->redirectToRoute('app_adminSite');
}
}
}

View File

@@ -17,7 +17,7 @@
</a>
</li>
<li>
<a href="#" class="block text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded">
<a href="{{ path('app_adminSite') }}" class="block text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded">
📍 Sites
</a>
</li>

View File

@@ -0,0 +1,81 @@
{% extends 'main/base.html.twig' %}
{% block title %}&#128227; Sortie.com Admin Site &#128266;{% endblock %}
{% block content %}
<div class="flex">
{% include 'admin/sidebar.html.twig' %}
<!-- Main Content -->
<div class="ml-64 p-8 w-full">
<h1 class="text-2xl font-semibold mb-4">Gestion des sites</h1>
<!-- Actions: Ajouter -->
<div class="mb-4">
<!-- Bouton pour ouvrir la modale -->
<button id="openModal" class="inline-block bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-700">
Ajouter un site
</button>
</div>
<!-- Participants Table -->
<div class="overflow-x-auto bg-white rounded shadow">
<table class="min-w-full bg-white divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Site</th>
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
{% for site in sites %}
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ site.nom }}</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<a href="{{ path('app_adminSiteDelete', {'id': city.idSite}) }}" class="text-red-600 hover:text-red-900 ml-4">Supprimer</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="8" class="px-6 py-4 text-center text-gray-500">Aucun site trouvée</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!-- Modale pour ajouter une ville -->
<div id="siteModal" class="fixed inset-0 z-50 hidden bg-gray-900 bg-opacity-50">
<div class="flex justify-center items-center min-h-screen">
<div class="bg-white p-6 rounded shadow-md w-1/3">
<h2 class="text-xl font-semibold mb-4">Ajouter un site</h2>
<form id="addSiteForm" method="POST" action="{{ path('app_adminSiteAdd') }}">
<div class="mb-4">
<label for="nom" class="block text-sm font-medium text-gray-700">Nom</label>
<input id="nom" name="nom" type="text" class="mt-1 block w-full px-4 py-2 border rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div>
<div class="flex justify-end">
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-700">Ajouter</button>
<button type="button" id="closeModal" class="ml-2 bg-gray-500 text-white px-4 py-2 rounded hover:bg-gray-700">Annuler</button>
</div>
</form>
</div>
</div>
</div>
<script>
// Ouvrir la modale
document.getElementById('openModal').addEventListener('click', function() {
document.getElementById('siteModal').classList.remove('hidden');
});
// Fermer la modale
document.getElementById('closeModal').addEventListener('click', function() {
document.getElementById('siteModal').classList.add('hidden');
});
</script>
</div>
{% endblock %}