Merge branch 'feature/Back' into develop

This commit is contained in:
Joshua 2024-12-20 10:38:51 +01:00
commit 78515d6c87
6 changed files with 105 additions and 14 deletions

View File

@ -36,8 +36,8 @@ security:
access_control: access_control:
# - { path: ^/, roles: ROLE_USER } # - { path: ^/, roles: ROLE_USER }
- { path: ^/logout, roles: IS_AUTHENTICATED }
- { path: ^/login, roles: PUBLIC_ACCESS } - { path: ^/login, roles: PUBLIC_ACCESS }
- { path: ^/logout, roles: ROLE_USER }
- { path: ^/index, roles: [ROLE_ADMIN, ROLE_CUISINIER, ROLE_SERVEUR]} - { path: ^/index, roles: [ROLE_ADMIN, ROLE_CUISINIER, ROLE_SERVEUR]}
- { path: ^/user, roles: ROLE_ADMIN } - { path: ^/user, roles: ROLE_ADMIN }

View File

@ -0,0 +1,77 @@
document.querySelector('.btn-gestion-promotion').addEventListener('click', function(event) {
event.preventDefault();
document.getElementById('container_modal');
fetch('/reductions')
.then(response => {
if (!response.ok) {
throw new Error('Erreur de chargement de la section Promotions');
}
return response.text();
})
.then(html => {
// Insérer le HTML dans le conteneur et l'afficher
container_modal.innerHTML = html;
container_modal.style.display = 'block';
})
.catch(error => {
console.error('Erreur:', error);
});
});
function addPromotion (event) {
document.getElementById('container_modal');
fetch(`/reductions/new`)
.then(response => {
return response.text();
})
.then(html => {
// Insérer le HTML dans le conteneur et l'afficher
container_modal.innerHTML = html;
container_modal.style.display = 'block';
})
.catch(error => {
console.error('Erreur:', error);
});
}
function updatePromotion (event) {
document.getElementById('container_modal');
const reductionsIdString = event.getAttribute('data-id');
let reductionsId = parseInt(reductionsIdString);
fetch(`/reductions/${reductionsId}/edit`)
.then(response => {
return response.text();
})
.then(html => {
// Insérer le HTML dans le conteneur et l'afficher
container_modal.innerHTML = html;
container_modal.style.display = 'block';
})
.catch(error => {
console.error('Erreur:', error);
});
}
function deletePromotion (event) {
document.getElementById('container_modal');
const reductionsIdString = event.getAttribute('data-id');
let reductionsId = parseInt(reductionsIdString);
fetch(`/reductions/${reductionsId}`)
.then(response => {
return response.text();
})
.then(html => {
// Insérer le HTML dans le conteneur et l'afficher
container_modal.innerHTML = html;
container_modal.style.display = 'block';
})
.catch(error => {
console.error('Erreur:', error);
});
}

View File

@ -26,14 +26,17 @@ final class ReductionsController extends AbstractController
public function new(Request $request, EntityManagerInterface $entityManager): Response public function new(Request $request, EntityManagerInterface $entityManager): Response
{ {
$reduction = new Reductions(); $reduction = new Reductions();
$form = $this->createForm(ReductionsType::class, $reduction); $form = $this->createForm(ReductionsType::class, $reduction, [
'action' => $this->generateUrl('app_reductions_new')
] );
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($reduction); $entityManager->persist($reduction);
$entityManager->flush(); $entityManager->flush();
return $this->redirectToRoute('app_reductions_index', [], Response::HTTP_SEE_OTHER); return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER);
} }
return $this->render('reductions/new.html.twig', [ return $this->render('reductions/new.html.twig', [
@ -46,13 +49,15 @@ final class ReductionsController extends AbstractController
#[Route('/{id}/edit', name: 'app_reductions_edit', methods: ['GET', 'POST'])] #[Route('/{id}/edit', name: 'app_reductions_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Reductions $reduction, EntityManagerInterface $entityManager): Response public function edit(Request $request, Reductions $reduction, EntityManagerInterface $entityManager): Response
{ {
$form = $this->createForm(ReductionsType::class, $reduction); $form = $this->createForm(ReductionsType::class, $reduction, [
'action' => $this->generateUrl('app_reductions_edit', ['id' => $reduction->getId()])
]);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush(); $entityManager->flush();
return $this->redirectToRoute('app_reductions_index', [], Response::HTTP_SEE_OTHER); return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER);
} }
return $this->render('reductions/edit.html.twig', [ return $this->render('reductions/edit.html.twig', [
@ -69,6 +74,6 @@ final class ReductionsController extends AbstractController
$entityManager->flush(); $entityManager->flush();
} }
return $this->redirectToRoute('app_reductions_index', [], Response::HTTP_SEE_OTHER); return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER);
} }
} }

