module LoggedIn.Home.View.Table exposing ( view ) import Dict exposing (..) import Date exposing (Date) import String exposing (append) import FontAwesome import View.Color as Color import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) import Msg exposing (Msg) import LoggedData exposing (LoggedData) import LoggedIn.Msg as LoggedInMsg import LoggedIn.Home.Msg as HomeMsg import LoggedIn.Home.Model as HomeModel import View.Date as Date import LoggedIn.View.Format as Format import Model.User exposing (getUserName) import Model.Payment as Payment exposing (..) import Model.Translations exposing (getMessage) import Dialog view : LoggedData -> HomeModel.Model -> Payments -> Frequency -> Html Msg view loggedData homeModel payments frequency = let visiblePayments = payments |> List.drop ((homeModel.currentPage - 1) * perPage) |> List.take perPage in div [ class "table" ] [ div [ class "lines" ] ( headerLine loggedData frequency :: List.map (paymentLine loggedData homeModel frequency) visiblePayments ) , if List.isEmpty visiblePayments then div [ class "noPayment" ] [ text <| getMessage "NoPayment" loggedData.translations ] else text "" ] headerLine : LoggedData -> Frequency -> Html Msg headerLine loggedData frequency = div [ class "header" ] [ div [ class "cell category" ] [ text <| getMessage "Name" loggedData.translations ] , div [ class "cell cost" ] [ text <| getMessage "Cost" loggedData.translations ] , div [ class "cell user" ] [ text <| getMessage "Payer" loggedData.translations ] , case frequency of Punctual -> div [ class "cell date" ] [ text <| getMessage "Date" loggedData.translations ] Monthly -> text "" , div [ class "cell" ] [] ] paymentLine : LoggedData -> HomeModel.Model -> Frequency -> Payment -> Html Msg paymentLine loggedData homeModel frequency payment = div [ class "row" ] [ div [ class "cell category" ] [ text payment.name ] , div [ classList [ ("cell cost", True) , ("refund", payment.cost < 0) ] ] [ text (Format.price loggedData.conf payment.cost) ] , div [ class "cell user" ] [ payment.userId |> getUserName loggedData.users |> Maybe.withDefault "−" |> text ] , case frequency of Punctual -> div [ class "cell date" ] [ span [ class "shortDate" ] [ text (Date.shortView payment.date loggedData.translations) ] , span [ class "longDate" ] [ text (Date.longView payment.date loggedData.translations) ] ] Monthly -> text "" , div [ class "cell delete" ] [ if loggedData.me /= payment.userId then text "" else let dialogConfig = { className = "paymentDialog" , title = getMessage "ConfirmPaymentDelete" loggedData.translations , body = always <| text "" , confirm = getMessage "Confirm" loggedData.translations , confirmMsg = always <| Ok <| Msg.UpdateLoggedIn <| LoggedInMsg.DeletePayment payment.id , undo = getMessage "Undo" loggedData.translations } in button [ onClick (Msg.Dialog <| Dialog.Open dialogConfig) ] [ FontAwesome.trash Color.chestnutRose 18 ] ] ]