]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
add filter on domain name 1342/head
authorNicolas Lœuillet <nicolas@loeuillet.org>
Tue, 18 Aug 2015 15:28:12 +0000 (17:28 +0200)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Wed, 19 Aug 2015 12:27:00 +0000 (14:27 +0200)
src/Wallabag/CoreBundle/Filter/EntryFilterType.php
src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php

index 2fa2f8a08033beada4f9e36436e3373b45a68dc9..d1057fb56f7d9a4a6231fd11e2cdf70a9d6c71e9 100644 (file)
@@ -5,6 +5,8 @@ namespace Wallabag\CoreBundle\Filter;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\OptionsResolver\OptionsResolver;
+use Lexik\Bundle\FormFilterBundle\Filter\FilterOperands;
+use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
 
 class EntryFilterType extends AbstractType
 {
@@ -24,7 +26,18 @@ class EntryFilterType extends AbstractType
                             'placeholder' => 'dd/mm/yyyy'),
                         'format' => 'dd/MM/yyyy',
                         'widget' => 'single_text'
-                    )));
+                )))
+            ->add('domainName', 'filter_text', array(
+                'apply_filter' => function (QueryInterface $filterQuery, $field, $values)
+                    {
+                        $value = $values['value'];
+                        if (strlen($value) <= 3 || empty($value)) {
+                            return null;
+                        }
+                        $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%'));
+                        return $filterQuery->createCondition($expression);
+                    }
+            ));
     }
 
     public function getName()
index 41ce9eee71897d4f474f94a19fa55cda07418c05..67061e4c7441e03893d43c81fc7975959fd99c2d 100644 (file)
                     <label for="entry_filter_readingTime_right_number">{% trans %}to{% endtrans %}</label>
                 </div>
 
+
                 <div class="col s12">
+
                     <label>{% trans %}Create at{% endtrans %}</label>
+
+                    <label>{% trans %}Domain name{% endtrans %}</label>
+                </div>
+                <div class="input-field col s6">
+                    {{ form_widget(form.domainName, {'type': 'text'}) }}
+                    <label for="entry_filter_domainName">{% trans %}www.website.com{% endtrans %}</label>
                 </div>
 
                 <div class="input-field col s6">
index 87c164157c928149a0daaf9c1bb35bcc1cd79cba..8d013ec002c626b73b3c9fbd59b70ad374e4e380 100644 (file)
@@ -293,7 +293,6 @@ class EntryControllerTest extends WallabagCoreTestCase
     {
         $this->logInAs('admin');
         $client = $this->getClient();
-
         $crawler = $client->request('GET', '/config');
 
         $form = $crawler->filter('button[id=config_save]')->form();
@@ -310,4 +309,27 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $this->assertContains($parameters, $client->getResponse()->getContent());
     }
+
+    public function testFilterOnDomainName()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $crawler = $client->request('GET', '/unread/list');
+        $form = $crawler->filter('button[id=submit-filter]')->form();
+        $data = array(
+            'entry_filter[domainName]' => 'monde'
+        );
+
+        $crawler = $client->submit($form, $data);
+        $this->assertCount(1, $crawler->filter('div[class=entry]'));
+
+        $form = $crawler->filter('button[id=submit-filter]')->form();
+        $data = array(
+            'entry_filter[domainName]' => 'wallabag'
+        );
+
+        $crawler = $client->submit($form, $data);
+        $this->assertCount(0, $crawler->filter('div[class=entry]'));
+    }
 }