2015-09-17 22:41:37 +00:00
|
|
|
module Handler.Item where
|
|
|
|
|
|
|
|
import Import
|
2016-01-17 19:05:42 +00:00
|
|
|
import Yesod.Default.Util (widgetFileReload)
|
2015-09-17 22:41:37 +00:00
|
|
|
|
|
|
|
itemsPerPage :: Int
|
|
|
|
itemsPerPage = 100
|
|
|
|
|
|
|
|
getItemR :: Int64 -> Handler Html
|
2015-09-17 23:08:15 +00:00
|
|
|
getItemR transactionTypeId = getItemPagedR transactionTypeId 1
|
2015-09-17 22:41:37 +00:00
|
|
|
|
|
|
|
getItemPagedR :: Int64 -> Int -> Handler Html
|
2015-09-17 23:08:15 +00:00
|
|
|
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))]
|
2015-09-17 22:41:37 +00:00
|
|
|
total <- runDB $ count [TransactionTypeId ==. tid]
|
|
|
|
let offset = itemsPerPage * page
|
2015-09-17 23:08:15 +00:00
|
|
|
let maxPages = total `div` itemsPerPage
|
|
|
|
let paginatePages = [1..maxPages+1]
|
2016-01-17 19:05:42 +00:00
|
|
|
loginLayout user $ $(widgetFileReload def "item")
|
2015-09-17 22:41:37 +00:00
|
|
|
)
|
|
|
|
|