diff options
Diffstat (limited to 'src/client/elm/LoggedIn/Income')
-rw-r--r-- | src/client/elm/LoggedIn/Income/Action.elm | 9 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Income/Model.elm | 6 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Income/Msg.elm | 9 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Income/Update.elm | 19 | ||||
-rw-r--r-- | src/client/elm/LoggedIn/Income/View.elm | 38 |
5 files changed, 40 insertions, 41 deletions
diff --git a/src/client/elm/LoggedIn/Income/Action.elm b/src/client/elm/LoggedIn/Income/Action.elm deleted file mode 100644 index 68b343a..0000000 --- a/src/client/elm/LoggedIn/Income/Action.elm +++ /dev/null @@ -1,9 +0,0 @@ -module LoggedIn.Income.Action - ( Action(..) - ) where - -import Form exposing (Form) - -type Action = - NoOp - | AddIncomeAction Form.Action diff --git a/src/client/elm/LoggedIn/Income/Model.elm b/src/client/elm/LoggedIn/Income/Model.elm index fdfb964..bc09f0e 100644 --- a/src/client/elm/LoggedIn/Income/Model.elm +++ b/src/client/elm/LoggedIn/Income/Model.elm @@ -1,12 +1,12 @@ -module LoggedIn.Income.Model +module LoggedIn.Income.Model exposing ( Model , AddIncome , init - ) where + ) import String exposing (toInt, split) import Date exposing (Date) -import Date.Utils exposing (dateFromFields) +import Date.Extra.Create exposing (dateFromFields) import Utils.Date exposing (numToMonth) import Form exposing (Form) diff --git a/src/client/elm/LoggedIn/Income/Msg.elm b/src/client/elm/LoggedIn/Income/Msg.elm new file mode 100644 index 0000000..0a09dad --- /dev/null +++ b/src/client/elm/LoggedIn/Income/Msg.elm @@ -0,0 +1,9 @@ +module LoggedIn.Income.Msg exposing + ( Msg(..) + ) + +import Form exposing (Form) + +type Msg = + NoOp + | AddIncomeMsg Form.Msg diff --git a/src/client/elm/LoggedIn/Income/Update.elm b/src/client/elm/LoggedIn/Income/Update.elm index 4e673fa..74920f3 100644 --- a/src/client/elm/LoggedIn/Income/Update.elm +++ b/src/client/elm/LoggedIn/Income/Update.elm @@ -1,25 +1,24 @@ -module LoggedIn.Income.Update +module LoggedIn.Income.Update exposing ( update - ) where + ) -import Effects exposing (Effects) import Form exposing (Form) import LoggedData exposing (LoggedData) import LoggedIn.Income.Model as IncomeModel -import LoggedIn.Income.Action as IncomeAction +import LoggedIn.Income.Msg as IncomeMsg -update : LoggedData -> IncomeAction.Action -> IncomeModel.Model -> (IncomeModel.Model, Effects IncomeAction.Action) +update : LoggedData -> IncomeMsg.Msg -> IncomeModel.Model -> (IncomeModel.Model, Cmd IncomeMsg.Msg) update loggedData action model = case action of - IncomeAction.NoOp -> + IncomeMsg.NoOp -> ( model - , Effects.none + , Cmd.none ) - IncomeAction.AddIncomeAction formAction -> - ( { model | addIncome = Form.update formAction model.addIncome } - , Effects.none + IncomeMsg.AddIncomeMsg formMsg -> + ( { model | addIncome = Form.update formMsg model.addIncome } + , Cmd.none ) diff --git a/src/client/elm/LoggedIn/Income/View.elm b/src/client/elm/LoggedIn/Income/View.elm index 0d6e02d..39f16f4 100644 --- a/src/client/elm/LoggedIn/Income/View.elm +++ b/src/client/elm/LoggedIn/Income/View.elm @@ -1,17 +1,20 @@ -module LoggedIn.Income.View +module LoggedIn.Income.View exposing ( view - ) where + ) import Dict import Date import Time exposing (Time) +import Html.App as Html import Html exposing (..) import Html.Events exposing (..) import Html.Attributes exposing (..) import Form exposing (Form) import Form.Input as Input +import Msg exposing (Msg) + import LoggedData exposing (LoggedData) import Model.Income exposing (IncomeId, Income, userCumulativeIncomeSince) @@ -20,11 +23,8 @@ import Model.Payer exposing (useIncomesFrom) import Model.User exposing (UserId, User) import LoggedIn.Income.Model as IncomeModel -import Mailbox - -import Action -import LoggedIn.Action as LoggedInAction -import LoggedIn.Income.Action as IncomeAction +import LoggedIn.Msg as LoggedInMsg +import LoggedIn.Income.Msg as IncomeMsg import LoggedIn.View.Date exposing (renderShortDate) import LoggedIn.View.Format as Format @@ -34,7 +34,7 @@ import Utils.Maybe exposing (isJust) import LoggedIn.View.Date exposing (renderLongDate) import View.Events exposing (onSubmitPrevDefault) -view : LoggedData -> IncomeModel.Model -> Html +view : LoggedData -> IncomeModel.Model -> Html Msg view loggedData incomeModel = div [ class "income" ] @@ -47,7 +47,7 @@ view loggedData incomeModel = , incomesView loggedData ] -cumulativeIncomesView : LoggedData -> Time -> Html +cumulativeIncomesView : LoggedData -> Time -> Html Msg cumulativeIncomesView loggedData since = let longDate = renderLongDate (Date.fromTime since) loggedData.translations in div @@ -71,38 +71,38 @@ cumulativeIncomesView loggedData since = ) ] -addIncomeView : LoggedData -> Form () IncomeModel.AddIncome -> Html +addIncomeView : LoggedData -> Form () IncomeModel.AddIncome -> Html Msg addIncomeView loggedData addIncome = let - formAddress = Signal.forwardTo Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.IncomeAction << IncomeAction.AddIncomeAction) errorFor error field = if isJust field.liveError then div [ class "error" ] [ text (getMessage error loggedData.translations) ] else text "" creation = Form.getFieldAsString "creation" addIncome amount = Form.getFieldAsString "amount" addIncome + htmlMap = Html.map (Msg.UpdateLoggedIn << LoggedInMsg.IncomeMsg << IncomeMsg.AddIncomeMsg) in Html.form - [ onSubmitPrevDefault Mailbox.address Action.NoOp ] + [ onSubmitPrevDefault Msg.NoOp ] [ label [] [ text "Creation" ] - , Input.textInput creation formAddress [] + , htmlMap <| Input.textInput creation [] , errorFor "DateValidationError" creation , label [] [ text "amount" ] - , Input.textInput amount formAddress [] + , htmlMap <| Input.textInput amount [] , errorFor "IncomeValidationError" amount , button [ case Form.getOutput addIncome of Just data -> - onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.AddIncome data.creation data.amount) + onClick (Msg.UpdateLoggedIn <| LoggedInMsg.AddIncome data.creation data.amount) Nothing -> - onClick formAddress Form.Submit + onClick (Msg.UpdateLoggedIn <| LoggedInMsg.IncomeMsg <| IncomeMsg.AddIncomeMsg <| Form.Submit) ] [ text (getMessage "Add" loggedData.translations) ] ] -incomesView : LoggedData -> Html +incomesView : LoggedData -> Html Msg incomesView loggedData = ul [] @@ -114,7 +114,7 @@ incomesView loggedData = |> List.map (incomeView loggedData) ) -incomeView : LoggedData -> (IncomeId, Income) -> Html +incomeView : LoggedData -> (IncomeId, Income) -> Html Msg incomeView loggedData (incomeId, income) = li [] @@ -123,6 +123,6 @@ incomeView loggedData (incomeId, income) = , text <| Format.price loggedData.conf income.amount , text " − " , button - [ onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeleteIncome incomeId) ] + [ onClick (Msg.UpdateLoggedIn <| LoggedInMsg.DeleteIncome incomeId) ] [ text "x" ] ] |