1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-15 18:57:05 +00:00

Merge pull request #3574 from shulard/feature/rename-tags

Allow to rename tags from the web interface.
This commit is contained in:
Jérémy Benoist 2018-10-15 08:32:59 +00:00 committed by GitHub
commit e673b54f70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 247 additions and 13 deletions

View file

@ -11,6 +11,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\CoreBundle\Form\Type\NewTagType;
use Wallabag\CoreBundle\Form\Type\RenameTagType;
class TagController extends Controller
{
@ -87,8 +88,14 @@ class TagController extends Controller
$tags = $this->get('wallabag_core.tag_repository')
->findAllFlatTagsWithNbEntries($this->getUser()->getId());
$renameForms = [];
foreach ($tags as $tag) {
$renameForms[$tag['id']] = $this->createForm(RenameTagType::class, new Tag())->createView();
}
return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
'tags' => $tags,
'renameForms' => $renameForms,
]);
}
@ -130,4 +137,48 @@ class TagController extends Controller
'tag' => $tag,
]);
}
/**
* Rename a given tag with a new label
* Create a new tag with the new name and drop the old one.
*
* @param Tag $tag
* @param Request $request
*
* @Route("/tag/rename/{slug}", name="tag_rename")
* @ParamConverter("tag", options={"mapping": {"slug": "slug"}})
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function renameTagAction(Tag $tag, Request $request)
{
$form = $this->createForm(RenameTagType::class, new Tag());
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entries = $this->get('wallabag_core.entry_repository')->findAllByTagId(
$this->getUser()->getId(),
$tag->getId()
);
foreach ($entries as $entry) {
$this->get('wallabag_core.tags_assigner')->assignTagsToEntry(
$entry,
$form->get('label')->getData()
);
$entry->removeTag($tag);
}
$em = $this->getDoctrine()->getManager();
$em->flush();
}
$this->get('session')->getFlashBag()->add(
'notice',
'flashes.tag.notice.tag_renamed'
);
$redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true);
return $this->redirect($redirectUrl);
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Wallabag\CoreBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RenameTagType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('label', TextType::class, [
'required' => true,
'attr' => [
'placeholder' => 'tag.rename.placeholder',
],
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'Wallabag\CoreBundle\Entity\Tag',
]);
}
public function getBlockPrefix()
{
return 'tag';
}
}

View file

@ -399,6 +399,8 @@ tag:
new:
# add: 'Add'
# placeholder: 'You can add several tags, separated by a comma.'
rename:
# placeholder: 'You can update tag name.'
# export:
# footer_template: '<div style="text-align:center;"><p>Produced by wallabag with %method%</p><p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
# tag_added: 'Tag added'
# tag_renamed: 'Tag renamed'
import:
notice:
# failed: 'Import failed, please try again.'

View file

@ -399,6 +399,8 @@ tag:
new:
add: 'Hinzufügen'
placeholder: 'Du kannst verschiedene Tags, getrennt von einem Komma, hinzufügen.'
rename:
# placeholder: 'You can update tag name.'
export:
footer_template: '<div style="text-align:center;"><p>Generiert von wallabag mit Hilfe von %method%</p><p>Bitte öffne <a href="https://github.com/wallabag/wallabag/issues">ein Ticket</a> wenn du ein Problem mit der Darstellung von diesem E-Book auf deinem Gerät hast.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
tag_added: 'Tag hinzugefügt'
#tag_renamed: 'Tag renamed'
import:
notice:
failed: 'Import fehlgeschlagen, bitte erneut probieren.'

View file

@ -399,6 +399,8 @@ tag:
new:
add: 'Add'
placeholder: 'You can add several tags, separated by a comma.'
rename:
placeholder: 'You can update tag name.'
export:
footer_template: '<div style="text-align:center;"><p>Produced by wallabag with %method%</p><p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
tag_added: 'Tag added'
tag_renamed: 'Tag renamed'
import:
notice:
failed: 'Import failed, please try again.'

View file

@ -399,6 +399,8 @@ tag:
new:
add: 'Añadir'
placeholder: 'Puedes añadir varias etiquetas, separadas por una coma.'
rename:
# placeholder: 'You can update tag name.'
# export:
# footer_template: '<div style="text-align:center;"><p>Produced by wallabag with %method%</p><p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
tag_added: 'Etiqueta añadida'
# tag_renamed: 'Tag renamed'
import:
notice:
failed: 'Importación fallida, por favor, inténtelo de nuevo.'

View file

@ -399,6 +399,8 @@ tag:
new:
# add: 'Add'
# placeholder: 'You can add several tags, separated by a comma.'
rename:
# placeholder: 'You can update tag name.'
# export:
# footer_template: '<div style="text-align:center;"><p>Produced by wallabag with %method%</p><p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
tag_added: 'برچسب افزوده شد'
# tag_renamed: 'Tag renamed'
import:
notice:
failed: 'درون‌ریزی شکست خورد. لطفاً دوباره تلاش کنید.'

View file

@ -399,6 +399,8 @@ tag:
new:
add: "Ajouter"
placeholder: "Vous pouvez ajouter plusieurs tags, séparés par une virgule."
rename:
placeholder: 'Vous pouvez changer le nom de votre tag.'
export:
footer_template: '<div style="text-align:center;"><p>Généré par wallabag with %method%</p><p>Merci d''ouvrir <a href="https://github.com/wallabag/wallabag/issues">un ticket</a> si vous rencontrez des soucis d''affichage avec ce document sur votre support.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
tag_added: "Tag ajouté"
tag_renamed: "Tag renommé"
import:
notice:
failed: "Limport a échoué, veuillez ré-essayer"

View file

@ -399,6 +399,8 @@ tag:
new:
add: 'Aggiungi'
placeholder: 'Puoi aggiungere varie etichette, separate da una virgola.'
rename:
# placeholder: 'You can update tag name.'
# export:
# footer_template: '<div style="text-align:center;"><p>Produced by wallabag with %method%</p><p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
tag_added: 'Etichetta aggiunta'
# tag_renamed: 'Tag renamed'
import:
notice:
failed: 'Importazione fallita, riprova.'

View file

@ -399,6 +399,8 @@ tag:
new:
add: 'Ajustar'
placeholder: "Podètz ajustar mai qu'una etiqueta, separadas per de virgula."
rename:
# placeholder: 'You can update tag name.'
export:
footer_template: '<div style="text-align:center;"><p>Produch per wallabag amb %method%</p><p>Mercés de dobrir <a href="https://github.com/wallabag/wallabag/issues">una sollicitacion</a> savètz de problèmas amb lafichatge daqueste E-Book sus vòstre periferic.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
tag_added: 'Etiqueta ajustada'
# tag_renamed: 'Tag renamed'
import:
notice:
failed: "L'importacion a fracassat, mercés de tornar ensajar."

View file

@ -399,6 +399,8 @@ tag:
new:
add: 'Dodaj'
placeholder: 'Możesz dodać kilka tagów, oddzielając je przecinkami.'
rename:
# placeholder: 'You can update tag name.'
export:
footer_template: '<div style="text-align:center;"><p>Stworzone przez wallabag z %method%</p><p>Proszę zgłoś <a href="https://github.com/wallabag/wallabag/issues">sprawę</a>, jeżeli masz problem z wyświetleniem tego e-booka na swoim urządzeniu.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
tag_added: 'Tag dodany'
# tag_renamed: 'Tag renamed'
import:
notice:
failed: 'Nieudany import, prosimy spróbować ponownie.'

View file

@ -399,6 +399,8 @@ tag:
new:
# add: 'Add'
# placeholder: 'You can add several tags, separated by a comma.'
rename:
# placeholder: 'You can update tag name.'
# export:
# footer_template: '<div style="text-align:center;"><p>Produced by wallabag with %method%</p><p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
tag_added: 'Tag adicionada'
# tag_renamed: 'Tag renamed'
import:
notice:
failed: 'Importação falhou, por favor tente novamente.'

View file

@ -399,6 +399,8 @@ tag:
new:
# add: 'Add'
# placeholder: 'You can add several tags, separated by a comma.'
rename:
# placeholder: 'You can update tag name.'
# export:
# footer_template: '<div style="text-align:center;"><p>Produced by wallabag with %method%</p><p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p></div>'
@ -585,6 +587,7 @@ flashes:
tag:
notice:
# tag_added: 'Tag added'
# tag_renamed: 'Tag renamed'
import:
notice:
# failed: 'Import failed, please try again.'

View file

@ -387,6 +387,8 @@ tag:
new:
add: 'Добавить'
placeholder: 'Вы можете добавить несколько тегов, разделенных запятой.'
rename:
# placeholder: 'You can update tag name.'
import:
page_title: 'Импорт'
@ -547,6 +549,7 @@ flashes:
tag:
notice:
tag_added: 'Тег добавлен'
# tag_renamed: 'Tag renamed'
import:
notice:
failed: 'Во время импорта произошла ошибка, повторите попытку.'
@ -564,4 +567,4 @@ flashes:
notice:
added: 'Пользователь "%username%" добавлен'
updated: 'Пользователь "%username%" обновлен'
deleted: 'Пользователь "%username%" удален'
deleted: 'Пользователь "%username%" удален'

View file

@ -397,6 +397,8 @@ tag:
new:
add: 'เพิ่ม'
placeholder: 'คุณสามารถเพิ่มได้หลายแท็ก, จากการแบ่งโดย comma'
rename:
# placeholder: 'You can update tag name.'
export:
footer_template: '<div style="text-align:center;"><p>ผลิตโดย wallabag กับ %method%</p><p>ให้ทำการเปิด <a href="https://github.com/wallabag/wallabag/issues">ฉบับนี้</a> ถ้าคุณมีข้อบกพร่องif you have trouble with the display of this E-Book on your device.</p></div>'
@ -583,6 +585,7 @@ flashes:
tag:
notice:
tag_added: 'แท็กที่เพิ่ม'
# tag_renamed: 'Tag renamed'
import:
notice:
failed: 'นำข้อมูลเข้าล้มเหลว, ลองใหม่อีกครั้ง'

View file

@ -397,6 +397,8 @@ tag:
new:
# add: 'Add'
# placeholder: 'You can add several tags, separated by a comma.'
rename:
# placeholder: 'You can update tag name.'
# export:
# footer_template: '<div style="text-align:center;"><p>Produced by wallabag with %method%</p><p>Please open <a href="https://github.com/wallabag/wallabag/issues">an issue</a> if you have trouble with the display of this E-Book on your device.</p></div>'
@ -563,6 +565,7 @@ flashes:
tag:
notice:
tag_added: 'Etiket eklendi'
# tag_renamed: 'Tag renamed'
import:
notice:
# failed: 'Import failed, please try again.'

View file

@ -10,10 +10,22 @@
<ul>
{% for tag in tags %}
<li id="tag-{{ tag.id|e }}">
<a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.nbEntries }})</a>
<a rel="alternate" type="application/rss+xml" href="{{ path('tag_rss', {'username': app.user.username, 'token': app.user.config.rssToken, 'slug': tag.slug}) }}" class="right">
<i class="material-icons md-24">rss_feed</i>
<a href="{{ path('tag_entries', {'slug': tag.slug}) }}" data-handle="tag-link">{{ tag.label }}&nbsp;({{ tag.nbEntries }})</a>
{% if renameForms is defined and renameForms[tag.id] is defined %}
<form class="card-tag-form hidden" data-handle="tag-rename-form" action="{{ path('tag_rename', {'slug': tag.slug})}}" method="POST">
{{ form_widget(renameForms[tag.id].label, {'attr': {'value': tag.label}}) }}
{{ form_rest(renameForms[tag.id]) }}
</form>
<a class="card-tag-rename" data-handler="tag-rename" href="javascript:void(0);">
<i class="material-icons">mode_edit</i>
</a>
{% endif %}
{% if app.user.config.rssToken %}
<a rel="alternate" type="application/rss+xml" href="{{ path('tag_rss', {'username': app.user.username, 'token': app.user.config.rssToken, 'slug': tag.slug}) }}" class="right">
<i class="material-icons md-24">rss_feed</i>
</a>
{% endif %}
</li>
{% endfor %}
</ul>

View file

@ -13,7 +13,18 @@
<ul class="card-tag-labels">
{% for tag in tags %}
<li title="{{tag.label}} ({{ tag.nbEntries }})" id="tag-{{ tag.id }}">
<a href="{{ path('tag_entries', {'slug': tag.slug}) }}" class="card-tag-link">{{tag.label}} ({{ tag.nbEntries }})</a>
<a href="{{ path('tag_entries', {'slug': tag.slug}) }}" class="card-tag-link" data-handle="tag-link">
{{ tag.label }}&nbsp;({{ tag.nbEntries }})
</a>
{% if renameForms is defined and renameForms[tag.id] is defined %}
<form class="card-tag-form hidden" data-handle="tag-rename-form" action="{{ path('tag_rename', {'slug': tag.slug})}}" method="POST">
{{ form_widget(renameForms[tag.id].label, {'attr': {'value': tag.label}}) }}
{{ form_rest(renameForms[tag.id]) }}
</form>
<a class="card-tag-rename" data-handler="tag-rename" href="javascript:void(0);">
<i class="material-icons">mode_edit</i>
</a>
{% endif %}
{% if app.user.config.rssToken %}
<a rel="alternate" type="application/rss+xml" href="{{ path('tag_rss', {'username': app.user.username, 'token': app.user.config.rssToken, 'slug': tag.slug}) }}" class="card-tag-rss"><i class="material-icons">rss_feed</i></a>
{% endif %}