1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2025-01-28 11:57:51 +09:00

Pagination widget: Display prev and next pages' links

This commit is contained in:
fr33domlover 2016-06-07 12:57:05 +00:00
parent be458d3689
commit d500b85c57
2 changed files with 28 additions and 7 deletions

View file

@ -109,10 +109,10 @@ data NavModel = NavModel
{
nmFirst :: Bool
, nmPrevJumps :: [Int]
, nmPrev :: [Int]
, nmPrev :: Maybe ([Int], Int)
, nmCurrent :: Int
, nmTotal :: Int
, nmNext :: [Int]
, nmNext :: Maybe (Int, [Int])
, nmNextJumps :: [Int]
, nmLast :: Bool
}
@ -131,14 +131,14 @@ navModel ns curr total = NavModel
, nmPrevJumps = [] --TODO
, nmPrev =
if curr == 1 || navNext ns < 1
then []
else [max 1 (curr - navNext ns) .. curr - 1]
then Nothing
else Just ([max 1 (curr - navNext ns) .. curr - 2], curr - 1)
, nmCurrent = curr
, nmTotal = total
, nmNext =
if curr >= total || navNext ns < 1
then []
else [curr + 1 .. min total (curr + navNext ns)]
then Nothing
else Just (curr + 1, [curr + 2 .. min total (curr + navNext ns)])
, nmNextJumps = [] --TODO
, nmLast = navEdges ns
}

View file

@ -34,11 +34,12 @@ import Text.Blaze (ToMarkup)
import Yesod.Core (RenderRoute (..))
import Yesod.Core.Widget (WidgetT, whamlet)
import qualified Data.Text as T (pack)
import qualified Formatting as F
import Data.Paginate.Local
-- | Settings for building a UI page navigation widget.
-- | Settings for building a page navigation UI widget.
data NavWidgetSettings = NavWidgetSettings
{ -- | Label for the first page link. Examples: 1, First, ≪, ⋘.
nwsFirst :: Text
@ -82,7 +83,27 @@ pageNavWidget nm nws mklink =
$if nmFirst nm
<li>
^{link 1 $ nwsFirst nws}
$#--------- TODO prev jumps --------
$maybe (ps, p) <- nmPrev nm
$forall m <- ps
<li>
^{link m (T.pack $ show m)}
<li>
^{link p (nwsPrev nws p)}
<li>#{nwsCurrent nws (nmCurrent nm) (nmTotal nm)}
$maybe (n, ns) <- nmNext nm
<li>
^{link n (nwsNext nws n)}
$forall m <- ns
<li>
^{link m (T.pack $ show m)}
$#--------- TODO next jumps --------
$if nmLast nm
<li>
^{link (nmTotal nm) (nwsLast nws $ nmTotal nm)}