From e101052afc69efb18c413776e39a0281576c4ca4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 22 Apr 2020 10:05:12 +0200 Subject: [PATCH] First draft --- app/Resources/static/themes/material/index.js | 26 +++++++++++++++++++ app/config/config.yml | 1 + .../CoreBundle/Controller/EntryController.php | 8 ++++++ .../themes/material/Entry/entry.html.twig | 9 +++---- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/Resources/static/themes/material/index.js b/app/Resources/static/themes/material/index.js index d8f5628c..185ac1e0 100755 --- a/app/Resources/static/themes/material/index.js +++ b/app/Resources/static/themes/material/index.js @@ -120,4 +120,30 @@ $(document).ready(() => { }); }); } + + $('.markasread').on('click', () => { + const article = document.getElementById('article'); + const link = document.getElementById('link-archive'); + const articleId = article.dataset.id; + const xhr = new XMLHttpRequest(); + + xhr.onload = function toggleArchive() { + if (xhr.status === 200) { + const previousStatus = document.getElementById('archive-icon').innerHTML; + let status = link.dataset.iconUnread; + let label = link.dataset.labelUnread; + if (previousStatus === 'unarchive') { + status = link.dataset.iconRead; + label = link.dataset.labelRead; + } + document.getElementById('archive-icon').innerHTML = status; + document.getElementById('archive-label').innerHTML = label; + window.Materialize.toast(xhr.responseText, 4000); + } + }; + + const url = `${Routing.generate('archive_entry', { id: articleId })}?some_var_name=true`; + xhr.open('GET', url, false); + xhr.send(null); + }); }); diff --git a/app/config/config.yml b/app/config/config.yml index 4eea0531..f87835cf 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -373,6 +373,7 @@ fos_js_routing: - howto - fos_user_security_logout - new + - archive_entry jms_serializer: handlers: diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 9b2954e7..5fc6fc55 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -7,6 +7,7 @@ use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Exception\OutOfRangeCurrentPageException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -371,6 +372,11 @@ class EntryController extends Controller $message = 'flashes.entry.notice.entry_archived'; } + if ($request->query->get('some_var_name')) { + + return new JsonResponse($this->get('translator')->trans($message)); + } + $this->get('session')->getFlashBag()->add( 'notice', $message @@ -381,6 +387,8 @@ class EntryController extends Controller return $this->redirect($redirectUrl); } + + /** * Changes starred status for an entry. * 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 527b1afc..899a8a7f 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 @@ -67,9 +67,9 @@ {% endif %}
  • - - {% if entry.isArchived == 0 %}done{% else %}unarchive{% endif %} - {{ markAsReadLabel|trans }} + + {% if entry.isArchived == 0 %}done{% else %}unarchive{% endif %} + {{ markAsReadLabel|trans }}
  • @@ -221,7 +221,7 @@ {% endblock %} {% block content %} -
    +

    {{ entry.title|striptags|default('entry.default_title'|trans)|raw }} create

    @@ -291,7 +291,6 @@
    -