From: Jeremy Benoist Date: Fri, 7 Jun 2019 15:58:11 +0000 (+0200) Subject: Fix sort X-Git-Url: https://git.immae.eu/?p=github%2Fwallabag%2Fwallabag.git;a=commitdiff_plain;h=136f710ddb48f01e24892c5d2dde3b1f3a069fc4 Fix sort --- diff --git a/app/Resources/static/themes/material/index.js b/app/Resources/static/themes/material/index.js index d8f5628c..6d9b145e 100755 --- a/app/Resources/static/themes/material/index.js +++ b/app/Resources/static/themes/material/index.js @@ -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); diff --git a/app/Resources/static/themes/material/js/tools.js b/app/Resources/static/themes/material/js/tools.js index 0b3d3038..8563a14a 100644 --- a/app/Resources/static/themes/material/js/tools.js +++ b/app/Resources/static/themes/material/js/tools.js @@ -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, }; diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index b3ec7729..5157653c 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -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); } diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index cf1cdb8a..aa761df3 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -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)); } } diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index deeb19a3..1654a0e0 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig @@ -210,8 +210,7 @@ {% endif %} -
- +

{{ 'entry.sort.title'|trans }}

@@ -239,9 +238,8 @@
- - {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} + {# {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} #} {% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig index 95d7da9a..0c3d4d5b 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig @@ -93,7 +93,7 @@
  • - + sort_by_alpha