diff options
author | Joris | 2015-09-06 00:05:50 +0200 |
---|---|---|
committer | Joris | 2015-09-06 00:05:50 +0200 |
commit | 24633871359ec9fbd63fdfebf79a6351b2792f77 (patch) | |
tree | a87c8a964a3c5114da13e622c604cf99ab905a06 /src/client/Model | |
parent | 8c328987901973cd0ffd2e03cae547717ebbbc67 (diff) |
Can add monthly payments, not visible at the moment though, just the count is printed
Diffstat (limited to 'src/client/Model')
-rw-r--r-- | src/client/Model/Payment.elm | 22 | ||||
-rw-r--r-- | src/client/Model/View/LoggedView.elm | 8 | ||||
-rw-r--r-- | src/client/Model/View/Payment/Add.elm | 6 |
3 files changed, 14 insertions, 22 deletions
diff --git a/src/client/Model/Payment.elm b/src/client/Model/Payment.elm index 4ae50de..313c6be 100644 --- a/src/client/Model/Payment.elm +++ b/src/client/Model/Payment.elm @@ -3,26 +3,22 @@ module Model.Payment , Payments , Payment , PaymentId - , PaymentWithId , paymentsDecoder - , removePayment ) where import Date exposing (..) import Json.Decode as Json exposing ((:=)) -import Dict exposing (..) import Model.User exposing (UserId, userIdDecoder) perPage : Int perPage = 8 -type alias Payments = Dict PaymentId Payment - -type alias PaymentWithId = (PaymentId, Payment) +type alias Payments = List Payment type alias Payment = - { creation : Date + { id : PaymentId + , creation : Date , name : String , cost : Int , userId : UserId @@ -31,15 +27,12 @@ type alias Payment = type alias PaymentId = Int paymentsDecoder : Json.Decoder Payments -paymentsDecoder = Json.map Dict.fromList (Json.list paymentWithIdDecoder) - -paymentWithIdDecoder : Json.Decoder (PaymentId, Payment) -paymentWithIdDecoder = - paymentDecoder `Json.andThen` (\payment -> Json.map (\id -> (id, payment)) ("id" := paymentIdDecoder)) +paymentsDecoder = Json.list paymentDecoder paymentDecoder : Json.Decoder Payment paymentDecoder = - Json.object4 Payment + Json.object5 Payment + ("id" := paymentIdDecoder) ("creation" := dateDecoder) ("name" := Json.string) ("cost" := Json.int) @@ -50,6 +43,3 @@ paymentIdDecoder = Json.int dateDecoder : Json.Decoder Date dateDecoder = Json.customDecoder Json.string Date.fromString - -removePayment : Payments -> PaymentId -> Payments -removePayment payments paymentId = Dict.remove paymentId payments diff --git a/src/client/Model/View/LoggedView.elm b/src/client/Model/View/LoggedView.elm index 35fd9e5..34a55a2 100644 --- a/src/client/Model/View/LoggedView.elm +++ b/src/client/Model/View/LoggedView.elm @@ -13,6 +13,7 @@ type alias LoggedView = { users : Users , me : UserId , add : AddPayment + , monthlyPayments : Payments , payments : Payments , paymentsCount : Int , payers : Payers @@ -20,11 +21,12 @@ type alias LoggedView = , currentPage : Int } -initLoggedView : Users -> UserId -> Payments -> Int -> Payers -> LoggedView -initLoggedView users me payments paymentsCount payers = +initLoggedView : Users -> UserId -> Payments -> Payments -> Int -> Payers -> LoggedView +initLoggedView users me monthlyPayments payments paymentsCount payers = { users = users , me = me - , add = initAddPayment + , add = initAddPayment Punctual + , monthlyPayments = monthlyPayments , payments = payments , paymentsCount = paymentsCount , payers = payers diff --git a/src/client/Model/View/Payment/Add.elm b/src/client/Model/View/Payment/Add.elm index da5d0f2..dc00e86 100644 --- a/src/client/Model/View/Payment/Add.elm +++ b/src/client/Model/View/Payment/Add.elm @@ -20,13 +20,13 @@ type alias AddPayment = , frequency : Frequency } -initAddPayment : AddPayment -initAddPayment = +initAddPayment : Frequency -> AddPayment +initAddPayment frequency = { name = "" , nameError = Nothing , cost = "" , costError = Nothing - , frequency = Punctual + , frequency = frequency } validateName : String -> Translations -> Result String String |