aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2019-06-07 17:58:11 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2020-04-28 10:13:57 +0200
commit136f710ddb48f01e24892c5d2dde3b1f3a069fc4 (patch)
tree1cfb16a7be14879a2af2df0c4390ba8c49d60f89
parente70e383378fc38f8154d482a247a0d2ca23a4925 (diff)
downloadwallabag-136f710ddb48f01e24892c5d2dde3b1f3a069fc4.tar.gz
wallabag-136f710ddb48f01e24892c5d2dde3b1f3a069fc4.tar.zst
wallabag-136f710ddb48f01e24892c5d2dde3b1f3a069fc4.zip
Fix sort
-rwxr-xr-xapp/Resources/static/themes/material/index.js3
-rw-r--r--app/Resources/static/themes/material/js/tools.js8
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php2
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php15
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig6
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig2
6 files changed, 28 insertions, 8 deletions
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';
8import '../_global/index'; 8import '../_global/index';
9 9
10/* Tools */ 10/* Tools */
11import { initExport, initFilters, initRandom } from './js/tools'; 11import { initExport, initFilters, initRandom, initSort } from './js/tools';
12 12
13/* Import shortcuts */ 13/* Import shortcuts */
14import './js/shortcuts/main'; 14import './js/shortcuts/main';
@@ -70,6 +70,7 @@ $(document).ready(() => {
70 initRandom(); 70 initRandom();
71 stickyNav(); 71 stickyNav();
72 articleScroll(); 72 articleScroll();
73 initSort();
73 74
74 const toggleNav = (toShow, toFocus) => { 75 const toggleNav = (toShow, toFocus) => {
75 $('.nav-panel-actions').hide(100); 76 $('.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() {
29 } 29 }
30} 30}
31 31
32function initSort() {
33 // no display if export (ie: entries) not available
34 if ($('div').is('#sort')) {
35 $('#button_sort').show();
36 }
37}
38
32export { 39export {
33 initExport, 40 initExport,
34 initFilters, 41 initFilters,
35 initRandom, 42 initRandom,
43 initSort,
36}; 44};
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
535 // defined as null by default because each repository method have the right field as default value too 535 // defined as null by default because each repository method have the right field as default value too
536 // like `getBuilderForStarredByUser` will have `starredAt` sort by default 536 // like `getBuilderForStarredByUser` will have `starredAt` sort by default
537 $sortBy = null; 537 $sortBy = null;
538 if (in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { 538 if (\in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
539 $sortBy = $request->get('sort', null); 539 $sortBy = $request->get('sort', null);
540 } 540 }
541 541
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
24 */ 24 */
25 public function getBuilderForAllByUser($userId, $sortBy = 'id', $direction = 'DESC') 25 public function getBuilderForAllByUser($userId, $sortBy = 'id', $direction = 'DESC')
26 { 26 {
27 $sortBy = $sortBy ?: 'id';
28
27 return $this 29 return $this
28 ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) 30 ->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
29 ; 31 ;
@@ -40,6 +42,8 @@ class EntryRepository extends EntityRepository
40 */ 42 */
41 public function getBuilderForUnreadByUser($userId, $sortBy = 'id', $direction = 'DESC') 43 public function getBuilderForUnreadByUser($userId, $sortBy = 'id', $direction = 'DESC')
42 { 44 {
45 $sortBy = $sortBy ?: 'id';
46
43 return $this 47 return $this
44 ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) 48 ->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
45 ->andWhere('e.isArchived = false') 49 ->andWhere('e.isArchived = false')
@@ -57,6 +61,8 @@ class EntryRepository extends EntityRepository
57 */ 61 */
58 public function getBuilderForArchiveByUser($userId, $sortBy = 'archivedAt', $direction = 'DESC') 62 public function getBuilderForArchiveByUser($userId, $sortBy = 'archivedAt', $direction = 'DESC')
59 { 63 {
64 $sortBy = $sortBy ?: 'archivedAt';
65
60 return $this 66 return $this
61 ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) 67 ->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
62 ->andWhere('e.isArchived = true') 68 ->andWhere('e.isArchived = true')
@@ -74,6 +80,8 @@ class EntryRepository extends EntityRepository
74 */ 80 */
75 public function getBuilderForStarredByUser($userId, $sortBy = 'starredAt', $direction = 'DESC') 81 public function getBuilderForStarredByUser($userId, $sortBy = 'starredAt', $direction = 'DESC')
76 { 82 {
83 $sortBy = $sortBy ?: 'starredAt';
84
77 return $this 85 return $this
78 ->getSortedQueryBuilderByUser($userId, $sortBy, $direction) 86 ->getSortedQueryBuilderByUser($userId, $sortBy, $direction)
79 ->andWhere('e.isStarred = true') 87 ->andWhere('e.isStarred = true')
@@ -579,6 +587,11 @@ class EntryRepository extends EntityRepository
579 */ 587 */
580 private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc') 588 private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc')
581 { 589 {
582 return $qb->orderBy(sprintf('e.%s', $sortBy), $direction); 590 // in case one of these isn't defined, don't apply the orderBy
591 if (!$sortBy || !$direction) {
592 return $qb;
593 }
594
595 return $qb->orderBy(sprintf('e.%s', $sortBy), strtoupper($direction));
583 } 596 }
584} 597}
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 @@
210 {% endif %} 210 {% endif %}
211 211
212 <!-- Sort --> 212 <!-- Sort -->
213 <div id="sort" class="side-nav fixed right-aligned"> 213 <div id="sort" class="side-nav right-aligned">
214
215 <h4 class="center">{{ 'entry.sort.title'|trans }}</h4> 214 <h4 class="center">{{ 'entry.sort.title'|trans }}</h4>
216 215
217 <div class="row"> 216 <div class="row">
@@ -239,9 +238,8 @@
239 </div> 238 </div>
240 </div> 239 </div>
241 </div> 240 </div>
242
243 </div> 241 </div>
244 242
245 {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} 243 {# {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} #}
246 244
247{% endblock %} 245{% 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 @@
93 </a> 93 </a>
94 </li> 94 </li>
95 <li id="button_sort"> 95 <li id="button_sort">
96 <a title="{{ 'menu.top.sort_entries'|trans }}" href="#" data-activates="sort" class="nav-panel-menu button-collapse-right"> 96 <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">
97 <i class="material-icons">sort_by_alpha</i> 97 <i class="material-icons">sort_by_alpha</i>
98 </a> 98 </a>
99 </li> 99 </li>