]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Display entries number for each category
authorNicolas LÅ“uillet <nicolas@loeuillet.org>
Thu, 21 Apr 2016 20:30:50 +0000 (22:30 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Tue, 23 Aug 2016 05:47:55 +0000 (07:47 +0200)
app/Resources/static/themes/material/css/main.css
app/config/services.yml
src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
src/Wallabag/CoreBundle/Twig/WallabagExtension.php

index cade37f634f79d6744ded02292a8bb1c3055c7b6..99892401620b43404b7f3ad284bb90ff57ae69ee 100755 (executable)
@@ -303,6 +303,10 @@ nav input {
   margin: 0 1rem;
 }
 
+span.numberItems {
+  float: right;
+}
+
 /* ==========================================================================
  * 3 = Filters slider
  * ========================================================================== */
index 480408d918c3e01ea34cc74ea61fd919ff7b82b0..95b8f26f5b7b0509239b03f9e2ac48d5cd0415c2 100644 (file)
@@ -16,6 +16,9 @@ services:
     wallabag.twig_extension:
         class: Wallabag\CoreBundle\Twig\WallabagExtension
         public: false
+        arguments:
+            - "@wallabag_core.entry_repository"
+            - "@security.token_storage"
         tags:
             - { name: twig.extension }
 
index 50134357f942a47327a10b8c146f80c3244d94ea..f64c3da281bf5e19edf6a3dad50a06ec567c3160 100644 (file)
             {% set currentRoute = app.request.attributes.get('_route') %}
 
             <li class="bold {% if currentRoute == 'unread' or currentRoute == 'homepage' %}active{% endif %}">
-                <a class="waves-effect" href="{{ path('unread') }}">{{ 'menu.left.unread'|trans }}</a>
+                <a class="waves-effect" href="{{ path('unread') }}">{{ 'menu.left.unread'|trans }} <span class="numberItems grey-text">{{ unreadEntries }}</span></a>
             </li>
             <li class="bold {% if currentRoute == 'starred' %}active{% endif %}">
-                <a class="waves-effect" href="{{ path('starred') }}">{{ 'menu.left.starred'|trans }}</a>
+                <a class="waves-effect" href="{{ path('starred') }}">{{ 'menu.left.starred'|trans }} <span class="numberItems grey-text">{{ starredEntries }}</span></a>
             </li>
             <li class="bold {% if currentRoute == 'archive' %}active{% endif %}">
-                <a class="waves-effect" href="{{ path('archive') }}">{{ 'menu.left.archive'|trans }}</a>
+                <a class="waves-effect" href="{{ path('archive') }}">{{ 'menu.left.archive'|trans }} <span class="numberItems grey-text">{{ archivedEntries }}</span></a>
             </li>
             <li class="bold border-bottom {% if currentRoute == 'all' %}active{% endif %}">
-                <a class="waves-effect" href="{{ path('all') }}">{{ 'menu.left.all_articles'|trans }}</a>
+                <a class="waves-effect" href="{{ path('all') }}">{{ 'menu.left.all_articles'|trans }} <span class="numberItems grey-text">{{ allEntries }}</span></a>
             </li>
             <li class="bold border-bottom {% if currentRoute == 'tags' %}active{% endif %}">
                 <a class="waves-effect" href="{{ path('tag') }}">{{ 'menu.left.tags'|trans }}</a>
index 1a308070672e057bea8277288c46684ca6e5eb29..c116248ffa6833fb9f1a1141311ee4779280aca4 100644 (file)
@@ -2,8 +2,20 @@
 
 namespace Wallabag\CoreBundle\Twig;
 
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
+use Wallabag\CoreBundle\Repository\EntryRepository;
+
 class WallabagExtension extends \Twig_Extension
 {
+    private $tokenStorage;
+    private $repository;
+
+    public function __construct(EntryRepository $repository = null, TokenStorageInterface $tokenStorage = null)
+    {
+        $this->repository = $repository;
+        $this->tokenStorage = $tokenStorage;
+    }
+
     public function getFilters()
     {
         return [
@@ -16,6 +28,27 @@ class WallabagExtension extends \Twig_Extension
         return preg_replace('/^www\./i', '', $url);
     }
 
+    public function getGlobals()
+    {
+        $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
+
+        if (null === $user || !is_object($user)) {
+            return array();
+        }
+
+        $unreadEntries = $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery()->getResult();
+        $starredEntries = $this->repository->getBuilderForStarredByUser($user->getId())->getQuery()->getResult();
+        $archivedEntries = $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery()->getResult();
+        $allEntries = $this->repository->getBuilderForAllByUser($user->getId())->getQuery()->getResult();
+
+        return array(
+            'unreadEntries' => count($unreadEntries),
+            'starredEntries' => count($starredEntries),
+            'archivedEntries' => count($archivedEntries),
+            'allEntries' => count($allEntries),
+        );
+    }
+
     public function getName()
     {
         return 'wallabag_extension';