From 889df8caf04de5f10a9e623bab3e502e9573159d Mon Sep 17 00:00:00 2001 From: Joris Date: Thu, 3 Sep 2015 23:32:39 +0200 Subject: Give the payments count to the client --- src/client/Main.elm | 7 +++++-- src/client/Model/View/PaymentView.elm | 6 ++++-- src/client/Update.elm | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/client') diff --git a/src/client/Main.elm b/src/client/Main.elm index 57e41d4..6ca2743 100644 --- a/src/client/Main.elm +++ b/src/client/Main.elm @@ -9,7 +9,7 @@ import Html exposing (Html) import Http import Task exposing (..) import Time exposing (..) -import Json.Decode as Json +import Json.Decode as Json exposing ((:=)) import Model exposing (Model, initialModel) import Model.Payment exposing (Payments, paymentsDecoder) @@ -56,7 +56,7 @@ port initView = Just msg -> Signal.send actions.address (SignInError msg) Nothing -> - Task.map3 GoPaymentView getUserName getPayments getPayers + Task.map4 GoPaymentView getUserName getPayments getPaymentsCount getPayers |> flip Task.andThen (Signal.send actions.address) |> flip Task.onError (\_ -> Signal.send actions.address GoSignInView) @@ -66,6 +66,9 @@ getUserName = Http.get messageDecoder "/userName" getPayments : Task Http.Error Payments getPayments = Http.get paymentsDecoder "/payments" +getPaymentsCount : Task Http.Error Int +getPaymentsCount = Http.get ("number" := Json.int) "/payments/count" + getPayers : Task Http.Error Payers getPayers = Http.get payersDecoder "/payments/total" diff --git a/src/client/Model/View/PaymentView.elm b/src/client/Model/View/PaymentView.elm index 19ad355..117be59 100644 --- a/src/client/Model/View/PaymentView.elm +++ b/src/client/Model/View/PaymentView.elm @@ -12,15 +12,17 @@ type alias PaymentView = { userName : String , add : AddPayment , payments : Payments + , paymentsCount : Int , payers : Payers , edition : Maybe Edition } -initPaymentView : String -> Payments -> Payers -> PaymentView -initPaymentView userName payments payers = +initPaymentView : String -> Payments -> Int -> Payers -> PaymentView +initPaymentView userName payments paymentsCount payers = { userName = userName , add = initAddPayment , payments = payments + , paymentsCount = paymentsCount , payers = payers , edition = Nothing } diff --git a/src/client/Update.elm b/src/client/Update.elm index df19775..374c5d0 100644 --- a/src/client/Update.elm +++ b/src/client/Update.elm @@ -22,7 +22,7 @@ type Action = | GoSignInView | SignInError String | UpdateSignIn SignInAction - | GoPaymentView String Payments Payers + | GoPaymentView String Payments Int Payers | UpdatePayment PaymentAction actions : Signal.Mailbox Action @@ -37,8 +37,8 @@ updateModel action model = { model | currentTime <- time } GoSignInView -> { model | view <- V.SignInView initSignInView } - GoPaymentView userName payments payers -> - { model | view <- V.PaymentView (initPaymentView userName payments payers) } + GoPaymentView userName payments paymentsCount payers -> + { model | view <- V.PaymentView (initPaymentView userName payments paymentsCount payers) } SignInError msg -> let signInView = { initSignInView | result <- Just (Err msg) } in { model | view <- V.SignInView signInView } -- cgit v1.2.3