View File

@ -26,7 +26,9 @@ class UserController extends AbstractController
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager): Response public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager): Response
{ {
$user = new Utilisateurs(); $user = new Utilisateurs();
$form = $this->createForm(AddUserFormType::class, $user); $form = $this->createForm(AddUserFormType::class, $user, [
'action' => $this->generateUrl('add_user')
]);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
@ -53,7 +55,9 @@ class UserController extends AbstractController
public function update(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager, int $id): Response public function update(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager, int $id): Response
{ {
$user = $this->utilisateursRepository->find($id); $user = $this->utilisateursRepository->find($id);
$form = $this->createForm(UpdateUserType::class, $user); $form = $this->createForm(UpdateUserType::class, $user , [
'action' => $this->generateUrl('update-user', ['id' => $user->getId()])
]);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
@ -66,7 +70,7 @@ class UserController extends AbstractController
$entityManager->persist($user); $entityManager->persist($user);
$entityManager->flush(); $entityManager->flush();
return $this->redirectToRoute('app_index'); return $security->login($user, LoginAuthenticator::class, 'main');
} }
return $this->render('user/update.html.twig', [ return $this->render('user/update.html.twig', [

View File

@ -53,7 +53,7 @@
</div> </div>
</li> </li>
<li> <li>
<div class="btn-custom icon-container"> <div class="btn-custom btn-gestion-promotion icon-container">
<i class="icon-medium"> {{ ux_icon('lsicon:badge-promotion-outline') }}</i> <i class="icon-medium"> {{ ux_icon('lsicon:badge-promotion-outline') }}</i>
<span>Gestion Promotion</span> <span>Gestion Promotion</span>
</div> </div>
@ -119,7 +119,7 @@
</div> </div>
<div id="container_modal"> <div id="container_modal">
<!-- Contenu par défaut, ou vous pouvez laisser vide --> <!-- Contenu par défaut, ou vous p ouvez laisser vide -->
</div> </div>
<script> <script>
@ -133,4 +133,5 @@
{% block javascripts %} {% block javascripts %}
<script src="{{ asset('js/Compte/CompteModal.js') }}" defer></script> <script src="{{ asset('js/Compte/CompteModal.js') }}" defer></script>
<script src="{{ asset('js/GestionUtilisateurs/GestionUtilisateurs.js') }}" defer></script> <script src="{{ asset('js/GestionUtilisateurs/GestionUtilisateurs.js') }}" defer></script>
<script src="{{ asset('js/GestionPromotion/GestionPromotion.js') }}" defer></script>
{% endblock %} {% endblock %}

View File

@ -32,11 +32,11 @@
<td>{{ reduction.DateDebut ? reduction.DateDebut|date('Y-m-d H:i:s') : '' }}</td> <td>{{ reduction.DateDebut ? reduction.DateDebut|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ reduction.DateFin ? reduction.DateFin|date('Y-m-d H:i:s') : '' }}</td> <td>{{ reduction.DateFin ? reduction.DateFin|date('Y-m-d H:i:s') : '' }}</td>
<td> <td>
<form method="post" action="{{ path('app_reductions_delete', {'id': reduction.id}) }}" onsubmit="return confirm('Es-tu sur de vouloir le supprimer ?');"> <form method="post" action="{{ path('app_reductions_delete', {'id': reduction.id}) }}" onsubmit="return confirm('Es-tu sur de vouloir le supprimer ?'); ">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ reduction.id) }}"> <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ reduction.id) }}">
{{ include('reductions/_delete_form.html.twig') }} {{ include('reductions/_delete_form.html.twig') }}
</form> </form>
<a href="{{ path('app_reductions_edit', {'id': reduction.id}) }}">Modifier</a> <button onclick="updatePromotion(this)" data-id="{{ reduction.id }}" href="{{ path('app_reductions_edit', {'id': reduction.id}) }}">Modifier</button>
</td> </td>
</tr> </tr>
{% else %} {% else %}
@ -47,5 +47,9 @@
</tbody> </tbody>
</table> </table>
<a href="{{ path('app_reductions_new') }}">Créer une réduction</a> <button onclick="addPromotion(this)" href="{{ path('app_reductions_new') }}">Créer une réduction</button>
{% endblock %}
{% block javascripts %}
<script src="{{ asset('js/GestionPromotion/GestionPromotion.js') }}" defer></script>
{% endblock %} {% endblock %}