aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Income/View.elm
diff options
context:
space:
mode:
authorJoris2016-04-05 13:39:48 +0200
committerJoris2016-04-05 13:39:48 +0200
commitedca79a7e2bfed1a08de780cc6ab7eac430ef950 (patch)
tree02f794910924f1ca0114d08a254deed98388c70f /src/client/elm/LoggedIn/Income/View.elm
parentd19b69eeeb0c24ee7e4a75b0da32eefba1d43928 (diff)
downloadbudget-edca79a7e2bfed1a08de780cc6ab7eac430ef950.tar.gz
budget-edca79a7e2bfed1a08de780cc6ab7eac430ef950.tar.bz2
budget-edca79a7e2bfed1a08de780cc6ab7eac430ef950.zip
Add a statistics empty page
Diffstat (limited to 'src/client/elm/LoggedIn/Income/View.elm')
-rw-r--r--src/client/elm/LoggedIn/Income/View.elm95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/client/elm/LoggedIn/Income/View.elm b/src/client/elm/LoggedIn/Income/View.elm
new file mode 100644
index 0000000..010b503
--- /dev/null
+++ b/src/client/elm/LoggedIn/Income/View.elm
@@ -0,0 +1,95 @@
+module LoggedIn.Income.View
+ ( view
+ ) where
+
+import Dict
+import Date
+
+import Html exposing (..)
+import Html.Events exposing (..)
+import Html.Attributes exposing (..)
+import Form exposing (Form)
+import Form.Input as Input
+
+import LoggedData exposing (LoggedData)
+
+import Model.Income exposing (IncomeId, Income)
+import Model.Translations exposing (getMessage)
+import LoggedIn.Income.Model as IncomeModel
+
+import Mailbox
+
+import Action
+import LoggedIn.Action as LoggedInAction
+import LoggedIn.Income.Action as IncomeAction
+
+import LoggedIn.View.Date exposing (renderShortDate)
+import LoggedIn.View.Price exposing (price)
+
+import Utils.Maybe exposing (isJust)
+
+view : LoggedData -> IncomeModel.Model -> Html
+view loggedData incomeModel =
+ div
+ []
+ [ h1 [] [ text <| getMessage "AddIncome" loggedData.translations ]
+ , addIncomeView loggedData incomeModel.addIncome
+ , h1 [] [ text <| getMessage "MonthlyNetIncomes" loggedData.translations ]
+ , incomesView loggedData
+ ]
+
+addIncomeView : LoggedData -> Form () IncomeModel.AddIncome -> Html
+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
+ in
+ div
+ []
+ [ label [] [ text "Creation" ]
+ , Input.textInput creation formAddress []
+ , errorFor "DateValidationError" creation
+
+ , label [] [ text "amount" ]
+ , Input.textInput amount formAddress []
+ , errorFor "IncomeValidationError" amount
+
+ , button
+ [ case Form.getOutput addIncome of
+ Just data ->
+ onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.AddIncome data.creation data.amount)
+ Nothing ->
+ onClick formAddress Form.Submit
+ ]
+ [ text (getMessage "Add" loggedData.translations) ]
+ ]
+
+incomesView : LoggedData -> Html
+incomesView loggedData =
+ ol
+ []
+ ( loggedData.incomes
+ |> Dict.toList
+ |> List.filter ((==) loggedData.me << .userId << snd)
+ |> List.sortBy (.creation << snd)
+ |> List.reverse
+ |> List.map (incomeView loggedData)
+ )
+
+incomeView : LoggedData -> (IncomeId, Income) -> Html
+incomeView loggedData (incomeId, income) =
+ li
+ []
+ [ text <| renderShortDate (Date.fromTime income.creation) loggedData.translations
+ , text " − "
+ , text <| price loggedData.conf income.amount
+ , text " − "
+ , button
+ [ onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeleteIncome incomeId) ]
+ [ text "x" ]
+ ]