Paginate 'all snapshots' list. (#41)

This commit is contained in:
Dan Burton 2014-12-19 18:33:58 -08:00
parent a554c308ac
commit edb4b93b49
3 changed files with 23 additions and 0 deletions

View File

@ -8,6 +8,9 @@ import Formatting
import Formatting.Time
import Import
snapshotsPerPage :: Integral a => a
snapshotsPerPage = 50
-- This is a handler function for the GET request method on the HomeR
-- resource pattern. All of your resource patterns are defined in
-- config/routes
@ -18,10 +21,15 @@ import Import
getAllSnapshotsR :: Handler Html
getAllSnapshotsR = do
now' <- liftIO getCurrentTime
currentPageMay <- lookupGetParam "page"
let currentPage :: Int64
currentPage = fromMaybe 1 (currentPageMay >>= readMay)
groups <- fmap (groupBy (on (==) (\(_,_,uploaded,_,_) -> uploaded)) . map (uncrapify now')) $
runDB $ E.select $ E.from $ \(stackage `E.InnerJoin` user) -> do
E.on (stackage E.^. StackageUser E.==. user E.^. UserId)
E.orderBy [E.desc $ stackage E.^. StackageUploaded]
E.limit snapshotsPerPage
E.offset ((currentPage - 1) * snapshotsPerPage)
return
( stackage E.^. StackageSlug
, stackage E.^. StackageTitle
@ -31,6 +39,7 @@ getAllSnapshotsR = do
)
defaultLayout $ do
setTitle "Stackage Server"
let snapshotsNav = $(widgetFile "snapshots-nav")
$(widgetFile "all-snapshots")
where uncrapify now' c =
let (E.Value ident, E.Value title, E.Value uploaded, E.Value display, E.Value handle') = c

View File

@ -1,6 +1,7 @@
<div .container>
<div .content>
<h1>Snapshots
^{snapshotsNav}
$forall stackages <- groups
$forall (_, _, uploaded, _, _) <- take 1 stackages
<h3>
@ -13,3 +14,4 @@
#{title}
<p>
#{display} (#{handle})
^{snapshotsNav}

View File

@ -0,0 +1,12 @@
<div .snapshot-nav>
$if currentPage > 1
<a href=@{AllSnapshotsR}?page=#{currentPage - 1}>
see newer --
$else
at newest --
\ Page #{currentPage} #
$if length (concat groups) == snapshotsPerPage
<a href=@{AllSnapshotsR}?page=#{currentPage + 1}>
++ see older
$else
++ at oldest