pagination now works, but always shows all pages (#items/100) for selection. could get messy afterwards. but fixes #5
This commit is contained in:
parent
6235692988
commit
5266c5c5da
@ -6,20 +6,23 @@ itemsPerPage :: Int
|
|||||||
itemsPerPage = 100
|
itemsPerPage = 100
|
||||||
|
|
||||||
getItemR :: Int64 -> Handler Html
|
getItemR :: Int64 -> Handler Html
|
||||||
getItemR transactionTypeId = getItemPagedR transactionTypeId 0
|
getItemR transactionTypeId = getItemPagedR transactionTypeId 1
|
||||||
|
|
||||||
getItemPagedR :: Int64 -> Int -> Handler Html
|
getItemPagedR :: Int64 -> Int -> Handler Html
|
||||||
getItemPagedR tid page =
|
getItemPagedR tid page
|
||||||
loginOrDo (\(uid,user) -> do
|
| page < 1 = getItemPagedR tid 1
|
||||||
items <- runDB $ selectList [TransactionTypeId ==. tid] [Desc TransactionDateTime, LimitTo itemsPerPage, OffsetBy (itemsPerPage*page)]
|
| otherwise = loginOrDo (\(uid,user) -> do
|
||||||
|
items <- runDB $ selectList [TransactionTypeId ==. tid] [Desc TransactionDateTime, LimitTo itemsPerPage, OffsetBy (itemsPerPage*(page-1))]
|
||||||
total <- runDB $ count [TransactionTypeId ==. tid]
|
total <- runDB $ count [TransactionTypeId ==. tid]
|
||||||
let offset = itemsPerPage * page
|
let offset = itemsPerPage * page
|
||||||
|
let maxPages = total `div` itemsPerPage
|
||||||
|
let paginatePages = [1..maxPages+1]
|
||||||
loginLayout user $ [whamlet|
|
loginLayout user $ [whamlet|
|
||||||
<div .panel .panel-default>
|
<div .panel .panel-default>
|
||||||
$if page > 0
|
$if page > 0
|
||||||
<div .panel-heading>#{itemsPerPage} Transactions (starting at #{offset})
|
<div .panel-heading>#{itemsPerPage} Transactions (starting at #{offset}) of #{total}
|
||||||
$else
|
$else
|
||||||
<div .panel-heading>#{itemsPerPage} Transactions
|
<div .panel-heading>#{itemsPerPage} Transactions of #{total}
|
||||||
<table .table .table-condensed .small>
|
<table .table .table-condensed .small>
|
||||||
<tr>
|
<tr>
|
||||||
<th .text-center>Time
|
<th .text-center>Time
|
||||||
@ -79,6 +82,12 @@ getItemPagedR tid page =
|
|||||||
<td>#{transactionStationName t}
|
<td>#{transactionStationName t}
|
||||||
<td>
|
<td>
|
||||||
<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>
|
||||||
|]
|
|]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,3 +15,4 @@
|
|||||||
/analysis/items/#Int64 ProfitItemsDetailsR GET
|
/analysis/items/#Int64 ProfitItemsDetailsR GET
|
||||||
/orders OrdersR GET
|
/orders OrdersR GET
|
||||||
/history/#Int64 ItemR GET
|
/history/#Int64 ItemR GET
|
||||||
|
/history/#Int64/#Int ItemPagedR GET
|
||||||
|
Loading…
Reference in New Issue
Block a user