From cc6a51b5ca03ee1a3b5de7c32dd1324e1053f42a Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 5 Sep 2015 14:14:25 +0200 Subject: Renaming PaymentView to LoggedView --- src/client/Main.elm | 2 +- src/client/Model/View.elm | 4 +-- src/client/Model/View/LoggedView.elm | 33 +++++++++++++++++++++++++ src/client/Model/View/PaymentView.elm | 33 ------------------------- src/client/ServerCommunication.elm | 3 ++- src/client/Update.elm | 12 ++++----- src/client/Update/Payment.elm | 26 ++++++++++---------- src/client/View/Header.elm | 2 +- src/client/View/Page.elm | 2 +- src/client/View/Payments.elm | 14 +++++------ src/client/View/Payments/Add.elm | 14 +++++------ src/client/View/Payments/ExceedingPayer.elm | 14 +++++------ src/client/View/Payments/Paging.elm | 38 ++++++++++++++--------------- src/client/View/Payments/Table.elm | 28 ++++++++++----------- 14 files changed, 113 insertions(+), 112 deletions(-) create mode 100644 src/client/Model/View/LoggedView.elm delete mode 100644 src/client/Model/View/PaymentView.elm diff --git a/src/client/Main.elm b/src/client/Main.elm index 07f8294..368d930 100644 --- a/src/client/Main.elm +++ b/src/client/Main.elm @@ -57,7 +57,7 @@ port initView = Just msg -> Signal.send actions.address (SignInError msg) Nothing -> - Task.map5 GoPaymentView getUsers whoAmI getPayments getPaymentsCount getPayers + Task.map5 GoLoggedView getUsers whoAmI getPayments getPaymentsCount getPayers |> flip Task.andThen (Signal.send actions.address) |> flip Task.onError (\_ -> Signal.send actions.address GoSignInView) diff --git a/src/client/Model/View.elm b/src/client/Model/View.elm index 7befca4..4c5fc6f 100644 --- a/src/client/Model/View.elm +++ b/src/client/Model/View.elm @@ -4,9 +4,9 @@ module Model.View import Model.Payment exposing (Payments) import Model.View.SignInView exposing (..) -import Model.View.PaymentView exposing (..) +import Model.View.LoggedView exposing (..) type View = LoadingView | SignInView SignInView - | PaymentView PaymentView + | LoggedView LoggedView diff --git a/src/client/Model/View/LoggedView.elm b/src/client/Model/View/LoggedView.elm new file mode 100644 index 0000000..35fd9e5 --- /dev/null +++ b/src/client/Model/View/LoggedView.elm @@ -0,0 +1,33 @@ +module Model.View.LoggedView + ( LoggedView + , initLoggedView + ) where + +import Model.User exposing (Users, UserId) +import Model.Payment exposing (Payments) +import Model.Payers exposing (Payers) +import Model.View.Payment.Add exposing (..) +import Model.View.Payment.Edition exposing (..) + +type alias LoggedView = + { users : Users + , me : UserId + , add : AddPayment + , payments : Payments + , paymentsCount : Int + , payers : Payers + , edition : Maybe Edition + , currentPage : Int + } + +initLoggedView : Users -> UserId -> Payments -> Int -> Payers -> LoggedView +initLoggedView users me payments paymentsCount payers = + { users = users + , me = me + , add = initAddPayment + , payments = payments + , paymentsCount = paymentsCount + , payers = payers + , edition = Nothing + , currentPage = 1 + } diff --git a/src/client/Model/View/PaymentView.elm b/src/client/Model/View/PaymentView.elm deleted file mode 100644 index 93ab457..0000000 --- a/src/client/Model/View/PaymentView.elm +++ /dev/null @@ -1,33 +0,0 @@ -module Model.View.PaymentView - ( PaymentView - , initPaymentView - ) where - -import Model.User exposing (Users, UserId) -import Model.Payment exposing (Payments) -import Model.Payers exposing (Payers) -import Model.View.Payment.Add exposing (..) -import Model.View.Payment.Edition exposing (..) - -type alias PaymentView = - { users : Users - , me : UserId - , add : AddPayment - , payments : Payments - , paymentsCount : Int - , payers : Payers - , edition : Maybe Edition - , currentPage : Int - } - -initPaymentView : Users -> UserId -> Payments -> Int -> Payers -> PaymentView -initPaymentView users me payments paymentsCount payers = - { users = users - , me = me - , add = initAddPayment - , payments = payments - , paymentsCount = paymentsCount - , payers = payers - , edition = Nothing - , currentPage = 1 - } diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm index 5ddcfb9..c38805b 100644 --- a/src/client/ServerCommunication.elm +++ b/src/client/ServerCommunication.elm @@ -35,7 +35,8 @@ sendRequest communication = Nothing -> Task.succeed U.NoOp Just request -> - (Http.send Http.defaultSettings request) `Task.andThen` (serverResult communication) + Http.send Http.defaultSettings request + |> flip Task.andThen (serverResult communication) getRequest : Communication -> Maybe Http.Request getRequest communication = diff --git a/src/client/Update.elm b/src/client/Update.elm index 910f080..d643d4e 100644 --- a/src/client/Update.elm +++ b/src/client/Update.elm @@ -12,7 +12,7 @@ import Model.Payment exposing (Payments) import Model.Payers exposing (Payers) import Model.View as V import Model.View.SignInView exposing (..) -import Model.View.PaymentView exposing (..) +import Model.View.LoggedView exposing (..) import Update.SignIn exposing (..) import Update.Payment exposing (..) @@ -23,7 +23,7 @@ type Action = | GoSignInView | SignInError String | UpdateSignIn SignInAction - | GoPaymentView Users UserId Payments Int Payers + | GoLoggedView Users UserId Payments Int Payers | UpdatePayment PaymentAction actions : Signal.Mailbox Action @@ -38,8 +38,8 @@ updateModel action model = { model | currentTime <- time } GoSignInView -> { model | view <- V.SignInView initSignInView } - GoPaymentView users me payments paymentsCount payers -> - { model | view <- V.PaymentView (initPaymentView users me payments paymentsCount payers) } + GoLoggedView users me payments paymentsCount payers -> + { model | view <- V.LoggedView (initLoggedView users me payments paymentsCount payers) } SignInError msg -> let signInView = { initSignInView | result <- Just (Err msg) } in { model | view <- V.SignInView signInView } @@ -51,7 +51,7 @@ updateModel action model = model UpdatePayment paymentAction -> case model.view of - V.PaymentView paymentView -> - { model | view <- V.PaymentView (updatePayment model paymentAction paymentView) } + V.LoggedView loggedView -> + { model | view <- V.LoggedView (updatePayment model paymentAction loggedView) } _ -> model diff --git a/src/client/Update/Payment.elm b/src/client/Update/Payment.elm index 1b43f6f..f063b4c 100644 --- a/src/client/Update/Payment.elm +++ b/src/client/Update/Payment.elm @@ -10,7 +10,7 @@ import Model exposing (Model) import Model.User exposing (UserId) import Model.Payment exposing (..) import Model.Payers exposing (..) -import Model.View.PaymentView exposing (..) +import Model.View.LoggedView exposing (..) import Model.View.Payment.Add exposing (..) import Update.Payment.Add exposing (..) @@ -23,31 +23,31 @@ type PaymentAction = | Remove UserId Int Payments | UpdatePage Int Payments -updatePayment : Model -> PaymentAction -> PaymentView -> PaymentView -updatePayment model action paymentView = +updatePayment : Model -> PaymentAction -> LoggedView -> LoggedView +updatePayment model action loggedView = case action of UpdateAdd addPaymentAction -> - { paymentView | add <- updateAddPayment addPaymentAction paymentView.add } + { loggedView | add <- updateAddPayment addPaymentAction loggedView.add } UpdatePayments payments -> - { paymentView | payments <- payments } + { loggedView | payments <- payments } AddPayment userId cost payments -> - { paymentView + { loggedView | payments <- payments , currentPage <- 1 , add <- initAddPayment - , payers <- updatePayers paymentView.payers userId cost - , paymentsCount <- paymentView.paymentsCount + 1 + , payers <- updatePayers loggedView.payers userId cost + , paymentsCount <- loggedView.paymentsCount + 1 } ToggleEdit id -> - { paymentView | edition <- if paymentView.edition == Just id then Nothing else Just id } + { loggedView | edition <- if loggedView.edition == Just id then Nothing else Just id } Remove userId cost payments -> - { paymentView + { loggedView | payments <- payments - , payers <- updatePayers paymentView.payers userId -cost - , paymentsCount <- paymentView.paymentsCount - 1 + , payers <- updatePayers loggedView.payers userId -cost + , paymentsCount <- loggedView.paymentsCount - 1 } UpdatePage page payments -> - { paymentView + { loggedView | currentPage <- page , payments <- payments } diff --git a/src/client/View/Header.elm b/src/client/View/Header.elm index 1738d71..31d8b7c 100644 --- a/src/client/View/Header.elm +++ b/src/client/View/Header.elm @@ -27,7 +27,7 @@ renderHeader model = text "" SignInView _ -> text "" - PaymentView _ -> + LoggedView _ -> button [ class "signOut" , onClick serverCommunications.address SC.SignOut diff --git a/src/client/View/Page.elm b/src/client/View/Page.elm index 7015317..199c67f 100644 --- a/src/client/View/Page.elm +++ b/src/client/View/Page.elm @@ -27,5 +27,5 @@ renderMain model = renderLoading SignInView signInView -> renderSignIn model signInView - PaymentView paymentsView -> + LoggedView paymentsView -> renderPayments model paymentsView diff --git a/src/client/View/Payments.elm b/src/client/View/Payments.elm index 256e686..b51c9a0 100644 --- a/src/client/View/Payments.elm +++ b/src/client/View/Payments.elm @@ -7,19 +7,19 @@ import Html.Attributes exposing (..) import Model exposing (Model) import Model.Payment exposing (Payments) -import Model.View.PaymentView exposing (PaymentView) +import Model.View.LoggedView exposing (LoggedView) import View.Payments.ExceedingPayer exposing (exceedingPayers) import View.Payments.Add exposing (addPayment) import View.Payments.Table exposing (paymentsTable) import View.Payments.Paging exposing (paymentsPaging) -renderPayments : Model -> PaymentView -> Html -renderPayments model paymentView = +renderPayments : Model -> LoggedView -> Html +renderPayments model loggedView = div [ class "payments" ] - [ exceedingPayers model paymentView - , addPayment model paymentView - , paymentsTable model paymentView - , paymentsPaging paymentView + [ exceedingPayers model loggedView + , addPayment model loggedView + , paymentsTable model loggedView + , paymentsPaging loggedView ] diff --git a/src/client/View/Payments/Add.elm b/src/client/View/Payments/Add.elm index 32233ed..77d40ea 100644 --- a/src/client/View/Payments/Add.elm +++ b/src/client/View/Payments/Add.elm @@ -17,7 +17,7 @@ import Update.Payment.Add exposing (..) import Model exposing (Model) import Model.View.Payment.Add exposing (..) import Model.Translations exposing (getMessage) -import Model.View.PaymentView exposing (PaymentView) +import Model.View.LoggedView exposing (LoggedView) import View.Events exposing (onSubmitPrevDefault) import View.Icon exposing (renderIcon) @@ -25,18 +25,18 @@ import View.Icon exposing (renderIcon) import Utils.Maybe exposing (isJust) import Utils.Either exposing (toMaybeError) -addPayment : Model -> PaymentView -> Html -addPayment model paymentView = +addPayment : Model -> LoggedView -> Html +addPayment model loggedView = H.form [ class "add" - , case (validateName paymentView.add.name model.translations, validateCost paymentView.add.cost model.translations) of + , case (validateName loggedView.add.name model.translations, validateCost loggedView.add.cost model.translations) of (Ok name, Ok cost) -> - onSubmitPrevDefault serverCommunications.address (SC.AddPayment paymentView.me name cost) + onSubmitPrevDefault serverCommunications.address (SC.AddPayment loggedView.me name cost) (resName, resCost) -> onSubmitPrevDefault actions.address (UpdatePayment <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost)) ] - [ addPaymentName paymentView.add - , addPaymentCost model paymentView.add + [ addPaymentName loggedView.add + , addPaymentCost model loggedView.add , button [ type' "submit" ] [ text (getMessage "Add" model.translations)] diff --git a/src/client/View/Payments/ExceedingPayer.elm b/src/client/View/Payments/ExceedingPayer.elm index f249383..88b3a72 100644 --- a/src/client/View/Payments/ExceedingPayer.elm +++ b/src/client/View/Payments/ExceedingPayer.elm @@ -9,23 +9,23 @@ import List import Model exposing (Model) import Model.User exposing (getUserName) import Model.Payers exposing (..) -import Model.View.PaymentView exposing (PaymentView) +import Model.View.LoggedView exposing (LoggedView) import Model.Translations exposing (getMessage) -exceedingPayers : Model -> PaymentView -> Html -exceedingPayers model paymentView = +exceedingPayers : Model -> LoggedView -> Html +exceedingPayers model loggedView = div [ class "exceedingPayers" ] - (List.map (exceedingPayer model paymentView) (getOrderedExceedingPayers paymentView.payers)) + (List.map (exceedingPayer model loggedView) (getOrderedExceedingPayers loggedView.payers)) -exceedingPayer : Model -> PaymentView -> ExceedingPayer -> Html -exceedingPayer model paymentView payer = +exceedingPayer : Model -> LoggedView -> ExceedingPayer -> Html +exceedingPayer model loggedView payer = div [ class "exceedingPayer" ] [ span [ class "userName" ] [ payer.userId - |> getUserName paymentView.users + |> getUserName loggedView.users |> Maybe.withDefault "−" |> text ] diff --git a/src/client/View/Payments/Paging.elm b/src/client/View/Payments/Paging.elm index c3db819..b06d749 100644 --- a/src/client/View/Payments/Paging.elm +++ b/src/client/View/Payments/Paging.elm @@ -6,7 +6,7 @@ import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) -import Model.View.PaymentView exposing (..) +import Model.View.LoggedView exposing (..) import Model.Payment exposing (perPage) import ServerCommunication as SC exposing (serverCommunications) @@ -19,23 +19,23 @@ import View.Icon exposing (renderIcon) showedPages : Int showedPages = 5 -paymentsPaging : PaymentView -> Html -paymentsPaging paymentView = - let maxPage = ceiling (toFloat paymentView.paymentsCount / toFloat perPage) - pages = truncatePages paymentView.currentPage [1..maxPage] +paymentsPaging : LoggedView -> Html +paymentsPaging loggedView = + let maxPage = ceiling (toFloat loggedView.paymentsCount / toFloat perPage) + pages = truncatePages loggedView.currentPage [1..maxPage] in if maxPage == 1 then text "" else ul [ class "pages" ] - ( ( if paymentView.currentPage > 1 - then [ firstPage, previousPage paymentView ] + ( ( if loggedView.currentPage > 1 + then [ firstPage, previousPage loggedView ] else [] ) - ++ ( List.map (paymentsPage paymentView) pages) - ++ ( if paymentView.currentPage < maxPage - then [ nextPage paymentView, lastPage maxPage ] + ++ ( List.map (paymentsPage loggedView) pages) + ++ ( if loggedView.currentPage < maxPage + then [ nextPage loggedView, lastPage maxPage ] else [] ) ) @@ -62,19 +62,19 @@ firstPage = ] [ renderIcon "fast-backward" ] -previousPage : PaymentView -> Html -previousPage paymentView = +previousPage : LoggedView -> Html +previousPage loggedView = li [ class "page" - , onClick serverCommunications.address (SC.UpdatePage (paymentView.currentPage - 1)) + , onClick serverCommunications.address (SC.UpdatePage (loggedView.currentPage - 1)) ] [ renderIcon "backward" ] -nextPage : PaymentView -> Html -nextPage paymentView = +nextPage : LoggedView -> Html +nextPage loggedView = li [ class "page" - , onClick serverCommunications.address (SC.UpdatePage (paymentView.currentPage + 1)) + , onClick serverCommunications.address (SC.UpdatePage (loggedView.currentPage + 1)) ] [ renderIcon "forward" ] @@ -86,9 +86,9 @@ lastPage maxPage = ] [ renderIcon "fast-forward" ] -paymentsPage : PaymentView -> Int -> Html -paymentsPage paymentView page = - let onCurrentPage = page == paymentView.currentPage +paymentsPage : LoggedView -> Int -> Html +paymentsPage loggedView page = + let onCurrentPage = page == loggedView.currentPage in li [ class ("page" ++ (if onCurrentPage then " current" else "")) , onClick serverCommunications.address <| diff --git a/src/client/View/Payments/Table.elm b/src/client/View/Payments/Table.elm index 743a8a9..5374c44 100644 --- a/src/client/View/Payments/Table.elm +++ b/src/client/View/Payments/Table.elm @@ -15,7 +15,7 @@ import String exposing (append) import Model exposing (Model) import Model.User exposing (getUserName) import Model.Payment exposing (..) -import Model.View.PaymentView exposing (PaymentView) +import Model.View.LoggedView exposing (LoggedView) import Model.Translations exposing (getMessage) import ServerCommunication as SC exposing (serverCommunications) @@ -26,8 +26,8 @@ import Update.Payment exposing (..) import View.Icon exposing (renderIcon) import View.Date exposing (..) -paymentsTable : Model -> PaymentView -> Html -paymentsTable model paymentView = +paymentsTable : Model -> LoggedView -> Html +paymentsTable model loggedView = div [ class "table" ] ([ div @@ -38,20 +38,20 @@ paymentsTable model paymentView = , div [ class "cell date" ] [ renderIcon "calendar" ] , div [ class "cell" ] [] ] - ] ++ (paymentLines model paymentView)) + ] ++ (paymentLines model loggedView)) -paymentLines : Model -> PaymentView -> List Html -paymentLines model paymentView = - paymentView.payments +paymentLines : Model -> LoggedView -> List Html +paymentLines model loggedView = + loggedView.payments |> Dict.toList |> List.sortBy (\(_, payment) -> Date.toTime payment.creation) |> List.reverse - |> List.map (paymentLine model paymentView) + |> List.map (paymentLine model loggedView) -paymentLine : Model -> PaymentView -> PaymentWithId -> Html -paymentLine model paymentView (id, payment) = +paymentLine : Model -> LoggedView -> PaymentWithId -> Html +paymentLine model loggedView (id, payment) = a - [ class ("row " ++ (if paymentView.edition == Just id then "edition" else "")) + [ class ("row " ++ (if loggedView.edition == Just id then "edition" else "")) , onClick actions.address (UpdatePayment (ToggleEdit id)) ] [ div [ class "cell category" ] [ text payment.name ] @@ -59,7 +59,7 @@ paymentLine model paymentView (id, payment) = , div [ class "cell user" ] [ payment.userId - |> getUserName paymentView.users + |> getUserName loggedView.users |> Maybe.withDefault "−" |> text ] @@ -72,11 +72,11 @@ paymentLine model paymentView (id, payment) = [ class "longDate" ] [ text (renderLongDate payment.creation model.translations) ] ] - , if paymentView.me == payment.userId + , if loggedView.me == payment.userId then div [ class "cell remove" - , onClick serverCommunications.address (SC.DeletePayment id payment.userId payment.cost paymentView.currentPage) + , onClick serverCommunications.address (SC.DeletePayment id payment.userId payment.cost loggedView.currentPage) ] [ renderIcon "times" ] else -- cgit v1.2.3