]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Fix sort
authorJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 7 Jun 2019 15:58:11 +0000 (17:58 +0200)
committerNicolas LÅ“uillet <nicolas@loeuillet.org>
Tue, 28 Apr 2020 08:13:57 +0000 (10:13 +0200)
app/Resources/static/themes/material/index.js
app/Resources/static/themes/material/js/tools.js
src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php
src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig

index d8f5628cd5cf866f2ebdb7c848ec7d91ee1d7764..6d9b145e21aa78e30b2fb1a290080381b31ff240 100755 (executable)
@@ -8,7 +8,7 @@ import 'materialize-css/dist/js/materialize';
 import '../_global/index';
 
 /* Tools */
-import { initExport, initFilters, initRandom } from './js/tools';
+import { initExport, initFilters, initRandom, initSort } from './js/tools';
 
 /* Import shortcuts */
 import './js/shortcuts/main';
@@ -70,6 +70,7 @@ $(document).ready(() => {
   initRandom();
   stickyNav();
   articleScroll();
+  initSort();
 
   const toggleNav = (toShow, toFocus) => {
     $('.nav-panel-actions').hide(100);
index 0b3d303856a5b0b806390bd795fab6c00c5ac3a6..8563a14ab5f958397a67138d3a2b1db984531273 100644 (file)
@@ -29,8 +29,16 @@ function initRandom() {
   }
 }
 
+function initSort() {
+  // no display if export (ie: entries) not available
+  if ($('div').is('#sort')) {
+    $('#button_sort').show();
+  }
+}
+
 export {
   initExport,
   initFilters,
   initRandom,
+  initSort,
 };
index b3ec7729e673f87a5d2435558842797933905c37..5157653c6480f05cbb106e34547eb5c350e678cd 100644 (file)
@@ -535,7 +535,7 @@ class EntryController extends Controller
         // 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('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
+        if (\in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
             $sortBy = $request->get('sort', null);
         }
 
index cf1cdb8a5e0a77c8fbb349458099d90baa8a9e40..aa761df38fd127e4fe9f8d7115d522b27a310361 100644 (file)
@@ -24,6 +24,8 @@ class EntryRepository extends EntityRepository
      */
     public function getBuilderForAllByUser($userId, $sortBy = 'id', $direction = 'DESC')
     {
+        $sortBy = $sortBy ?: 'id';
+
         return $this
             ->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
         ;
@@ -40,6 +42,8 @@ class EntryRepository extends EntityRepository
      */
     public function getBuilderForUnreadByUser($userId, $sortBy = 'id', $direction = 'DESC')
     {
+        $sortBy = $sortBy ?: 'id';
+
         return $this
             ->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
             ->andWhere('e.isArchived = false')
@@ -57,6 +61,8 @@ class EntryRepository extends EntityRepository
      */
     public function getBuilderForArchiveByUser($userId, $sortBy = 'archivedAt', $direction = 'DESC')
     {
+        $sortBy = $sortBy ?: 'archivedAt';
+
         return $this
             ->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
             ->andWhere('e.isArchived = true')
@@ -74,6 +80,8 @@ class EntryRepository extends EntityRepository
      */
     public function getBuilderForStarredByUser($userId, $sortBy = 'starredAt', $direction = 'DESC')
     {
+        $sortBy = $sortBy ?: 'starredAt';
+
         return $this
             ->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
             ->andWhere('e.isStarred = true')
@@ -579,6 +587,11 @@ class EntryRepository extends EntityRepository
      */
     private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc')
     {
-        return $qb->orderBy(sprintf('e.%s', $sortBy), $direction);
+        // in case one of these isn't defined, don't apply the orderBy
+        if (!$sortBy || !$direction) {
+            return $qb;
+        }
+
+        return $qb->orderBy(sprintf('e.%s', $sortBy), strtoupper($direction));
     }
 }
index deeb19a366d3902cefd66aae0a024575d36311a5..1654a0e02a1accc5f102a72e9aa16b12893555d8 100644 (file)
     {% endif %}
 
     <!-- Sort -->
-    <div id="sort" class="side-nav fixed right-aligned">
-
+    <div id="sort" class="side-nav right-aligned">
         <h4 class="center">{{ 'entry.sort.title'|trans }}</h4>
 
         <div class="row">
                 </div>
             </div>
         </div>
-
     </div>
 
-    {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %}
+    {# {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} #}
 
 {% endblock %}
index 95d7da9a36cb2b95ae44dde9bb82c70c25150551..0c3d4d5b7d6d3d3886b4bc0333e4883895ed5a04 100644 (file)
@@ -93,7 +93,7 @@
                         </a>
                     </li>
                     <li id="button_sort">
-                        <a title="{{ 'menu.top.sort_entries'|trans }}" href="#" data-activates="sort" class="nav-panel-menu button-collapse-right">
+                        <a class="nav-panel-menu button-collapse-right tooltipped js-sort-action" data-position="bottom" data-delay="50" data-tooltip="{{ 'menu.top.sort_entries'|trans }}" href="#" data-activates="sort">
                             <i class="material-icons">sort_by_alpha</i>
                         </a>
                     </li>