From 70720548c9af024dbb6080638ac8e5470c2213eb Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 25 Jun 2016 15:10:03 +0200 Subject: Use the search to view either punctual or monthly payments --- src/client/elm/LoggedIn/Home/AddPayment/View.elm | 68 --------------- src/client/elm/LoggedIn/Home/Header/View.elm | 97 ++++++++++++++++++++++ src/client/elm/LoggedIn/Home/Model.elm | 44 +++------- src/client/elm/LoggedIn/Home/Msg.elm | 3 - src/client/elm/LoggedIn/Home/Search/View.elm | 56 ------------- src/client/elm/LoggedIn/Home/Update.elm | 44 ++++------ src/client/elm/LoggedIn/Home/View.elm | 28 ++++--- .../elm/LoggedIn/Home/View/ExceedingPayers.elm | 45 ++++++++++ src/client/elm/LoggedIn/Home/View/Monthly.elm | 93 --------------------- src/client/elm/LoggedIn/Home/View/Paging.elm | 8 +- src/client/elm/LoggedIn/Home/View/Table.elm | 74 ++++++++++------- 11 files changed, 230 insertions(+), 330 deletions(-) delete mode 100644 src/client/elm/LoggedIn/Home/AddPayment/View.elm create mode 100644 src/client/elm/LoggedIn/Home/Header/View.elm delete mode 100644 src/client/elm/LoggedIn/Home/Search/View.elm create mode 100644 src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm delete mode 100644 src/client/elm/LoggedIn/Home/View/Monthly.elm (limited to 'src/client/elm/LoggedIn/Home') diff --git a/src/client/elm/LoggedIn/Home/AddPayment/View.elm b/src/client/elm/LoggedIn/Home/AddPayment/View.elm deleted file mode 100644 index 5ccdb35..0000000 --- a/src/client/elm/LoggedIn/Home/AddPayment/View.elm +++ /dev/null @@ -1,68 +0,0 @@ -module LoggedIn.Home.AddPayment.View exposing - ( view - ) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Html.App as Html -import Task - -import Form exposing (Form) - -import Dialog - -import View.Form as Form -import View.Events exposing (onSubmitPrevDefault) - -import Msg exposing (Msg) -import LoggedIn.Msg as LoggedInMsg -import LoggedIn.Home.Msg as HomeMsg - -import Model.Translations exposing (getMessage) -import Model.Payment as Payment -import Model.View exposing (View(LoggedInView)) - -import LoggedData exposing (LoggedData) -import LoggedIn.Home.Model as HomeModel - -view : LoggedData -> Html Msg -view loggedData = - let dialogConfig = - { title = getMessage "AddPayment" loggedData.translations - , body = \view -> ( - case view of - LoggedInView loggedIn -> addPaymentForm loggedData loggedIn.home - _ -> text "" - ) - , confirm = getMessage "Confirm" loggedData.translations - , confirmMsg = \view -> ( - case view of - LoggedInView loggedIn -> - case Form.getOutput loggedIn.home.addPayment of - Just data -> - Ok (Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.frequency) - Nothing -> - Err (Msg.UpdateLoggedIn <| LoggedInMsg.HomeMsg <| HomeMsg.AddPaymentMsg <| Form.Submit) - _ -> - Err (Msg.UpdateLoggedIn LoggedInMsg.NoOp) - ) - , undo = getMessage "Undo" loggedData.translations - } - in button - [ class "addPayment" - , onClick (Msg.Dialog <| Dialog.Open dialogConfig) - ] - [ text (getMessage "AddPayment" loggedData.translations) ] - -addPaymentForm : LoggedData -> HomeModel.Model -> Html Msg -addPaymentForm loggedData { addPayment } = - let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.AddPaymentMsg) - in Html.form - [ class "addPayment" - , onSubmitPrevDefault Msg.NoOp - ] - [ Form.textInput loggedData.translations addPayment htmlMap "name" - , Form.textInput loggedData.translations addPayment htmlMap "cost" - , Form.radioInputs loggedData.translations addPayment htmlMap "frequency" [ toString Payment.Punctual, toString Payment.Monthly ] - ] diff --git a/src/client/elm/LoggedIn/Home/Header/View.elm b/src/client/elm/LoggedIn/Home/Header/View.elm new file mode 100644 index 0000000..f9fbb6a --- /dev/null +++ b/src/client/elm/LoggedIn/Home/Header/View.elm @@ -0,0 +1,97 @@ +module LoggedIn.Home.Header.View exposing + ( view + ) + +import Html exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) +import Html.App as Html +import String +import Dict + +import Form exposing (Form) +import View.Form as Form + +import Msg exposing (Msg) +import LoggedIn.Msg as LoggedInMsg +import LoggedIn.Home.Msg as HomeMsg + +import LoggedData exposing (LoggedData) +import LoggedIn.Home.Model as Home +import Model.Translations exposing (getParamMessage) +import Model.Conf exposing (Conf) +import Model.Payment as Payment exposing (Payments, Frequency(..)) +import Model.Translations exposing (getMessage) + +import Dialog.AddPayment.View as AddPayment + +import LoggedIn.Home.View.ExceedingPayers as ExceedingPayers +import LoggedIn.View.Format as Format +import View.Plural exposing (plural) + +import Utils.Tuple as Tuple + +view : LoggedData -> Home.Model -> Payments -> Frequency -> Html Msg +view loggedData { search } payments frequency = + Html.div + [ class "header" ] + [ ExceedingPayers.view loggedData + , searchLine loggedData search frequency + , infos loggedData payments + ] + +searchLine : LoggedData -> Form String Home.Search -> Frequency -> Html Msg +searchLine loggedData search frequency = + Html.div + [ class "searchLine" ] + [ searchForm loggedData search + , AddPayment.view loggedData frequency + ] + +searchForm : LoggedData -> Form String Home.Search -> Html Msg +searchForm loggedData search = + let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.SearchMsg) + in Html.form + [] + [ Form.textInput loggedData.translations search htmlMap "search" "name" + , if List.isEmpty (Payment.monthly loggedData.payments) + then text "" + else Form.radioInputs loggedData.translations search htmlMap "search" "frequency" [ toString Punctual, toString Monthly ] + ] + +infos : LoggedData -> Payments -> Html Msg +infos loggedData payments = + let paymentsCount = List.length payments + in if paymentsCount == 0 + then text "" + else + let count = plural loggedData.translations (List.length payments) "Payment" "Payments" + sum = paymentsSum loggedData.conf payments + in div + [ class "infos" ] + [ text <| getParamMessage [ count, sum ] "Worth" loggedData.translations + , span + [ class "partition" ] + [ text <| paymentsPartition loggedData payments ] + ] + +paymentsPartition : LoggedData -> Payments -> String +paymentsPartition loggedData payments = + String.join + ", " + ( loggedData.users + |> Dict.toList + |> List.map (Tuple.mapFst (\userId -> Payment.totalPayments (always True) userId payments)) + |> List.sortBy fst + |> List.reverse + |> List.map (\(sum, user) -> + getParamMessage [ user.name, Format.price loggedData.conf sum ] "By" loggedData.translations + ) + ) + +paymentsSum : Conf -> Payments -> String +paymentsSum conf payments = + payments + |> List.map .cost + |> List.sum + |> Format.price conf diff --git a/src/client/elm/LoggedIn/Home/Model.elm b/src/client/elm/LoggedIn/Home/Model.elm index e802828..be32fb7 100644 --- a/src/client/elm/LoggedIn/Home/Model.elm +++ b/src/client/elm/LoggedIn/Home/Model.elm @@ -2,7 +2,7 @@ module LoggedIn.Home.Model exposing ( Model , Search , init - , addPaymentInitial + , searchInitial ) import Form exposing (Form) @@ -10,24 +10,17 @@ import Form.Validate as Validate exposing (Validation) import Form.Field as Field exposing (Field) import Model.User exposing (Users, UserId) -import Model.Payment exposing (PaymentId, Payments, Frequency(..)) +import Model.Payment as Payment exposing (PaymentId, Payments, Frequency(..)) import Model.Payer exposing (Payers) type alias Model = { paymentEdition : Maybe PaymentId , currentPage : Int - , monthlyDetail : Bool , search : Form String Search - , addPayment : Form String AddPayment } type alias Search = - { searchText : Maybe String - } - -type alias AddPayment = - { name : String - , cost : Int + { name : Maybe String , frequency : Frequency } @@ -35,31 +28,14 @@ init : Model init = { paymentEdition = Nothing , currentPage = 1 - , monthlyDetail = False - , search = Form.initial [] searchValidation - , addPayment = Form.initial addPaymentInitial addPaymentValidation + , search = Form.initial (searchInitial Punctual) searchValidation } +searchInitial : Frequency -> List (String, Field) +searchInitial frequency = [ ("frequency", Field.Radio (toString frequency)) ] + searchValidation : Validation String Search searchValidation = - Validate.form1 Search - (Validate.get "searchText" (Validate.maybe Validate.string)) - -addPaymentInitial : List (String, Field) -addPaymentInitial = [ ("frequency", Field.Radio (toString Punctual)) ] - -addPaymentValidation : Validation String AddPayment -addPaymentValidation = - Validate.form3 AddPayment - (Validate.get "name" (Validate.string `Validate.andThen` (Validate.nonEmpty))) - (Validate.get "cost" (Validate.int `Validate.andThen` (Validate.minInt 1))) - (Validate.get "frequency" validateFrequency) - -validateFrequency : Validation String Frequency -validateFrequency = - Validate.customValidation Validate.string (\str -> - case str of - "Punctual" -> Ok Punctual - "Monthly" -> Ok Monthly - _ -> Err (Validate.customError "InvalidFrequency") - ) + Validate.form2 Search + (Validate.get "name" (Validate.maybe Validate.string)) + (Validate.get "frequency" Payment.validateFrequency) diff --git a/src/client/elm/LoggedIn/Home/Msg.elm b/src/client/elm/LoggedIn/Home/Msg.elm index bb6f77d..73b8980 100644 --- a/src/client/elm/LoggedIn/Home/Msg.elm +++ b/src/client/elm/LoggedIn/Home/Msg.elm @@ -10,7 +10,4 @@ type Msg = NoOp | ToggleEdit PaymentId | UpdatePage Int - | ShowMonthlyDetail - | ToggleMonthlyDetail | SearchMsg Form.Msg - | AddPaymentMsg Form.Msg diff --git a/src/client/elm/LoggedIn/Home/Search/View.elm b/src/client/elm/LoggedIn/Home/Search/View.elm deleted file mode 100644 index 99eec95..0000000 --- a/src/client/elm/LoggedIn/Home/Search/View.elm +++ /dev/null @@ -1,56 +0,0 @@ -module LoggedIn.Home.Search.View exposing - ( view - ) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Html.App as Html - -import Form exposing (Form) -import View.Form as Form - -import Msg exposing (Msg) -import LoggedIn.Msg as LoggedInMsg -import LoggedIn.Home.Msg as HomeMsg - -import LoggedData exposing (LoggedData) -import LoggedIn.Home.Model as HomeModel -import Model.Translations exposing (getParamMessage) -import Model.Conf exposing (Conf) -import Model.Payment exposing (Payments) -import Model.Translations exposing (getMessage) - -import LoggedIn.Home.AddPayment.View as AddPayment - -import LoggedIn.View.Format as Format -import View.Plural exposing (plural) - -view : LoggedData -> HomeModel.Model -> Payments -> Html Msg -view loggedData { search } payments = - Html.div - [ class "search" ] - [ searchForm loggedData search - , paymentsStat loggedData payments - , AddPayment.view loggedData - ] - -searchForm : LoggedData -> Form String HomeModel.Search -> Html Msg -searchForm loggedData search = - let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.SearchMsg) - in Form.textInput loggedData.translations search htmlMap "searchText" - -paymentsStat : LoggedData -> Payments -> Html Msg -paymentsStat loggedData payments = - let count = plural loggedData.translations (List.length payments) "Payment" "Payments" - sum = paymentsSum loggedData.conf payments - in span - [ class "stat" ] - [ text <| getParamMessage [ count, sum ] "Worth" loggedData.translations ] - -paymentsSum : Conf -> Payments -> String -paymentsSum conf payments = - payments - |> List.map .cost - |> List.sum - |> Format.price conf diff --git a/src/client/elm/LoggedIn/Home/Update.elm b/src/client/elm/LoggedIn/Home/Update.elm index 562cd20..160e279 100644 --- a/src/client/elm/LoggedIn/Home/Update.elm +++ b/src/client/elm/LoggedIn/Home/Update.elm @@ -6,49 +6,35 @@ import Form exposing (Form) import LoggedData exposing (LoggedData) -import LoggedIn.Home.Msg as HomeMsg -import LoggedIn.Home.Model as HomeModel +import LoggedIn.Home.Msg as Home +import LoggedIn.Home.Model as Home -update : LoggedData -> HomeMsg.Msg -> HomeModel.Model -> (HomeModel.Model, Cmd HomeMsg.Msg) -update loggedData msg homeModel = +update : LoggedData -> Home.Msg -> Home.Model -> (Home.Model, Cmd Home.Msg) +update loggedData msg model = case msg of - HomeMsg.NoOp -> (homeModel, Cmd.none) - - HomeMsg.ToggleEdit id -> - ( { homeModel | paymentEdition = if homeModel.paymentEdition == Just id then Nothing else Just id } - , Cmd.none - ) - - HomeMsg.UpdatePage page -> - ( { homeModel | currentPage = page } + Home.NoOp -> + ( model , Cmd.none ) - HomeMsg.ShowMonthlyDetail -> - ( { homeModel | monthlyDetail = True } + Home.ToggleEdit id -> + ( { model | paymentEdition = if model.paymentEdition == Just id then Nothing else Just id } , Cmd.none ) - HomeMsg.ToggleMonthlyDetail -> - ( { homeModel | monthlyDetail = not homeModel.monthlyDetail } + Home.UpdatePage page -> + ( { model | currentPage = page } , Cmd.none ) - HomeMsg.SearchMsg formMsg -> - ( { homeModel - | search = Form.update formMsg homeModel.search + Home.SearchMsg formMsg -> + ( { model + | search = Form.update formMsg model.search , currentPage = case formMsg of - Form.Input "searchText" _ -> 1 - _ -> homeModel.currentPage - } - , Cmd.none - ) - - HomeMsg.AddPaymentMsg formMsg -> - ( { homeModel - | addPayment = Form.update formMsg homeModel.addPayment + Form.Input "name" _ -> 1 + _ -> model.currentPage } , Cmd.none ) diff --git a/src/client/elm/LoggedIn/Home/View.elm b/src/client/elm/LoggedIn/Home/View.elm index 8076673..0def64e 100644 --- a/src/client/elm/LoggedIn/Home/View.elm +++ b/src/client/elm/LoggedIn/Home/View.elm @@ -12,22 +12,24 @@ import Utils.Form as Form import Msg exposing (Msg) import LoggedData exposing (LoggedData) -import Model.Payment as Payment +import Model.Payment as Payment exposing (Frequency(..)) -import LoggedIn.Home.Model as LoggedInModel -import LoggedIn.Home.Search.View as SearchView -import LoggedIn.Home.View.Monthly as MonthlyView +import LoggedIn.Home.Model as Home +import LoggedIn.Home.Header.View as Header -import LoggedIn.Home.View.Table exposing (paymentsTable) -import LoggedIn.Home.View.Paging exposing (paymentsPaging) +import LoggedIn.Home.View.Table as Table +import LoggedIn.Home.View.Paging as Paging -view : LoggedData -> LoggedInModel.Model -> Html Msg -view loggedData loggedIn = - let punctualPayments = Payment.sortedFiltredPunctual (Form.fieldAsText loggedIn.search "searchText") loggedData.payments +view : LoggedData -> Home.Model -> Html Msg +view loggedData home = + let (name, frequency) = + case Form.getOutput home.search of + Just data -> (Maybe.withDefault "" data.name, data.frequency) + Nothing -> ("", Punctual) + payments = Payment.search name frequency loggedData.payments in div [ class "home" ] - [ SearchView.view loggedData loggedIn punctualPayments - , MonthlyView.view loggedData loggedIn - , paymentsTable loggedData loggedIn punctualPayments - , paymentsPaging loggedIn punctualPayments + [ Header.view loggedData home payments frequency + , Table.view loggedData home payments frequency + , Paging.view home payments ] diff --git a/src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm b/src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm new file mode 100644 index 0000000..15f5cf5 --- /dev/null +++ b/src/client/elm/LoggedIn/Home/View/ExceedingPayers.elm @@ -0,0 +1,45 @@ +module LoggedIn.Home.View.ExceedingPayers exposing + ( view + ) + +import Html exposing (..) +import Html.Attributes exposing (..) + +import Msg exposing (Msg) + +import LoggedData exposing (LoggedData) + +import LoggedIn.View.Format as Format + +import Model exposing (Model) +import Model.User exposing (getUserName) +import Model.Payment as Payment +import Model.Payer exposing (..) +import Model.Translations exposing (getMessage) + +view : LoggedData -> Html Msg +view loggedData = + let payments = Payment.punctual loggedData.payments + exceedingPayers = getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes payments + in div + [ class "exceedingPayers" ] + ( if List.isEmpty exceedingPayers + then [ text <| getMessage "PaymentsAreBalanced" loggedData.translations ] + else (List.map (exceedingPayer loggedData) exceedingPayers) + ) + +exceedingPayer : LoggedData -> ExceedingPayer -> Html Msg +exceedingPayer loggedData payer = + span + [ class "exceedingPayer" ] + [ span + [ class "userName" ] + [ payer.userId + |> getUserName loggedData.users + |> Maybe.withDefault "−" + |> text + ] + , span + [ class "amount" ] + [ text ("+ " ++ (Format.price loggedData.conf payer.amount)) ] + ] diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm deleted file mode 100644 index 20dda19..0000000 --- a/src/client/elm/LoggedIn/Home/View/Monthly.elm +++ /dev/null @@ -1,93 +0,0 @@ -module LoggedIn.Home.View.Monthly exposing - ( view - ) - -import String -import Color - -import FontAwesome - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) - -import Msg exposing (Msg) - -import LoggedIn.Msg as LoggedInMsg - -import LoggedIn.Home.Msg as HomeMsg -import LoggedIn.Home.Model as HomeModel -import LoggedIn.View.Format as Format -import LoggedIn.Home.View.Expand exposing (..) - -import Model.Payment as Payment exposing (Payments, Payment, monthly) -import Model.Translations exposing (getMessage, getParamMessage) -import LoggedData exposing (LoggedData) - -view : LoggedData -> HomeModel.Model -> Html Msg -view loggedData homeModel = - let monthlyPayments = Payment.monthly loggedData.me loggedData.payments - in if List.length monthlyPayments == 0 - then - text "" - else - div - [ classList - [ ("monthly", True) - , ("detail", homeModel.monthlyDetail) - ] - ] - [ monthlyCount loggedData monthlyPayments homeModel - , if homeModel.monthlyDetail - then paymentsTable loggedData monthlyPayments homeModel - else text "" - ] - -monthlyCount : LoggedData -> Payments -> HomeModel.Model -> Html Msg -monthlyCount loggedData monthlyPayments homeModel = - let count = List.length monthlyPayments - total = List.sum << List.map .cost <| monthlyPayments - key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount" - in button - [ class "header" - , onClick (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg <| HomeMsg.ToggleMonthlyDetail) - ] - [ text (getParamMessage [toString count, Format.price loggedData.conf total] key loggedData.translations) - , expand ExpandDown homeModel.monthlyDetail - ] - -paymentsTable : LoggedData -> Payments -> HomeModel.Model -> Html Msg -paymentsTable loggedData monthlyPayments homeModel = - div - [ class "table" ] - ( monthlyPayments - |> List.sortBy (String.toLower << .name) - |> List.map (paymentLine loggedData homeModel) - ) - -paymentLine : LoggedData -> HomeModel.Model -> Payment -> Html Msg -paymentLine loggedData homeModel payment = - a - [ classList - [ ("row", True) - , ("edition", homeModel.paymentEdition == Just payment.id) - ] - , onClick (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg <| HomeMsg.ToggleEdit payment.id) - ] - [ 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 delete" - , onClick (Msg.UpdateLoggedIn <| LoggedInMsg.DeletePayment payment.id) - ] - [ button - [] - [ FontAwesome.times Color.white 20 ] - ] - ] diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm index da69232..90ae522 100644 --- a/src/client/elm/LoggedIn/Home/View/Paging.elm +++ b/src/client/elm/LoggedIn/Home/View/Paging.elm @@ -1,5 +1,5 @@ module LoggedIn.Home.View.Paging exposing - ( paymentsPaging + ( view ) import Color exposing (Color) @@ -22,11 +22,11 @@ import Model.Payment as Payment exposing (Payments, perPage) showedPages : Int showedPages = 5 -paymentsPaging : HomeModel.Model -> Payments -> Html Msg -paymentsPaging homeModel payments = +view : HomeModel.Model -> Payments -> Html Msg +view homeModel payments = let maxPage = ceiling (toFloat (List.length payments) / toFloat perPage) pages = truncatePages homeModel.currentPage [1..maxPage] - in if maxPage == 1 + in if maxPage <= 1 then text "" else diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm index a03faa2..9cd43a7 100644 --- a/src/client/elm/LoggedIn/Home/View/Table.elm +++ b/src/client/elm/LoggedIn/Home/View/Table.elm @@ -1,5 +1,5 @@ module LoggedIn.Home.View.Table exposing - ( paymentsTable + ( view ) import Dict exposing (..) @@ -26,33 +26,43 @@ import LoggedIn.View.Format as Format import Model.User exposing (getUserName) import Model.Payment as Payment exposing (..) +import Model.Translations exposing (getMessage) -paymentsTable : LoggedData -> HomeModel.Model -> Payments -> Html Msg -paymentsTable loggedData homeModel punctualPayments = - div - [ class "table" ] - ( headerLine loggedData :: paymentLines loggedData homeModel punctualPayments) +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 -> Html Msg -headerLine loggedData = +headerLine : LoggedData -> Frequency -> Html Msg +headerLine loggedData frequency = div [ class "header" ] - [ div [ class "cell category" ] [ FontAwesome.shopping_cart Color.white 28 ] - , div [ class "cell cost" ] [ text loggedData.conf.currency ] - , div [ class "cell user" ] [ FontAwesome.user Color.white 28 ] - , div [ class "cell date" ] [ FontAwesome.calendar Color.white 28 ] + [ 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" ] [] ] -paymentLines : LoggedData -> HomeModel.Model -> Payments -> List (Html Msg) -paymentLines loggedData homeModel punctualPayments = - punctualPayments - |> List.drop ((homeModel.currentPage - 1) * perPage) - |> List.take perPage - |> List.map (paymentLine loggedData homeModel) - -paymentLine : LoggedData -> HomeModel.Model -> Payment -> Html Msg -paymentLine loggedData homeModel payment = +paymentLine : LoggedData -> HomeModel.Model -> Frequency -> Payment -> Html Msg +paymentLine loggedData homeModel frequency payment = a [ classList [ ("row", True) @@ -75,15 +85,19 @@ paymentLine loggedData homeModel payment = |> Maybe.withDefault "−" |> text ] - , div - [ class "cell date" ] - [ span - [ class "shortDate" ] - [ text (renderShortDate payment.creation loggedData.translations) ] - , span - [ class "longDate" ] - [ text (renderLongDate payment.creation loggedData.translations) ] - ] + , case frequency of + Punctual -> + div + [ class "cell date" ] + [ span + [ class "shortDate" ] + [ text (renderShortDate payment.creation loggedData.translations) ] + , span + [ class "longDate" ] + [ text (renderLongDate payment.creation loggedData.translations) ] + ] + Monthly -> + text "" , if loggedData.me == payment.userId then div -- cgit v1.2.3