Added annotated filter

This commit is contained in:
Nicolas Lœuillet 2021-08-02 16:57:42 +02:00 committed by Jeremy Benoist
parent 6dfc031839
commit cd975c5f13
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
4 changed files with 63 additions and 5 deletions

View file

@ -93,7 +93,7 @@ class EntryFilterType extends AbstractType
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
$value = $values['value']; $value = $values['value'];
if (\strlen($value) <= 2 || empty($value)) { if (\strlen($value) <= 2 || empty($value)) {
return; return false;
} }
$expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%' . $value . '%'))); $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) { 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
$value = $values['value']; $value = $values['value'];
if (false === \array_key_exists($value, Response::$statusTexts)) { if (false === \array_key_exists($value, Response::$statusTexts)) {
return; return false;
} }
$paramName = sprintf('%s', str_replace('.', '_', $field)); $paramName = sprintf('%s', str_replace('.', '_', $field));
@ -129,7 +129,7 @@ class EntryFilterType extends AbstractType
'data' => $options['filter_unread'], 'data' => $options['filter_unread'],
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
if (false === $values['value']) { if (false === $values['value']) {
return; return false;
} }
$expression = $filterQuery->getExpr()->eq('e.isArchived', 'false'); $expression = $filterQuery->getExpr()->eq('e.isArchived', 'false');
@ -137,10 +137,22 @@ class EntryFilterType extends AbstractType
return $filterQuery->createCondition($expression); 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, [ ->add('previewPicture', CheckboxFilterType::class, [
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
if (false === $values['value']) { if (false === $values['value']) {
return; return false;
} }
$expression = $filterQuery->getExpr()->isNotNull($field); $expression = $filterQuery->getExpr()->isNotNull($field);
@ -152,7 +164,7 @@ class EntryFilterType extends AbstractType
->add('isPublic', CheckboxFilterType::class, [ ->add('isPublic', CheckboxFilterType::class, [
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
if (false === $values['value']) { if (false === $values['value']) {
return; return false;
} }
// is_public isn't a real field // is_public isn't a real field
@ -183,6 +195,7 @@ class EntryFilterType extends AbstractType
'filter_archived' => false, 'filter_archived' => false,
'filter_starred' => false, 'filter_starred' => false,
'filter_unread' => false, 'filter_unread' => false,
'filter_annotated' => false,
]); ]);
} }
} }

View file

@ -247,6 +247,7 @@ entry:
archived_label: Archived archived_label: Archived
starred_label: Starred starred_label: Starred
unread_label: Unread unread_label: Unread
annotated_label: Annotated
preview_picture_label: Has a preview picture preview_picture_label: Has a preview picture
preview_picture_help: Preview picture preview_picture_help: Preview picture
is_public_label: Has a public link is_public_label: Has a public link

View file

@ -131,6 +131,11 @@
{{ form_label(form.isUnread) }} {{ form_label(form.isUnread) }}
</div> </div>
<div class="input-field col s6 with-checkbox">
{{ form_widget(form.isAnnotated) }}
{{ form_label(form.isAnnotated) }}
</div>
<div class="col s12"> <div class="col s12">
<label>{{ 'entry.filters.preview_picture_help'|trans }}</label> <label>{{ 'entry.filters.preview_picture_help'|trans }}</label>
</div> </div>

View file

@ -3,6 +3,7 @@
namespace Tests\Wallabag\CoreBundle\Controller; namespace Tests\Wallabag\CoreBundle\Controller;
use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
use Wallabag\AnnotationBundle\Entity\Annotation;
use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Config;
use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\SiteCredential; use Wallabag\CoreBundle\Entity\SiteCredential;
@ -888,6 +889,44 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->assertCount(0, $crawler->filter('li.entry')); $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() public function testPaginationWithFilter()
{ {
$this->logInAs('admin'); $this->logInAs('admin');