aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-02-11 16:49:03 +0100
committerJeremy Benoist <j0k3r@users.noreply.github.com>2016-02-11 16:49:03 +0100
commit9b5edf33a00490b033692efca9987a35225835ba (patch)
tree73d3c24ecdeab3b65b1ea2ca2d90fe6d31d5780c
parent5db084e05b84ac87179336b96b5db9579fa78c67 (diff)
parente686a76d343a3745c3dfe8010d9e5784e56bb17c (diff)
downloadwallabag-9b5edf33a00490b033692efca9987a35225835ba.tar.gz
wallabag-9b5edf33a00490b033692efca9987a35225835ba.tar.zst
wallabag-9b5edf33a00490b033692efca9987a35225835ba.zip
Merge pull request #1663 from wallabag/v2-remove-tags-from-entry
remove tag from entry #1377
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php20
-rw-r--r--src/Wallabag/CoreBundle/Entity/Tag.php10
-rw-r--r--src/Wallabag/CoreBundle/Repository/TagRepository.php16
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig2
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig2
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php30
6 files changed, 77 insertions, 3 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..afeb985b 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 findOneByEntryAndTagLabel($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/Resources/views/themes/material/Tag/tags.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig
index 9f92c178..19754d41 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}}</li> 12 <li id="tag-{{ tag.id|e }}" class="col l4 m6 s12">{{tag.label}} ({{ tag.entries.getValues | length }})</li>
13 {% endfor %} 13 {% endfor %}
14 </ul> 14 </ul>
15{% endblock %} 15{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php
index dc93dd6b..d6391282 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
7class TagControllerTest extends WallabagCoreTestCase 7class 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,30 @@ 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 ->findOneByEntryAndTagLabel($entry, $this->tagName);
85
86 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
87
88 $this->assertEquals(302, $client->getResponse()->getStatusCode());
89
90 $this->assertNotContains($this->tagName, $entry->getTags());
91
92 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
93
94 $this->assertEquals(404, $client->getResponse()->getStatusCode());
95 }
68} 96}