From: Jérémy Benoist Date: Mon, 15 Oct 2018 08:32:59 +0000 (+0000) Subject: Merge pull request #3574 from shulard/feature/rename-tags X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=e673b54f702f274a087e4feff409663d9636e57b;hp=5bb01c034424b56a0a0ae4bc34ae5bb9a514deba;p=github%2Fwallabag%2Fwallabag.git Merge pull request #3574 from shulard/feature/rename-tags Allow to rename tags from the web interface. --- diff --git a/app/Resources/static/themes/_global/index.js b/app/Resources/static/themes/_global/index.js index ae598e56..bb3e95b6 100644 --- a/app/Resources/static/themes/_global/index.js +++ b/app/Resources/static/themes/_global/index.js @@ -70,4 +70,23 @@ $(document).ready(() => { retrievePercent(x.entryId, true); }); } + + document.querySelectorAll('[data-handler=tag-rename]').forEach((item) => { + const current = item; + current.wallabag_edit_mode = false; + current.onclick = (event) => { + const target = event.currentTarget; + + if (target.wallabag_edit_mode === false) { + $(target.parentNode.querySelector('[data-handle=tag-link]')).addClass('hidden'); + $(target.parentNode.querySelector('[data-handle=tag-rename-form]')).removeClass('hidden'); + target.parentNode.querySelector('[data-handle=tag-rename-form] input').focus(); + target.querySelector('.material-icons').innerHTML = 'done'; + + target.wallabag_edit_mode = true; + } else { + target.parentNode.querySelector('[data-handle=tag-rename-form]').submit(); + } + }; + }); }); diff --git a/app/Resources/static/themes/baggy/css/layout.scss b/app/Resources/static/themes/baggy/css/layout.scss index cb14e62d..0293ebe5 100644 --- a/app/Resources/static/themes/baggy/css/layout.scss +++ b/app/Resources/static/themes/baggy/css/layout.scss @@ -295,6 +295,15 @@ div.pagination ul { } } -.hide { +.card-tag-form { + display: inline-block; +} + +.card-tag-form input[type="text"] { + min-width: 20em; +} + +.hide, +.hidden { display: none; } diff --git a/app/Resources/static/themes/material/css/cards.scss b/app/Resources/static/themes/material/css/cards.scss index 8f7f8f7b..f3319f3d 100644 --- a/app/Resources/static/themes/material/css/cards.scss +++ b/app/Resources/static/themes/material/css/cards.scss @@ -180,6 +180,17 @@ a.original:not(.waves-effect) { flex-grow: 1; } +.card-tag-form { + display: flex; + min-width: 100px; + flex-grow: 1; +} + +.card-tag-form input { + margin-bottom: 0; + height: 2rem; +} + .card-tag-rss { display: flex; } diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 15f06ff5..d0155c60 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -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); + } } diff --git a/src/Wallabag/CoreBundle/Form/Type/RenameTagType.php b/src/Wallabag/CoreBundle/Form/Type/RenameTagType.php new file mode 100644 index 00000000..e6270048 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/RenameTagType.php @@ -0,0 +1,35 @@ +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'; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index e1384675..c8500ad3 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -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: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' @@ -585,6 +587,7 @@ flashes: tag: notice: # tag_added: 'Tag added' + # tag_renamed: 'Tag renamed' import: notice: # failed: 'Import failed, please try again.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index c297ffb5..888d9b39 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -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: '

Generiert von wallabag mit Hilfe von %method%

Bitte öffne ein Ticket wenn du ein Problem mit der Darstellung von diesem E-Book auf deinem Gerät hast.

' @@ -585,6 +587,7 @@ flashes: tag: notice: tag_added: 'Tag hinzugefügt' + #tag_renamed: 'Tag renamed' import: notice: failed: 'Import fehlgeschlagen, bitte erneut probieren.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index bd81c72f..827bf770 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -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: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' @@ -585,6 +587,7 @@ flashes: tag: notice: tag_added: 'Tag added' + tag_renamed: 'Tag renamed' import: notice: failed: 'Import failed, please try again.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 700190a6..e5878f2c 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -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: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' @@ -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.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 83645933..2e922358 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -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: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' @@ -585,6 +587,7 @@ flashes: tag: notice: tag_added: 'برچسب افزوده شد' + # tag_renamed: 'Tag renamed' import: notice: failed: 'درون‌ریزی شکست خورد. لطفاً دوباره تلاش کنید.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index edf29654..cf5031d3 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -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: '

Généré par wallabag with %method%

Merci d''ouvrir un ticket si vous rencontrez des soucis d''affichage avec ce document sur votre support.

' @@ -585,6 +587,7 @@ flashes: tag: notice: tag_added: "Tag ajouté" + tag_renamed: "Tag renommé" import: notice: failed: "L’import a échoué, veuillez ré-essayer" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 47292116..1563703a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -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: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' @@ -585,6 +587,7 @@ flashes: tag: notice: tag_added: 'Etichetta aggiunta' + # tag_renamed: 'Tag renamed' import: notice: failed: 'Importazione fallita, riprova.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 95bc9560..9e9f8a2f 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -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: '

Produch per wallabag amb %method%

Mercés de dobrir una sollicitacion s’avètz de problèmas amb l’afichatge d’aqueste E-Book sus vòstre periferic.

' @@ -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." diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index a64e60b0..4e2238d2 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -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: '

Stworzone przez wallabag z %method%

Proszę zgłoś sprawę, jeżeli masz problem z wyświetleniem tego e-booka na swoim urządzeniu.

' @@ -585,6 +587,7 @@ flashes: tag: notice: tag_added: 'Tag dodany' + # tag_renamed: 'Tag renamed' import: notice: failed: 'Nieudany import, prosimy spróbować ponownie.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index 7aef9694..127b425e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -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: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' @@ -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.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 9b7068c6..e68a91ec 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -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: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' @@ -585,6 +587,7 @@ flashes: tag: notice: # tag_added: 'Tag added' + # tag_renamed: 'Tag renamed' import: notice: # failed: 'Import failed, please try again.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml index 5f210c93..d713f13f 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml @@ -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%" удален' \ No newline at end of file + deleted: 'Пользователь "%username%" удален' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml index 9d22f90d..78e0f0ee 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml @@ -397,6 +397,8 @@ tag: new: add: 'เพิ่ม' placeholder: 'คุณสามารถเพิ่มได้หลายแท็ก, จากการแบ่งโดย comma' + rename: + # placeholder: 'You can update tag name.' export: footer_template: '

ผลิตโดย wallabag กับ %method%

ให้ทำการเปิด ฉบับนี้ ถ้าคุณมีข้อบกพร่องif you have trouble with the display of this E-Book on your device.

' @@ -583,6 +585,7 @@ flashes: tag: notice: tag_added: 'แท็กที่เพิ่ม' + # tag_renamed: 'Tag renamed' import: notice: failed: 'นำข้อมูลเข้าล้มเหลว, ลองใหม่อีกครั้ง' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 5c95fe63..c48a885f 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -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: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' @@ -563,6 +565,7 @@ flashes: tag: notice: tag_added: 'Etiket eklendi' + # tag_renamed: 'Tag renamed' import: notice: # failed: 'Import failed, please try again.' 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 070d5629..35351ab1 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 @@ -10,10 +10,22 @@ 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 c15b5146..21e88a9a 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 @@ -13,7 +13,18 @@