diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-02-10 17:41:28 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2016-02-10 17:41:28 +0100 |
commit | 567421af5019bf5937aa2b4214b405d87a1f1f86 (patch) | |
tree | d1f8d3ad8593a3a6f33662217a81cbd731287fc9 | |
parent | ae5b37ef2e52c06182bc6edb14f6b3aae381ddb4 (diff) | |
download | wallabag-567421af5019bf5937aa2b4214b405d87a1f1f86.tar.gz wallabag-567421af5019bf5937aa2b4214b405d87a1f1f86.tar.zst wallabag-567421af5019bf5937aa2b4214b405d87a1f1f86.zip |
remove tag from entry #1377
5 files changed, 74 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index ff4d64a8..7b34939d 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -56,6 +56,26 @@ class TagController extends Controller | |||
56 | } | 56 | } |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Removes tag from entry. | ||
60 | * | ||
61 | * @Route("/remove-tag/{entry}/{tag}", requirements={"entry" = "\d+", "tag" = "\d+"}, name="remove_tag") | ||
62 | * | ||
63 | * @return \Symfony\Component\HttpFoundation\Response | ||
64 | */ | ||
65 | public function removeTagFromEntry(Request $request, Entry $entry, Tag $tag) | ||
66 | { | ||
67 | $entry->removeTag($tag); | ||
68 | $em = $this->getDoctrine()->getManager(); | ||
69 | $em->flush(); | ||
70 | if (count($tag->getEntries()) == 0) { | ||
71 | $em->remove($tag); | ||
72 | } | ||
73 | $em->flush(); | ||
74 | |||
75 | return $this->redirect($request->headers->get('referer')); | ||
76 | } | ||
77 | |||
78 | /** | ||
59 | * Shows tags for current user. | 79 | * Shows tags for current user. |
60 | * | 80 | * |
61 | * @Route("/tag/list", name="tag") | 81 | * @Route("/tag/list", name="tag") |
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index c1940e99..a6e2d023 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php | |||
@@ -107,4 +107,14 @@ class Tag | |||
107 | { | 107 | { |
108 | return $this->entries->contains($entry); | 108 | return $this->entries->contains($entry); |
109 | } | 109 | } |
110 | |||
111 | /** | ||
112 | * Get entries for this tag. | ||
113 | * | ||
114 | * @return ArrayCollection<Entry> | ||
115 | */ | ||
116 | public function getEntries() | ||
117 | { | ||
118 | return $this->entries; | ||
119 | } | ||
110 | } | 120 | } |
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index c4aeb594..8d9cf85c 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php | |||
@@ -51,4 +51,20 @@ class TagRepository extends EntityRepository | |||
51 | ->getQuery() | 51 | ->getQuery() |
52 | ->getResult(); | 52 | ->getResult(); |
53 | } | 53 | } |
54 | |||
55 | /** | ||
56 | * Used only in test case to get a tag for our entry. | ||
57 | * | ||
58 | * @return Tag | ||
59 | */ | ||
60 | public function findOnebyEntryAndLabel($entry, $label) | ||
61 | { | ||
62 | return $this->createQueryBuilder('t') | ||
63 | ->leftJoin('t.entries', 'e') | ||
64 | ->where('e.id = :entryId')->setParameter('entryId', $entry->getId()) | ||
65 | ->andWhere('t.label = :label')->setParameter('label', $label) | ||
66 | ->setMaxResults(1) | ||
67 | ->getQuery() | ||
68 | ->getSingleResult(); | ||
69 | } | ||
54 | } | 70 | } |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig index 2d3fd516..87af07dd 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig | |||
@@ -159,7 +159,7 @@ main { | |||
159 | <div id="list"> | 159 | <div id="list"> |
160 | {% for tag in entry.tags %} | 160 | {% for tag in entry.tags %} |
161 | <div class="chip"> | 161 | <div class="chip"> |
162 | {{ tag.label }} | 162 | {{ tag.label }} <a href="{{ path('remove_tag', { 'entry': entry.id, 'tag': tag.id }) }}"><i class="chip">✘</i></a> |
163 | </div> | 163 | </div> |
164 | {% endfor %} | 164 | {% endfor %} |
165 | </div> | 165 | </div> |
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php index dc93dd6b..ae29a2a6 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php | |||
@@ -6,6 +6,8 @@ use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | |||
6 | 6 | ||
7 | class TagControllerTest extends WallabagCoreTestCase | 7 | class TagControllerTest extends WallabagCoreTestCase |
8 | { | 8 | { |
9 | public $tagName = 'opensource'; | ||
10 | |||
9 | public function testList() | 11 | public function testList() |
10 | { | 12 | { |
11 | $this->logInAs('admin'); | 13 | $this->logInAs('admin'); |
@@ -31,7 +33,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
31 | $form = $crawler->filter('button[id=tag_save]')->form(); | 33 | $form = $crawler->filter('button[id=tag_save]')->form(); |
32 | 34 | ||
33 | $data = array( | 35 | $data = array( |
34 | 'tag[label]' => 'opensource', | 36 | 'tag[label]' => $this->tagName, |
35 | ); | 37 | ); |
36 | 38 | ||
37 | $client->submit($form, $data); | 39 | $client->submit($form, $data); |
@@ -65,4 +67,28 @@ class TagControllerTest extends WallabagCoreTestCase | |||
65 | 67 | ||
66 | $this->assertEquals(2, count($newEntry->getTags())); | 68 | $this->assertEquals(2, count($newEntry->getTags())); |
67 | } | 69 | } |
70 | |||
71 | public function testRemoveTagFromEntry() | ||
72 | { | ||
73 | $this->logInAs('admin'); | ||
74 | $client = $this->getClient(); | ||
75 | |||
76 | $entry = $client->getContainer() | ||
77 | ->get('doctrine.orm.entity_manager') | ||
78 | ->getRepository('WallabagCoreBundle:Entry') | ||
79 | ->findOneByUsernameAndNotArchived('admin'); | ||
80 | |||
81 | $tag = $client->getContainer() | ||
82 | ->get('doctrine.orm.entity_manager') | ||
83 | ->getRepository('WallabagCoreBundle:Tag') | ||
84 | ->findOnebyEntryAndLabel($entry, $this->tagName); | ||
85 | |||
86 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | ||
87 | |||
88 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
89 | |||
90 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | ||
91 | |||
92 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
93 | } | ||
68 | } | 94 | } |