From 522da12175c5da2c5c025fd2490e745ac31eda19 Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 7 Sep 2015 18:15:30 +0200 Subject: [PATCH] added journal pagination forgot template file --- Handler/Journal.hs | 18 ++++++++++++++++++ config/routes | 1 + messages/de.msg | 2 ++ messages/en.msg | 2 ++ static/css/main.css | 14 +++++++++++++- templates/journal.hamlet | 4 ++++ templates/journalPage.hamlet | 37 ++++++++++++++++++++++++++++++++++++ 7 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 templates/journalPage.hamlet diff --git a/Handler/Journal.hs b/Handler/Journal.hs index 23fd1c6..299facb 100644 --- a/Handler/Journal.hs +++ b/Handler/Journal.hs @@ -23,6 +23,7 @@ getJournalR :: Handler Html getJournalR = do master <- getYesod rawEntries <- runDB $ selectList [] [Desc TransactionId] + next <- runDB $ selectList [] [Desc TransactionId, OffsetBy 30] entries <- return $ L.reverse $ L.take 30 rawEntries total <- return $ L.sum $ I.map (transactionAmount . entityVal) rawEntries timeLimit <- case L.null entries of @@ -41,3 +42,20 @@ merge (t:ts) [] = (Left $ entityVal t) : merge ts [] merge (t:ts) (c:cs) | transactionTime (entityVal t) < cashCheckTime (entityVal c) = (Left $ entityVal t) : merge ts (c:cs) | transactionTime (entityVal t) > cashCheckTime (entityVal c) = (Right $ entityVal c) : merge (t:ts) cs + +getJournalPageR :: Int -> Handler Html +getJournalPageR p = do + master <- getYesod + rawEntries <- runDB $ selectList [] [Desc TransactionId, OffsetBy (p * 30)] + next <- runDB $ selectList [] [Desc TransactionId, OffsetBy ((p + 1) * 30)] + entries <- return $ L.reverse $ L.take 30 rawEntries + lTimeLimit <- case L.null entries of + False -> return $ transactionTime $ entityVal $ L.head $ entries + True -> liftIO getCurrentTime + uTimeLimit <- case L.null entries of + False -> return $ transactionTime $ entityVal $ L.last $ entries + True -> liftIO getCurrentTime + cashChecks <- runDB $ selectList [CashCheckTime >=. lTimeLimit, CashCheckTime <. uTimeLimit] [Asc CashCheckId] + list <- return $ merge entries cashChecks + defaultLayout $ do + $(widgetFile "journalPage") diff --git a/config/routes b/config/routes index c238b7a..d18ce50 100644 --- a/config/routes +++ b/config/routes @@ -17,6 +17,7 @@ /user/#UserId/buy/#BeverageId BuyR GET POST !/user/cash/buy/#BeverageId BuyCashR GET POST /journal JournalR GET +/journal/#Int JournalPageR GET /payout PayoutR GET POST /summary SummaryR GET /summary.json SummaryJsonR GET diff --git a/messages/de.msg b/messages/de.msg index e39e8fa..59e1a0c 100644 --- a/messages/de.msg +++ b/messages/de.msg @@ -113,3 +113,5 @@ TransferTo: Guthaben transferieren an NegativeTransfer: Keine negativen Beträge transferieren TransferComplete: Transfer abgeschlossen TransferError: Fehler beim Transfer +PreviousPage: vorherige Seite +NextPage: nächste Seite diff --git a/messages/en.msg b/messages/en.msg index f37a65d..fb22226 100644 --- a/messages/en.msg +++ b/messages/en.msg @@ -113,3 +113,5 @@ TransferTo: Transfer credit to NegativeTransfer: Please do not transfer negative amounts TransferComplete: Transfer complete TransferError: Transfer error +PreviousPage: previous page +NextPage: next page diff --git a/static/css/main.css b/static/css/main.css index d93b491..6e75796 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -19,6 +19,18 @@ text-align: right; } +.left { + display: inline-block; + /*float: left;*/ + padding: 2em; +} + +.right { + display: inline-block; + /*float: right;*/ + padding: 2em; +} + article#func.article { background-color: #fff7bd; } @@ -262,4 +274,4 @@ input[type] { } #barcodeContent { text-align: center; -} \ No newline at end of file +} diff --git a/templates/journal.hamlet b/templates/journal.hamlet index 561538e..810c2a5 100644 --- a/templates/journal.hamlet +++ b/templates/journal.hamlet @@ -27,6 +27,10 @@ $if not $ L.null entries #{formatIntCurrency (fromIntegral total)} #{appCurrency $ appSettings master}

_{MsgCashStock}: #{formatIntCurrency (fromIntegral cashBalance)} #{appCurrency $ appSettings master} + $if not $ L.null next +

+
+ _{MsgNextPage}
  • diff --git a/templates/journalPage.hamlet b/templates/journalPage.hamlet new file mode 100644 index 0000000..4f8bd30 --- /dev/null +++ b/templates/journalPage.hamlet @@ -0,0 +1,37 @@ +$doctype 5 + +

    Journal + +$if not $ L.null entries + + + + + +
    _{MsgTime} + _{MsgDescription} + _{MsgValueIn $ appCurrency $ appSettings master} + $forall (eTransCash) <- list + $case eTransCash + $of Left trans +
    #{formatTime defaultTimeLocale "%A %F %H:%M" $ transactionTime trans} + #{transactionDescription trans} + #{formatIntCurrency (transactionAmount trans)} #{appCurrency $ appSettings master} + $of Right cash +
    + _{MsgCashCheckOf $ formatTime defaultTimeLocale "%A %F %H:%M" $ cashCheckTime cash}: + #{formatIntCurrency (cashCheckBalance cash)} #{appCurrency $ appSettings master} + +