]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
Fixed UI
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index ff90957b9917661f879472a5186d28dea6ab26a1..6e56c2373313dde73d3bf3cd52f6937ce672a6d8 100644 (file)
@@ -15,6 +15,7 @@ use Wallabag\CoreBundle\Event\EntryDeletedEvent;
 use Wallabag\CoreBundle\Event\EntrySavedEvent;
 use Wallabag\CoreBundle\Form\Type\EditEntryType;
 use Wallabag\CoreBundle\Form\Type\EntryFilterType;
+use Wallabag\CoreBundle\Form\Type\EntrySortType;
 use Wallabag\CoreBundle\Form\Type\NewEntryType;
 use Wallabag\CoreBundle\Form\Type\SearchEntryType;
 
@@ -531,14 +532,15 @@ class EntryController extends Controller
         $repository = $this->get('wallabag_core.entry_repository');
         $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
         $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
+        $direction = (null !== $request->query->get('entry_sort')['sortOrder'] ? $request->query->get('entry_sort')['sortOrder'] : 'asc');
 
-        $sortBy = 'id';
-        if (in_array($request->get('sort', 'id'), ['id', 'created_at', 'title', 'updated_at'], true)) {
-            $sortBy = $request->get('sort', 'id');
+        // defined as null by default because each repository method have the right field as default value too
+        // like `getBuilderForStarredByUser` will have `starredAt` sort by default
+        $sortBy = null;
+        if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
+            $sortBy = $request->get('entry_sort')['sortType'];
         }
 
-        $direction = 'DESC' === $request->get('direction') ? 'DESC' : 'ASC';
-
         switch ($type) {
             case 'search':
                 $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
@@ -563,6 +565,7 @@ class EntryController extends Controller
         }
 
         $form = $this->createForm(EntryFilterType::class);
+        $sortForm = $this->createForm(EntrySortType::class);
 
         if ($request->query->has($form->getName())) {
             // manually bind values from the request
@@ -572,6 +575,11 @@ class EntryController extends Controller
             $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb);
         }
 
+        if ($request->query->has($sortForm->getName())) {
+            // manually bind values from the request
+            $sortForm->submit($request->query->get($sortForm->getName()));
+        }
+
         $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
 
         $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter);
@@ -590,6 +598,7 @@ class EntryController extends Controller
         return $this->render(
             'WallabagCoreBundle:Entry:entries.html.twig', [
                 'form' => $form->createView(),
+                'sortForm' => $sortForm->createView(),
                 'entries' => $entries,
                 'currentPage' => $page,
                 'searchTerm' => $searchTerm,