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) {
$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,
]);
}
}

View file

@ -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

View file

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

View file

@ -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');