From 9fb6ac830fa669beef1dd11070421262c073192c Mon Sep 17 00:00:00 2001 From: Francois Gravelaine Date: Mon, 27 Jul 2015 23:20:32 +0200 Subject: [PATCH] Adds pagerfanta paginator everywhere, modifies article routing. Change API for is_starred and is_archived --- app/config/routing.yml | 12 ++++-- .../Controller/WallabagRestController.php | 4 +- .../CoreBundle/Controller/EntryController.php | 42 ++++++++++++------- .../CoreBundle/Controller/RssController.php | 21 ++++++---- .../CoreBundle/Repository/EntryRepository.php | 38 ++++++----------- .../Resources/views/Entry/entries.html.twig | 4 +- .../views/themes/baggy/public/css/main.css | 10 +++++ .../Tests/Controller/EntryControllerTest.php | 4 +- 8 files changed, 76 insertions(+), 59 deletions(-) diff --git a/app/config/routing.yml b/app/config/routing.yml index 8710e97f..e8bf08a5 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -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+ diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 2f5923c8..692a4ae0 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -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); diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 4a7a0644..49714d02 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -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 + ) ); } diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php index 86754e15..8428dce0 100644 --- a/src/Wallabag/CoreBundle/Controller/RssController.php +++ b/src/Wallabag/CoreBundle/Controller/RssController.php @@ -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, diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 1335e808..a4514d9e 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -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); } /** diff --git a/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig index acb96420..bf3caf09 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Entry/entries.html.twig @@ -8,9 +8,9 @@
{{ entries.count }} {% trans %}entries{% endtrans %}
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/css/main.css b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/css/main.css index ff1a36a1..e2844ccc 100755 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/css/main.css +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/css/main.css @@ -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 ========================================================================== */ diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 904e2a5c..2cd50130 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -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()); } -- 2.41.0