From 3853811450d4fe801da996eb48825049c3541030 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 6 Sep 2015 16:46:59 +0200 Subject: Renaming PaymentView to LoggedInView --- src/client/Main.elm | 2 +- src/client/Model/View.elm | 4 +- src/client/Model/View/LoggedIn/Add.elm | 43 ++++++++++++ src/client/Model/View/LoggedIn/Edition.elm | 7 ++ src/client/Model/View/LoggedIn/Monthly.elm | 17 +++++ src/client/Model/View/LoggedInView.elm | 36 ++++++++++ src/client/Model/View/LoggedView.elm | 36 ---------- src/client/Model/View/Payment/Add.elm | 43 ------------ src/client/Model/View/Payment/Edition.elm | 7 -- src/client/Model/View/Payment/Monthly.elm | 17 ----- src/client/ServerCommunication.elm | 16 ++--- src/client/Update.elm | 18 ++--- src/client/Update/LoggedIn.elm | 65 +++++++++++++++++ src/client/Update/LoggedIn/Add.elm | 29 ++++++++ src/client/Update/LoggedIn/Monthly.elm | 27 +++++++ src/client/Update/LoggedView.elm | 65 ----------------- src/client/Update/LoggedView/Add.elm | 29 -------- src/client/Update/LoggedView/Monthly.elm | 27 ------- src/client/View/Header.elm | 2 +- src/client/View/LoggedIn.elm | 27 +++++++ src/client/View/LoggedIn/Add.elm | 105 ++++++++++++++++++++++++++++ src/client/View/LoggedIn/ExceedingPayer.elm | 35 ++++++++++ src/client/View/LoggedIn/Monthly.elm | 72 +++++++++++++++++++ src/client/View/LoggedIn/Paging.elm | 97 +++++++++++++++++++++++++ src/client/View/LoggedIn/Table.elm | 86 +++++++++++++++++++++++ src/client/View/Page.elm | 6 +- src/client/View/Payments.elm | 27 ------- src/client/View/Payments/Add.elm | 105 ---------------------------- src/client/View/Payments/ExceedingPayer.elm | 35 ---------- src/client/View/Payments/Monthly.elm | 72 ------------------- src/client/View/Payments/Paging.elm | 97 ------------------------- src/client/View/Payments/Table.elm | 86 ----------------------- 32 files changed, 670 insertions(+), 670 deletions(-) create mode 100644 src/client/Model/View/LoggedIn/Add.elm create mode 100644 src/client/Model/View/LoggedIn/Edition.elm create mode 100644 src/client/Model/View/LoggedIn/Monthly.elm create mode 100644 src/client/Model/View/LoggedInView.elm delete mode 100644 src/client/Model/View/LoggedView.elm delete mode 100644 src/client/Model/View/Payment/Add.elm delete mode 100644 src/client/Model/View/Payment/Edition.elm delete mode 100644 src/client/Model/View/Payment/Monthly.elm create mode 100644 src/client/Update/LoggedIn.elm create mode 100644 src/client/Update/LoggedIn/Add.elm create mode 100644 src/client/Update/LoggedIn/Monthly.elm delete mode 100644 src/client/Update/LoggedView.elm delete mode 100644 src/client/Update/LoggedView/Add.elm delete mode 100644 src/client/Update/LoggedView/Monthly.elm create mode 100644 src/client/View/LoggedIn.elm create mode 100644 src/client/View/LoggedIn/Add.elm create mode 100644 src/client/View/LoggedIn/ExceedingPayer.elm create mode 100644 src/client/View/LoggedIn/Monthly.elm create mode 100644 src/client/View/LoggedIn/Paging.elm create mode 100644 src/client/View/LoggedIn/Table.elm delete mode 100644 src/client/View/Payments.elm delete mode 100644 src/client/View/Payments/Add.elm delete mode 100644 src/client/View/Payments/ExceedingPayer.elm delete mode 100644 src/client/View/Payments/Monthly.elm delete mode 100644 src/client/View/Payments/Paging.elm delete mode 100644 src/client/View/Payments/Table.elm (limited to 'src') diff --git a/src/client/Main.elm b/src/client/Main.elm index 3174ba6..c2ba408 100644 --- a/src/client/Main.elm +++ b/src/client/Main.elm @@ -63,7 +63,7 @@ port initView = Task.andThen getPayments <| \payments -> Task.andThen getPaymentsCount <| \paymentsCount -> Task.andThen getPayers <| \payers -> - Signal.send actions.address (GoLoggedView users me monthlyPayments payments paymentsCount payers) + Signal.send actions.address (GoLoggedInView users me monthlyPayments payments paymentsCount payers) |> flip Task.onError (\_ -> Signal.send actions.address GoSignInView) getUsers : Task Http.Error Users diff --git a/src/client/Model/View.elm b/src/client/Model/View.elm index 4c5fc6f..90c0e53 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.LoggedView exposing (..) +import Model.View.LoggedInView exposing (..) type View = LoadingView | SignInView SignInView - | LoggedView LoggedView + | LoggedInView LoggedInView diff --git a/src/client/Model/View/LoggedIn/Add.elm b/src/client/Model/View/LoggedIn/Add.elm new file mode 100644 index 0000000..abd8a4d --- /dev/null +++ b/src/client/Model/View/LoggedIn/Add.elm @@ -0,0 +1,43 @@ +module Model.View.LoggedIn.Add + ( AddPayment + , Frequency(..) + , initAddPayment + , validateName + , validateCost + ) where + +import Result as Result exposing (Result(..)) + +import Utils.Validation exposing (..) + +import Model.Translations exposing (..) + +type alias AddPayment = + { name : String + , nameError : Maybe String + , cost : String + , costError : Maybe String + , frequency : Frequency + } + +initAddPayment : Frequency -> AddPayment +initAddPayment frequency = + { name = "" + , nameError = Nothing + , cost = "" + , costError = Nothing + , frequency = frequency + } + +validateName : String -> Translations -> Result String String +validateName name translations = + name + |> validateNonEmpty (getMessage "CategoryRequired" translations) + +validateCost : String -> Translations -> Result String Int +validateCost cost translations = + cost + |> validateNonEmpty (getMessage "CostRequired" translations) + |> flip Result.andThen (validateNumber (getMessage "CostMustBeNumber" translations) (\number -> number >= 0)) + +type Frequency = Punctual | Monthly diff --git a/src/client/Model/View/LoggedIn/Edition.elm b/src/client/Model/View/LoggedIn/Edition.elm new file mode 100644 index 0000000..da6d7b0 --- /dev/null +++ b/src/client/Model/View/LoggedIn/Edition.elm @@ -0,0 +1,7 @@ +module Model.View.LoggedIn.Edition + ( Edition + ) where + +import Model.Payment exposing (PaymentId) + +type alias Edition = PaymentId diff --git a/src/client/Model/View/LoggedIn/Monthly.elm b/src/client/Model/View/LoggedIn/Monthly.elm new file mode 100644 index 0000000..3c6f66a --- /dev/null +++ b/src/client/Model/View/LoggedIn/Monthly.elm @@ -0,0 +1,17 @@ +module Model.View.LoggedIn.Monthly + ( Monthly + , initMonthly + ) where + +import Model.Payment exposing (Payments) + +type alias Monthly = + { payments : Payments + , visibleDetail : Bool + } + +initMonthly : Payments -> Monthly +initMonthly payments = + { payments = payments + , visibleDetail = False + } diff --git a/src/client/Model/View/LoggedInView.elm b/src/client/Model/View/LoggedInView.elm new file mode 100644 index 0000000..cf7f552 --- /dev/null +++ b/src/client/Model/View/LoggedInView.elm @@ -0,0 +1,36 @@ +module Model.View.LoggedInView + ( LoggedInView + , initLoggedInView + ) where + +import Model.User exposing (Users, UserId) +import Model.Payment exposing (Payments) +import Model.Payers exposing (Payers) +import Model.View.LoggedIn.Add exposing (..) +import Model.View.LoggedIn.Edition exposing (..) +import Model.View.LoggedIn.Monthly exposing (..) + +type alias LoggedInView = + { users : Users + , me : UserId + , add : AddPayment + , monthly : Monthly + , payments : Payments + , paymentsCount : Int + , payers : Payers + , paymentEdition : Maybe Edition + , currentPage : Int + } + +initLoggedInView : Users -> UserId -> Payments -> Payments -> Int -> Payers -> LoggedInView +initLoggedInView users me monthlyPayments payments paymentsCount payers = + { users = users + , me = me + , add = initAddPayment Punctual + , monthly = initMonthly monthlyPayments + , payments = payments + , paymentsCount = paymentsCount + , payers = payers + , paymentEdition = Nothing + , currentPage = 1 + } diff --git a/src/client/Model/View/LoggedView.elm b/src/client/Model/View/LoggedView.elm deleted file mode 100644 index 264fdf5..0000000 --- a/src/client/Model/View/LoggedView.elm +++ /dev/null @@ -1,36 +0,0 @@ -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 (..) -import Model.View.Payment.Monthly exposing (..) - -type alias LoggedView = - { users : Users - , me : UserId - , add : AddPayment - , monthly : Monthly - , payments : Payments - , paymentsCount : Int - , payers : Payers - , paymentEdition : Maybe Edition - , currentPage : Int - } - -initLoggedView : Users -> UserId -> Payments -> Payments -> Int -> Payers -> LoggedView -initLoggedView users me monthlyPayments payments paymentsCount payers = - { users = users - , me = me - , add = initAddPayment Punctual - , monthly = initMonthly monthlyPayments - , payments = payments - , paymentsCount = paymentsCount - , payers = payers - , paymentEdition = Nothing - , currentPage = 1 - } diff --git a/src/client/Model/View/Payment/Add.elm b/src/client/Model/View/Payment/Add.elm deleted file mode 100644 index dc00e86..0000000 --- a/src/client/Model/View/Payment/Add.elm +++ /dev/null @@ -1,43 +0,0 @@ -module Model.View.Payment.Add - ( AddPayment - , Frequency(..) - , initAddPayment - , validateName - , validateCost - ) where - -import Result as Result exposing (Result(..)) - -import Utils.Validation exposing (..) - -import Model.Translations exposing (..) - -type alias AddPayment = - { name : String - , nameError : Maybe String - , cost : String - , costError : Maybe String - , frequency : Frequency - } - -initAddPayment : Frequency -> AddPayment -initAddPayment frequency = - { name = "" - , nameError = Nothing - , cost = "" - , costError = Nothing - , frequency = frequency - } - -validateName : String -> Translations -> Result String String -validateName name translations = - name - |> validateNonEmpty (getMessage "CategoryRequired" translations) - -validateCost : String -> Translations -> Result String Int -validateCost cost translations = - cost - |> validateNonEmpty (getMessage "CostRequired" translations) - |> flip Result.andThen (validateNumber (getMessage "CostMustBeNumber" translations) (\number -> number >= 0)) - -type Frequency = Punctual | Monthly diff --git a/src/client/Model/View/Payment/Edition.elm b/src/client/Model/View/Payment/Edition.elm deleted file mode 100644 index f58ce43..0000000 --- a/src/client/Model/View/Payment/Edition.elm +++ /dev/null @@ -1,7 +0,0 @@ -module Model.View.Payment.Edition - ( Edition - ) where - -import Model.Payment exposing (PaymentId) - -type alias Edition = PaymentId diff --git a/src/client/Model/View/Payment/Monthly.elm b/src/client/Model/View/Payment/Monthly.elm deleted file mode 100644 index 15a5f2e..0000000 --- a/src/client/Model/View/Payment/Monthly.elm +++ /dev/null @@ -1,17 +0,0 @@ -module Model.View.Payment.Monthly - ( Monthly - , initMonthly - ) where - -import Model.Payment exposing (Payments) - -type alias Monthly = - { payments : Payments - , visibleDetail : Bool - } - -initMonthly : Payments -> Monthly -initMonthly payments = - { payments = payments - , visibleDetail = False - } diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm index 20e2b14..6d65552 100644 --- a/src/client/ServerCommunication.elm +++ b/src/client/ServerCommunication.elm @@ -13,12 +13,12 @@ import Date import Model.Message exposing (messageDecoder) import Model.User exposing (UserId) import Model.Payment exposing (..) -import Model.View.Payment.Add exposing (Frequency(..)) +import Model.View.LoggedIn.Add exposing (Frequency(..)) import Update as U import Update.SignIn exposing (..) -import Update.LoggedView as UL -import Update.LoggedView.Monthly as UM +import Update.LoggedIn as UL +import Update.LoggedIn.Monthly as UM type Communication = NoCommunication @@ -86,24 +86,24 @@ serverResult communication response = AddPayment userId name cost -> Http.send Http.defaultSettings (updatePageRequest 1) |> flip Task.andThen (decodeOkResponse paymentsDecoder (\payments -> - Task.succeed <| U.UpdateLoggedView (UL.AddPayment userId name cost payments) + Task.succeed <| U.UpdateLoggedIn (UL.AddPayment userId name cost payments) )) AddMonthlyPayment name cost -> decodeOkResponse ("id" := paymentIdDecoder) - (\id -> Task.succeed <| U.UpdateLoggedView (UL.AddMonthlyPayment id name cost)) + (\id -> Task.succeed <| U.UpdateLoggedIn (UL.AddMonthlyPayment id name cost)) response DeletePayment id userId cost currentPage -> Http.send Http.defaultSettings (updatePageRequest currentPage) |> flip Task.andThen (decodeOkResponse paymentsDecoder (\payments -> - Task.succeed <| U.UpdateLoggedView (UL.DeletePayment userId cost payments) + Task.succeed <| U.UpdateLoggedIn (UL.DeletePayment userId cost payments) )) DeleteMonthlyPayment id -> - Task.succeed <| U.UpdateLoggedView (UL.UpdateMonthly (UM.DeletePayment id)) + Task.succeed <| U.UpdateLoggedIn (UL.UpdateMonthly (UM.DeletePayment id)) UpdatePage page -> decodeOkResponse paymentsDecoder - (\payments -> Task.succeed <| U.UpdateLoggedView (UL.UpdatePage page payments)) + (\payments -> Task.succeed <| U.UpdateLoggedIn (UL.UpdatePage page payments)) response SignOut -> Task.succeed (U.GoSignInView) diff --git a/src/client/Update.elm b/src/client/Update.elm index 6ee5ab6..23e5c84 100644 --- a/src/client/Update.elm +++ b/src/client/Update.elm @@ -12,10 +12,10 @@ import Model.Payment exposing (Payments) import Model.Payers exposing (Payers) import Model.View as V import Model.View.SignInView exposing (..) -import Model.View.LoggedView exposing (..) +import Model.View.LoggedInView exposing (..) import Update.SignIn exposing (..) -import Update.LoggedView exposing (..) +import Update.LoggedIn exposing (..) type Action = NoOp @@ -23,8 +23,8 @@ type Action = | GoSignInView | SignInError String | UpdateSignIn SignInAction - | GoLoggedView Users UserId Payments Payments Int Payers - | UpdateLoggedView LoggedAction + | GoLoggedInView Users UserId Payments Payments Int Payers + | UpdateLoggedIn LoggedAction actions : Signal.Mailbox Action actions = Signal.mailbox NoOp @@ -38,8 +38,8 @@ updateModel action model = { model | currentTime <- time } GoSignInView -> { model | view <- V.SignInView initSignInView } - GoLoggedView users me monthlyPayments payments paymentsCount payers -> - { model | view <- V.LoggedView (initLoggedView users me monthlyPayments payments paymentsCount payers) } + GoLoggedInView users me monthlyPayments payments paymentsCount payers -> + { model | view <- V.LoggedInView (initLoggedInView users me monthlyPayments payments paymentsCount payers) } SignInError msg -> let signInView = { initSignInView | result <- Just (Err msg) } in { model | view <- V.SignInView signInView } @@ -49,9 +49,9 @@ updateModel action model = { model | view <- V.SignInView (updateSignIn signInAction signInView) } _ -> model - UpdateLoggedView loggedAction -> + UpdateLoggedIn loggedAction -> case model.view of - V.LoggedView loggedView -> - { model | view <- V.LoggedView (updateLoggedView model loggedAction loggedView) } + V.LoggedInView loggedInView -> + { model | view <- V.LoggedInView (updateLoggedIn model loggedAction loggedInView) } _ -> model diff --git a/src/client/Update/LoggedIn.elm b/src/client/Update/LoggedIn.elm new file mode 100644 index 0000000..03eb137 --- /dev/null +++ b/src/client/Update/LoggedIn.elm @@ -0,0 +1,65 @@ +module Update.LoggedIn + ( LoggedAction(..) + , updateLoggedIn + ) where + +import Date +import Dict + +import Model exposing (Model) +import Model.User exposing (UserId) +import Model.Payment exposing (..) +import Model.Payers exposing (..) +import Model.View.LoggedInView exposing (..) +import Model.View.LoggedIn.Add exposing (..) + +import Update.LoggedIn.Add exposing (..) +import Update.LoggedIn.Monthly as UM + +type LoggedAction = + UpdateAdd AddPaymentAction + | UpdatePayments Payments + | AddPayment UserId String Int Payments + | AddMonthlyPayment PaymentId String Int + | ToggleEdit PaymentId + | DeletePayment UserId Int Payments + | UpdatePage Int Payments + | UpdateMonthly UM.MonthlyAction + +updateLoggedIn : Model -> LoggedAction -> LoggedInView -> LoggedInView +updateLoggedIn model action loggedInView = + case action of + UpdateAdd addPaymentAction -> + { loggedInView | add <- updateAddPayment addPaymentAction loggedInView.add } + UpdatePayments payments -> + { loggedInView | payments <- payments } + AddPayment userId name cost payments -> + { loggedInView + | payments <- payments + , currentPage <- 1 + , add <- initAddPayment Punctual + , payers <- updatePayers loggedInView.payers userId cost + , paymentsCount <- loggedInView.paymentsCount + 1 + } + AddMonthlyPayment id name cost -> + { loggedInView + | add <- initAddPayment Monthly + , monthly <- + let payment = Payment id (Date.fromTime model.currentTime) name cost loggedInView.me + in UM.updateMonthly (UM.AddPayment payment) loggedInView.monthly + } + ToggleEdit id -> + { loggedInView | paymentEdition <- if loggedInView.paymentEdition == Just id then Nothing else Just id } + DeletePayment userId cost payments -> + { loggedInView + | payments <- payments + , payers <- updatePayers loggedInView.payers userId -cost + , paymentsCount <- loggedInView.paymentsCount - 1 + } + UpdatePage page payments -> + { loggedInView + | currentPage <- page + , payments <- payments + } + UpdateMonthly monthlyAction -> + { loggedInView | monthly <- UM.updateMonthly monthlyAction loggedInView.monthly } diff --git a/src/client/Update/LoggedIn/Add.elm b/src/client/Update/LoggedIn/Add.elm new file mode 100644 index 0000000..1f28997 --- /dev/null +++ b/src/client/Update/LoggedIn/Add.elm @@ -0,0 +1,29 @@ +module Update.LoggedIn.Add + ( AddPaymentAction(..) + , updateAddPayment + ) where + +import Model.View.LoggedIn.Add exposing (..) + +type AddPaymentAction = + UpdateName String + | UpdateCost String + | AddError (Maybe String) (Maybe String) + | ToggleFrequency + +updateAddPayment : AddPaymentAction -> AddPayment -> AddPayment +updateAddPayment action addPayment = + case action of + UpdateName name -> + { addPayment | name <- name } + UpdateCost cost -> + { addPayment | cost <- cost } + AddError nameError costError -> + { addPayment + | nameError <- nameError + , costError <- costError + } + ToggleFrequency -> + { addPayment + | frequency <- if addPayment.frequency == Punctual then Monthly else Punctual + } diff --git a/src/client/Update/LoggedIn/Monthly.elm b/src/client/Update/LoggedIn/Monthly.elm new file mode 100644 index 0000000..1379323 --- /dev/null +++ b/src/client/Update/LoggedIn/Monthly.elm @@ -0,0 +1,27 @@ +module Update.LoggedIn.Monthly + ( MonthlyAction(..) + , updateMonthly + ) where + +import Model.Payment exposing (Payment, PaymentId) +import Model.View.LoggedIn.Monthly exposing (..) + +type MonthlyAction = + ToggleDetail + | AddPayment Payment + | DeletePayment PaymentId + +updateMonthly : MonthlyAction -> Monthly -> Monthly +updateMonthly action monthly = + case action of + ToggleDetail -> + { monthly | visibleDetail <- not monthly.visibleDetail } + AddPayment payment -> + { monthly + | payments <- payment :: monthly.payments + , visibleDetail <- True + } + DeletePayment id -> + { monthly + | payments <- List.filter (\payment -> payment.id /= id) monthly.payments + } diff --git a/src/client/Update/LoggedView.elm b/src/client/Update/LoggedView.elm deleted file mode 100644 index cf6bcb2..0000000 --- a/src/client/Update/LoggedView.elm +++ /dev/null @@ -1,65 +0,0 @@ -module Update.LoggedView - ( LoggedAction(..) - , updateLoggedView - ) where - -import Date -import Dict - -import Model exposing (Model) -import Model.User exposing (UserId) -import Model.Payment exposing (..) -import Model.Payers exposing (..) -import Model.View.LoggedView exposing (..) -import Model.View.Payment.Add exposing (..) - -import Update.LoggedView.Add exposing (..) -import Update.LoggedView.Monthly as UM - -type LoggedAction = - UpdateAdd AddPaymentAction - | UpdatePayments Payments - | AddPayment UserId String Int Payments - | AddMonthlyPayment PaymentId String Int - | ToggleEdit PaymentId - | DeletePayment UserId Int Payments - | UpdatePage Int Payments - | UpdateMonthly UM.MonthlyAction - -updateLoggedView : Model -> LoggedAction -> LoggedView -> LoggedView -updateLoggedView model action loggedView = - case action of - UpdateAdd addPaymentAction -> - { loggedView | add <- updateAddPayment addPaymentAction loggedView.add } - UpdatePayments payments -> - { loggedView | payments <- payments } - AddPayment userId name cost payments -> - { loggedView - | payments <- payments - , currentPage <- 1 - , add <- initAddPayment Punctual - , payers <- updatePayers loggedView.payers userId cost - , paymentsCount <- loggedView.paymentsCount + 1 - } - AddMonthlyPayment id name cost -> - { loggedView - | add <- initAddPayment Monthly - , monthly <- - let payment = Payment id (Date.fromTime model.currentTime) name cost loggedView.me - in UM.updateMonthly (UM.AddPayment payment) loggedView.monthly - } - ToggleEdit id -> - { loggedView | paymentEdition <- if loggedView.paymentEdition == Just id then Nothing else Just id } - DeletePayment userId cost payments -> - { loggedView - | payments <- payments - , payers <- updatePayers loggedView.payers userId -cost - , paymentsCount <- loggedView.paymentsCount - 1 - } - UpdatePage page payments -> - { loggedView - | currentPage <- page - , payments <- payments - } - UpdateMonthly monthlyAction -> - { loggedView | monthly <- UM.updateMonthly monthlyAction loggedView.monthly } diff --git a/src/client/Update/LoggedView/Add.elm b/src/client/Update/LoggedView/Add.elm deleted file mode 100644 index 05c2c30..0000000 --- a/src/client/Update/LoggedView/Add.elm +++ /dev/null @@ -1,29 +0,0 @@ -module Update.LoggedView.Add - ( AddPaymentAction(..) - , updateAddPayment - ) where - -import Model.View.Payment.Add exposing (..) - -type AddPaymentAction = - UpdateName String - | UpdateCost String - | AddError (Maybe String) (Maybe String) - | ToggleFrequency - -updateAddPayment : AddPaymentAction -> AddPayment -> AddPayment -updateAddPayment action addPayment = - case action of - UpdateName name -> - { addPayment | name <- name } - UpdateCost cost -> - { addPayment | cost <- cost } - AddError nameError costError -> - { addPayment - | nameError <- nameError - , costError <- costError - } - ToggleFrequency -> - { addPayment - | frequency <- if addPayment.frequency == Punctual then Monthly else Punctual - } diff --git a/src/client/Update/LoggedView/Monthly.elm b/src/client/Update/LoggedView/Monthly.elm deleted file mode 100644 index 567025f..0000000 --- a/src/client/Update/LoggedView/Monthly.elm +++ /dev/null @@ -1,27 +0,0 @@ -module Update.LoggedView.Monthly - ( MonthlyAction(..) - , updateMonthly - ) where - -import Model.Payment exposing (Payment, PaymentId) -import Model.View.Payment.Monthly exposing (..) - -type MonthlyAction = - ToggleDetail - | AddPayment Payment - | DeletePayment PaymentId - -updateMonthly : MonthlyAction -> Monthly -> Monthly -updateMonthly action monthly = - case action of - ToggleDetail -> - { monthly | visibleDetail <- not monthly.visibleDetail } - AddPayment payment -> - { monthly - | payments <- payment :: monthly.payments - , visibleDetail <- True - } - DeletePayment id -> - { monthly - | payments <- List.filter (\payment -> payment.id /= id) monthly.payments - } diff --git a/src/client/View/Header.elm b/src/client/View/Header.elm index 31d8b7c..9d31183 100644 --- a/src/client/View/Header.elm +++ b/src/client/View/Header.elm @@ -27,7 +27,7 @@ renderHeader model = text "" SignInView _ -> text "" - LoggedView _ -> + LoggedInView _ -> button [ class "signOut" , onClick serverCommunications.address SC.SignOut diff --git a/src/client/View/LoggedIn.elm b/src/client/View/LoggedIn.elm new file mode 100644 index 0000000..57a8eb0 --- /dev/null +++ b/src/client/View/LoggedIn.elm @@ -0,0 +1,27 @@ +module View.LoggedIn + ( renderLoggedIn + ) where + +import Html exposing (..) +import Html.Attributes exposing (..) + +import Model exposing (Model) +import Model.Payment exposing (Payments) +import Model.View.LoggedInView exposing (LoggedInView) + +import View.LoggedIn.ExceedingPayer exposing (exceedingPayers) +import View.LoggedIn.Add exposing (addPayment) +import View.LoggedIn.Monthly exposing (monthlyPayments) +import View.LoggedIn.Table exposing (paymentsTable) +import View.LoggedIn.Paging exposing (paymentsPaging) + +renderLoggedIn : Model -> LoggedInView -> Html +renderLoggedIn model loggedInView = + div + [ class "payments" ] + [ exceedingPayers model loggedInView + , addPayment model loggedInView + , monthlyPayments model loggedInView + , paymentsTable model loggedInView + , paymentsPaging loggedInView + ] diff --git a/src/client/View/LoggedIn/Add.elm b/src/client/View/LoggedIn/Add.elm new file mode 100644 index 0000000..acdda2d --- /dev/null +++ b/src/client/View/LoggedIn/Add.elm @@ -0,0 +1,105 @@ +module View.LoggedIn.Add + ( addPayment + ) where + +import Html as H exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) +import Reads exposing (readInt) +import Result exposing (..) + +import ServerCommunication as SC exposing (serverCommunications) + +import Update exposing (..) +import Update.LoggedIn exposing (..) +import Update.LoggedIn.Add exposing (..) + +import Model exposing (Model) +import Model.View.LoggedIn.Add exposing (..) +import Model.Translations exposing (getMessage) +import Model.View.LoggedInView exposing (LoggedInView) + +import View.Events exposing (onSubmitPrevDefault) +import View.Icon exposing (renderIcon) + +import Utils.Maybe exposing (isJust) +import Utils.Either exposing (toMaybeError) + +addPayment : Model -> LoggedInView -> Html +addPayment model loggedInView = + H.form + [ case (validateName loggedInView.add.name model.translations, validateCost loggedInView.add.cost model.translations) of + (Ok name, Ok cost) -> + let action = + case loggedInView.add.frequency of + Punctual -> SC.AddPayment loggedInView.me name cost + Monthly -> SC.AddMonthlyPayment name cost + in onSubmitPrevDefault serverCommunications.address action + (resName, resCost) -> + onSubmitPrevDefault actions.address (UpdateLoggedIn <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost)) + ] + [ addPaymentName loggedInView.add + , addPaymentCost model loggedInView.add + , paymentFrequency model loggedInView.add + , button + [ type' "submit" + , class "add" ] + [ text (getMessage "Add" model.translations)] + ] + +addPaymentName : AddPayment -> Html +addPaymentName addPayment = + div + [ class ("name " ++ (if isJust addPayment.nameError then "error" else "")) ] + [ input + [ id "nameInput" + , value addPayment.name + , on "input" targetValue (Signal.message actions.address << UpdateLoggedIn << UpdateAdd << UpdateName) + , maxlength 20 + ] + [] + , label + [ for "nameInput" ] + [ renderIcon "shopping-cart" ] + , case addPayment.nameError of + Just error -> + div [ class "errorMessage" ] [ text error ] + Nothing -> + text "" + ] + +addPaymentCost : Model -> AddPayment -> Html +addPaymentCost model addPayment = + div + [ class ("cost " ++ (if isJust addPayment.costError then "error" else "")) ] + [ input + [ id "costInput" + , value addPayment.cost + , on "input" targetValue (Signal.message actions.address << UpdateLoggedIn << UpdateAdd << UpdateCost) + , maxlength 7 + ] + [] + , label + [ for "costInput" ] + [ text (getMessage "MoneySymbol" model.translations) ] + , case addPayment.costError of + Just error -> + div [ class "errorMessage" ] [ text error ] + Nothing -> + text "" + ] + +paymentFrequency : Model -> AddPayment -> Html +paymentFrequency model addPayment = + button + [ type' "button" + , class "frequency" + , onClick actions.address (UpdateLoggedIn << UpdateAdd <| ToggleFrequency) + ] + [ div + [ class ("punctual" ++ if addPayment.frequency == Punctual then " selected" else "") ] + [ text (getMessage "Punctual" model.translations) ] + , div + [ class ("monthly" ++ if addPayment.frequency == Monthly then " selected" else "") ] + [ text (getMessage "Monthly" model.translations) ] + ] diff --git a/src/client/View/LoggedIn/ExceedingPayer.elm b/src/client/View/LoggedIn/ExceedingPayer.elm new file mode 100644 index 0000000..ea848b6 --- /dev/null +++ b/src/client/View/LoggedIn/ExceedingPayer.elm @@ -0,0 +1,35 @@ +module View.LoggedIn.ExceedingPayer + ( exceedingPayers + ) where + +import Html exposing (..) +import Html.Attributes exposing (..) +import List + +import Model exposing (Model) +import Model.User exposing (getUserName) +import Model.Payers exposing (..) +import Model.View.LoggedInView exposing (LoggedInView) +import Model.Translations exposing (getMessage) + +exceedingPayers : Model -> LoggedInView -> Html +exceedingPayers model loggedInView = + div + [ class "exceedingPayers" ] + (List.map (exceedingPayer model loggedInView) (getOrderedExceedingPayers loggedInView.payers)) + +exceedingPayer : Model -> LoggedInView -> ExceedingPayer -> Html +exceedingPayer model loggedInView payer = + div + [ class "exceedingPayer" ] + [ span + [ class "userName" ] + [ payer.userId + |> getUserName loggedInView.users + |> Maybe.withDefault "−" + |> text + ] + , span + [ class "amount" ] + [ text ("+ " ++ (toString payer.amount) ++ " " ++ (getMessage "MoneySymbol" model.translations)) ] + ] diff --git a/src/client/View/LoggedIn/Monthly.elm b/src/client/View/LoggedIn/Monthly.elm new file mode 100644 index 0000000..14c3de7 --- /dev/null +++ b/src/client/View/LoggedIn/Monthly.elm @@ -0,0 +1,72 @@ +module View.LoggedIn.Monthly + ( monthlyPayments + ) where + +import Html exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) + +import Update exposing (..) +import Update.LoggedIn exposing (..) +import Update.LoggedIn.Monthly exposing (..) + +import Model exposing (Model) +import Model.View.LoggedIn.Monthly exposing (Monthly) +import Model.Payment exposing (Payments, Payment) +import Model.View.LoggedInView exposing (LoggedInView) +import Model.Translations exposing (getMessage, getParamMessage) + +import ServerCommunication as SC exposing (serverCommunications) + +import View.Icon exposing (renderIcon) + +monthlyPayments : Model -> LoggedInView -> Html +monthlyPayments model loggedInView = + let monthly = loggedInView.monthly + in if List.isEmpty monthly.payments + then + text "" + else + div + [ class ("monthlyPayments" ++ if monthly.visibleDetail then " detail" else "") ] + [ monthlyCount model monthly + , if monthly.visibleDetail then paymentsTable model loggedInView monthly else text "" + ] + +monthlyCount : Model -> Monthly -> Html +monthlyCount model monthly = + let count = List.length monthly.payments + key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount" + in button + [ class "count" + , onClick actions.address (UpdateLoggedIn << UpdateMonthly <| ToggleDetail) + ] + [ text (getParamMessage [toString count] key model.translations) + , div + [ class "expand" ] + [ if monthly.visibleDetail + then renderIcon "chevron-up" + else renderIcon "chevron-down" + ] + ] + +paymentsTable : Model -> LoggedInView -> Monthly -> Html +paymentsTable model loggedInView monthly = + div + [ class "table" ] + ( List.map (paymentLine model loggedInView) monthly.payments ) + +paymentLine : Model -> LoggedInView -> Payment -> Html +paymentLine model loggedInView payment = + a + [ class ("row" ++ (if loggedInView.paymentEdition == Just payment.id then " edition" else "")) + , onClick actions.address (UpdateLoggedIn (ToggleEdit payment.id)) + ] + [ div [ class "cell" ] [ text (payment.name) ] + , div [ class "cell" ] [ text (toString payment.cost ++ " " ++ getMessage "MoneySymbol" model.translations) ] + , div + [ class "cell delete" + , onClick serverCommunications.address (SC.DeleteMonthlyPayment payment.id) + ] + [ renderIcon "times" ] + ] diff --git a/src/client/View/LoggedIn/Paging.elm b/src/client/View/LoggedIn/Paging.elm new file mode 100644 index 0000000..5d5f2db --- /dev/null +++ b/src/client/View/LoggedIn/Paging.elm @@ -0,0 +1,97 @@ +module View.LoggedIn.Paging + ( paymentsPaging + ) where + +import Html exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) + +import Model.View.LoggedInView exposing (..) +import Model.Payment exposing (perPage) + +import ServerCommunication as SC exposing (serverCommunications) + +import Update exposing (..) +import Update.LoggedIn exposing (..) + +import View.Icon exposing (renderIcon) + +showedPages : Int +showedPages = 5 + +paymentsPaging : LoggedInView -> Html +paymentsPaging loggedInView = + let maxPage = ceiling (toFloat loggedInView.paymentsCount / toFloat perPage) + pages = truncatePages loggedInView.currentPage [1..maxPage] + in if maxPage == 1 + then + text "" + else + div + [ class "pages" ] + ( ( if loggedInView.currentPage > 1 + then [ firstPage, previousPage loggedInView ] + else [] + ) + ++ ( List.map (paymentsPage loggedInView) pages) + ++ ( if loggedInView.currentPage < maxPage + then [ nextPage loggedInView, lastPage 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 -> + [1..showedPages] + | currentPage > totalPages - showedRightPages -> + [(totalPages - showedPages)..totalPages] + | otherwise -> + [(currentPage - showedLeftPages)..(currentPage + showedRightPages)] + in List.filter (flip List.member pages) truncatedPages + +firstPage : Html +firstPage = + button + [ class "page" + , onClick serverCommunications.address (SC.UpdatePage 1) + ] + [ renderIcon "fast-backward" ] + +previousPage : LoggedInView -> Html +previousPage loggedInView = + button + [ class "page" + , onClick serverCommunications.address (SC.UpdatePage (loggedInView.currentPage - 1)) + ] + [ renderIcon "backward" ] + +nextPage : LoggedInView -> Html +nextPage loggedInView = + button + [ class "page" + , onClick serverCommunications.address (SC.UpdatePage (loggedInView.currentPage + 1)) + ] + [ renderIcon "forward" ] + +lastPage : Int -> Html +lastPage maxPage = + button + [ class "page" + , onClick serverCommunications.address (SC.UpdatePage maxPage) + ] + [ renderIcon "fast-forward" ] + +paymentsPage : LoggedInView -> Int -> Html +paymentsPage loggedInView page = + let onCurrentPage = page == loggedInView.currentPage + in button + [ class ("page" ++ (if onCurrentPage then " current" else "")) + , onClick serverCommunications.address <| + if onCurrentPage then SC.NoCommunication else SC.UpdatePage page + ] + [ text (toString page) ] diff --git a/src/client/View/LoggedIn/Table.elm b/src/client/View/LoggedIn/Table.elm new file mode 100644 index 0000000..6342369 --- /dev/null +++ b/src/client/View/LoggedIn/Table.elm @@ -0,0 +1,86 @@ +module View.LoggedIn.Table + ( paymentsTable + ) where + +import Html exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) +import Dict exposing (..) + +import Date +import Date exposing (Date) + +import String exposing (append) + +import Model exposing (Model) +import Model.User exposing (getUserName) +import Model.Payment exposing (..) +import Model.View.LoggedInView exposing (LoggedInView) +import Model.Translations exposing (getMessage) + +import ServerCommunication as SC exposing (serverCommunications) + +import Update exposing (..) +import Update.LoggedIn exposing (..) + +import View.Icon exposing (renderIcon) +import View.Date exposing (..) + +paymentsTable : Model -> LoggedInView -> Html +paymentsTable model loggedInView = + div + [ class "table" ] + ( headerLine model :: paymentLines model loggedInView) + +headerLine : Model -> Html +headerLine model = + div + [ class "header" ] + [ div [ class "cell category" ] [ renderIcon "shopping-cart" ] + , div [ class "cell cost" ] [ text (getMessage "MoneySymbol" model.translations) ] + , div [ class "cell user" ] [ renderIcon "user" ] + , div [ class "cell date" ] [ renderIcon "calendar" ] + , div [ class "cell" ] [] + ] + +paymentLines : Model -> LoggedInView -> List Html +paymentLines model loggedInView = + loggedInView.payments + |> List.sortBy (Date.toTime << .creation) + |> List.reverse + |> List.map (paymentLine model loggedInView) + +paymentLine : Model -> LoggedInView -> Payment -> Html +paymentLine model loggedInView payment = + a + [ class ("row" ++ (if loggedInView.paymentEdition == Just payment.id then " edition" else "")) + , onClick actions.address (UpdateLoggedIn (ToggleEdit payment.id)) + ] + [ div [ class "cell category" ] [ text payment.name ] + , div [ class "cell cost" ] [ text ((toString payment.cost) ++ " " ++ (getMessage "MoneySymbol" model.translations)) ] + , div + [ class "cell user" ] + [ payment.userId + |> getUserName loggedInView.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 loggedInView.me == payment.userId + then + div + [ class "cell delete" + , onClick serverCommunications.address (SC.DeletePayment payment.id payment.userId payment.cost loggedInView.currentPage) + ] + [ renderIcon "times" ] + else + div [ class "cell" ] [] + ] diff --git a/src/client/View/Page.elm b/src/client/View/Page.elm index 199c67f..763734d 100644 --- a/src/client/View/Page.elm +++ b/src/client/View/Page.elm @@ -10,7 +10,7 @@ import Model.View exposing (..) import View.Header exposing (renderHeader) import View.Loading exposing (renderLoading) import View.SignIn exposing (renderSignIn) -import View.Payments exposing (renderPayments) +import View.LoggedIn exposing (renderLoggedIn) renderPage : Model -> Html renderPage model = @@ -27,5 +27,5 @@ renderMain model = renderLoading SignInView signInView -> renderSignIn model signInView - LoggedView paymentsView -> - renderPayments model paymentsView + LoggedInView loggedInView -> + renderLoggedIn model loggedInView diff --git a/src/client/View/Payments.elm b/src/client/View/Payments.elm deleted file mode 100644 index ac19df7..0000000 --- a/src/client/View/Payments.elm +++ /dev/null @@ -1,27 +0,0 @@ -module View.Payments - ( renderPayments - ) where - -import Html exposing (..) -import Html.Attributes exposing (..) - -import Model exposing (Model) -import Model.Payment exposing (Payments) -import Model.View.LoggedView exposing (LoggedView) - -import View.Payments.ExceedingPayer exposing (exceedingPayers) -import View.Payments.Add exposing (addPayment) -import View.Payments.Monthly exposing (monthlyPayments) -import View.Payments.Table exposing (paymentsTable) -import View.Payments.Paging exposing (paymentsPaging) - -renderPayments : Model -> LoggedView -> Html -renderPayments model loggedView = - div - [ class "payments" ] - [ exceedingPayers model loggedView - , addPayment model loggedView - , monthlyPayments model loggedView - , paymentsTable model loggedView - , paymentsPaging loggedView - ] diff --git a/src/client/View/Payments/Add.elm b/src/client/View/Payments/Add.elm deleted file mode 100644 index f352f1f..0000000 --- a/src/client/View/Payments/Add.elm +++ /dev/null @@ -1,105 +0,0 @@ -module View.Payments.Add - ( addPayment - ) where - -import Html as H exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Reads exposing (readInt) -import Result exposing (..) - -import ServerCommunication as SC exposing (serverCommunications) - -import Update exposing (..) -import Update.LoggedView exposing (..) -import Update.LoggedView.Add exposing (..) - -import Model exposing (Model) -import Model.View.Payment.Add exposing (..) -import Model.Translations exposing (getMessage) -import Model.View.LoggedView exposing (LoggedView) - -import View.Events exposing (onSubmitPrevDefault) -import View.Icon exposing (renderIcon) - -import Utils.Maybe exposing (isJust) -import Utils.Either exposing (toMaybeError) - -addPayment : Model -> LoggedView -> Html -addPayment model loggedView = - H.form - [ case (validateName loggedView.add.name model.translations, validateCost loggedView.add.cost model.translations) of - (Ok name, Ok cost) -> - let action = - case loggedView.add.frequency of - Punctual -> SC.AddPayment loggedView.me name cost - Monthly -> SC.AddMonthlyPayment name cost - in onSubmitPrevDefault serverCommunications.address action - (resName, resCost) -> - onSubmitPrevDefault actions.address (UpdateLoggedView <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost)) - ] - [ addPaymentName loggedView.add - , addPaymentCost model loggedView.add - , paymentFrequency model loggedView.add - , button - [ type' "submit" - , class "add" ] - [ text (getMessage "Add" model.translations)] - ] - -addPaymentName : AddPayment -> Html -addPaymentName addPayment = - div - [ class ("name " ++ (if isJust addPayment.nameError then "error" else "")) ] - [ input - [ id "nameInput" - , value addPayment.name - , on "input" targetValue (Signal.message actions.address << UpdateLoggedView << UpdateAdd << UpdateName) - , maxlength 20 - ] - [] - , label - [ for "nameInput" ] - [ renderIcon "shopping-cart" ] - , case addPayment.nameError of - Just error -> - div [ class "errorMessage" ] [ text error ] - Nothing -> - text "" - ] - -addPaymentCost : Model -> AddPayment -> Html -addPaymentCost model addPayment = - div - [ class ("cost " ++ (if isJust addPayment.costError then "error" else "")) ] - [ input - [ id "costInput" - , value addPayment.cost - , on "input" targetValue (Signal.message actions.address << UpdateLoggedView << UpdateAdd << UpdateCost) - , maxlength 7 - ] - [] - , label - [ for "costInput" ] - [ text (getMessage "MoneySymbol" model.translations) ] - , case addPayment.costError of - Just error -> - div [ class "errorMessage" ] [ text error ] - Nothing -> - text "" - ] - -paymentFrequency : Model -> AddPayment -> Html -paymentFrequency model addPayment = - button - [ type' "button" - , class "frequency" - , onClick actions.address (UpdateLoggedView << UpdateAdd <| ToggleFrequency) - ] - [ div - [ class ("punctual" ++ if addPayment.frequency == Punctual then " selected" else "") ] - [ text (getMessage "Punctual" model.translations) ] - , div - [ class ("monthly" ++ if addPayment.frequency == Monthly then " selected" else "") ] - [ text (getMessage "Monthly" model.translations) ] - ] diff --git a/src/client/View/Payments/ExceedingPayer.elm b/src/client/View/Payments/ExceedingPayer.elm deleted file mode 100644 index 88b3a72..0000000 --- a/src/client/View/Payments/ExceedingPayer.elm +++ /dev/null @@ -1,35 +0,0 @@ -module View.Payments.ExceedingPayer - ( exceedingPayers - ) where - -import Html exposing (..) -import Html.Attributes exposing (..) -import List - -import Model exposing (Model) -import Model.User exposing (getUserName) -import Model.Payers exposing (..) -import Model.View.LoggedView exposing (LoggedView) -import Model.Translations exposing (getMessage) - -exceedingPayers : Model -> LoggedView -> Html -exceedingPayers model loggedView = - div - [ class "exceedingPayers" ] - (List.map (exceedingPayer model loggedView) (getOrderedExceedingPayers loggedView.payers)) - -exceedingPayer : Model -> LoggedView -> ExceedingPayer -> Html -exceedingPayer model loggedView payer = - div - [ class "exceedingPayer" ] - [ span - [ class "userName" ] - [ payer.userId - |> getUserName loggedView.users - |> Maybe.withDefault "−" - |> text - ] - , span - [ class "amount" ] - [ text ("+ " ++ (toString payer.amount) ++ " " ++ (getMessage "MoneySymbol" model.translations)) ] - ] diff --git a/src/client/View/Payments/Monthly.elm b/src/client/View/Payments/Monthly.elm deleted file mode 100644 index 944314c..0000000 --- a/src/client/View/Payments/Monthly.elm +++ /dev/null @@ -1,72 +0,0 @@ -module View.Payments.Monthly - ( monthlyPayments - ) where - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) - -import Update exposing (..) -import Update.LoggedView exposing (..) -import Update.LoggedView.Monthly exposing (..) - -import Model exposing (Model) -import Model.View.Payment.Monthly exposing (Monthly) -import Model.Payment exposing (Payments, Payment) -import Model.View.LoggedView exposing (LoggedView) -import Model.Translations exposing (getMessage, getParamMessage) - -import ServerCommunication as SC exposing (serverCommunications) - -import View.Icon exposing (renderIcon) - -monthlyPayments : Model -> LoggedView -> Html -monthlyPayments model loggedView = - let monthly = loggedView.monthly - in if List.isEmpty monthly.payments - then - text "" - else - div - [ class ("monthlyPayments" ++ if monthly.visibleDetail then " detail" else "") ] - [ monthlyCount model monthly - , if monthly.visibleDetail then paymentsTable model loggedView monthly else text "" - ] - -monthlyCount : Model -> Monthly -> Html -monthlyCount model monthly = - let count = List.length monthly.payments - key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount" - in button - [ class "count" - , onClick actions.address (UpdateLoggedView << UpdateMonthly <| ToggleDetail) - ] - [ text (getParamMessage [toString count] key model.translations) - , div - [ class "expand" ] - [ if monthly.visibleDetail - then renderIcon "chevron-up" - else renderIcon "chevron-down" - ] - ] - -paymentsTable : Model -> LoggedView -> Monthly -> Html -paymentsTable model loggedView monthly = - div - [ class "table" ] - ( List.map (paymentLine model loggedView) monthly.payments ) - -paymentLine : Model -> LoggedView -> Payment -> Html -paymentLine model loggedView payment = - a - [ class ("row" ++ (if loggedView.paymentEdition == Just payment.id then " edition" else "")) - , onClick actions.address (UpdateLoggedView (ToggleEdit payment.id)) - ] - [ div [ class "cell" ] [ text (payment.name) ] - , div [ class "cell" ] [ text (toString payment.cost ++ " " ++ getMessage "MoneySymbol" model.translations) ] - , div - [ class "cell delete" - , onClick serverCommunications.address (SC.DeleteMonthlyPayment payment.id) - ] - [ renderIcon "times" ] - ] diff --git a/src/client/View/Payments/Paging.elm b/src/client/View/Payments/Paging.elm deleted file mode 100644 index b9a0109..0000000 --- a/src/client/View/Payments/Paging.elm +++ /dev/null @@ -1,97 +0,0 @@ -module View.Payments.Paging - ( paymentsPaging - ) where - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) - -import Model.View.LoggedView exposing (..) -import Model.Payment exposing (perPage) - -import ServerCommunication as SC exposing (serverCommunications) - -import Update exposing (..) -import Update.LoggedView exposing (..) - -import View.Icon exposing (renderIcon) - -showedPages : Int -showedPages = 5 - -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 - div - [ class "pages" ] - ( ( if loggedView.currentPage > 1 - then [ firstPage, previousPage loggedView ] - else [] - ) - ++ ( List.map (paymentsPage loggedView) pages) - ++ ( if loggedView.currentPage < maxPage - then [ nextPage loggedView, lastPage 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 -> - [1..showedPages] - | currentPage > totalPages - showedRightPages -> - [(totalPages - showedPages)..totalPages] - | otherwise -> - [(currentPage - showedLeftPages)..(currentPage + showedRightPages)] - in List.filter (flip List.member pages) truncatedPages - -firstPage : Html -firstPage = - button - [ class "page" - , onClick serverCommunications.address (SC.UpdatePage 1) - ] - [ renderIcon "fast-backward" ] - -previousPage : LoggedView -> Html -previousPage loggedView = - button - [ class "page" - , onClick serverCommunications.address (SC.UpdatePage (loggedView.currentPage - 1)) - ] - [ renderIcon "backward" ] - -nextPage : LoggedView -> Html -nextPage loggedView = - button - [ class "page" - , onClick serverCommunications.address (SC.UpdatePage (loggedView.currentPage + 1)) - ] - [ renderIcon "forward" ] - -lastPage : Int -> Html -lastPage maxPage = - button - [ class "page" - , onClick serverCommunications.address (SC.UpdatePage maxPage) - ] - [ renderIcon "fast-forward" ] - -paymentsPage : LoggedView -> Int -> Html -paymentsPage loggedView page = - let onCurrentPage = page == loggedView.currentPage - in button - [ class ("page" ++ (if onCurrentPage then " current" else "")) - , onClick serverCommunications.address <| - if onCurrentPage then SC.NoCommunication else SC.UpdatePage page - ] - [ text (toString page) ] diff --git a/src/client/View/Payments/Table.elm b/src/client/View/Payments/Table.elm deleted file mode 100644 index 1646186..0000000 --- a/src/client/View/Payments/Table.elm +++ /dev/null @@ -1,86 +0,0 @@ -module View.Payments.Table - ( paymentsTable - ) where - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Dict exposing (..) - -import Date -import Date exposing (Date) - -import String exposing (append) - -import Model exposing (Model) -import Model.User exposing (getUserName) -import Model.Payment exposing (..) -import Model.View.LoggedView exposing (LoggedView) -import Model.Translations exposing (getMessage) - -import ServerCommunication as SC exposing (serverCommunications) - -import Update exposing (..) -import Update.LoggedView exposing (..) - -import View.Icon exposing (renderIcon) -import View.Date exposing (..) - -paymentsTable : Model -> LoggedView -> Html -paymentsTable model loggedView = - div - [ class "table" ] - ( headerLine model :: paymentLines model loggedView) - -headerLine : Model -> Html -headerLine model = - div - [ class "header" ] - [ div [ class "cell category" ] [ renderIcon "shopping-cart" ] - , div [ class "cell cost" ] [ text (getMessage "MoneySymbol" model.translations) ] - , div [ class "cell user" ] [ renderIcon "user" ] - , div [ class "cell date" ] [ renderIcon "calendar" ] - , div [ class "cell" ] [] - ] - -paymentLines : Model -> LoggedView -> List Html -paymentLines model loggedView = - loggedView.payments - |> List.sortBy (Date.toTime << .creation) - |> List.reverse - |> List.map (paymentLine model loggedView) - -paymentLine : Model -> LoggedView -> Payment -> Html -paymentLine model loggedView payment = - a - [ class ("row" ++ (if loggedView.paymentEdition == Just payment.id then " edition" else "")) - , onClick actions.address (UpdateLoggedView (ToggleEdit payment.id)) - ] - [ div [ class "cell category" ] [ text payment.name ] - , div [ class "cell cost" ] [ text ((toString payment.cost) ++ " " ++ (getMessage "MoneySymbol" model.translations)) ] - , div - [ class "cell user" ] - [ payment.userId - |> getUserName loggedView.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 loggedView.me == payment.userId - then - div - [ class "cell delete" - , onClick serverCommunications.address (SC.DeletePayment payment.id payment.userId payment.cost loggedView.currentPage) - ] - [ renderIcon "times" ] - else - div [ class "cell" ] [] - ] -- cgit v1.2.3