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