diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index 176b7ea07..ba2f53662 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -93,7 +93,7 @@ class EntryFilterType extends AbstractType 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { $value = $values['value']; if (\strlen($value) <= 2 || empty($value)) { - return; + return false; } $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%' . $value . '%'))); @@ -105,7 +105,7 @@ class EntryFilterType extends AbstractType 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { $value = $values['value']; if (false === \array_key_exists($value, Response::$statusTexts)) { - return; + return false; } $paramName = sprintf('%s', str_replace('.', '_', $field)); @@ -129,7 +129,7 @@ class EntryFilterType extends AbstractType 'data' => $options['filter_unread'], 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { if (false === $values['value']) { - return; + return false; } $expression = $filterQuery->getExpr()->eq('e.isArchived', 'false'); @@ -137,10 +137,22 @@ class EntryFilterType extends AbstractType return $filterQuery->createCondition($expression); }, ]) + ->add('isAnnotated', CheckboxFilterType::class, [ + 'label' => 'entry.filters.annotated_label', + 'data' => $options['filter_annotated'], + 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { + if (false === $values['value']) { + return false; + } + + $qb = $filterQuery->getQueryBuilder(); + $qb->innerJoin('e.annotations', 'a'); + }, + ]) ->add('previewPicture', CheckboxFilterType::class, [ 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { if (false === $values['value']) { - return; + return false; } $expression = $filterQuery->getExpr()->isNotNull($field); @@ -152,7 +164,7 @@ class EntryFilterType extends AbstractType ->add('isPublic', CheckboxFilterType::class, [ 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { if (false === $values['value']) { - return; + return false; } // is_public isn't a real field @@ -183,6 +195,7 @@ class EntryFilterType extends AbstractType 'filter_archived' => false, 'filter_starred' => false, 'filter_unread' => false, + 'filter_annotated' => false, ]); } } diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 98d374a2d..775006fc1 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -247,6 +247,7 @@ entry: archived_label: Archived starred_label: Starred unread_label: Unread + annotated_label: Annotated preview_picture_label: Has a preview picture preview_picture_help: Preview picture is_public_label: Has a public link 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 f80156834..604d399da 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 @@ -131,6 +131,11 @@ {{ form_label(form.isUnread) }} +
+ {{ form_widget(form.isAnnotated) }} + {{ form_label(form.isAnnotated) }} +
+
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index d010db097..7c105ac78 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -3,6 +3,7 @@ namespace Tests\Wallabag\CoreBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\AnnotationBundle\Entity\Annotation; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\SiteCredential; @@ -888,6 +889,44 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(0, $crawler->filter('li.entry')); } + public function testFilterOnAnnotatedStatus() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/all/list'); + + $form = $crawler->filter('button[id=submit-filter]')->form(); + + $data = [ + 'entry_filter[isAnnotated]' => true, + ]; + + $crawler = $client->submit($form, $data); + + $this->assertCount(2, $crawler->filter('li.entry')); + + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + + $em = $this->getClient()->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUserName('admin'); + + $annotation = new Annotation($user); + $annotation->setEntry($entry); + $annotation->setText('This is my annotation /o/'); + $annotation->setQuote('content'); + + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + + $crawler = $client->submit($form, $data); + + $this->assertCount(3, $crawler->filter('li.entry')); + } + public function testPaginationWithFilter() { $this->logInAs('admin');