diff options
| author | Joris | 2016-04-06 00:12:07 +0200 | 
|---|---|---|
| committer | Joris | 2016-04-06 00:12:07 +0200 | 
| commit | d889c728c6ef1462fdeb56891de8d4d1a3df70c6 (patch) | |
| tree | c2fc12fed618f06d90ffd022e263e18df42cb0b8 /src/client/elm/LoggedIn/Home/View/Paging.elm | |
| parent | fe50c4042848681833d15fab27466d1d2d4bda45 (diff) | |
Show first, previous, next and last page even if the action does not do anything
Diffstat (limited to 'src/client/elm/LoggedIn/Home/View/Paging.elm')
| -rw-r--r-- | src/client/elm/LoggedIn/Home/View/Paging.elm | 62 | 
1 files changed, 32 insertions, 30 deletions
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  | 
