]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #1292 from wallabag/v2-tags-route
authorJeremy Benoist <j0k3r@users.noreply.github.com>
Sun, 9 Aug 2015 20:47:28 +0000 (22:47 +0200)
committerJeremy Benoist <j0k3r@users.noreply.github.com>
Sun, 9 Aug 2015 20:47:28 +0000 (22:47 +0200)
Add tags list display

src/Wallabag/CoreBundle/Controller/TagController.php [new file with mode: 0644]
src/Wallabag/CoreBundle/Repository/TagRepository.php
src/Wallabag/CoreBundle/Resources/views/Tag/tags.html.twig [new file with mode: 0644]
src/Wallabag/CoreBundle/Resources/views/base.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/base.html.twig
src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php [new file with mode: 0644]

diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
new file mode 100644 (file)
index 0000000..e448cea
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace Wallabag\CoreBundle\Controller;
+
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+
+class TagController extends Controller
+{
+    /**
+     * Shows tags for current user.
+     *
+     * @Route("/tag/list", name="tag")
+     *
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
+    public function showTagAction()
+    {
+        $tags = $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Tag')
+            ->findTags($this->getUser()->getId());
+
+        return $this->render(
+            'WallabagCoreBundle:Tag:tags.html.twig',
+            array(
+                'tags'       => $tags
+            )
+        );
+    }
+
+}
index 52f319f11158f69315b30650d5ba9ce0782f8fc8..51f1cd42924b22a88eb879fd6b5b3b14cfff058f 100644 (file)
@@ -3,7 +3,25 @@
 namespace Wallabag\CoreBundle\Repository;
 
 use Doctrine\ORM\EntityRepository;
+use Pagerfanta\Adapter\DoctrineORMAdapter;
+use Pagerfanta\Pagerfanta;
 
 class TagRepository extends EntityRepository
 {
+    /**
+     * Find Tags.
+     *
+     * @param int    $userId
+     *
+     * @return array
+     */
+    public function findTags($userId)
+    {
+        $qb = $this->createQueryBuilder('t')
+            ->where('t.user =:userId')->setParameter('userId', $userId);
+
+        $pagerAdapter = new DoctrineORMAdapter($qb);
+
+        return new Pagerfanta($pagerAdapter);
+    }
 }
diff --git a/src/Wallabag/CoreBundle/Resources/views/Tag/tags.html.twig b/src/Wallabag/CoreBundle/Resources/views/Tag/tags.html.twig
new file mode 100644 (file)
index 0000000..c2a461b
--- /dev/null
@@ -0,0 +1,13 @@
+{% extends "WallabagCoreBundle::layout.html.twig" %}
+
+{% block title "Tags" %}
+
+{% block content %}
+    {% if tags is empty %}
+        <div class="messages warning"><p>{% trans %}No tags found.{% endtrans %}</p></div>
+    {% else %}
+        {% for tag in tags %}
+            {{tag.label}}
+        {% endfor %}
+    {% endif %}
+{% endblock %}
index 4f27f413fc23a7fef1449d48555299a288b618d4..223e8433c0a83dab128617d39d6c2f81e7499423 100644 (file)
@@ -71,7 +71,7 @@
                     <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="?view=tags">{% trans %}tags{% endtrans %}</a></li>
+                    <li><a href="{{ path ('tag') }}">{% trans %}tags{% endtrans %}</a></li>
                     <li><a href="{{ path('new_entry') }}">{% 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">
index a56f58f3520d9782f4ded682ecfb443a987cbca7..7070a399349f4b1f44d01901d1099dbf5c9b0baf 100644 (file)
@@ -74,7 +74,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 border-bottom {% if currentRoute == 'tags' %}active{% endif %}"><a class="waves-effect" href="?view=tags">{% trans %}tags{% 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"><a class="waves-effect" class="icon icon-power" href="{{ path('logout') }}" title="{% trans %}logout{% endtrans %}">{% trans %}logout{% endtrans %}</a></li>
                     </ul>
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php
new file mode 100644 (file)
index 0000000..34faf70
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+namespace Wallabag\CoreBundle\Tests\Controller;
+
+use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
+use Doctrine\ORM\AbstractQuery;
+
+class TagControllerTest extends WallabagCoreTestCase
+{
+    public function testList()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $client->request('GET', '/tag/list');
+
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());
+    }
+}