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 [ class "category" ] [ renderIcon "shopping-cart" ] , th [ class "cost" ] [ renderIcon "euro" ] , th [ class "user" ] [ renderIcon "user" ] , th [ class "date" ] [ 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.name ] , td [] [ text ((toString payment.cost) ++ " €") ] , td [] [ text payment.userName ] , 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)))