aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas@loeuillet.org>2016-08-23 11:51:13 +0200
committerGitHub <noreply@github.com>2016-08-23 11:51:13 +0200
commit1bee9e0760c89756ebab0b67f9ab7efc5c6a709b (patch)
treecd6200f084675195aaa5789a3d0e1297eca1a94a
parent79efca1e6ff28362d4bd2713f68205294cdd07de (diff)
parent97e7ad4dc7bfc26cea334bc880a39e388d6848f3 (diff)
downloadwallabag-1bee9e0760c89756ebab0b67f9ab7efc5c6a709b.tar.gz
wallabag-1bee9e0760c89756ebab0b67f9ab7efc5c6a709b.tar.zst
wallabag-1bee9e0760c89756ebab0b67f9ab7efc5c6a709b.zip
Merge pull request #2218 from wallabag/api-delete-tags-1982
Delete tag or tags by label
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php72
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php6
-rw-r--r--src/Wallabag/CoreBundle/Controller/ExportController.php2
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php44
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php7
-rw-r--r--src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php34
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php13
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml6
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.da.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.de.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.en.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.es.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig24
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig2
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig7
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig2
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php113
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php31
24 files changed, 357 insertions, 16 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index 03eb9b08..869fdc56 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -334,6 +334,77 @@ class WallabagRestController extends FOSRestController
334 * 334 *
335 * @ApiDoc( 335 * @ApiDoc(
336 * requirements={ 336 * requirements={
337 * {"name"="tag", "dataType"="string", "required"=true, "requirement"="\w+", "description"="Tag as a string"}
338 * }
339 * )
340 *
341 * @return Response
342 */
343 public function deleteTagLabelAction(Request $request)
344 {
345 $this->validateAuthentication();
346 $label = $request->request->get('tag', '');
347
348 $tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($label);
349
350 if (empty($tag)) {
351 throw $this->createNotFoundException('Tag not found');
352 }
353
354 $this->getDoctrine()
355 ->getRepository('WallabagCoreBundle:Entry')
356 ->removeTag($this->getUser()->getId(), $tag);
357
358 $json = $this->get('serializer')->serialize($tag, 'json');
359
360 return $this->renderJsonResponse($json);
361 }
362
363 /**
364 * Permanently remove some tags from **every** entry.
365 *
366 * @ApiDoc(
367 * requirements={
368 * {"name"="tags", "dataType"="string", "required"=true, "format"="tag1,tag2", "description"="Tags as strings (comma splitted)"}
369 * }
370 * )
371 *
372 * @return Response
373 */
374 public function deleteTagsLabelAction(Request $request)
375 {
376 $this->validateAuthentication();
377
378 $tagsLabels = $request->request->get('tags', '');
379
380 $tags = [];
381
382 foreach (explode(',', $tagsLabels) as $tagLabel) {
383 $tagEntity = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel);
384
385 if (!empty($tagEntity)) {
386 $tags[] = $tagEntity;
387 }
388 }
389
390 if (empty($tags)) {
391 throw $this->createNotFoundException('Tags not found');
392 }
393
394 $this->getDoctrine()
395 ->getRepository('WallabagCoreBundle:Entry')
396 ->removeTags($this->getUser()->getId(), $tags);
397
398 $json = $this->get('serializer')->serialize($tags, 'json');
399
400 return $this->renderJsonResponse($json);
401 }
402
403 /**
404 * Permanently remove one tag from **every** entry.
405 *
406 * @ApiDoc(
407 * requirements={
337 * {"name"="tag", "dataType"="integer", "requirement"="\w+", "description"="The tag"} 408 * {"name"="tag", "dataType"="integer", "requirement"="\w+", "description"="The tag"}
338 * } 409 * }
339 * ) 410 * )
@@ -352,6 +423,7 @@ class WallabagRestController extends FOSRestController
352 423
353 return $this->renderJsonResponse($json); 424 return $this->renderJsonResponse($json);
354 } 425 }
426
355 /** 427 /**
356 * Retrieve version number. 428 * Retrieve version number.
357 * 429 *
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index ccdf9406..93db0d6c 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -4,7 +4,6 @@ namespace Wallabag\CoreBundle\Controller;
4 4
5use Pagerfanta\Adapter\DoctrineORMAdapter; 5use Pagerfanta\Adapter\DoctrineORMAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException; 6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7use Pagerfanta\Pagerfanta;
8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9use Symfony\Bundle\FrameworkBundle\Controller\Controller; 8use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
@@ -257,9 +256,10 @@ class EntryController extends Controller
257 } 256 }
258 257
259 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); 258 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery());
260 $entries = new Pagerfanta($pagerAdapter);
261 259
262 $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); 260 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
261 ->prepare($pagerAdapter, $page);
262
263 try { 263 try {
264 $entries->setCurrentPage($page); 264 $entries->setCurrentPage($page);
265 } catch (OutOfRangeCurrentPageException $e) { 265 } catch (OutOfRangeCurrentPageException $e) {
diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php
index 944c755d..959b308d 100644
--- a/src/Wallabag/CoreBundle/Controller/ExportController.php
+++ b/src/Wallabag/CoreBundle/Controller/ExportController.php
@@ -46,7 +46,7 @@ class ExportController extends Controller
46 * 46 *
47 * @Route("/export/{category}.{format}", name="export_entries", requirements={ 47 * @Route("/export/{category}.{format}", name="export_entries", requirements={
48 * "format": "epub|mobi|pdf|json|xml|txt|csv", 48 * "format": "epub|mobi|pdf|json|xml|txt|csv",
49 * "category": "all|unread|starred|archive" 49 * "category": "all|unread|starred|archive|tag_entries"
50 * }) 50 * })
51 * 51 *
52 * @return \Symfony\Component\HttpFoundation\Response 52 * @return \Symfony\Component\HttpFoundation\Response
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index 8645fb44..1cbc413d 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -2,12 +2,15 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Pagerfanta\Adapter\ArrayAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller; 8use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
8use Wallabag\CoreBundle\Entity\Entry; 10use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag; 11use Wallabag\CoreBundle\Entity\Tag;
10use Wallabag\CoreBundle\Form\Type\NewTagType; 12use Wallabag\CoreBundle\Form\Type\NewTagType;
13use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
11 14
12class TagController extends Controller 15class TagController extends Controller
13{ 16{
@@ -90,4 +93,45 @@ class TagController extends Controller
90 ] 93 ]
91 ); 94 );
92 } 95 }
96
97 /**
98 * @param Tag $tag
99 * @param int $page
100 *
101 * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"})
102 * @ParamConverter("tag", options={"mapping": {"slug": "slug"}})
103 *
104 * @return \Symfony\Component\HttpFoundation\Response
105 */
106 public function showEntriesForTagAction(Tag $tag, $page, Request $request)
107 {
108 $entriesByTag = $this->getDoctrine()
109 ->getRepository('WallabagCoreBundle:Entry')
110 ->findAllByTagId($this->getUser()->getId(), $tag->getId());
111
112 $pagerAdapter = new ArrayAdapter($entriesByTag);
113
114 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
115 ->prepare($pagerAdapter, $page);
116
117 try {
118 $entries->setCurrentPage($page);
119 } catch (OutOfRangeCurrentPageException $e) {
120 if ($page > 1) {
121 return $this->redirect($this->generateUrl($request->get('_route'), [
122 'slug' => $tag->getSlug(),
123 'page' => $entries->getNbPages(),
124 ]), 302);
125 }
126 }
127
128 return $this->render(
129 'WallabagCoreBundle:Entry:entries.html.twig',
130 [
131 'form' => null,
132 'entries' => $entries,
133 'currentPage' => $page,
134 ]
135 );
136 }
93} 137}
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php
index 8553dced..09e99f36 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php
@@ -28,6 +28,13 @@ class LoadTagData extends AbstractFixture implements OrderedFixtureInterface
28 28
29 $this->addReference('bar-tag', $tag2); 29 $this->addReference('bar-tag', $tag2);
30 30
31 $tag3 = new Tag();
32 $tag3->setLabel('baz');
33
34 $manager->persist($tag3);
35
36 $this->addReference('baz-tag', $tag3);
37
31 $manager->flush(); 38 $manager->flush();
32 } 39 }
33 40
diff --git a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php
new file mode 100644
index 00000000..f9066bee
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php
@@ -0,0 +1,34 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Pagerfanta\Adapter\AdapterInterface;
6use Pagerfanta\Pagerfanta;
7use Symfony\Component\Routing\Router;
8use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
9
10class PreparePagerForEntries
11{
12 private $user;
13 private $router;
14
15 public function __construct(TokenStorage $token, Router $router)
16 {
17 $this->user = $token->getToken()->getUser();
18 $this->router = $router;
19 }
20
21 /**
22 * @param AdapterInterface $adapter
23 * @param int $page
24 *
25 * @return null|Pagerfanta
26 */
27 public function prepare(AdapterInterface $adapter, $page = 1)
28 {
29 $entries = new Pagerfanta($adapter);
30 $entries->setMaxPerPage($this->user->getConfig()->getItemsPerPage());
31
32 return $entries;
33 }
34}
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index e9351d85..fada40bb 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -223,6 +223,19 @@ class EntryRepository extends EntityRepository
223 } 223 }
224 224
225 /** 225 /**
226 * Remove tags from all user entries.
227 *
228 * @param int $userId
229 * @param Array<Tag> $tags
230 */
231 public function removeTags($userId, $tags)
232 {
233 foreach ($tags as $tag) {
234 $this->removeTag($userId, $tag);
235 }
236 }
237
238 /**
226 * Find all entries that are attached to a give tag id. 239 * Find all entries that are attached to a give tag id.
227 * 240 *
228 * @param int $userId 241 * @param int $userId
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index f8835198..e95ef452 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -119,3 +119,9 @@ services:
119 class: Wallabag\CoreBundle\Helper\Redirect 119 class: Wallabag\CoreBundle\Helper\Redirect
120 arguments: 120 arguments:
121 - "@router" 121 - "@router"
122
123 wallabag_core.helper.prepare_pager_for_entries:
124 class: Wallabag\CoreBundle\Helper\PreparePagerForEntries
125 arguments:
126 - "@security.token_storage"
127 - "@router"
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
index c24475d2..87988539 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
@@ -139,6 +139,7 @@ entry:
139 # starred: 'Starred entries' 139 # starred: 'Starred entries'
140 # archived: 'Archived entries' 140 # archived: 'Archived entries'
141 # filtered: 'Filtered entries' 141 # filtered: 'Filtered entries'
142 # filtered_tags: 'Filtered by tags'
142 list: 143 list:
143 # number_on_the_page: '{0} There is no entry.|{1} There is one entry.|]1,Inf[ There are %count% entries.' 144 # number_on_the_page: '{0} There is no entry.|{1} There is one entry.|]1,Inf[ There are %count% entries.'
144 reading_time: 'estimeret læsetid' 145 reading_time: 'estimeret læsetid'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
index 384ec09a..461967d6 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
@@ -139,6 +139,7 @@ entry:
139 starred: 'Favorisierte Einträge' 139 starred: 'Favorisierte Einträge'
140 archived: 'Archivierte Einträge' 140 archived: 'Archivierte Einträge'
141 filtered: 'Gefilterte Einträge' 141 filtered: 'Gefilterte Einträge'
142 # filtered_tags: 'Filtered by tags'
142 list: 143 list:
143 number_on_the_page: '{0} Es gibt keine Einträge.|{1} Es gibt einen Eintrag.|]1,Inf[ Es gibt %count% Einträge.' 144 number_on_the_page: '{0} Es gibt keine Einträge.|{1} Es gibt einen Eintrag.|]1,Inf[ Es gibt %count% Einträge.'
144 reading_time: 'geschätzte Lesezeit' 145 reading_time: 'geschätzte Lesezeit'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
index ea860564..600b7472 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
@@ -139,6 +139,7 @@ entry:
139 starred: 'Starred entries' 139 starred: 'Starred entries'
140 archived: 'Archived entries' 140 archived: 'Archived entries'
141 filtered: 'Filtered entries' 141 filtered: 'Filtered entries'
142 filtered_tags: 'Filtered by tags'
142 list: 143 list:
143 number_on_the_page: '{0} There are no entries.|{1} There is one entry.|]1,Inf[ There are %count% entries.' 144 number_on_the_page: '{0} There are no entries.|{1} There is one entry.|]1,Inf[ There are %count% entries.'
144 reading_time: 'estimated reading time' 145 reading_time: 'estimated reading time'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
index f64e95d5..6da8a593 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
@@ -139,6 +139,7 @@ entry:
139 starred: 'Artículos favoritos' 139 starred: 'Artículos favoritos'
140 archived: 'Artículos archivados' 140 archived: 'Artículos archivados'
141 filtered: 'Artículos filtrados' 141 filtered: 'Artículos filtrados'
142 # filtered_tags: 'Filtered by tags'
142 list: 143 list:
143 number_on_the_page: '{0} No hay artículos.|{1} Hay un artículo.|]1,Inf[ Hay %count% artículos.' 144 number_on_the_page: '{0} No hay artículos.|{1} Hay un artículo.|]1,Inf[ Hay %count% artículos.'
144 reading_time: 'tiempo estimado de lectura' 145 reading_time: 'tiempo estimado de lectura'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
index e3592a78..4684b08b 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
@@ -139,6 +139,7 @@ entry:
139 starred: 'مقاله‌های برگزیده' 139 starred: 'مقاله‌های برگزیده'
140 archived: 'مقاله‌های بایگانی‌شده' 140 archived: 'مقاله‌های بایگانی‌شده'
141 filtered: 'مقاله‌های فیلترشده' 141 filtered: 'مقاله‌های فیلترشده'
142 # filtered_tags: 'Filtered by tags'
142 list: 143 list:
143 number_on_the_page: '{0} هیج مقاله‌ای نیست.|{1} یک مقاله هست.|]1,Inf[ %count% مقاله هست.' 144 number_on_the_page: '{0} هیج مقاله‌ای نیست.|{1} یک مقاله هست.|]1,Inf[ %count% مقاله هست.'
144 reading_time: 'زمان تخمینی برای خواندن' 145 reading_time: 'زمان تخمینی برای خواندن'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index 9e47d600..2b6e4194 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -139,6 +139,7 @@ entry:
139 starred: 'Articles favoris' 139 starred: 'Articles favoris'
140 archived: 'Articles lus' 140 archived: 'Articles lus'
141 filtered: 'Articles filtrés' 141 filtered: 'Articles filtrés'
142 filtered_tags: 'Articles filtrés par tags'
142 list: 143 list:
143 number_on_the_page: "{0} Il n'y a pas d'articles.|{1} Il y a un article.|]1,Inf[ Il y a %count% articles." 144 number_on_the_page: "{0} Il n'y a pas d'articles.|{1} Il y a un article.|]1,Inf[ Il y a %count% articles."
144 reading_time: 'durée de lecture' 145 reading_time: 'durée de lecture'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
index 1e23168b..95435606 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
@@ -139,6 +139,7 @@ entry:
139 starred: 'Articles favorits' 139 starred: 'Articles favorits'
140 archived: 'Articles legits' 140 archived: 'Articles legits'
141 filtered: 'Articles filtrats' 141 filtered: 'Articles filtrats'
142 # filtered_tags: 'Filtered by tags'
142 list: 143 list:
143 number_on_the_page: "{0} I a pas cap d'article.|{1} I a un article.|]1,Inf[ I a %count% articles." 144 number_on_the_page: "{0} I a pas cap d'article.|{1} I a un article.|]1,Inf[ I a %count% articles."
144 reading_time: 'durada de lectura' 145 reading_time: 'durada de lectura'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
index 0a325c57..b0b7e49b 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
@@ -139,6 +139,7 @@ entry:
139 starred: 'Wpisy oznaczone gwiazdką' 139 starred: 'Wpisy oznaczone gwiazdką'
140 archived: 'Zarchiwizowane wpisy' 140 archived: 'Zarchiwizowane wpisy'
141 filtered: 'Odfiltrowane wpisy' 141 filtered: 'Odfiltrowane wpisy'
142 # filtered_tags: 'Filtered by tags'
142 list: 143 list:
143 number_on_the_page: '{0} Nie ma wpisów.|{1} Jest jeden wpis.|]1,Inf[ Są %count% wpisy.' 144 number_on_the_page: '{0} Nie ma wpisów.|{1} Jest jeden wpis.|]1,Inf[ Są %count% wpisy.'
144 reading_time: 'szacunkowy czas czytania' 145 reading_time: 'szacunkowy czas czytania'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
index 42ad28ee..d735df4c 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
@@ -139,6 +139,7 @@ entry:
139 # starred: 'Starred entries' 139 # starred: 'Starred entries'
140 # archived: 'Archived entries' 140 # archived: 'Archived entries'
141 # filtered: 'Filtered entries' 141 # filtered: 'Filtered entries'
142 # filtered_tags: 'Filtered by tags'
142 list: 143 list:
143 # number_on_the_page: '{0} There is no entry.|{1} There is one entry.|]1,Inf[ There are %count% entries.' 144 # number_on_the_page: '{0} There is no entry.|{1} There is one entry.|]1,Inf[ There are %count% entries.'
144 reading_time: 'timp estimat de citire' 145 reading_time: 'timp estimat de citire'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
index a60dfc86..77bfa0f0 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
@@ -139,6 +139,7 @@ entry:
139 # starred: 'Starred entries' 139 # starred: 'Starred entries'
140 # archived: 'Archived entries' 140 # archived: 'Archived entries'
141 # filtered: 'Filtered entries' 141 # filtered: 'Filtered entries'
142 # filtered_tags: 'Filtered by tags'
142 list: 143 list:
143 number_on_the_page: '{0} Herhangi bir makale yok.|{1} Burada bir adet makale var.|]1,Inf[ Burada %count% adet makale var.' 144 number_on_the_page: '{0} Herhangi bir makale yok.|{1} Burada bir adet makale var.|]1,Inf[ Burada %count% adet makale var.'
144 reading_time: 'tahmini okuma süresi' 145 reading_time: 'tahmini okuma süresi'
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
index 92eecb9b..9380e67a 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig
@@ -1,6 +1,20 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %} 1{% extends "WallabagCoreBundle::layout.html.twig" %}
2 2
3{% block title %}{{ 'entry.page_titles.unread'|trans }}{% endblock %} 3{% block title %}
4 {% set currentRoute = app.request.attributes.get('_route') %}
5
6 {% if currentRoute == 'starred' %}
7 {{ 'entry.page_titles.starred'|trans }}
8 {% elseif currentRoute == 'archive' %}
9 {{ 'entry.page_titles.archived'|trans }}
10 {% elseif currentRoute == 'all' %}
11 {{ 'entry.page_titles.filtered'|trans }}
12 {% elseif currentRoute == 'tag_entries' %}
13 {{ 'entry.page_titles.filtered_tags'|trans }}
14 {% else %}
15 {{ 'entry.page_titles.unread'|trans }}
16 {% endif %}
17{% endblock %}
4 18
5{% block content %} 19{% block content %}
6 {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} 20 {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %}
@@ -44,7 +58,6 @@
44 </div> 58 </div>
45 {% endfor %} 59 {% endfor %}
46 60
47
48 <!-- Export --> 61 <!-- Export -->
49 <aside id="download-form"> 62 <aside id="download-form">
50 {% set currentRoute = app.request.attributes.get('_route') %} 63 {% set currentRoute = app.request.attributes.get('_route') %}
@@ -63,8 +76,10 @@
63 {% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml' }) }}">XML</a></li>{% endif %} 76 {% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml' }) }}">XML</a></li>{% endif %}
64 </ul> 77 </ul>
65 </aside> 78 </aside>
79
66 <!-- Filter --> 80 <!-- Filter -->
67 <aside id="filter-form"> 81 {% if form is not null %}
82 <aside id="filter-form" class="">
68 <form method="get" action="{{ path('all') }}"> 83 <form method="get" action="{{ path('all') }}">
69 <h2>{{ 'entry.filters.title'|trans }}</h2> 84 <h2>{{ 'entry.filters.title'|trans }}</h2>
70 <a href="javascript: void(null);" id="filter-form-close" class="close-button--popup close-button">&times;</a> 85 <a href="javascript: void(null);" id="filter-form-close" class="close-button--popup close-button">&times;</a>
@@ -145,6 +160,5 @@
145 </div> 160 </div>
146 </form> 161 </form>
147 </aside> 162 </aside>
148 163 {% endif %}
149 {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %}
150{% endblock %} 164{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig
index 524a1d23..739e1486 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Tag/tags.html.twig
@@ -9,7 +9,7 @@
9 9
10 <ul> 10 <ul>
11 {% for tag in tags %} 11 {% for tag in tags %}
12 <li id="tag-{{ tag.id|e }}">{{tag.label}} ({{ tag.getEntriesByUserId(app.user.id) | length }})</li> 12 <li id="tag-{{ tag.id|e }}"><a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.entries.getValues | length }})</a></li>
13 {% endfor %} 13 {% endfor %}
14 </ul> 14 </ul>
15{% endblock %} 15{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
index eca8924e..2a972e1c 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig
@@ -9,10 +9,11 @@
9 {{ 'entry.page_titles.archived'|trans }} 9 {{ 'entry.page_titles.archived'|trans }}
10 {% elseif currentRoute == 'all' %} 10 {% elseif currentRoute == 'all' %}
11 {{ 'entry.page_titles.filtered'|trans }} 11 {{ 'entry.page_titles.filtered'|trans }}
12 {% elseif currentRoute == 'tag_entries' %}
13 {{ 'entry.page_titles.filtered_tags'|trans }}
12 {% else %} 14 {% else %}
13 {{ 'entry.page_titles.unread'|trans }} 15 {{ 'entry.page_titles.unread'|trans }}
14 {% endif %} 16 {% endif %}
15
16{% endblock %} 17{% endblock %}
17 18
18{% block content %} 19{% block content %}
@@ -122,6 +123,7 @@
122 </div> 123 </div>
123 124
124 <!-- Filters --> 125 <!-- Filters -->
126 {% if form is not null %}
125 <div id="filters" class="side-nav fixed right-aligned"> 127 <div id="filters" class="side-nav fixed right-aligned">
126 <form action="{{ path('all') }}"> 128 <form action="{{ path('all') }}">
127 129
@@ -205,5 +207,6 @@
205 207
206 </form> 208 </form>
207 </div> 209 </div>
208 {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} 210 {% endif %}
211
209{% endblock %} 212{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig
index d958c4b8..9495f543 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig
@@ -9,7 +9,7 @@
9 <br /> 9 <br />
10 <ul class="row data"> 10 <ul class="row data">
11 {% for tag in tags %} 11 {% for tag in tags %}
12 <li id="tag-{{ tag.id|e }}" class="col l4 m6 s12">{{tag.label}} ({{ tag.getEntriesByUserId(app.user.id) | length }})</li> 12 <li id="tag-{{ tag.id|e }}" class="col l4 m6 s12"><a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.entries.getValues | length }})</a></li>
13 {% endfor %} 13 {% endfor %}
14 </ul> 14 </ul>
15{% endblock %} 15{% endblock %}
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index 528366af..ee5b2ab7 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\ApiBundle\Controller; 3namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase; 5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6use Wallabag\CoreBundle\Entity\Tag;
6 7
7class WallabagRestControllerTest extends WallabagApiTestCase 8class WallabagRestControllerTest extends WallabagApiTestCase
8{ 9{
@@ -359,7 +360,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
359 $entry = $this->client->getContainer() 360 $entry = $this->client->getContainer()
360 ->get('doctrine.orm.entity_manager') 361 ->get('doctrine.orm.entity_manager')
361 ->getRepository('WallabagCoreBundle:Entry') 362 ->getRepository('WallabagCoreBundle:Entry')
362 ->findOneWithTags(1); 363 ->findOneWithTags($this->user->getId());
363 364
364 $entry = $entry[0]; 365 $entry = $entry[0];
365 366
@@ -421,7 +422,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
421 $entry = $this->client->getContainer() 422 $entry = $this->client->getContainer()
422 ->get('doctrine.orm.entity_manager') 423 ->get('doctrine.orm.entity_manager')
423 ->getRepository('WallabagCoreBundle:Entry') 424 ->getRepository('WallabagCoreBundle:Entry')
424 ->findOneWithTags(1); 425 ->findOneWithTags($this->user->getId());
425 $entry = $entry[0]; 426 $entry = $entry[0];
426 427
427 if (!$entry) { 428 if (!$entry) {
@@ -472,7 +473,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
472 $this->assertEquals($tag['label'], $content['label']); 473 $this->assertEquals($tag['label'], $content['label']);
473 $this->assertEquals($tag['slug'], $content['slug']); 474 $this->assertEquals($tag['slug'], $content['slug']);
474 475
475 $entries = $entry = $this->client->getContainer() 476 $entries = $this->client->getContainer()
476 ->get('doctrine.orm.entity_manager') 477 ->get('doctrine.orm.entity_manager')
477 ->getRepository('WallabagCoreBundle:Entry') 478 ->getRepository('WallabagCoreBundle:Entry')
478 ->findAllByTagId($this->user->getId(), $tag['id']); 479 ->findAllByTagId($this->user->getId(), $tag['id']);
@@ -480,6 +481,112 @@ class WallabagRestControllerTest extends WallabagApiTestCase
480 $this->assertCount(0, $entries); 481 $this->assertCount(0, $entries);
481 } 482 }
482 483
484 public function testDeleteTagByLabel()
485 {
486 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
487 $entry = $this->client->getContainer()
488 ->get('doctrine.orm.entity_manager')
489 ->getRepository('WallabagCoreBundle:Entry')
490 ->findOneWithTags($this->user->getId());
491
492 $entry = $entry[0];
493
494 $tag = new Tag();
495 $tag->setLabel('Awesome tag for test');
496 $em->persist($tag);
497
498 $entry->addTag($tag);
499
500 $em->persist($entry);
501 $em->flush();
502
503 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]);
504
505 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
506
507 $content = json_decode($this->client->getResponse()->getContent(), true);
508
509 $this->assertArrayHasKey('label', $content);
510 $this->assertEquals($tag->getLabel(), $content['label']);
511 $this->assertEquals($tag->getSlug(), $content['slug']);
512
513 $entries = $this->client->getContainer()
514 ->get('doctrine.orm.entity_manager')
515 ->getRepository('WallabagCoreBundle:Entry')
516 ->findAllByTagId($this->user->getId(), $tag->getId());
517
518 $this->assertCount(0, $entries);
519 }
520
521 public function testDeleteTagByLabelNotFound()
522 {
523 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']);
524
525 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
526 }
527
528 public function testDeleteTagsByLabel()
529 {
530 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
531 $entry = $this->client->getContainer()
532 ->get('doctrine.orm.entity_manager')
533 ->getRepository('WallabagCoreBundle:Entry')
534 ->findOneWithTags($this->user->getId());
535
536 $entry = $entry[0];
537
538 $tag = new Tag();
539 $tag->setLabel('Awesome tag for tagsLabel');
540 $em->persist($tag);
541
542 $tag2 = new Tag();
543 $tag2->setLabel('Awesome tag for tagsLabel 2');
544 $em->persist($tag2);
545
546 $entry->addTag($tag);
547 $entry->addTag($tag2);
548
549 $em->persist($entry);
550 $em->flush();
551
552 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]);
553
554 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
555
556 $content = json_decode($this->client->getResponse()->getContent(), true);
557
558 $this->assertCount(2, $content);
559
560 $this->assertArrayHasKey('label', $content[0]);
561 $this->assertEquals($tag->getLabel(), $content[0]['label']);
562 $this->assertEquals($tag->getSlug(), $content[0]['slug']);
563
564 $this->assertArrayHasKey('label', $content[1]);
565 $this->assertEquals($tag2->getLabel(), $content[1]['label']);
566 $this->assertEquals($tag2->getSlug(), $content[1]['slug']);
567
568 $entries = $this->client->getContainer()
569 ->get('doctrine.orm.entity_manager')
570 ->getRepository('WallabagCoreBundle:Entry')
571 ->findAllByTagId($this->user->getId(), $tag->getId());
572
573 $this->assertCount(0, $entries);
574
575 $entries = $this->client->getContainer()
576 ->get('doctrine.orm.entity_manager')
577 ->getRepository('WallabagCoreBundle:Entry')
578 ->findAllByTagId($this->user->getId(), $tag2->getId());
579
580 $this->assertCount(0, $entries);
581 }
582
583 public function testDeleteTagsByLabelNotFound()
584 {
585 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']);
586
587 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
588 }
589
483 public function testGetVersion() 590 public function testGetVersion()
484 { 591 {
485 $this->client->request('GET', '/api/version'); 592 $this->client->request('GET', '/api/version');
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 58450e5f..71652760 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -131,4 +131,35 @@ class TagControllerTest extends WallabagCoreTestCase
131 131
132 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 132 $this->assertEquals(404, $client->getResponse()->getStatusCode());
133 } 133 }
134
135 public function testShowEntriesForTagAction()
136 {
137 $this->logInAs('admin');
138 $client = $this->getClient();
139
140 $entry = $client->getContainer()
141 ->get('doctrine.orm.entity_manager')
142 ->getRepository('WallabagCoreBundle:Entry')
143 ->findOneByUsernameAndNotArchived('admin');
144
145 $tag = $client->getContainer()
146 ->get('doctrine.orm.entity_manager')
147 ->getRepository('WallabagCoreBundle:Tag')
148 ->findOneByEntryAndTagLabel($entry, 'foo');
149
150 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
151
152 $this->assertEquals(200, $client->getResponse()->getStatusCode());
153 $this->assertCount(2, $crawler->filter('div[class=entry]'));
154
155 $tag = $client->getContainer()
156 ->get('doctrine.orm.entity_manager')
157 ->getRepository('WallabagCoreBundle:Tag')
158 ->findOneByLabel('baz');
159
160 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
161
162 $this->assertEquals(200, $client->getResponse()->getStatusCode());
163 $this->assertCount(0, $crawler->filter('div[class=entry]'));
164 }
134} 165}