diff options
Diffstat (limited to 'src/client/elm/LoggedIn/Home')
-rw-r--r-- | src/client/elm/LoggedIn/Home/Account/View.elm | 42 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/Model.elm | 1 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/Search/View.elm | 50 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/Update.elm | 5 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View.elm | 20 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Monthly.elm | 2 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Paging.elm | 4 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Home/View/Search.elm | 26 |
8 files changed, 64 insertions, 86 deletions
diff --git a/src/client/elm/LoggedIn/Home/Account/View.elm b/src/client/elm/LoggedIn/Home/Account/View.elm deleted file mode 100644 index fdc1941..0000000 --- a/src/client/elm/LoggedIn/Home/Account/View.elm +++ /dev/null @@ -1,42 +0,0 @@ -module LoggedIn.Home.Account.View exposing - ( view - ) - -import Html exposing (..) -import Html.Attributes exposing (..) - -import Msg exposing (Msg) - -import LoggedData exposing (LoggedData) - -import LoggedIn.Home.Model as HomeModel -import LoggedIn.View.Format as Format - -import Model exposing (Model) -import Model.User exposing (getUserName) -import Model.Payer exposing (..) - -view : LoggedData -> HomeModel.Model -> Html Msg -view loggedData homeModel = - div - [ class "account" ] - [ div - [ class "header" ] - (List.map (exceedingPayer loggedData homeModel) (getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes loggedData.payments)) - ] - -exceedingPayer : LoggedData -> HomeModel.Model -> ExceedingPayer -> Html Msg -exceedingPayer loggedData homeModel payer = - div - [ 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/Model.elm b/src/client/elm/LoggedIn/Home/Model.elm index a653995..6b29d8c 100644 --- a/src/client/elm/LoggedIn/Home/Model.elm +++ b/src/client/elm/LoggedIn/Home/Model.elm @@ -1,5 +1,6 @@ module LoggedIn.Home.Model exposing ( Model + , Search , init ) diff --git a/src/client/elm/LoggedIn/Home/Search/View.elm b/src/client/elm/LoggedIn/Home/Search/View.elm new file mode 100644 index 0000000..f06377d --- /dev/null +++ b/src/client/elm/LoggedIn/Home/Search/View.elm @@ -0,0 +1,50 @@ +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 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 + ] + +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 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 302509f..078036d 100644 --- a/src/client/elm/LoggedIn/Home/Update.elm +++ b/src/client/elm/LoggedIn/Home/Update.elm @@ -45,7 +45,10 @@ update loggedData action homeModel = HomeMsg.SearchMsg formMsg -> ( { homeModel | search = Form.update formMsg homeModel.search - , currentPage = 1 + , currentPage = + case formMsg of + Form.Input "searchText" _ -> 1 + _ -> homeModel.currentPage } , Cmd.none ) diff --git a/src/client/elm/LoggedIn/Home/View.elm b/src/client/elm/LoggedIn/Home/View.elm index 5ed54b9..82ec8a3 100644 --- a/src/client/elm/LoggedIn/Home/View.elm +++ b/src/client/elm/LoggedIn/Home/View.elm @@ -7,6 +7,7 @@ import Html.Attributes exposing (..) import Date import Form +import Utils.Form as Form import Msg exposing (Msg) @@ -14,30 +15,21 @@ import LoggedData exposing (LoggedData) import Model.Payment as Payment import LoggedIn.Home.Model as LoggedInModel -import LoggedIn.Home.Account.View as AccountView +import LoggedIn.Home.Search.View as SearchView import LoggedIn.Home.AddPayment.View as AddPaymentView import LoggedIn.Home.View.Monthly as MonthlyView -import LoggedIn.Home.View.Search exposing (paymentsSearch) import LoggedIn.Home.View.Table exposing (paymentsTable) import LoggedIn.Home.View.Paging exposing (paymentsPaging) view : LoggedData -> LoggedInModel.Model -> Html Msg view loggedData loggedIn = - let searchText = - Form.getFieldAsString "searchText" loggedIn.search - |> .value - |> Maybe.withDefault "" - punctualPayments = Payment.sortedFiltredPunctual searchText loggedData.payments + let punctualPayments = Payment.sortedFiltredPunctual (Form.fieldAsText loggedIn.search "searchText") loggedData.payments in div [ class "home" ] [ AddPaymentView.view loggedData loggedIn - , div - [ class "expandables" ] - [ AccountView.view loggedData loggedIn - , MonthlyView.view loggedData loggedIn - ] - , paymentsSearch loggedData loggedIn + , MonthlyView.view loggedData loggedIn + , SearchView.view loggedData loggedIn punctualPayments , paymentsTable loggedData loggedIn punctualPayments - , paymentsPaging punctualPayments loggedIn + , paymentsPaging loggedIn punctualPayments ] diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm index 398059c..20dda19 100644 --- a/src/client/elm/LoggedIn/Home/View/Monthly.elm +++ b/src/client/elm/LoggedIn/Home/View/Monthly.elm @@ -33,7 +33,7 @@ view loggedData homeModel = else div [ classList - [ ("monthlyPayments", True) + [ ("monthly", True) , ("detail", homeModel.monthlyDetail) ] ] diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm index fb78810..da69232 100644 --- a/src/client/elm/LoggedIn/Home/View/Paging.elm +++ b/src/client/elm/LoggedIn/Home/View/Paging.elm @@ -22,8 +22,8 @@ import Model.Payment as Payment exposing (Payments, perPage) showedPages : Int showedPages = 5 -paymentsPaging : Payments -> HomeModel.Model -> Html Msg -paymentsPaging payments homeModel = +paymentsPaging : HomeModel.Model -> Payments -> Html Msg +paymentsPaging homeModel payments = let maxPage = ceiling (toFloat (List.length payments) / toFloat perPage) pages = truncatePages homeModel.currentPage [1..maxPage] in if maxPage == 1 diff --git a/src/client/elm/LoggedIn/Home/View/Search.elm b/src/client/elm/LoggedIn/Home/View/Search.elm deleted file mode 100644 index 62db1b2..0000000 --- a/src/client/elm/LoggedIn/Home/View/Search.elm +++ /dev/null @@ -1,26 +0,0 @@ -module LoggedIn.Home.View.Search exposing - ( paymentsSearch - ) - -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 (getMessage) - -paymentsSearch : LoggedData -> HomeModel.Model -> Html Msg -paymentsSearch loggedData { search } = - let htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.SearchMsg) - in Html.div - [ class "search" ] - [ Form.textInput loggedData.translations search htmlMap "searchText" ] |