From a271d6034bc4cc631a64476d25d21c83a701fa39 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Mon, 20 Jul 2015 21:55:52 +0200 Subject: Add a payment from the UI, it needs polishing however --- src/client/View/Payments/Add.elm | 34 +++++++++++++++++++++++++ src/client/View/Payments/Table.elm | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/client/View/Payments/Add.elm create mode 100644 src/client/View/Payments/Table.elm (limited to 'src/client/View/Payments') diff --git a/src/client/View/Payments/Add.elm b/src/client/View/Payments/Add.elm new file mode 100644 index 0000000..f2230be --- /dev/null +++ b/src/client/View/Payments/Add.elm @@ -0,0 +1,34 @@ +module View.Payments.Add + ( addPayment + ) where + +import Html exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) + +import ServerCommunication as SC +import ServerCommunication exposing (serverCommunications) + +import Update exposing (..) +import Update.Payment exposing (..) + +addPayment : String -> String -> Html +addPayment name cost = + div + [ class "add" ] + [ text "Name" + , input + [ value name + , on "input" targetValue (Signal.message actions.address << UpdatePayment << UpdateName) + ] + [] + , text "Cost" + , input + [ value cost + , on "input" targetValue (Signal.message actions.address << UpdatePayment << UpdateCost) + ] + [] + , button + [ onClick serverCommunications.address (SC.AddPayment name cost) ] + [ text "Add" ] + ] diff --git a/src/client/View/Payments/Table.elm b/src/client/View/Payments/Table.elm new file mode 100644 index 0000000..34dc058 --- /dev/null +++ b/src/client/View/Payments/Table.elm @@ -0,0 +1,51 @@ +module View.Payments.Table + ( paymentsTable + ) where + +import Html exposing (..) +import Html.Attributes exposing (..) + +import Date +import Date exposing (Date) + +import String exposing (append) + +import Model.Payment exposing (Payments, Payment) + +import View.Icon exposing (renderIcon) + +paymentsTable : Payments -> Html +paymentsTable payments = + table + [] + ([ tr + [] + [ th [] [ renderIcon "user" ] + , th [] [ renderIcon "shopping-cart" ] + , th [] [ renderIcon "euro" ] + , th [] [ renderIcon "calendar" ] + ] + ] ++ (paymentLines payments)) + +paymentLines : Payments -> List Html +paymentLines payments = + payments + |> List.sortBy (Date.toTime << .creation) + |> List.reverse + |> List.map paymentLine + +paymentLine : Payment -> Html +paymentLine payment = + tr + [] + [ td [] [ text payment.userName ] + , td [] [ text payment.name ] + , td [] [ text ((toString payment.cost) ++ " €") ] + , td [] [ text (renderDate payment.creation) ] + ] + +renderDate : Date -> String +renderDate date = + toString (Date.day date) + |> flip append (" " ++ (toString (Date.month date)) ++ ".") + |> flip append (" " ++ (toString (Date.year date))) -- cgit v1.2.3