From 89659c9eae338cd29e5919b5ffde6924189a59ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= <nicolas@loeuillet.org> Date: Thu, 20 Aug 2015 15:59:47 +0200 Subject: [PATCH 1/4] filters: implement status filter and a new view (to display all entries) --- composer.lock | 22 +++++----- .../CoreBundle/Controller/EntryController.php | 42 +++++++++++++++++++ .../CoreBundle/Filter/EntryFilterType.php | 4 +- .../CoreBundle/Resources/views/base.html.twig | 3 +- .../themes/material/Entry/entries.html.twig | 19 ++++++++- .../views/themes/material/layout.html.twig | 1 + .../views/themes/material/public/js/init.js | 1 + 7 files changed, 77 insertions(+), 15 deletions(-) diff --git a/composer.lock b/composer.lock index 559a08dc6..59f3343e9 100644 --- a/composer.lock +++ b/composer.lock @@ -3466,16 +3466,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.4", + "version": "4.8.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "55bf1d6092b0e13a1f26bd5eaffeef3d8ad85ea7" + "reference": "9b7417edaf28059ea63d86be941e6004dbfcc0cc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/55bf1d6092b0e13a1f26bd5eaffeef3d8ad85ea7", - "reference": "55bf1d6092b0e13a1f26bd5eaffeef3d8ad85ea7", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9b7417edaf28059ea63d86be941e6004dbfcc0cc", + "reference": "9b7417edaf28059ea63d86be941e6004dbfcc0cc", "shasum": "" }, "require": { @@ -3534,24 +3534,24 @@ "testing", "xunit" ], - "time": "2015-08-15 04:21:23" + "time": "2015-08-19 09:20:57" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.6", + "version": "2.3.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42" + "reference": "5e2645ad49d196e020b85598d7c97e482725786a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/18dfbcb81d05e2296c0bcddd4db96cade75e6f42", - "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5e2645ad49d196e020b85598d7c97e482725786a", + "reference": "5e2645ad49d196e020b85598d7c97e482725786a", "shasum": "" }, "require": { - "doctrine/instantiator": "~1.0,>=1.0.2", + "doctrine/instantiator": "^1.0.2", "php": ">=5.3.3", "phpunit/php-text-template": "~1.2", "sebastian/exporter": "~1.2" @@ -3590,7 +3590,7 @@ "mock", "xunit" ], - "time": "2015-07-10 06:54:24" + "time": "2015-08-19 09:14:08" }, { "name": "sebastian/comparator", diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index dc399b8a3..4070a6037 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -101,6 +101,48 @@ class EntryController extends Controller )); } + /** + * Shows all entries for current user. + * + * @param Request $request + * @param int $page + * + * @Route("/all/list/{page}", name="all", defaults={"page" = "1"}) + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function showAllAction(Request $request, $page) + { + $form = $this->get('form.factory')->create(new EntryFilterType()); + + $filterBuilder = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->findAllByUser($this->getUser()->getId()); + + if ($request->query->has($form->getName())) { + // manually bind values from the request + $form->submit($request->query->get($form->getName())); + + // build the query from the given form object + $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $filterBuilder); + } + + $pagerAdapter = new DoctrineORMAdapter($filterBuilder->getQuery()); + $entries = new Pagerfanta($pagerAdapter); + + $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); + $entries->setCurrentPage($page); + + return $this->render( + 'WallabagCoreBundle:Entry:entries.html.twig', + array( + 'form' => $form->createView(), + 'entries' => $entries, + 'currentPage' => $page, + ) + ); + } + /** * Shows unread entries for current user. * diff --git a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php index 771daef17..ff51785b8 100644 --- a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php @@ -39,7 +39,9 @@ class EntryFilterType extends AbstractType return $filterQuery->createCondition($expression); }, - )); + )) + ->add('isArchived', 'filter_checkbox') + ->add('isStarred', 'filter_checkbox'); } public function getName() diff --git a/src/Wallabag/CoreBundle/Resources/views/base.html.twig b/src/Wallabag/CoreBundle/Resources/views/base.html.twig index ac5d2bf9c..3ad776b99 100644 --- a/src/Wallabag/CoreBundle/Resources/views/base.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/base.html.twig @@ -71,7 +71,8 @@ <li><a href="{{ path('unread') }}">{% trans %}unread{% endtrans %}</a></li> <li><a href="{{ path('starred') }}">{% trans %}favorites{% endtrans %}</a></li> <li><a href="{{ path('archive') }}"}>{% trans %}archive{% endtrans %}</a></li> - <li><a href="{{ path('tag') }}">{% trans %}tags{% endtrans %}</a></li> + <li><a href="{{ path('all') }}"}>{% trans %}all{% endtrans %}</a></li> + <li><a href="{{ path ('tag') }}">{% trans %}tags{% endtrans %}</a></li> <li><a href="{{ path('new') }}">{% trans %}save a link{% endtrans %}</a></li> <li style="position: relative;"><a href="javascript: void(null);" id="search">{% trans %}search{% endtrans %}</a> <div id="search-form" class="messages info popup-form"> 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 bd64067c5..b45552f2d 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 @@ -7,6 +7,8 @@ {% trans %}Starred{% endtrans %} {% elseif currentRoute == 'archive' %} {% trans %}Archive{% endtrans %} + {% elseif currentRoute == 'all' %} + {% trans %}Filtered{% endtrans %} {% else %} {% trans %}Unread{% endtrans %} {% endif %} @@ -59,12 +61,26 @@ <!-- Filters --> <div id="filters" class="side-nav fixed right-aligned"> - <form> + <form action="{{ path('all') }}"> <h4 class="center">{% trans %}Filters{% endtrans %}</h1> <div class="row"> + + <div class="col s12"> + <label>{% trans %}Status{% endtrans %}</label> + </div> + <div class="input-field col s6"> + {{ form_widget(form.isArchived) }} + <label for="entry_filter_isArchived">{% trans %}Archived{% endtrans %}</label> + </div> + + <div class="input-field col s6"> + {{ form_widget(form.isStarred) }} + <label for="entry_filter_isStarred">{% trans %}Starred{% endtrans %}</label> + </div> + <div class="col s12"> <label>{% trans %}Reading time in minutes{% endtrans %}</label> </div> @@ -77,7 +93,6 @@ <label for="entry_filter_readingTime_right_number">{% trans %}to{% endtrans %}</label> </div> - <div class="input-field col s6"> {{ form_widget(form.domainName, {'type': 'text', 'attr' : {'placeholder': 'website.com'} }) }} <label for="entry_filter_domainName">{% trans %}Domain name{% endtrans %}</label> 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 1456d5dd6..0ec2e082b 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig @@ -42,6 +42,7 @@ <li class="bold {% if currentRoute == 'unread' or currentRoute == 'homepage' %}active{% endif %}"><a class="waves-effect" href="{{ path('unread') }}">{% trans %}unread{% endtrans %}</a></li> <li class="bold {% if currentRoute == 'starred' %}active{% endif %}"><a class="waves-effect" href="{{ path('starred') }}">{% trans %}starred{% endtrans %}</a></li> <li class="bold {% if currentRoute == 'archive' %}active{% endif %}"><a class="waves-effect" href="{{ path('archive') }}">{% trans %}archive{% endtrans %}</a></li> + <li class="bold {% if currentRoute == 'all' %}active{% endif %}"><a class="waves-effect" href="{{ path('all') }}">{% trans %}all{% endtrans %}</a></li> <li class="bold border-bottom {% if currentRoute == 'tags' %}active{% endif %}"><a class="waves-effect" href="{{ path('tag') }}">{% trans %}tags{% endtrans %}</a></li> <li class="bold {% if currentRoute == 'config' %}active{% endif %}"><a class="waves-effect" href="{{ path('config') }}">{% trans %}config{% endtrans %}</a></li> <li class="bold {% if currentRoute == 'howto' %}active{% endif %}"><a class="waves-effect" href="{{ path('howto') }}">{% trans %}howto{% endtrans %}</a></li> diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/public/js/init.js b/src/Wallabag/CoreBundle/Resources/views/themes/material/public/js/init.js index c0700c2cb..d397f8e5c 100755 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/public/js/init.js +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/public/js/init.js @@ -5,6 +5,7 @@ function init_filters() { $('.button-collapse-right').sideNav({ edge: 'right' }); $('#clear_form_filters').on('click', function(){ $('#filters input').val(''); + $('#filters :checked').removeAttr('checked'); return false; }); } From e1779760999f676cb7a74a201bc2a389959702d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= <nicolas@loeuillet.org> Date: Thu, 20 Aug 2015 17:59:58 +0200 Subject: [PATCH 2/4] filters: add test for status filter and adapt other tests results --- .../Resources/views/Entry/entries.html.twig | 2 +- .../Tests/Controller/EntryControllerTest.php | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig index a794df0e5..118a2f4be 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig @@ -21,7 +21,7 @@ {% if entries is empty %} <div class="messages warning"><p>{% trans %}No articles found.{% endtrans %}</p></div> {% else %} - <div><form>{{ form_rest(form) }}<button class="btn waves-effect waves-light" type="submit" id="submit-filter" value="filter">Filter</button></form></div> + <div><form action="{{ path('all') }}">{{ form_rest(form) }}<button class="btn waves-effect waves-light" type="submit" id="submit-filter" value="filter">Filter</button></form></div> {% for entry in entries %} <div id="entry-{{ entry.id|e }}" class="entry"> <h2><a href="{{ path('view', { 'id': entry.id }) }}">{{ entry.title|raw }}</a></h2> diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 86a19f616..5f0a60763 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -276,7 +276,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(4, $crawler->filter('div[class=entry]')); + $this->assertCount(5, $crawler->filter('div[class=entry]')); $data = array( 'entry_filter[createdAt][left_date]' => '01/01/1970', @@ -307,6 +307,14 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', 'unread/list'.$parameters); $this->assertContains($parameters, $client->getResponse()->getContent()); + + // reset pagination + $crawler = $client->request('GET', '/config'); + $form = $crawler->filter('button[id=config_save]')->form(); + $data = array( + 'config[items_per_page]' => '12', + ); + $client->submit($form, $data); } public function testFilterOnDomainName() @@ -331,4 +339,25 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); $this->assertCount(0, $crawler->filter('div[class=entry]')); } + + public function testFilterOnStatus() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + $form['entry_filter[isArchived]']->tick(); + $form['entry_filter[isStarred]']->untick(); + + $crawler = $client->submit($form); + $this->assertCount(1, $crawler->filter('div[class=entry]')); + + $form = $crawler->filter('button[id=submit-filter]')->form(); + $form['entry_filter[isArchived]']->untick(); + $form['entry_filter[isStarred]']->tick(); + + $crawler = $client->submit($form); + $this->assertCount(1, $crawler->filter('div[class=entry]')); + } } From 2b7a4889178b35b64e0297d12abef79dd0b70df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= <nicolas@loeuillet.org> Date: Fri, 21 Aug 2015 07:38:18 +0200 Subject: [PATCH 3/4] filters: adapt queryBuilder for 'all' view --- .../CoreBundle/Controller/EntryController.php | 33 +++---------------- .../CoreBundle/Repository/EntryRepository.php | 14 ++++++++ 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 4070a6037..c4975ae66 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -113,34 +113,7 @@ class EntryController extends Controller */ public function showAllAction(Request $request, $page) { - $form = $this->get('form.factory')->create(new EntryFilterType()); - - $filterBuilder = $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->findAllByUser($this->getUser()->getId()); - - if ($request->query->has($form->getName())) { - // manually bind values from the request - $form->submit($request->query->get($form->getName())); - - // build the query from the given form object - $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $filterBuilder); - } - - $pagerAdapter = new DoctrineORMAdapter($filterBuilder->getQuery()); - $entries = new Pagerfanta($pagerAdapter); - - $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); - $entries->setCurrentPage($page); - - return $this->render( - 'WallabagCoreBundle:Entry:entries.html.twig', - array( - 'form' => $form->createView(), - 'entries' => $entries, - 'currentPage' => $page, - ) - ); + return $this->showEntries('all', $request, $page); } /** @@ -215,6 +188,10 @@ class EntryController extends Controller $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId()); break; + case 'all': + $qb = $repository->getBuilderForAllByUser($this->getUser()->getId()); + break; + default: throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); } diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 5538ae82b..e764e8f70 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -24,6 +24,20 @@ class EntryRepository extends EntityRepository ; } + /** + * Retrieves all entries for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getBuilderForAllByUser($userId) + { + return $this + ->getBuilderByUser($userId) + ; + } + /** * Retrieves unread entries for a user. * From 3b84dc08fcc663f758c4fbba186aeb95f212fddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= <nicolas@loeuillet.org> Date: Fri, 21 Aug 2015 11:02:22 +0200 Subject: [PATCH 4/4] restore composer.lock --- composer.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index 59f3343e9..559a08dc6 100644 --- a/composer.lock +++ b/composer.lock @@ -3466,16 +3466,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.5", + "version": "4.8.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "9b7417edaf28059ea63d86be941e6004dbfcc0cc" + "reference": "55bf1d6092b0e13a1f26bd5eaffeef3d8ad85ea7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9b7417edaf28059ea63d86be941e6004dbfcc0cc", - "reference": "9b7417edaf28059ea63d86be941e6004dbfcc0cc", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/55bf1d6092b0e13a1f26bd5eaffeef3d8ad85ea7", + "reference": "55bf1d6092b0e13a1f26bd5eaffeef3d8ad85ea7", "shasum": "" }, "require": { @@ -3534,24 +3534,24 @@ "testing", "xunit" ], - "time": "2015-08-19 09:20:57" + "time": "2015-08-15 04:21:23" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.7", + "version": "2.3.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "5e2645ad49d196e020b85598d7c97e482725786a" + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5e2645ad49d196e020b85598d7c97e482725786a", - "reference": "5e2645ad49d196e020b85598d7c97e482725786a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/18dfbcb81d05e2296c0bcddd4db96cade75e6f42", + "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.2", + "doctrine/instantiator": "~1.0,>=1.0.2", "php": ">=5.3.3", "phpunit/php-text-template": "~1.2", "sebastian/exporter": "~1.2" @@ -3590,7 +3590,7 @@ "mock", "xunit" ], - "time": "2015-08-19 09:14:08" + "time": "2015-07-10 06:54:24" }, { "name": "sebastian/comparator",