aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/LoggedIn/Home')
-rw-r--r--src/client/elm/LoggedIn/Home/View.elm2
-rw-r--r--src/client/elm/LoggedIn/Home/View/Paging.elm62
2 files changed, 33 insertions, 31 deletions
diff --git a/src/client/elm/LoggedIn/Home/View.elm b/src/client/elm/LoggedIn/Home/View.elm
index 43cc9cf..4c5e330 100644
--- a/src/client/elm/LoggedIn/Home/View.elm
+++ b/src/client/elm/LoggedIn/Home/View.elm
@@ -28,5 +28,5 @@ view loggedData loggedIn =
, MonthlyView.view loggedData loggedIn
]
, paymentsTable loggedData loggedIn
- , paymentsPaging Mailbox.address loggedData.payments loggedIn
+ , paymentsPaging loggedData.payments loggedIn
]
diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm
index 0385941..b669b6e 100644
--- a/src/client/elm/LoggedIn/Home/View/Paging.elm
+++ b/src/client/elm/LoggedIn/Home/View/Paging.elm
@@ -2,8 +2,6 @@ module LoggedIn.Home.View.Paging
( paymentsPaging
) where
-import Signal exposing (Address)
-
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
@@ -14,6 +12,7 @@ import LoggedIn.Home.Action as HomeAction
import LoggedIn.Home.Model as HomeModel
import Action exposing (Action)
+import Mailbox
import LoggedData exposing (LoggedData)
import Model.Payment as Payment exposing (Payments, perPage)
@@ -22,8 +21,8 @@ import View.Icon exposing (renderIcon)
showedPages : Int
showedPages = 5
-paymentsPaging : Address Action -> Payments -> HomeModel.Model -> Html
-paymentsPaging address payments homeModel =
+paymentsPaging : Payments -> HomeModel.Model -> Html
+paymentsPaging payments homeModel =
let maxPage = ceiling (toFloat (List.length (Payment.punctual payments)) / toFloat perPage)
pages = truncatePages homeModel.currentPage [1..maxPage]
in if maxPage == 1
@@ -32,15 +31,9 @@ paymentsPaging address payments homeModel =
else
div
[ class "pages" ]
- ( ( if homeModel.currentPage > 1
- then [ firstPage address, previousPage address homeModel ]
- else []
- )
- ++ ( List.map (paymentsPage address homeModel) pages)
- ++ ( if homeModel.currentPage < maxPage
- then [ nextPage address homeModel, lastPage address maxPage ]
- else []
- )
+ ( [ firstPage homeModel, previousPage homeModel ]
+ ++ ( List.map (paymentsPage homeModel) pages)
+ ++ [ nextPage homeModel maxPage, lastPage homeModel maxPage ]
)
truncatePages : Int -> List Int -> List Int
@@ -49,7 +42,7 @@ truncatePages currentPage pages =
showedLeftPages = ceiling ((toFloat showedPages - 1) / 2)
showedRightPages = floor ((toFloat showedPages - 1) / 2)
truncatedPages =
- if currentPage < showedLeftPages then
+ if currentPage <= showedLeftPages then
[1..showedPages]
else if currentPage > totalPages - showedRightPages then
[(totalPages - showedPages)..totalPages]
@@ -57,47 +50,56 @@ truncatePages currentPage pages =
[(currentPage - showedLeftPages)..(currentPage + showedRightPages)]
in List.filter (flip List.member pages) truncatedPages
-firstPage : Address Action -> Html
-firstPage address =
+firstPage : HomeModel.Model -> Html
+firstPage homeModel =
button
- [ class "page"
- , onClick address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| 1)
+ [ classList
+ [ ("page", True)
+ , ("disable", homeModel.currentPage <= 1)
+ ]
+ , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| 1)
]
[ renderIcon "fast-backward" ]
-previousPage : Address Action -> HomeModel.Model -> Html
-previousPage address homeModel =
+previousPage : HomeModel.Model -> Html
+previousPage homeModel =
button
[ class "page"
- , onClick address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| homeModel.currentPage - 1)
+ , onClick Mailbox.address <|
+ if homeModel.currentPage > 1
+ then (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| homeModel.currentPage - 1)
+ else Action.NoOp
]
[ renderIcon "backward" ]
-nextPage : Address Action -> HomeModel.Model -> Html
-nextPage address homeModel =
+nextPage : HomeModel.Model -> Int -> Html
+nextPage homeModel maxPage =
button
[ class "page"
- , onClick address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| homeModel.currentPage + 1)
+ , onClick Mailbox.address <|
+ if homeModel.currentPage < maxPage
+ then (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| homeModel.currentPage + 1)
+ else Action.NoOp
]
[ renderIcon "forward" ]
-lastPage : Address Action -> Int -> Html
-lastPage address maxPage =
+lastPage : HomeModel.Model -> Int -> Html
+lastPage homeModel maxPage =
button
[ class "page"
- , onClick address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| maxPage)
+ , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| maxPage)
]
[ renderIcon "fast-forward" ]
-paymentsPage : Address Action -> HomeModel.Model -> Int -> Html
-paymentsPage address homeModel page =
+paymentsPage : HomeModel.Model -> Int -> Html
+paymentsPage homeModel page =
let onCurrentPage = page == homeModel.currentPage
in button
[ classList
[ ("page", True)
, ("current", onCurrentPage)
]
- , onClick address <|
+ , onClick Mailbox.address <|
if onCurrentPage
then Action.NoOp
else Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdatePage <| page