From 891456ba9a592a200d8b23029e8f4514d9803080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 14 Apr 2016 15:03:22 +0200 Subject: Links on each tag in Tags view --- .../CoreBundle/Controller/TagController.php | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 8645fb44..b6514ea6 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -2,12 +2,15 @@ namespace Wallabag\CoreBundle\Controller; +use Pagerfanta\Adapter\ArrayAdapter; +use Pagerfanta\Exception\OutOfRangeCurrentPageException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Form\Type\NewTagType; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; class TagController extends Controller { @@ -90,4 +93,41 @@ class TagController extends Controller ] ); } + + /** + * @param Tag $tag + * @param int $page + * + * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"}) + * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function showEntriesForTagAction(Tag $tag, $page, Request $request) + { + $pagerAdapter = new ArrayAdapter($tag->getEntries()->toArray()); + + $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') + ->prepare($pagerAdapter, $page); + + try { + $entries->setCurrentPage($page); + } catch (OutOfRangeCurrentPageException $e) { + if ($page > 1) { + return $this->redirect($this->generateUrl($request->get('_route'), [ + 'slug' => $tag->getSlug(), + 'page' => $entries->getNbPages(), + ]), 302); + } + } + + return $this->render( + 'WallabagCoreBundle:Entry:entries.html.twig', + [ + 'form' => null, + 'entries' => $entries, + 'currentPage' => $page, + ] + ); + } } -- cgit v1.2.3 From 267e8d6361f8e7791a8687f2370a3e9d08af6648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 30 Apr 2016 15:03:22 +0200 Subject: Add tests for tag list routes --- src/Wallabag/CoreBundle/Controller/TagController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index b6514ea6..1cbc413d 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -105,7 +105,11 @@ class TagController extends Controller */ public function showEntriesForTagAction(Tag $tag, $page, Request $request) { - $pagerAdapter = new ArrayAdapter($tag->getEntries()->toArray()); + $entriesByTag = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->findAllByTagId($this->getUser()->getId(), $tag->getId()); + + $pagerAdapter = new ArrayAdapter($entriesByTag); $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') ->prepare($pagerAdapter, $page); -- cgit v1.2.3 From 429d86f388da856c9d8d9a649147c5212bee4258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 4 Sep 2016 20:53:28 +0200 Subject: Added tags counter in sidebar (material theme) --- src/Wallabag/CoreBundle/Controller/TagController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 1cbc413d..bc95a4d3 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -84,7 +84,9 @@ class TagController extends Controller { $tags = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Tag') - ->findAllTags($this->getUser()->getId()); + ->findAllTags($this->getUser()->getId()) + ->getQuery() + ->getResult(); return $this->render( 'WallabagCoreBundle:Tag:tags.html.twig', -- cgit v1.2.3 From faa86e06ba3032fdb98f3c0f79c72e8581d3c96f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 11:21:13 +0200 Subject: Fix tags count in menu Move enable cache for Tag in the Entity because function `find*` should return result and not a Query --- .../CoreBundle/Controller/TagController.php | 28 ++++++++-------------- 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index bc95a4d3..07cd3edb 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -84,16 +84,11 @@ class TagController extends Controller { $tags = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Tag') - ->findAllTags($this->getUser()->getId()) - ->getQuery() - ->getResult(); - - return $this->render( - 'WallabagCoreBundle:Tag:tags.html.twig', - [ - 'tags' => $tags, - ] - ); + ->findAllTagsWithEntries($this->getUser()->getId()); + + return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ + 'tags' => $tags, + ]); } /** @@ -127,13 +122,10 @@ class TagController extends Controller } } - return $this->render( - 'WallabagCoreBundle:Entry:entries.html.twig', - [ - 'form' => null, - 'entries' => $entries, - 'currentPage' => $page, - ] - ); + return $this->render('WallabagCoreBundle:Entry:entries.html.twig',[ + 'form' => null, + 'entries' => $entries, + 'currentPage' => $page, + ]); } } -- cgit v1.2.3 From 82fc3290d4fec45ede270e2c1ad2079fe3020adc Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 12:03:12 +0200 Subject: CS --- src/Wallabag/CoreBundle/Controller/TagController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 07cd3edb..623a6146 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -122,7 +122,7 @@ class TagController extends Controller } } - return $this->render('WallabagCoreBundle:Entry:entries.html.twig',[ + return $this->render('WallabagCoreBundle:Entry:entries.html.twig', [ 'form' => null, 'entries' => $entries, 'currentPage' => $page, -- cgit v1.2.3 From ac8cf632bb3a225c1b69d16e714ff60a2e988c89 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 7 Oct 2016 23:31:53 +0200 Subject: Ensure orphan tag are remove in API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the association between a tag and an entry is removed, if the tag doesn’t have other entries, we can remove it. Also add more tests for that part and ensure TagControllerTest is isolated from the rest of the test suite (finally!) --- src/Wallabag/CoreBundle/Controller/TagController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 623a6146..c5746734 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -63,10 +63,12 @@ class TagController extends Controller $entry->removeTag($tag); $em = $this->getDoctrine()->getManager(); $em->flush(); - if (count($tag->getEntries()) == 0) { + + // remove orphan tag in case no entries are associated to it + if (count($tag->getEntries()) === 0) { $em->remove($tag); + $em->flush(); } - $em->flush(); $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer')); -- cgit v1.2.3 From 28bb48905a2104adad65508f51737f987dc1ad4c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 9 Oct 2016 18:41:19 +0200 Subject: Optimize the way tag list is rendered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of retrieve all informations about entries of a tag to just count them, we’ll count them before with a fastest query. Also change the layout of the tag list in material design --- src/Wallabag/CoreBundle/Controller/TagController.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index c5746734..5acc6852 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -86,10 +86,25 @@ class TagController extends Controller { $tags = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Tag') - ->findAllTagsWithEntries($this->getUser()->getId()); + ->findAllTags($this->getUser()->getId()); + + $flatTags = []; + + foreach ($tags as $key => $tag) { + $nbEntries = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag['id']); + + $flatTags[] = [ + 'id' => $tag['id'], + 'label' => $tag['label'], + 'slug' => $tag['slug'], + 'nbEntries' => $nbEntries, + ]; + } return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ - 'tags' => $tags, + 'tags' => $flatTags, ]); } -- cgit v1.2.3