From 359f837511597354bc6462cfc4200f54d647d728 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Thu, 13 Aug 2015 22:55:41 +0200 Subject: Giving the payment id to the client --- src/client/Model/Payment.elm | 6 ++++-- src/client/ServerCommunication.elm | 4 +++- src/client/Update/Payment.elm | 7 ++++--- src/client/View/Payments/Table.elm | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/client') diff --git a/src/client/Model/Payment.elm b/src/client/Model/Payment.elm index 4a08027..ff8f157 100644 --- a/src/client/Model/Payment.elm +++ b/src/client/Model/Payment.elm @@ -10,7 +10,8 @@ import Json.Decode as Json exposing ((:=)) type alias Payments = List Payment type alias Payment = - { creation : Date + { id : String + , creation : Date , name : String , cost : Int , userName : String @@ -21,7 +22,8 @@ paymentsDecoder = Json.list paymentDecoder paymentDecoder : Json.Decoder Payment paymentDecoder = - Json.object4 Payment + Json.object5 Payment + ("id" := Json.string) ("creation" := dateDecoder) ("name" := Json.string) ("cost" := Json.int) diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm index ccf63f2..b4b547d 100644 --- a/src/client/ServerCommunication.elm +++ b/src/client/ServerCommunication.elm @@ -71,7 +71,9 @@ communicationToAction communication response = SignIn login -> U.UpdateSignIn (ValidLogin login) AddPayment name cost -> - U.UpdatePayment (UP.AddPayment name cost) + decodeResponse + response + (\id -> U.UpdatePayment (UP.AddPayment id name cost)) SignOut -> U.GoSignInView else diff --git a/src/client/Update/Payment.elm b/src/client/Update/Payment.elm index 2d558fd..7826098 100644 --- a/src/client/Update/Payment.elm +++ b/src/client/Update/Payment.elm @@ -15,7 +15,7 @@ import Update.Payment.Add exposing (..) type PaymentAction = UpdateAdd AddPaymentAction | UpdatePayments Payments - | AddPayment String Int + | AddPayment String String Int updatePayment : Model -> PaymentAction -> PaymentView -> PaymentView updatePayment model action paymentView = @@ -24,9 +24,10 @@ updatePayment model action paymentView = { paymentView | add <- updateAddPayment addPaymentAction paymentView.add } UpdatePayments payments -> { paymentView | payments <- payments } - AddPayment name cost -> + AddPayment id name cost -> let payment = - { creation = Date.fromTime model.currentTime + { id = id + , creation = Date.fromTime model.currentTime , name = name , cost = cost , userName = paymentView.userName diff --git a/src/client/View/Payments/Table.elm b/src/client/View/Payments/Table.elm index 34dc058..b92735a 100644 --- a/src/client/View/Payments/Table.elm +++ b/src/client/View/Payments/Table.elm @@ -38,7 +38,7 @@ paymentLine : Payment -> Html paymentLine payment = tr [] - [ td [] [ text payment.userName ] + [ td [] [ text payment.id ] , td [] [ text payment.name ] , td [] [ text ((toString payment.cost) ++ " €") ] , td [] [ text (renderDate payment.creation) ] -- cgit v1.2.3