mirror of
https://code.sup39.dev/repos/Wqawg
synced 2025-01-30 04:57:51 +09:00
Pagination widget: Display prev and next pages' links
This commit is contained in:
parent
be458d3689
commit
d500b85c57
2 changed files with 28 additions and 7 deletions
|
@ -109,10 +109,10 @@ data NavModel = NavModel
|
||||||
{
|
{
|
||||||
nmFirst :: Bool
|
nmFirst :: Bool
|
||||||
, nmPrevJumps :: [Int]
|
, nmPrevJumps :: [Int]
|
||||||
, nmPrev :: [Int]
|
, nmPrev :: Maybe ([Int], Int)
|
||||||
, nmCurrent :: Int
|
, nmCurrent :: Int
|
||||||
, nmTotal :: Int
|
, nmTotal :: Int
|
||||||
, nmNext :: [Int]
|
, nmNext :: Maybe (Int, [Int])
|
||||||
, nmNextJumps :: [Int]
|
, nmNextJumps :: [Int]
|
||||||
, nmLast :: Bool
|
, nmLast :: Bool
|
||||||
}
|
}
|
||||||
|
@ -131,14 +131,14 @@ navModel ns curr total = NavModel
|
||||||
, nmPrevJumps = [] --TODO
|
, nmPrevJumps = [] --TODO
|
||||||
, nmPrev =
|
, nmPrev =
|
||||||
if curr == 1 || navNext ns < 1
|
if curr == 1 || navNext ns < 1
|
||||||
then []
|
then Nothing
|
||||||
else [max 1 (curr - navNext ns) .. curr - 1]
|
else Just ([max 1 (curr - navNext ns) .. curr - 2], curr - 1)
|
||||||
, nmCurrent = curr
|
, nmCurrent = curr
|
||||||
, nmTotal = total
|
, nmTotal = total
|
||||||
, nmNext =
|
, nmNext =
|
||||||
if curr >= total || navNext ns < 1
|
if curr >= total || navNext ns < 1
|
||||||
then []
|
then Nothing
|
||||||
else [curr + 1 .. min total (curr + navNext ns)]
|
else Just (curr + 1, [curr + 2 .. min total (curr + navNext ns)])
|
||||||
, nmNextJumps = [] --TODO
|
, nmNextJumps = [] --TODO
|
||||||
, nmLast = navEdges ns
|
, nmLast = navEdges ns
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,12 @@ import Text.Blaze (ToMarkup)
|
||||||
import Yesod.Core (RenderRoute (..))
|
import Yesod.Core (RenderRoute (..))
|
||||||
import Yesod.Core.Widget (WidgetT, whamlet)
|
import Yesod.Core.Widget (WidgetT, whamlet)
|
||||||
|
|
||||||
|
import qualified Data.Text as T (pack)
|
||||||
import qualified Formatting as F
|
import qualified Formatting as F
|
||||||
|
|
||||||
import Data.Paginate.Local
|
import Data.Paginate.Local
|
||||||
|
|
||||||
-- | Settings for building a UI page navigation widget.
|
-- | Settings for building a page navigation UI widget.
|
||||||
data NavWidgetSettings = NavWidgetSettings
|
data NavWidgetSettings = NavWidgetSettings
|
||||||
{ -- | Label for the first page link. Examples: 1, First, ≪, ⋘.
|
{ -- | Label for the first page link. Examples: 1, First, ≪, ⋘.
|
||||||
nwsFirst :: Text
|
nwsFirst :: Text
|
||||||
|
@ -82,7 +83,27 @@ pageNavWidget nm nws mklink =
|
||||||
$if nmFirst nm
|
$if nmFirst nm
|
||||||
<li>
|
<li>
|
||||||
^{link 1 $ nwsFirst nws}
|
^{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)}
|
<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
|
$if nmLast nm
|
||||||
<li>
|
<li>
|
||||||
^{link (nmTotal nm) (nwsLast nws $ nmTotal nm)}
|
^{link (nmTotal nm) (nwsLast nws $ nmTotal nm)}
|
||||||
|
|
Loading…
Add table
Reference in a new issue