Merge pull request #5861 from wallabag/feat-2952-delete-tag
Add tag deletion from tags list
This commit is contained in:
commit
1c66344a50
@ -211,6 +211,10 @@ a.original:not(.waves-effect) {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.card-tag-delete {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.card-tag-labels {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
|
@ -222,4 +222,30 @@ class TagController extends Controller
|
||||
|
||||
return $this->redirect($this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a given tag for the current user.
|
||||
*
|
||||
* @Route("/tag/delete/{slug}", name="tag_delete")
|
||||
* @ParamConverter("tag", options={"mapping": {"slug": "slug"}})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function removeTagAction(Tag $tag, Request $request)
|
||||
{
|
||||
foreach ($tag->getEntriesByUserId($this->getUser()->getId()) as $entry) {
|
||||
$this->get('wallabag_core.entry_repository')->removeTag($this->getUser()->getId(), $tag);
|
||||
}
|
||||
|
||||
// remove orphan tag in case no entries are associated to it
|
||||
if (0 === \count($tag->getEntries())) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove($tag);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
$redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true);
|
||||
|
||||
return $this->redirect($redirectUrl);
|
||||
}
|
||||
}
|
||||
|
@ -457,6 +457,8 @@ quickstart:
|
||||
email: By email
|
||||
gitter: On Gitter
|
||||
tag:
|
||||
confirm:
|
||||
delete: Delete the %name% tag
|
||||
page_title: Tags
|
||||
list:
|
||||
number_on_the_page: '{0} There are no tags.|{1} There is one tag.|]1,Inf[ There are %count% tags.'
|
||||
|
@ -458,6 +458,8 @@ quickstart:
|
||||
email: Par courriel
|
||||
gitter: Sur Gitter
|
||||
tag:
|
||||
confirm:
|
||||
delete: Supprimer le tag %name%
|
||||
page_title: Étiquettes
|
||||
list:
|
||||
number_on_the_page: '{0} Il n’y a pas d''étiquette.|{1} Il y a une étiquette.|]1,Inf[ Il y a %count% étiquettes.'
|
||||
|
@ -26,6 +26,9 @@
|
||||
<i class="material-icons">mode_edit</i>
|
||||
</a>
|
||||
{% endif %}
|
||||
<a id="delete-{{ tag.slug }}" href="{{ path('tag_delete', {'slug': tag.slug})}}" class="card-tag-icon card-tag-delete" onclick="return confirm('{{ 'tag.confirm.delete'|trans({'%name%': tag.label})|escape('js') }}')">
|
||||
<i class="material-icons">delete</i>
|
||||
</a>
|
||||
{% if app.user.config.feedToken %}
|
||||
<a rel="alternate" type="application/atom+xml" href="{{ path('tag_feed', {'username': app.user.username, 'token': app.user.config.feedToken, 'slug': tag.slug}) }}" class="card-tag-icon"><i class="material-icons">rss_feed</i></a>
|
||||
{% endif %}
|
||||
|
@ -6,6 +6,9 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\CoreBundle\Entity\Tag;
|
||||
|
||||
/**
|
||||
* @group Tag
|
||||
*/
|
||||
class TagControllerTest extends WallabagCoreTestCase
|
||||
{
|
||||
public $tagName = 'opensource';
|
||||
@ -141,6 +144,55 @@ class TagControllerTest extends WallabagCoreTestCase
|
||||
$this->assertNull($tag, $this->tagName . ' was removed because it begun an orphan tag');
|
||||
}
|
||||
|
||||
public function testRemoveTag()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$tag = new Tag();
|
||||
$tag->setLabel($this->tagName);
|
||||
|
||||
$entry = new Entry($this->getLoggedInUser());
|
||||
$entry->setUrl('http://0.0.0.0/foo');
|
||||
$entry->addTag($tag);
|
||||
$this->getEntityManager()->persist($entry);
|
||||
|
||||
$entry2 = new Entry($this->getLoggedInUser());
|
||||
$entry2->setUrl('http://0.0.0.0/bar');
|
||||
$entry2->addTag($tag);
|
||||
$this->getEntityManager()->persist($entry2);
|
||||
$this->getEntityManager()->flush();
|
||||
$this->getEntityManager()->clear();
|
||||
|
||||
$crawler = $client->request('GET', '/tag/list');
|
||||
$link = $crawler->filter('a[id="delete-' . $tag->getSlug() . '"]')->link();
|
||||
$client->click($link);
|
||||
|
||||
$tag = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Tag')
|
||||
->findOneByLabel($this->tagName);
|
||||
|
||||
$this->assertNull($tag, $this->tagName . ' was removed because it begun an orphan tag');
|
||||
|
||||
$user = $this->getEntityManager()
|
||||
->getRepository('WallabagUserBundle:User')
|
||||
->findOneByUserName('admin');
|
||||
|
||||
$entry = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findByUrlAndUserId('http://0.0.0.0/foo', $user->getId());
|
||||
|
||||
$entry2 = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findByUrlAndUserId('http://0.0.0.0/bar', $user->getId());
|
||||
|
||||
$this->assertEmpty($entry->getTagsLabel());
|
||||
$this->assertEmpty($entry2->getTagsLabel());
|
||||
}
|
||||
|
||||
public function testShowEntriesForTagAction()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user