From 76f8b85eb9f796d6df861a04f702ef5f48630795 Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 29 Mar 2016 23:46:47 +0200 Subject: Move logged data to LoggedIn component --- src/client/elm/LoggedIn/Home/Account/View.elm | 75 ++++++++++++++------------- 1 file changed, 39 insertions(+), 36 deletions(-) (limited to 'src/client/elm/LoggedIn/Home/Account/View.elm') diff --git a/src/client/elm/LoggedIn/Home/Account/View.elm b/src/client/elm/LoggedIn/Home/Account/View.elm index 252f8cf..a7d3e0c 100644 --- a/src/client/elm/LoggedIn/Home/Account/View.elm +++ b/src/client/elm/LoggedIn/Home/Account/View.elm @@ -3,13 +3,15 @@ module LoggedIn.Home.Account.View ) where import List -import Signal exposing (Address) +import Signal import Html exposing (..) import Html as H exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) +import LoggedData exposing (LoggedData) + import LoggedIn.Action as LoggedInAction import LoggedIn.Home.Action as HomeAction @@ -24,14 +26,15 @@ import LoggedIn.Home.Account.Model as AccountModel import Model exposing (Model) import Model.User exposing (getUserName) import Model.Translations exposing (getParamMessage, getMessage) -import Action exposing (..) +import Action +import Mailbox import View.Events exposing (onSubmitPrevDefault) import Utils.Either exposing (toMaybeError) -view : Address Action -> Model -> HomeModel.Model -> Html -view address model homeModel = +view : LoggedData -> HomeModel.Model -> Html +view loggedData homeModel = let account = homeModel.account in div [ classList @@ -39,76 +42,76 @@ view address model homeModel = , ("detail", account.visibleDetail) ] ] - [ exceedingPayers address model homeModel + [ exceedingPayers loggedData homeModel , if account.visibleDetail - then income address model account + then income loggedData account else text "" ] -exceedingPayers : Address Action -> Model -> HomeModel.Model -> Html -exceedingPayers address model homeModel = +exceedingPayers : LoggedData -> HomeModel.Model -> Html +exceedingPayers loggedData homeModel = button [ class "header" - , onClick address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount <| AccountAction.ToggleDetail) + , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount <| AccountAction.ToggleDetail) ] - ( (List.map (exceedingPayer model homeModel) (getOrderedExceedingPayers model.currentTime homeModel.users homeModel.account.incomes homeModel.payments)) + ( (List.map (exceedingPayer loggedData homeModel) (getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes loggedData.payments)) ++ [ expand ExpandDown homeModel.account.visibleDetail ] ) -exceedingPayer : Model -> HomeModel.Model -> ExceedingPayer -> Html -exceedingPayer model homeModel payer = +exceedingPayer : LoggedData -> HomeModel.Model -> ExceedingPayer -> Html +exceedingPayer loggedData homeModel payer = div [ class "exceedingPayer" ] [ span [ class "userName" ] [ payer.userId - |> getUserName homeModel.users + |> getUserName loggedData.users |> Maybe.withDefault "−" |> text ] , span [ class "amount" ] - [ text ("+ " ++ (price model payer.amount)) ] + [ text ("+ " ++ (price loggedData.conf payer.amount)) ] ] -income : Address Action -> Model -> AccountModel.Model -> Html -income address model account = +income : LoggedData -> AccountModel.Model -> Html +income loggedData account = case account.incomeEdition of Nothing -> - incomeRead address model account + incomeRead loggedData account Just edition -> - incomeEdition address model account edition + incomeEdition loggedData account edition -incomeRead : Address Action -> Model -> AccountModel.Model -> Html -incomeRead address model account = +incomeRead : LoggedData -> AccountModel.Model -> Html +incomeRead loggedData account = div [ class "income" ] - [ ( case AccountModel.getCurrentIncome account of + [ ( case AccountModel.getCurrentIncome loggedData.incomes loggedData.me account of Nothing -> - text (getMessage "NoIncome" model.translations) + text (getMessage "NoIncome" loggedData.translations) Just income -> - text (getParamMessage [price model income] "Income" model.translations) + text (getParamMessage [price loggedData.conf income] "Income" loggedData.translations) ) - , toggleIncomeEdition address "editIncomeEdition" (getMessage "Edit" model.translations) + , toggleIncomeEdition loggedData "editIncomeEdition" (getMessage "Edit" loggedData.translations) ] -incomeEdition : Address Action -> Model -> AccountModel.Model -> AccountModel.IncomeEdition -> Html -incomeEdition address model account edition = +incomeEdition : LoggedData -> AccountModel.Model -> AccountModel.IncomeEdition -> Html +incomeEdition loggedData account edition = H.form - [ case AccountModel.validateIncome edition.income model.translations of + [ case AccountModel.validateIncome edition.income loggedData.translations of Ok validatedAmount -> - onSubmitPrevDefault address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount <| AccountAction.UpdateIncome model.currentTime validatedAmount) + onSubmitPrevDefault Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.UpdateIncome validatedAmount) Err error -> - onSubmitPrevDefault address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount << AccountAction.UpdateEditionError <| error) + onSubmitPrevDefault Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount << AccountAction.UpdateEditionError <| error) , class "income" ] [ label [ for "incomeInput" ] - [ text (getMessage "NewIncome" model.translations) ] + [ text (getMessage "NewIncome" loggedData.translations) ] , input [ id "incomeInput" , value edition.income - , on "input" targetValue (Signal.message address << UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount << AccountAction.UpdateIncomeEdition) + , on "input" targetValue (Signal.message Mailbox.address << Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount << AccountAction.UpdateIncomeEdition) , maxlength 10 ] [] @@ -116,18 +119,18 @@ incomeEdition address model account edition = [ type' "submit" , class "validateIncomeEdition" ] - [ text (getMessage "Validate" model.translations) ] - , toggleIncomeEdition address "undoIncomeEdition" (getMessage "Undo" model.translations) + [ text (getMessage "Validate" loggedData.translations) ] + , toggleIncomeEdition loggedData "undoIncomeEdition" (getMessage "Undo" loggedData.translations) , case edition.error of Just error -> div [ class "error" ] [ text error ] Nothing -> text "" ] -toggleIncomeEdition : Address Action -> String -> String -> Html -toggleIncomeEdition address className name = +toggleIncomeEdition : LoggedData -> String -> String -> Html +toggleIncomeEdition loggedData className name = button [ type' "button" , class className - , onClick address (UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount <| AccountAction.ToggleIncomeEdition) + , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount <| AccountAction.ToggleIncomeEdition) ] [ text name ] -- cgit v1.2.3