aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2020-04-12 18:42:31 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2020-04-28 10:13:58 +0200
commit19c407f2967786bb106ebae636055b30af900e7b (patch)
tree8d908313c4183f74f6108a28a32efda103fa3070
parent4bc6ef346ab28025d613d308da84812325f4c7ce (diff)
downloadwallabag-19c407f2967786bb106ebae636055b30af900e7b.tar.gz
wallabag-19c407f2967786bb106ebae636055b30af900e7b.tar.zst
wallabag-19c407f2967786bb106ebae636055b30af900e7b.zip
First draft for EntrySortType
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php14
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/EntrySortType.php53
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml7
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig42
4 files changed, 90 insertions, 26 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 5157653c..85e71116 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -15,6 +15,7 @@ use Wallabag\CoreBundle\Event\EntryDeletedEvent;
15use Wallabag\CoreBundle\Event\EntrySavedEvent; 15use Wallabag\CoreBundle\Event\EntrySavedEvent;
16use Wallabag\CoreBundle\Form\Type\EditEntryType; 16use Wallabag\CoreBundle\Form\Type\EditEntryType;
17use Wallabag\CoreBundle\Form\Type\EntryFilterType; 17use Wallabag\CoreBundle\Form\Type\EntryFilterType;
18use Wallabag\CoreBundle\Form\Type\EntrySortType;
18use Wallabag\CoreBundle\Form\Type\NewEntryType; 19use Wallabag\CoreBundle\Form\Type\NewEntryType;
19use Wallabag\CoreBundle\Form\Type\SearchEntryType; 20use Wallabag\CoreBundle\Form\Type\SearchEntryType;
20 21
@@ -535,11 +536,11 @@ class EntryController extends Controller
535 // defined as null by default because each repository method have the right field as default value too 536 // 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 537 // like `getBuilderForStarredByUser` will have `starredAt` sort by default
537 $sortBy = null; 538 $sortBy = null;
538 if (\in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) { 539 if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
539 $sortBy = $request->get('sort', null); 540 $sortBy = $request->get('entry_sort')['sortType'];
540 } 541 }
541 542
542 $direction = 'DESC' === $request->get('direction') ? 'DESC' : 'ASC'; 543 $direction = isset($request->get('entry_sort')['sortOrder']) ? 'DESC' : 'ASC';
543 544
544 switch ($type) { 545 switch ($type) {
545 case 'search': 546 case 'search':
@@ -565,6 +566,7 @@ class EntryController extends Controller
565 } 566 }
566 567
567 $form = $this->createForm(EntryFilterType::class); 568 $form = $this->createForm(EntryFilterType::class);
569 $sortForm = $this->createForm(EntrySortType::class);
568 570
569 if ($request->query->has($form->getName())) { 571 if ($request->query->has($form->getName())) {
570 // manually bind values from the request 572 // manually bind values from the request
@@ -574,6 +576,11 @@ class EntryController extends Controller
574 $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb); 576 $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb);
575 } 577 }
576 578
579 if ($request->query->has($sortForm->getName())) {
580 // manually bind values from the request
581 $sortForm->submit($request->query->get($sortForm->getName()));
582 }
583
577 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); 584 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
578 585
579 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter); 586 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter);
@@ -592,6 +599,7 @@ class EntryController extends Controller
592 return $this->render( 599 return $this->render(
593 'WallabagCoreBundle:Entry:entries.html.twig', [ 600 'WallabagCoreBundle:Entry:entries.html.twig', [
594 'form' => $form->createView(), 601 'form' => $form->createView(),
602 'sortForm' => $sortForm->createView(),
595 'entries' => $entries, 603 'entries' => $entries,
596 'currentPage' => $page, 604 'currentPage' => $page,
597 'searchTerm' => $searchTerm, 605 'searchTerm' => $searchTerm,
diff --git a/src/Wallabag/CoreBundle/Form/Type/EntrySortType.php b/src/Wallabag/CoreBundle/Form/Type/EntrySortType.php
new file mode 100644
index 00000000..2555f68d
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Form/Type/EntrySortType.php
@@ -0,0 +1,53 @@
1<?php
2
3namespace Wallabag\CoreBundle\Form\Type;
4
5use Doctrine\ORM\EntityRepository;
6use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\CheckboxFilterType;
7use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType;
8use Symfony\Component\Form\AbstractType;
9use Symfony\Component\Form\FormBuilderInterface;
10use Symfony\Component\OptionsResolver\OptionsResolver;
11use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
12
13class EntrySortType extends AbstractType
14{
15 private $user;
16
17 public function __construct(TokenStorageInterface $tokenStorage)
18 {
19 $this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null;
20
21 if (null === $this->user || !\is_object($this->user)) {
22 return;
23 }
24 }
25
26 public function buildForm(FormBuilderInterface $builder, array $options)
27 {
28 $builder
29 ->add('sortOrder', CheckboxFilterType::class)
30 ->add('sortType', ChoiceFilterType::class, [
31 'choices' => [
32 'createdAt' => 'createdAt',
33 'title' => 'title',
34 'updatedAt' => 'updatedAt',
35 ],
36 'label' => 'entry.sort.status_label',
37 ])
38 ;
39 }
40
41 public function getBlockPrefix()
42 {
43 return 'entry_sort';
44 }
45
46 public function configureOptions(OptionsResolver $resolver)
47 {
48 $resolver->setDefaults([
49 'csrf_protection' => false,
50 'validation_groups' => ['sortering'],
51 ]);
52 }
53}
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index 8417ac35..8867ec0c 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -22,6 +22,13 @@ services:
22 tags: 22 tags:
23 - { name: form.type } 23 - { name: form.type }
24 24
25 wallabag_core.sort.type.entry:
26 class: Wallabag\CoreBundle\Form\Type\EntrySortType
27 arguments:
28 - "@security.token_storage"
29 tags:
30 - { name: form.type }
31
25 wallabag_core.param_converter.username_feed_token_converter: 32 wallabag_core.param_converter.username_feed_token_converter:
26 class: Wallabag\CoreBundle\ParamConverter\UsernameFeedTokenConverter 33 class: Wallabag\CoreBundle\ParamConverter\UsernameFeedTokenConverter
27 tags: 34 tags:
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 e6497893..7706896f 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
@@ -209,36 +209,32 @@
209 {% endif %} 209 {% endif %}
210 210
211 <!-- Sort --> 211 <!-- Sort -->
212 {% if sortForm is not null %}
212 <div id="sort" class="side-nav right-aligned"> 213 <div id="sort" class="side-nav right-aligned">
214 <form action="{{ path('all') }}">
213 <h4 class="center">{{ 'entry.sort.title'|trans }}</h4> 215 <h4 class="center">{{ 'entry.sort.title'|trans }}</h4>
214 216
215 <div class="row"> 217 <div class="row">
216 <div class="col s12"> 218 <div class="input-field col s6 with-checkbox">
217 <label>{{ 'entry.sort.status_label'|trans }}</label> 219 {{ form_widget(sortForm.sortType) }}
218 </div> 220 {{ form_label(sortForm.sortType) }}
221 </div>
219 222
220 <div class="input-field col s12 with-checkbox"> 223 <div class="col s12">
221 <select> 224 <div class="switch">
222 <option value="" disabled selected>Creation date</option> 225 <label>Ascendant
223 <option value="createdAt">{{ 'entry.sort.by.creation_date' | trans }}</option> 226 {{ form_widget(sortForm.sortOrder) }} <span class="lever"></span>
224 <option value="title">{{ 'entry.sort.by.title' | trans }}</option> 227 Descendant
225 <option value="updatedAt">{{ 'entry.sort.by.last_updated' | trans }}</option> 228 </label>
226 </select> 229 </div>
227 </div> 230 </div>
228 231
229 <div class="col s12"> 232 <div class="col s12">
230 <div class="switch"> 233 <button class="btn waves-effect waves-light" type="submit" id="submit-filter" value="filter">{{ 'entry.filters.action.filter'|trans }}</button>
231 <label>
232 Ascendant
233 <input type="checkbox">
234 <span class="lever"></span>
235 Descendant
236 </label>
237 </div> 234 </div>
238 </div> 235 </div>
239 </div> 236 </form>
240 </div> 237 </div>
241 238 {% endif %}
242 {# {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} #}
243 239
244{% endblock %} 240{% endblock %}