mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-28 10:30:28 +00:00
Links on each tag in Tags view
This commit is contained in:
parent
79efca1e6f
commit
891456ba9a
7 changed files with 88 additions and 6 deletions
|
@ -4,7 +4,6 @@ namespace Wallabag\CoreBundle\Controller;
|
|||
|
||||
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
||||
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -257,9 +256,10 @@ class EntryController extends Controller
|
|||
}
|
||||
|
||||
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery());
|
||||
$entries = new Pagerfanta($pagerAdapter);
|
||||
|
||||
$entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage());
|
||||
$entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
|
||||
->prepare($pagerAdapter, $page);
|
||||
|
||||
try {
|
||||
$entries->setCurrentPage($page);
|
||||
} catch (OutOfRangeCurrentPageException $e) {
|
||||
|
|
|
@ -46,7 +46,7 @@ class ExportController extends Controller
|
|||
*
|
||||
* @Route("/export/{category}.{format}", name="export_entries", requirements={
|
||||
* "format": "epub|mobi|pdf|json|xml|txt|csv",
|
||||
* "category": "all|unread|starred|archive"
|
||||
* "category": "all|unread|starred|archive|tag_entries"
|
||||
* })
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
|
|
|
@ -2,12 +2,15 @@
|
|||
|
||||
namespace Wallabag\CoreBundle\Controller;
|
||||
|
||||
use Pagerfanta\Adapter\ArrayAdapter;
|
||||
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\CoreBundle\Entity\Tag;
|
||||
use Wallabag\CoreBundle\Form\Type\NewTagType;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
|
||||
class TagController extends Controller
|
||||
{
|
||||
|
@ -90,4 +93,41 @@ class TagController extends Controller
|
|||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param int $page
|
||||
*
|
||||
* @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"})
|
||||
* @ParamConverter("tag", options={"mapping": {"slug": "slug"}})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function showEntriesForTagAction(Tag $tag, $page, Request $request)
|
||||
{
|
||||
$pagerAdapter = new ArrayAdapter($tag->getEntries()->toArray());
|
||||
|
||||
$entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
|
||||
->prepare($pagerAdapter, $page);
|
||||
|
||||
try {
|
||||
$entries->setCurrentPage($page);
|
||||
} catch (OutOfRangeCurrentPageException $e) {
|
||||
if ($page > 1) {
|
||||
return $this->redirect($this->generateUrl($request->get('_route'), [
|
||||
'slug' => $tag->getSlug(),
|
||||
'page' => $entries->getNbPages(),
|
||||
]), 302);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'WallabagCoreBundle:Entry:entries.html.twig',
|
||||
[
|
||||
'form' => null,
|
||||
'entries' => $entries,
|
||||
'currentPage' => $page,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
34
src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php
Normal file
34
src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Helper;
|
||||
|
||||
use Pagerfanta\Adapter\AdapterInterface;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||
|
||||
class PreparePagerForEntries
|
||||
{
|
||||
private $user;
|
||||
private $router;
|
||||
|
||||
public function __construct(TokenStorage $token, Router $router)
|
||||
{
|
||||
$this->user = $token->getToken()->getUser();
|
||||
$this->router = $router;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AdapterInterface $adapter
|
||||
* @param int $page
|
||||
*
|
||||
* @return null|Pagerfanta
|
||||
*/
|
||||
public function prepare(AdapterInterface $adapter, $page = 1)
|
||||
{
|
||||
$entries = new Pagerfanta($adapter);
|
||||
$entries->setMaxPerPage($this->user->getConfig()->getItemsPerPage());
|
||||
|
||||
return $entries;
|
||||
}
|
||||
}
|
|
@ -119,3 +119,9 @@ services:
|
|||
class: Wallabag\CoreBundle\Helper\Redirect
|
||||
arguments:
|
||||
- "@router"
|
||||
|
||||
wallabag_core.helper.prepare_pager_for_entries:
|
||||
class: Wallabag\CoreBundle\Helper\PreparePagerForEntries
|
||||
arguments:
|
||||
- "@security.token_storage"
|
||||
- "@router"
|
||||
|
|
|
@ -122,6 +122,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Filters -->
|
||||
{% if form is not null %}
|
||||
<div id="filters" class="side-nav fixed right-aligned">
|
||||
<form action="{{ path('all') }}">
|
||||
|
||||
|
@ -205,5 +206,6 @@
|
|||
|
||||
</form>
|
||||
</div>
|
||||
{% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<br />
|
||||
<ul class="row data">
|
||||
{% for tag in tags %}
|
||||
<li id="tag-{{ tag.id|e }}" class="col l4 m6 s12">{{tag.label}} ({{ tag.getEntriesByUserId(app.user.id) | length }})</li>
|
||||
<li id="tag-{{ tag.id|e }}" class="col l4 m6 s12"><a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.entries.getValues | length }})</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue