pagination now works, but always shows all pages (#items/100) for selection. could get messy afterwards. but fixes #5

This commit is contained in:
Nicole Dresselhaus 2015-09-18 01:08:15 +02:00
parent 6235692988
commit 5266c5c5da
2 changed files with 16 additions and 6 deletions

View File

@ -6,20 +6,23 @@ itemsPerPage :: Int
itemsPerPage = 100
getItemR :: Int64 -> Handler Html
getItemR transactionTypeId = getItemPagedR transactionTypeId 0
getItemR transactionTypeId = getItemPagedR transactionTypeId 1
getItemPagedR :: Int64 -> Int -> Handler Html
getItemPagedR tid page =
loginOrDo (\(uid,user) -> do
items <- runDB $ selectList [TransactionTypeId ==. tid] [Desc TransactionDateTime, LimitTo itemsPerPage, OffsetBy (itemsPerPage*page)]
getItemPagedR tid page
| page < 1 = getItemPagedR tid 1
| otherwise = loginOrDo (\(uid,user) -> do
items <- runDB $ selectList [TransactionTypeId ==. tid] [Desc TransactionDateTime, LimitTo itemsPerPage, OffsetBy (itemsPerPage*(page-1))]
total <- runDB $ count [TransactionTypeId ==. tid]
let offset = itemsPerPage * page
let maxPages = total `div` itemsPerPage
let paginatePages = [1..maxPages+1]
loginLayout user $ [whamlet|
<div .panel .panel-default>
$if page > 0
<div .panel-heading>#{itemsPerPage} Transactions (starting at #{offset})
<div .panel-heading>#{itemsPerPage} Transactions (starting at #{offset}) of #{total}
$else
<div .panel-heading>#{itemsPerPage} Transactions
<div .panel-heading>#{itemsPerPage} Transactions of #{total}
<table .table .table-condensed .small>
<tr>
<th .text-center>Time
@ -79,6 +82,12 @@ getItemPagedR tid page =
<td>#{transactionStationName t}
<td>
<td>
<ul class="pagination">
$forall p <- paginatePages
$if p == page
<li .active><a href="@{ItemPagedR tid p}">#{p}</a>
$else
<li><a href="@{ItemPagedR tid p}">#{p}</a>
|]
)

View File

@ -15,3 +15,4 @@
/analysis/items/#Int64 ProfitItemsDetailsR GET
/orders OrdersR GET
/history/#Int64 ItemR GET
/history/#Int64/#Int ItemPagedR GET