From 0620d925b1045b17cad613a3cc5a1fbb3748c83c Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 27 Mar 2016 21:35:52 +0200 Subject: Moving some files --- src/client/elm/Action.elm | 21 ++++++ src/client/elm/LoggedIn/Account/View.elm | 2 +- src/client/elm/LoggedIn/AddPayment/View.elm | 2 +- src/client/elm/LoggedIn/Model.elm | 5 +- src/client/elm/LoggedIn/Monthly/View.elm | 2 +- src/client/elm/LoggedIn/View.elm | 6 +- src/client/elm/LoggedIn/View/Paging.elm | 100 +++++++++++++++++++++++++ src/client/elm/LoggedIn/View/Table.elm | 96 ++++++++++++++++++++++++ src/client/elm/Main.elm | 8 +- src/client/elm/Model/Action.elm | 21 ------ src/client/elm/Model/View/LoggedIn/Edition.elm | 7 -- src/client/elm/SignIn/View.elm | 2 +- src/client/elm/Update.elm | 3 +- src/client/elm/View.elm | 2 +- src/client/elm/View/Header.elm | 2 +- src/client/elm/View/Loading.elm | 2 +- src/client/elm/View/LoggedIn/Paging.elm | 100 ------------------------- src/client/elm/View/LoggedIn/Table.elm | 96 ------------------------ 18 files changed, 234 insertions(+), 243 deletions(-) create mode 100644 src/client/elm/Action.elm create mode 100644 src/client/elm/LoggedIn/View/Paging.elm create mode 100644 src/client/elm/LoggedIn/View/Table.elm delete mode 100644 src/client/elm/Model/Action.elm delete mode 100644 src/client/elm/Model/View/LoggedIn/Edition.elm delete mode 100644 src/client/elm/View/LoggedIn/Paging.elm delete mode 100644 src/client/elm/View/LoggedIn/Table.elm diff --git a/src/client/elm/Action.elm b/src/client/elm/Action.elm new file mode 100644 index 0000000..33954dc --- /dev/null +++ b/src/client/elm/Action.elm @@ -0,0 +1,21 @@ +module Action + ( Action(..) + ) where + +import Time exposing (Time) +import Signal exposing (Address) + +import Model.Init exposing (Init) + +import SignIn.Action as SignInAction +import LoggedIn.Action as LoggedInAction + +type Action = + NoOp + | SignIn String + | UpdateTime Time + | GoLoggedInView Init + | UpdateSignIn SignInAction.Action + | UpdateLoggedIn LoggedInAction.Action + | GoSignInView + | SignOut diff --git a/src/client/elm/LoggedIn/Account/View.elm b/src/client/elm/LoggedIn/Account/View.elm index deee627..d074c41 100644 --- a/src/client/elm/LoggedIn/Account/View.elm +++ b/src/client/elm/LoggedIn/Account/View.elm @@ -20,7 +20,7 @@ import Model exposing (Model) import Model.User exposing (getUserName) import Model.Payer exposing (..) import Model.Translations exposing (getParamMessage, getMessage) -import Model.Action exposing (..) +import Action exposing (..) import View.Expand exposing (..) import View.Price exposing (price) diff --git a/src/client/elm/LoggedIn/AddPayment/View.elm b/src/client/elm/LoggedIn/AddPayment/View.elm index 50f7708..90f4f02 100644 --- a/src/client/elm/LoggedIn/AddPayment/View.elm +++ b/src/client/elm/LoggedIn/AddPayment/View.elm @@ -18,7 +18,7 @@ import LoggedIn.AddPayment.Model as AddPaymentModel import Model exposing (Model) import Model.Payment exposing (PaymentFrequency(..)) import Model.Translations exposing (getMessage) -import Model.Action as Action exposing (..) +import Action as Action exposing (..) import View.Events exposing (onSubmitPrevDefault) import View.Icon exposing (..) diff --git a/src/client/elm/LoggedIn/Model.elm b/src/client/elm/LoggedIn/Model.elm index 8f0843e..a268afc 100644 --- a/src/client/elm/LoggedIn/Model.elm +++ b/src/client/elm/LoggedIn/Model.elm @@ -3,9 +3,8 @@ module LoggedIn.Model , init ) where -import Model.View.LoggedIn.Edition exposing (..) import Model.User exposing (Users, UserId) -import Model.Payment exposing (Payments, PaymentFrequency(..)) +import Model.Payment exposing (PaymentId, Payments, PaymentFrequency(..)) import Model.Payer exposing (Payers) import Model.Init exposing (..) @@ -20,7 +19,7 @@ type alias Model = , account : AccountModel.Model , payments : Payments , paymentsCount : Int - , paymentEdition : Maybe Edition + , paymentEdition : Maybe PaymentId , currentPage : Int } diff --git a/src/client/elm/LoggedIn/Monthly/View.elm b/src/client/elm/LoggedIn/Monthly/View.elm index f9ea3bf..6fc90b2 100644 --- a/src/client/elm/LoggedIn/Monthly/View.elm +++ b/src/client/elm/LoggedIn/Monthly/View.elm @@ -18,7 +18,7 @@ import LoggedIn.Monthly.Model as MonthlyModel import Model exposing (Model) import Model.Payment as Payment exposing (Payments, Payment) import Model.Translations exposing (getMessage, getParamMessage) -import Model.Action exposing (..) +import Action exposing (..) import View.Icon exposing (renderIcon) import View.Expand exposing (..) diff --git a/src/client/elm/LoggedIn/View.elm b/src/client/elm/LoggedIn/View.elm index 25624ce..c9980dc 100644 --- a/src/client/elm/LoggedIn/View.elm +++ b/src/client/elm/LoggedIn/View.elm @@ -14,10 +14,10 @@ import LoggedIn.Monthly.View as MonthlyView import Model exposing (Model) import Model.Payment exposing (Payments) -import Model.Action exposing (Action) +import Action exposing (Action) -import View.LoggedIn.Table exposing (paymentsTable) -import View.LoggedIn.Paging exposing (paymentsPaging) +import LoggedIn.View.Table exposing (paymentsTable) +import LoggedIn.View.Paging exposing (paymentsPaging) view : Address Action -> Model -> LoggedInModel.Model -> Html view address model loggedInModel = diff --git a/src/client/elm/LoggedIn/View/Paging.elm b/src/client/elm/LoggedIn/View/Paging.elm new file mode 100644 index 0000000..0a149e9 --- /dev/null +++ b/src/client/elm/LoggedIn/View/Paging.elm @@ -0,0 +1,100 @@ +module LoggedIn.View.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 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/LoggedIn/View/Table.elm b/src/client/elm/LoggedIn/View/Table.elm new file mode 100644 index 0000000..7a156af --- /dev/null +++ b/src/client/elm/LoggedIn/View/Table.elm @@ -0,0 +1,96 @@ +module LoggedIn.View.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 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" ] [] + ] diff --git a/src/client/elm/Main.elm b/src/client/elm/Main.elm index c3d5192..0ba25b7 100644 --- a/src/client/elm/Main.elm +++ b/src/client/elm/Main.elm @@ -12,15 +12,13 @@ import Json.Decode as Json import Task exposing (..) import Time exposing (..) -import Model exposing (Model, initialModel) -import Model.Action exposing (..) +import Server +import Action exposing (..) +import Model exposing (Model, initialModel) import Update exposing (update) - import View exposing (view) -import Server - import Utils.Maybe exposing (isJust) main : Signal Html diff --git a/src/client/elm/Model/Action.elm b/src/client/elm/Model/Action.elm deleted file mode 100644 index 7c99f39..0000000 --- a/src/client/elm/Model/Action.elm +++ /dev/null @@ -1,21 +0,0 @@ -module Model.Action - ( Action(..) - ) where - -import Time exposing (Time) -import Signal exposing (Address) - -import Model.Init exposing (Init) - -import SignIn.Action as SignInAction -import LoggedIn.Action as LoggedInAction - -type Action = - NoOp - | SignIn String - | UpdateTime Time - | GoLoggedInView Init - | UpdateSignIn SignInAction.Action - | UpdateLoggedIn LoggedInAction.Action - | GoSignInView - | SignOut diff --git a/src/client/elm/Model/View/LoggedIn/Edition.elm b/src/client/elm/Model/View/LoggedIn/Edition.elm deleted file mode 100644 index da6d7b0..0000000 --- a/src/client/elm/Model/View/LoggedIn/Edition.elm +++ /dev/null @@ -1,7 +0,0 @@ -module Model.View.LoggedIn.Edition - ( Edition - ) where - -import Model.Payment exposing (PaymentId) - -type alias Edition = PaymentId diff --git a/src/client/elm/SignIn/View.elm b/src/client/elm/SignIn/View.elm index 2f63651..52fcde1 100644 --- a/src/client/elm/SignIn/View.elm +++ b/src/client/elm/SignIn/View.elm @@ -14,7 +14,7 @@ import SignIn.Model as SignInModel import Update exposing (..) import Model exposing (Model) -import Model.Action exposing (..) +import Action exposing (..) import Model.Translations exposing (getMessage) import View.Events exposing (onSubmitPrevDefault) diff --git a/src/client/elm/Update.elm b/src/client/elm/Update.elm index d25b852..5cac028 100644 --- a/src/client/elm/Update.elm +++ b/src/client/elm/Update.elm @@ -8,9 +8,10 @@ import Effects exposing (Effects) import Server +import Action exposing (..) + import Model exposing (Model) import Model.Translations exposing (getMessage) -import Model.Action exposing (..) import Model.View as V import LoggedIn.Model as LoggedInModel diff --git a/src/client/elm/View.elm b/src/client/elm/View.elm index 081166d..818daf4 100644 --- a/src/client/elm/View.elm +++ b/src/client/elm/View.elm @@ -6,7 +6,7 @@ import Html exposing (..) import Signal exposing (Address) import Model exposing (Model) -import Model.Action exposing (Action) +import Action exposing (Action) import Model.View exposing (..) import View.Header exposing (renderHeader) diff --git a/src/client/elm/View/Header.elm b/src/client/elm/View/Header.elm index b49cf74..f1b0e76 100644 --- a/src/client/elm/View/Header.elm +++ b/src/client/elm/View/Header.elm @@ -11,7 +11,7 @@ import Html.Events exposing (..) import Model exposing (Model) import Model.Translations exposing (getMessage) -import Model.Action exposing (..) +import Action exposing (..) import Model.View exposing (..) import View.Icon exposing (renderIcon) diff --git a/src/client/elm/View/Loading.elm b/src/client/elm/View/Loading.elm index cfd5d0f..5270099 100644 --- a/src/client/elm/View/Loading.elm +++ b/src/client/elm/View/Loading.elm @@ -6,7 +6,7 @@ import Signal exposing (Address) import Html exposing (..) -import Model.Action exposing (Action) +import Action exposing (Action) renderLoading : Address Action -> Html renderLoading address = text "" 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" ] [] - ] -- cgit v1.2.3