diff options
Diffstat (limited to 'src/client/elm/View/LoggedIn')
-rw-r--r-- | src/client/elm/View/LoggedIn/Paging.elm | 100 | ||||
-rw-r--r-- | src/client/elm/View/LoggedIn/Table.elm | 96 |
2 files changed, 0 insertions, 196 deletions
diff --git a/src/client/elm/View/LoggedIn/Paging.elm b/src/client/elm/View/LoggedIn/Paging.elm deleted file mode 100644 index 20396a6..0000000 --- a/src/client/elm/View/LoggedIn/Paging.elm +++ /dev/null @@ -1,100 +0,0 @@ -module View.LoggedIn.Paging - ( paymentsPaging - ) where - -import Signal exposing (Address) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) - -import LoggedIn.Action as LoggedInAction -import LoggedIn.Model as LoggedInModel - -import Model.Action as Action exposing (..) -import Model.Payment exposing (perPage) - -import View.Icon exposing (renderIcon) - -showedPages : Int -showedPages = 5 - -paymentsPaging : Address Action -> LoggedInModel.Model -> Html -paymentsPaging address loggedInModel = - let maxPage = ceiling (toFloat loggedInModel.paymentsCount / toFloat perPage) - pages = truncatePages loggedInModel.currentPage [1..maxPage] - in if maxPage == 1 - then - text "" - else - div - [ class "pages" ] - ( ( if loggedInModel.currentPage > 1 - then [ firstPage address, previousPage address loggedInModel ] - else [] - ) - ++ ( List.map (paymentsPage address loggedInModel) pages) - ++ ( if loggedInModel.currentPage < maxPage - then [ nextPage address loggedInModel, lastPage address maxPage ] - else [] - ) - ) - -truncatePages : Int -> List Int -> List Int -truncatePages currentPage pages = - let totalPages = List.length pages - showedLeftPages = ceiling ((toFloat showedPages - 1) / 2) - showedRightPages = floor ((toFloat showedPages - 1) / 2) - truncatedPages = - if currentPage < showedLeftPages then - [1..showedPages] - else if currentPage > totalPages - showedRightPages then - [(totalPages - showedPages)..totalPages] - else - [(currentPage - showedLeftPages)..(currentPage + showedRightPages)] - in List.filter (flip List.member pages) truncatedPages - -firstPage : Address Action -> Html -firstPage address = - button - [ class "page" - , onClick address (UpdateLoggedIn (LoggedInAction.UpdatePage 1)) - ] - [ renderIcon "fast-backward" ] - -previousPage : Address Action -> LoggedInModel.Model -> Html -previousPage address loggedInModel = - button - [ class "page" - , onClick address (UpdateLoggedIn (LoggedInAction.UpdatePage (loggedInModel.currentPage - 1))) - ] - [ renderIcon "backward" ] - -nextPage : Address Action -> LoggedInModel.Model -> Html -nextPage address loggedInModel = - button - [ class "page" - , onClick address (UpdateLoggedIn (LoggedInAction.UpdatePage (loggedInModel.currentPage + 1))) - ] - [ renderIcon "forward" ] - -lastPage : Address Action -> Int -> Html -lastPage address maxPage = - button - [ class "page" - , onClick address (UpdateLoggedIn (LoggedInAction.UpdatePage maxPage)) - ] - [ renderIcon "fast-forward" ] - -paymentsPage : Address Action -> LoggedInModel.Model -> Int -> Html -paymentsPage address loggedInModel page = - let onCurrentPage = page == loggedInModel.currentPage - in button - [ classList - [ ("page", True) - , ("current", onCurrentPage) - ] - , onClick address <| - if onCurrentPage then Action.NoOp else UpdateLoggedIn (LoggedInAction.UpdatePage page) - ] - [ text (toString page) ] diff --git a/src/client/elm/View/LoggedIn/Table.elm b/src/client/elm/View/LoggedIn/Table.elm deleted file mode 100644 index ababcbd..0000000 --- a/src/client/elm/View/LoggedIn/Table.elm +++ /dev/null @@ -1,96 +0,0 @@ -module View.LoggedIn.Table - ( paymentsTable - ) where - -import Dict exposing (..) -import Date exposing (Date) -import Signal exposing (Address) -import String exposing (append) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) - -import LoggedIn.Action as LoggedInAction -import LoggedIn.Model as LoggedInModel - -import Model exposing (Model) -import Model.User exposing (getUserName) -import Model.Payment exposing (..) -import Model.Translations exposing (getMessage) -import Model.Action exposing (..) - -import View.Icon exposing (renderIcon) -import View.Date exposing (..) -import View.Price exposing (price) - -paymentsTable : Address Action -> Model -> LoggedInModel.Model -> Html -paymentsTable address model loggedInModel = - div - [ class "table" ] - ( headerLine model :: paymentLines address model loggedInModel) - -headerLine : Model -> Html -headerLine model = - div - [ class "header" ] - [ div [ class "cell category" ] [ renderIcon "shopping-cart" ] - , div [ class "cell cost" ] [ text model.conf.currency ] - , div [ class "cell user" ] [ renderIcon "user" ] - , div [ class "cell date" ] [ renderIcon "calendar" ] - , div [ class "cell" ] [] - ] - -paymentLines : Address Action -> Model -> LoggedInModel.Model -> List Html -paymentLines address model loggedInModel = - loggedInModel.payments - |> List.sortBy (Date.toTime << .creation) - |> List.reverse - |> List.drop ((loggedInModel.currentPage - 1) * perPage) - |> List.take perPage - |> List.map (paymentLine address model loggedInModel) - -paymentLine : Address Action -> Model -> LoggedInModel.Model -> Payment -> Html -paymentLine address model loggedInModel payment = - a - [ classList - [ ("row", True) - , ("edition", loggedInModel.paymentEdition == Just payment.id) - ] - , onClick address (UpdateLoggedIn (LoggedInAction.ToggleEdit payment.id)) - ] - [ div [ class "cell category" ] [ text payment.name ] - , div - [ classList - [ ("cell cost", True) - , ("refund", payment.cost < 0) - ] - ] - [ text (price model payment.cost) ] - , div - [ class "cell user" ] - [ payment.userId - |> getUserName loggedInModel.users - |> Maybe.withDefault "−" - |> text - ] - , div - [ class "cell date" ] - [ span - [ class "shortDate" ] - [ text (renderShortDate payment.creation model.translations) ] - , span - [ class "longDate" ] - [ text (renderLongDate payment.creation model.translations) ] - ] - , if loggedInModel.account.me == payment.userId - then - div - [ class "cell delete" ] - [ button - [ onClick address (UpdateLoggedIn <| LoggedInAction.DeletePayment payment Punctual)] - [ renderIcon "times" ] - ] - else - div [ class "cell" ] [] - ] |