yesod-paginator-1.1.0.0: A pagination approach for yesod

Safe HaskellNone
LanguageHaskell2010

Yesod.Paginator

Contents

Description

There are two pagination functions. One for arbitrary items where you provide the list of things to be paginated:

getSomeRoute = do
    -- 10 items per page
    pages <- paginate 10 =<< getAllThings

    defaultLayout $ do
        [whamlet|
            $forall thing <- pageItems $ pagesCurrent pages
                ^{showThing thing}

            $# display at most 5 page elements, with current page middle-ish
            ^{simple 5 pages}
            |]

And another for paginating directly out of the database, you provide the same arguments as you would for selectList:

getSomeRoute something = do
    pages <- runDB $ selectPaginated 10 [SomeThing ==. something] []

    defaultLayout $ do
        [whamlet|
            $forall thing <- pageItems $ pagesCurrent pages
                ^{showThing $ entityVal thing}

            ^{simple 5 pages}
            |]

Synopsis

Type-safe numerics

data PageNumber Source #

Instances

Enum PageNumber Source # 
Eq PageNumber Source # 
Integral PageNumber Source # 
Num PageNumber Source # 
Ord PageNumber Source # 
Real PageNumber Source # 
Show PageNumber Source # 
ToMarkup PageNumber Source # 

data PerPage Source #

Instances

Enum PerPage Source # 
Eq PerPage Source # 

Methods

(==) :: PerPage -> PerPage -> Bool #

(/=) :: PerPage -> PerPage -> Bool #

Integral PerPage Source # 
Num PerPage Source # 
Ord PerPage Source # 
Read PerPage Source # 
Real PerPage Source # 
Show PerPage Source # 
PathPiece PerPage Source # 

data ItemsCount Source #

Instances

Enum ItemsCount Source # 
Eq ItemsCount Source # 
Integral ItemsCount Source # 
Num ItemsCount Source # 
Ord ItemsCount Source # 
Read ItemsCount Source # 
Real ItemsCount Source # 
Show ItemsCount Source # 
PathPiece ItemsCount Source # 

Paginated data

data Pages a Source #

Instances

Eq a => Eq (Pages a) Source # 

Methods

(==) :: Pages a -> Pages a -> Bool #

(/=) :: Pages a -> Pages a -> Bool #

Show a => Show (Pages a) Source # 

Methods

showsPrec :: Int -> Pages a -> ShowS #

show :: Pages a -> String #

showList :: [Pages a] -> ShowS #

The current page

data Page a Source #

Instances

Eq a => Eq (Page a) Source # 

Methods

(==) :: Page a -> Page a -> Bool #

(/=) :: Page a -> Page a -> Bool #

Show a => Show (Page a) Source # 

Methods

showsPrec :: Int -> Page a -> ShowS #

show :: Page a -> String #

showList :: [Page a] -> ShowS #

pageItems :: Page a -> [a] Source #

Paginators

paginate :: Yesod site => PerPage -> [a] -> HandlerFor site (Pages a) Source #

Paginate a list of items

selectPaginated :: (PersistEntity val, PersistEntityBackend val ~ BaseBackend (YesodPersistBackend site), PersistQuery (YesodPersistBackend site), Yesod site) => PerPage -> [Filter val] -> [SelectOpt val] -> YesodDB site (Pages (Entity val)) Source #

Paginate out of a persistent database

Widgets

simple :: Natural -> PaginationWidget m a Source #

Simple widget, limited to show the given number of total page elements

Pseudo-HTML for simple 5, on page 1:

  <ul .pagination>
    <li .prev .disabled><a>«
    <li .active .disabled><a>1
    <li .next><a href="?p=2">2
    <li .next><a href="?p=3">3
    <li .next><a href="?p=4">4
    <li .next><a href="?p=5">5
    <li .next><a href="?p=2">»

And page 7:

  <ul .pagination>
    <li .prev><a href="?p=6">«
    <li .prev><a href="?p=5">5
    <li .prev><a href="?p=6">6
    <li .active .disabled><a>7
    <li .next><a href="?p=8">8
    <li .next><a href="?p=9">9
    <li .next><a href="?p=8">»

ellipsed :: Natural -> PaginationWidget m a Source #

Show pages before and after, ellipsis, and first/last