Bläddra i källkod

AJout d'un bouton pour changer de vue

François Drouhard 1 år sedan
förälder
incheckning
43be7fb58c

+ 3 - 0
assets/app.js

@@ -16,6 +16,7 @@ import 'bootstrap-star-rating/themes/krajee-fa/theme.css';
 import './js/suivifilms2';
 import './js/addCollectionWidget';
 import './js/filtre';
+import './js/switchView';
 
 jQuery(function() {
     $('.add-another-collection-widget').addCollection();
@@ -23,4 +24,6 @@ jQuery(function() {
     $('[data-fonction="switch"]').switchEtat();
 
     $('[data-toggle="star-filter"]').filtreParNote();
+
+    $('#switchview').switchView();
 })

+ 20 - 0
assets/js/switchView.js

@@ -0,0 +1,20 @@
+(function ($) {
+    $.fn.switchView = function () {
+        $(this).on('click', function(e) {
+            e.preventDefault();
+            change();
+        });
+
+        function change () {
+            $.ajax({
+                url: "/changeview",
+                type: 'GET',
+                dataType: 'json',
+                success: function (reponse) {
+                    console.log(reponse);
+                    window.location.reload();
+                }
+            })
+        }
+    }
+})(jQuery);

+ 27 - 0
src/Controller/ProfilController.php

@@ -2,11 +2,13 @@
 
 namespace App\Controller;
 
+use App\Entity\Profile;
 use Doctrine\ORM\EntityManagerInterface;
 use App\Form\UserEditProfilType;
 use App\Form\ProfileType;
 use App\Repository\ProfileRepository;
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Routing\Annotation\Route;
@@ -51,4 +53,29 @@ class ProfilController extends AbstractController
         ]);
     }
 
+    #[Route("/changeview", name: "user_changeview")]
+    public function changeView(EntityManagerInterface $em): JsonResponse
+    {
+        /** @var \App\Entity\User $user */
+        $user = $this->getUser();
+        $profile = $user->getProfile();
+        if ($profile->getView() == Profile::$VIEW['liste']) {
+            $profile->setView(Profile::$VIEW['vignette']);
+        } else {
+            $profile->setView(Profile::$VIEW['liste']);
+        }
+        $em->flush();
+
+        return $this->json($profile->getView());
+    }
+
+    #[Route("/getview", name: "user_getview")]
+    public function getView(): JsonResponse
+    {
+        /** @var \App\Entity\User $user */
+        $user = $this->getUser();
+
+        return $this->json($user->getProfile()->getView());
+    }
+
 }

+ 4 - 2
templates/videotheque/_liste_header.html.twig

@@ -1,8 +1,10 @@
 <div class="d-flex flex-wrap">
     {% if is_granted('IS_AUTHENTICATED_REMEMBERED') %}
         <p class="me-2"><a class="btn btn-primary" role="button" href="{{ path('videotheque_ajouter') }}"><i class="fa fa-plus-square fa-lg"></i> Ajouter un film</a></p>
-        <p class="me-auto"><a class="btn btn-primary" role="button" href="{{ path('videotheque_ajouter_tmdb') }}"><i class="fa fa-plus-square fa-lg"></i> Ajouter par TMDB</a></p>
-    {% endif %}
+        <p class="me-2"><a class="btn btn-primary" role="button" href="{{ path('videotheque_ajouter_tmdb') }}"><i class="fa fa-plus-square fa-lg"></i> Ajouter par TMDB</a></p>
+        <p class="me-auto"><a href="#" role="button" class="btn btn-secondary" id="switchview">Changer de vue</a></p>
+          
+        {% endif %}
     <p class="">Filtrer par film au dessus de
     <input class="rating"
         data-disabled="false"