From bb316286b0859b5648c61f44c88399f4c1aad9cd Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 2 Jan 2016 19:07:19 +0100 Subject: Use start-app for elm --- src/client/elm/Model/Action.elm | 22 ++++++++++++ src/client/elm/Model/Action/AccountAction.elm | 15 ++++++++ src/client/elm/Model/Action/AddPaymentAction.elm | 9 +++++ src/client/elm/Model/Action/LoggedInAction.elm | 19 ++++++++++ src/client/elm/Model/Action/MonthlyAction.elm | 10 ++++++ src/client/elm/Model/Action/SignInAction.elm | 6 ++++ src/client/elm/Model/Communication.elm | 18 ++++++++++ src/client/elm/Model/View/LoggedIn/Add.elm | 43 ----------------------- src/client/elm/Model/View/LoggedIn/AddPayment.elm | 43 +++++++++++++++++++++++ src/client/elm/Model/View/LoggedInView.elm | 2 +- 10 files changed, 143 insertions(+), 44 deletions(-) create mode 100644 src/client/elm/Model/Action.elm create mode 100644 src/client/elm/Model/Action/AccountAction.elm create mode 100644 src/client/elm/Model/Action/AddPaymentAction.elm create mode 100644 src/client/elm/Model/Action/LoggedInAction.elm create mode 100644 src/client/elm/Model/Action/MonthlyAction.elm create mode 100644 src/client/elm/Model/Action/SignInAction.elm create mode 100644 src/client/elm/Model/Communication.elm delete mode 100644 src/client/elm/Model/View/LoggedIn/Add.elm create mode 100644 src/client/elm/Model/View/LoggedIn/AddPayment.elm (limited to 'src/client/elm/Model') diff --git a/src/client/elm/Model/Action.elm b/src/client/elm/Model/Action.elm new file mode 100644 index 0000000..9d5d125 --- /dev/null +++ b/src/client/elm/Model/Action.elm @@ -0,0 +1,22 @@ +module Model.Action + ( Action(..) + ) where + +import Time exposing (Time) +import Signal exposing (Address) + +import Model.User exposing (Users, UserId) +import Model.Payment exposing (Payments) +import Model.Payer exposing (Payers) +import Model.Action.SignInAction exposing (SignInAction) +import Model.Action.LoggedInAction exposing (LoggedInAction) +import Model.Communication exposing (Communication) + +type Action = + NoOp + | ServerCommunication Communication + | UpdateTime Time + | GoSignInView + | GoLoggedInView Users UserId Payments Payments Int Payers + | UpdateSignIn SignInAction + | UpdateLoggedIn LoggedInAction diff --git a/src/client/elm/Model/Action/AccountAction.elm b/src/client/elm/Model/Action/AccountAction.elm new file mode 100644 index 0000000..feddbea --- /dev/null +++ b/src/client/elm/Model/Action/AccountAction.elm @@ -0,0 +1,15 @@ +module Model.Action.AccountAction + ( AccountAction(..) + ) where + +import Time exposing (Time) + +import Model.User exposing (UserId) + +type AccountAction = + ToggleDetail + | UpdatePayer UserId Time Int + | ToggleIncomeEdition + | UpdateIncomeEdition String + | UpdateEditionError String + | UpdateIncome Time Int diff --git a/src/client/elm/Model/Action/AddPaymentAction.elm b/src/client/elm/Model/Action/AddPaymentAction.elm new file mode 100644 index 0000000..172f35f --- /dev/null +++ b/src/client/elm/Model/Action/AddPaymentAction.elm @@ -0,0 +1,9 @@ +module Model.Action.AddPaymentAction + ( AddPaymentAction(..) + ) where + +type AddPaymentAction = + UpdateName String + | UpdateCost String + | AddError (Maybe String) (Maybe String) + | ToggleFrequency diff --git a/src/client/elm/Model/Action/LoggedInAction.elm b/src/client/elm/Model/Action/LoggedInAction.elm new file mode 100644 index 0000000..22a7d3d --- /dev/null +++ b/src/client/elm/Model/Action/LoggedInAction.elm @@ -0,0 +1,19 @@ +module Model.Action.LoggedInAction + ( LoggedInAction(..) + ) where + +import Model.Payment exposing (Payments, Payment, PaymentId) +import Model.Action.MonthlyAction exposing (MonthlyAction) +import Model.Action.AccountAction exposing (AccountAction) +import Model.Action.AddPaymentAction exposing (AddPaymentAction) + +type LoggedInAction = + UpdateAdd AddPaymentAction + | UpdatePayments Payments + | AddPayment PaymentId String Int + | AddMonthlyPayment PaymentId String Int + | ToggleEdit PaymentId + | DeletePayment Payment + | UpdatePage Int + | UpdateMonthly MonthlyAction + | UpdateAccount AccountAction diff --git a/src/client/elm/Model/Action/MonthlyAction.elm b/src/client/elm/Model/Action/MonthlyAction.elm new file mode 100644 index 0000000..d985ccc --- /dev/null +++ b/src/client/elm/Model/Action/MonthlyAction.elm @@ -0,0 +1,10 @@ +module Model.Action.MonthlyAction + ( MonthlyAction(..) + ) where + +import Model.Payment exposing (Payment, PaymentId) + +type MonthlyAction = + ToggleDetail + | AddPayment Payment + | DeletePayment PaymentId diff --git a/src/client/elm/Model/Action/SignInAction.elm b/src/client/elm/Model/Action/SignInAction.elm new file mode 100644 index 0000000..6673c11 --- /dev/null +++ b/src/client/elm/Model/Action/SignInAction.elm @@ -0,0 +1,6 @@ +module Model.Action.SignInAction + ( SignInAction(..) + ) where + +type SignInAction = + ErrorLogin String diff --git a/src/client/elm/Model/Communication.elm b/src/client/elm/Model/Communication.elm new file mode 100644 index 0000000..dc4d412 --- /dev/null +++ b/src/client/elm/Model/Communication.elm @@ -0,0 +1,18 @@ +module Model.Communication + ( Communication(..) + ) where + +import Time exposing (Time) + +import Model.User exposing (UserId) +import Model.Payment exposing (..) + +type Communication = + NoCommunication + | SignIn String + | AddPayment String Int + | AddMonthlyPayment String Int + | SetIncome Time Int + | DeletePayment Payment Int + | DeleteMonthlyPayment PaymentId + | SignOut diff --git a/src/client/elm/Model/View/LoggedIn/Add.elm b/src/client/elm/Model/View/LoggedIn/Add.elm deleted file mode 100644 index c25c640..0000000 --- a/src/client/elm/Model/View/LoggedIn/Add.elm +++ /dev/null @@ -1,43 +0,0 @@ -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 "CostRequired" translations) ((/=) 0)) - -type Frequency = Punctual | Monthly diff --git a/src/client/elm/Model/View/LoggedIn/AddPayment.elm b/src/client/elm/Model/View/LoggedIn/AddPayment.elm new file mode 100644 index 0000000..b70b0c6 --- /dev/null +++ b/src/client/elm/Model/View/LoggedIn/AddPayment.elm @@ -0,0 +1,43 @@ +module Model.View.LoggedIn.AddPayment + ( 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 "CostRequired" translations) ((/=) 0)) + +type Frequency = Punctual | Monthly diff --git a/src/client/elm/Model/View/LoggedInView.elm b/src/client/elm/Model/View/LoggedInView.elm index 122c4be..712ce2d 100644 --- a/src/client/elm/Model/View/LoggedInView.elm +++ b/src/client/elm/Model/View/LoggedInView.elm @@ -6,7 +6,7 @@ module Model.View.LoggedInView import Model.User exposing (Users, UserId) import Model.Payment exposing (Payments) import Model.Payer exposing (Payers) -import Model.View.LoggedIn.Add exposing (..) +import Model.View.LoggedIn.AddPayment exposing (..) import Model.View.LoggedIn.Edition exposing (..) import Model.View.LoggedIn.Monthly exposing (..) import Model.View.LoggedIn.Account exposing (..) -- cgit v1.2.3