mirror of
https://github.com/wallabag/wallabag.git
synced 2025-02-01 11:32:22 +00:00
Merge pull request #1250 from frankoa/v2_pagination_and_api
Adds pagerfanta paginator everywhere, modifies article routing.
This commit is contained in:
commit
7e63b892f9
8 changed files with 76 additions and 59 deletions
|
@ -6,10 +6,6 @@ app:
|
||||||
resource: @WallabagCoreBundle/Controller/
|
resource: @WallabagCoreBundle/Controller/
|
||||||
type: annotation
|
type: annotation
|
||||||
|
|
||||||
homepage:
|
|
||||||
pattern: /
|
|
||||||
defaults: { _controller: WallabagCoreBundle:Entry:showUnread }
|
|
||||||
|
|
||||||
doc-api:
|
doc-api:
|
||||||
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
|
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
|
||||||
prefix: /api/doc
|
prefix: /api/doc
|
||||||
|
@ -17,8 +13,10 @@ doc-api:
|
||||||
login:
|
login:
|
||||||
pattern: /login
|
pattern: /login
|
||||||
defaults: { _controller: WallabagCoreBundle:Security:login }
|
defaults: { _controller: WallabagCoreBundle:Security:login }
|
||||||
|
|
||||||
login_check:
|
login_check:
|
||||||
pattern: /login_check
|
pattern: /login_check
|
||||||
|
|
||||||
logout:
|
logout:
|
||||||
path: /logout
|
path: /logout
|
||||||
|
|
||||||
|
@ -26,3 +24,9 @@ rest :
|
||||||
type : rest
|
type : rest
|
||||||
resource : "routing_rest.yml"
|
resource : "routing_rest.yml"
|
||||||
prefix : /api
|
prefix : /api
|
||||||
|
|
||||||
|
homepage:
|
||||||
|
pattern: "/{page}"
|
||||||
|
defaults: { _controller: WallabagCoreBundle:Entry:showUnread, page : 1 }
|
||||||
|
requirements:
|
||||||
|
page: \d+
|
||||||
|
|
|
@ -189,8 +189,8 @@ class WallabagRestController extends Controller
|
||||||
$this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId());
|
$this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId());
|
||||||
|
|
||||||
$title = $request->request->get('title');
|
$title = $request->request->get('title');
|
||||||
$isArchived = $request->request->get('archive');
|
$isArchived = $request->request->get('is_archived');
|
||||||
$isStarred = $request->request->get('star');
|
$isStarred = $request->request->get('is_starred');
|
||||||
|
|
||||||
if (!is_null($title)) {
|
if (!is_null($title)) {
|
||||||
$entry->setTitle($title);
|
$entry->setTitle($title);
|
||||||
|
|
|
@ -89,60 +89,72 @@ class EntryController extends Controller
|
||||||
/**
|
/**
|
||||||
* Shows unread entries for current user.
|
* Shows unread entries for current user.
|
||||||
*
|
*
|
||||||
* @Route("/unread", name="unread")
|
* @Route("/unread/list/{page}", name="unread", defaults={"page" = "1"})
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function showUnreadAction()
|
public function showUnreadAction($page)
|
||||||
{
|
{
|
||||||
// TODO change pagination
|
|
||||||
$entries = $this->getDoctrine()
|
$entries = $this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
->findUnreadByUser($this->getUser()->getId(), 0);
|
->findUnreadByUser($this->getUser()->getId());
|
||||||
|
|
||||||
|
$entries->setCurrentPage($page);
|
||||||
|
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'WallabagCoreBundle:Entry:entries.html.twig',
|
'WallabagCoreBundle:Entry:entries.html.twig',
|
||||||
array('entries' => $entries)
|
array(
|
||||||
|
'entries' => $entries,
|
||||||
|
'currentPage' => $page
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows read entries for current user.
|
* Shows read entries for current user.
|
||||||
*
|
*
|
||||||
* @Route("/archive", name="archive")
|
* @Route("/archive/list/{page}", name="archive", defaults={"page" = "1"})
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function showArchiveAction()
|
public function showArchiveAction($page)
|
||||||
{
|
{
|
||||||
// TODO change pagination
|
|
||||||
$entries = $this->getDoctrine()
|
$entries = $this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
->findArchiveByUser($this->getUser()->getId(), 0);
|
->findArchiveByUser($this->getUser()->getId());
|
||||||
|
|
||||||
|
$entries->setCurrentPage($page);
|
||||||
|
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'WallabagCoreBundle:Entry:entries.html.twig',
|
'WallabagCoreBundle:Entry:entries.html.twig',
|
||||||
array('entries' => $entries)
|
array(
|
||||||
|
'entries' => $entries,
|
||||||
|
'currentPage' => $page
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows starred entries for current user.
|
* Shows starred entries for current user.
|
||||||
*
|
*
|
||||||
* @Route("/starred", name="starred")
|
* @Route("/starred/list/{page}", name="starred", defaults={"page" = "1"})
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function showStarredAction()
|
public function showStarredAction($page)
|
||||||
{
|
{
|
||||||
// TODO change pagination
|
|
||||||
$entries = $this->getDoctrine()
|
$entries = $this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
->findStarredByUser($this->getUser()->getId(), 0);
|
->findStarredByUser($this->getUser()->getId());
|
||||||
|
|
||||||
|
$entries->setCurrentPage($page);
|
||||||
|
|
||||||
return $this->render(
|
return $this->render(
|
||||||
'WallabagCoreBundle:Entry:entries.html.twig',
|
'WallabagCoreBundle:Entry:entries.html.twig',
|
||||||
array('entries' => $entries)
|
array(
|
||||||
|
'entries' => $entries,
|
||||||
|
'currentPage' => $page
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,12 @@ class RssController extends Controller
|
||||||
$entries = $this->getDoctrine()
|
$entries = $this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
->findUnreadByUser(
|
->findUnreadByUser(
|
||||||
$user->getId(),
|
$user->getId()
|
||||||
0,
|
|
||||||
$user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit');
|
||||||
|
$entries->setMaxPerPage($perPage);
|
||||||
|
|
||||||
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
|
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
|
||||||
'type' => 'unread',
|
'type' => 'unread',
|
||||||
'entries' => $entries,
|
'entries' => $entries,
|
||||||
|
@ -47,11 +48,12 @@ class RssController extends Controller
|
||||||
$entries = $this->getDoctrine()
|
$entries = $this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
->findArchiveByUser(
|
->findArchiveByUser(
|
||||||
$user->getId(),
|
$user->getId()
|
||||||
0,
|
|
||||||
$user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit');
|
||||||
|
$entries->setMaxPerPage($perPage);
|
||||||
|
|
||||||
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
|
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
|
||||||
'type' => 'archive',
|
'type' => 'archive',
|
||||||
'entries' => $entries,
|
'entries' => $entries,
|
||||||
|
@ -71,11 +73,12 @@ class RssController extends Controller
|
||||||
$entries = $this->getDoctrine()
|
$entries = $this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
->findStarredByUser(
|
->findStarredByUser(
|
||||||
$user->getId(),
|
$user->getId()
|
||||||
0,
|
|
||||||
$user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit');
|
||||||
|
$entries->setMaxPerPage($perPage);
|
||||||
|
|
||||||
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
|
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
|
||||||
'type' => 'starred',
|
'type' => 'starred',
|
||||||
'entries' => $entries,
|
'entries' => $entries,
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Wallabag\CoreBundle\Repository;
|
namespace Wallabag\CoreBundle\Repository;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
|
||||||
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
||||||
use Pagerfanta\Pagerfanta;
|
use Pagerfanta\Pagerfanta;
|
||||||
|
|
||||||
|
@ -13,77 +12,66 @@ class EntryRepository extends EntityRepository
|
||||||
* Retrieves unread entries for a user.
|
* Retrieves unread entries for a user.
|
||||||
*
|
*
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
* @param int $firstResult
|
|
||||||
* @param int $maxResults
|
|
||||||
*
|
*
|
||||||
* @return Paginator
|
* @return Pagerfanta
|
||||||
*/
|
*/
|
||||||
public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
|
public function findUnreadByUser($userId)
|
||||||
{
|
{
|
||||||
$qb = $this->createQueryBuilder('e')
|
$qb = $this->createQueryBuilder('e')
|
||||||
->setFirstResult($firstResult)
|
|
||||||
->setMaxResults($maxResults)
|
|
||||||
->leftJoin('e.user', 'u')
|
->leftJoin('e.user', 'u')
|
||||||
->where('e.isArchived = false')
|
->where('e.isArchived = false')
|
||||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||||
->orderBy('e.id', 'desc')
|
->orderBy('e.id', 'desc')
|
||||||
->getQuery();
|
->getQuery();
|
||||||
|
|
||||||
$paginator = new Paginator($qb);
|
$pagerAdapter = new DoctrineORMAdapter($qb);
|
||||||
|
|
||||||
return $paginator;
|
return new Pagerfanta($pagerAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves read entries for a user.
|
* Retrieves read entries for a user.
|
||||||
*
|
*
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
* @param int $firstResult
|
|
||||||
* @param int $maxResults
|
|
||||||
*
|
*
|
||||||
* @return Paginator
|
* @return Pagerfanta
|
||||||
*/
|
*/
|
||||||
public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
|
public function findArchiveByUser($userId)
|
||||||
{
|
{
|
||||||
$qb = $this->createQueryBuilder('e')
|
$qb = $this->createQueryBuilder('e')
|
||||||
->select('e')
|
->select('e')
|
||||||
->setFirstResult($firstResult)
|
|
||||||
->setMaxResults($maxResults)
|
|
||||||
->leftJoin('e.user', 'u')
|
->leftJoin('e.user', 'u')
|
||||||
->where('e.isArchived = true')
|
->where('e.isArchived = true')
|
||||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||||
->orderBy('e.id', 'desc')
|
->orderBy('e.id', 'desc')
|
||||||
->getQuery();
|
->getQuery();
|
||||||
|
|
||||||
$paginator = new Paginator($qb);
|
$pagerAdapter = new DoctrineORMAdapter($qb);
|
||||||
|
|
||||||
return $paginator;
|
return new Pagerfanta($pagerAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves starred entries for a user.
|
* Retrieves starred entries for a user.
|
||||||
*
|
*
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
* @param int $firstResult
|
|
||||||
* @param int $maxResults
|
|
||||||
*
|
*
|
||||||
* @return Paginator
|
* @return Pagerfanta
|
||||||
*/
|
*/
|
||||||
public function findStarredByUser($userId, $firstResult, $maxResults = 12)
|
public function findStarredByUser($userId)
|
||||||
{
|
{
|
||||||
|
|
||||||
$qb = $this->createQueryBuilder('e')
|
$qb = $this->createQueryBuilder('e')
|
||||||
->select('e')
|
->select('e')
|
||||||
->setFirstResult($firstResult)
|
|
||||||
->setMaxResults($maxResults)
|
|
||||||
->leftJoin('e.user', 'u')
|
->leftJoin('e.user', 'u')
|
||||||
->where('e.isStarred = true')
|
->where('e.isStarred = true')
|
||||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||||
->orderBy('e.id', 'desc')
|
->orderBy('e.id', 'desc')
|
||||||
->getQuery();
|
->getQuery();
|
||||||
|
|
||||||
$paginator = new Paginator($qb);
|
$pagerAdapter = new DoctrineORMAdapter($qb);
|
||||||
|
|
||||||
return $paginator;
|
return new Pagerfanta($pagerAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
<div class="results">
|
<div class="results">
|
||||||
<div class="nb-results">{{ entries.count }} {% trans %}entries{% endtrans %}</div>
|
<div class="nb-results">{{ entries.count }} {% trans %}entries{% endtrans %}</div>
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
{% for p in range(1, entries.count) %}
|
{% for p in range(1, entries.nbPages) %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ path(app.request.attributes.get('_route'), {'page': p}) }}">{{ p }}</a>
|
<a href="{{ path(app.request.attributes.get('_route'), {'page': p}) }}" class="{{ currentPage == p ? 'current':''}}" >{{ p }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -537,6 +537,16 @@ footer a {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pagination .current {
|
||||||
|
height: 25px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border: 1px solid #d5d5d5;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #000;
|
||||||
|
background-color: #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
/* ==========================================================================
|
/* ==========================================================================
|
||||||
2.1 = "save a link" related styles
|
2.1 = "save a link" related styles
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
|
|
|
@ -78,7 +78,7 @@ class EntryControllerTest extends WallabagCoreTestCase
|
||||||
$this->logInAs('admin');
|
$this->logInAs('admin');
|
||||||
$client = $this->getClient();
|
$client = $this->getClient();
|
||||||
|
|
||||||
$client->request('GET', '/archive');
|
$client->request('GET', '/archive/list');
|
||||||
|
|
||||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ class EntryControllerTest extends WallabagCoreTestCase
|
||||||
$this->logInAs('admin');
|
$this->logInAs('admin');
|
||||||
$client = $this->getClient();
|
$client = $this->getClient();
|
||||||
|
|
||||||
$client->request('GET', '/starred');
|
$client->request('GET', '/starred/list');
|
||||||
|
|
||||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue