aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home
diff options
context:
space:
mode:
authorJoris2016-04-04 01:27:36 +0200
committerJoris2016-04-04 01:27:36 +0200
commit8cd63a64abafe21378c35c2489d49f24c9ece3c9 (patch)
tree541145481d1492f3e388002d931cb3f8fec0acb2 /src/client/elm/LoggedIn/Home
parent01e4ce0fa7c369996ec4ef3a033d16d6fa0eb715 (diff)
downloadbudget-8cd63a64abafe21378c35c2489d49f24c9ece3c9.tar.gz
budget-8cd63a64abafe21378c35c2489d49f24c9ece3c9.tar.bz2
budget-8cd63a64abafe21378c35c2489d49f24c9ece3c9.zip
Add income list CRUD in user page
Diffstat (limited to 'src/client/elm/LoggedIn/Home')
-rw-r--r--src/client/elm/LoggedIn/Home/Account/Action.elm14
-rw-r--r--src/client/elm/LoggedIn/Home/Account/Model.elm60
-rw-r--r--src/client/elm/LoggedIn/Home/Account/Update.elm49
-rw-r--r--src/client/elm/LoggedIn/Home/Account/View.elm108
-rw-r--r--src/client/elm/LoggedIn/Home/Action.elm2
-rw-r--r--src/client/elm/LoggedIn/Home/Model.elm3
-rw-r--r--src/client/elm/LoggedIn/Home/Update.elm9
-rw-r--r--src/client/elm/LoggedIn/Home/View/Date.elm59
-rw-r--r--src/client/elm/LoggedIn/Home/View/Monthly.elm4
-rw-r--r--src/client/elm/LoggedIn/Home/View/Price.elm37
-rw-r--r--src/client/elm/LoggedIn/Home/View/Table.elm6
11 files changed, 11 insertions, 340 deletions
diff --git a/src/client/elm/LoggedIn/Home/Account/Action.elm b/src/client/elm/LoggedIn/Home/Account/Action.elm
deleted file mode 100644
index 4ce3b20..0000000
--- a/src/client/elm/LoggedIn/Home/Account/Action.elm
+++ /dev/null
@@ -1,14 +0,0 @@
-module LoggedIn.Home.Account.Action
- ( Action(..)
- ) where
-
-import Time exposing (Time)
-
-import Model.User exposing (UserId)
-
-type Action =
- NoOp
- | ToggleDetail
- | ToggleIncomeEdition
- | UpdateIncomeEdition String
- | UpdateEditionError String
diff --git a/src/client/elm/LoggedIn/Home/Account/Model.elm b/src/client/elm/LoggedIn/Home/Account/Model.elm
deleted file mode 100644
index d04f865..0000000
--- a/src/client/elm/LoggedIn/Home/Account/Model.elm
+++ /dev/null
@@ -1,60 +0,0 @@
-module LoggedIn.Home.Account.Model
- ( Model
- , IncomeEdition
- , init
- , initIncomeEdition
- , getCurrentIncome
- , validateIncome
- ) where
-
-import Result as Result exposing (Result(..))
-import Dict
-import String
-
-import Utils.Dict exposing (mapValues)
-
-import Model.Translations exposing (..)
-import Model.Income exposing (..)
-import Model.User exposing (UserId)
-
-type alias Model =
- { visibleDetail : Bool
- , incomeEdition : Maybe IncomeEdition
- }
-
-init : Model
-init =
- { visibleDetail = False
- , incomeEdition = Nothing
- }
-
-getCurrentIncome : Incomes -> UserId -> Model -> Maybe Int
-getCurrentIncome incomes me account =
- incomes
- |> Dict.filter (\_ income -> income.userId == me)
- |> Dict.values
- |> List.sortBy .creation
- |> List.reverse
- |> List.head
- |> Maybe.map .amount
-
-type alias IncomeEdition =
- { income : String
- , error : Maybe String
- }
-
-initIncomeEdition : Int -> IncomeEdition
-initIncomeEdition income =
- { income = toString income
- , error = Nothing
- }
-
-validateIncome : String -> Translations -> Result String Int
-validateIncome amount translations =
- case String.toInt amount of
- Ok number ->
- if number > 0
- then Ok number
- else Err <| getMessage "IncomeMustBePositiveNumber" translations
- Err _ ->
- Err <| getMessage "IncomeRequired" translations
diff --git a/src/client/elm/LoggedIn/Home/Account/Update.elm b/src/client/elm/LoggedIn/Home/Account/Update.elm
deleted file mode 100644
index 59f1402..0000000
--- a/src/client/elm/LoggedIn/Home/Account/Update.elm
+++ /dev/null
@@ -1,49 +0,0 @@
-module LoggedIn.Home.Account.Update
- ( update
- ) where
-
-import Maybe
-
-import Effects exposing (Effects)
-
-import LoggedData exposing (LoggedData)
-
-import LoggedIn.Home.Account.Action as AccountAction
-import LoggedIn.Home.Account.Model as AccountModel
-
-import Utils.Maybe exposing (isJust)
-
-update : LoggedData -> AccountAction.Action -> AccountModel.Model -> (AccountModel.Model, Effects AccountAction.Action)
-update loggedData action account =
- case action of
-
- AccountAction.NoOp ->
- (account, Effects.none)
-
- AccountAction.ToggleDetail ->
- ( { account | visibleDetail = not account.visibleDetail }
- , Effects.none
- )
-
- AccountAction.ToggleIncomeEdition ->
- ( { account | incomeEdition =
- if isJust account.incomeEdition
- then Nothing
- else Just (AccountModel.initIncomeEdition (Maybe.withDefault 0 (AccountModel.getCurrentIncome loggedData.incomes loggedData.me account)))
- }
- , Effects.none
- )
-
- AccountAction.UpdateIncomeEdition income ->
- ( case account.incomeEdition of
- Nothing -> account
- Just incomeEdition -> { account | incomeEdition = Just { incomeEdition | income = income } }
- , Effects.none
- )
-
- AccountAction.UpdateEditionError error ->
- ( case account.incomeEdition of
- Nothing -> account
- Just incomeEdition -> { account | incomeEdition = Just { incomeEdition | error = Just error } }
- , Effects.none
- )
diff --git a/src/client/elm/LoggedIn/Home/Account/View.elm b/src/client/elm/LoggedIn/Home/Account/View.elm
index a7d3e0c..63fb997 100644
--- a/src/client/elm/LoggedIn/Home/Account/View.elm
+++ b/src/client/elm/LoggedIn/Home/Account/View.elm
@@ -2,61 +2,26 @@ module LoggedIn.Home.Account.View
( view
) where
-import List
-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
import LoggedIn.Home.Model as HomeModel
import LoggedIn.Home.Model.Payer exposing (..)
-import LoggedIn.Home.View.Price exposing (price)
-import LoggedIn.Home.View.Expand exposing (..)
-
-import LoggedIn.Home.Account.Action as AccountAction
-import LoggedIn.Home.Account.Model as AccountModel
+import LoggedIn.View.Price exposing (price)
import Model exposing (Model)
import Model.User exposing (getUserName)
-import Model.Translations exposing (getParamMessage, getMessage)
-import Action
-import Mailbox
-
-import View.Events exposing (onSubmitPrevDefault)
-
-import Utils.Either exposing (toMaybeError)
view : LoggedData -> HomeModel.Model -> Html
view loggedData homeModel =
- let account = homeModel.account
- in div
- [ classList
- [ ("account", True)
- , ("detail", account.visibleDetail)
- ]
- ]
- [ exceedingPayers loggedData homeModel
- , if account.visibleDetail
- then income loggedData account
- else text ""
- ]
-
-exceedingPayers : LoggedData -> HomeModel.Model -> Html
-exceedingPayers loggedData homeModel =
- button
- [ class "header"
- , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount <| AccountAction.ToggleDetail)
+ div
+ [ class "account" ]
+ [ div
+ [ class "header" ]
+ (List.map (exceedingPayer loggedData homeModel) (getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes loggedData.payments))
]
- ( (List.map (exceedingPayer loggedData homeModel) (getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes loggedData.payments))
- ++ [ expand ExpandDown homeModel.account.visibleDetail ]
- )
exceedingPayer : LoggedData -> HomeModel.Model -> ExceedingPayer -> Html
exceedingPayer loggedData homeModel payer =
@@ -73,64 +38,3 @@ exceedingPayer loggedData homeModel payer =
[ class "amount" ]
[ text ("+ " ++ (price loggedData.conf payer.amount)) ]
]
-
-income : LoggedData -> AccountModel.Model -> Html
-income loggedData account =
- case account.incomeEdition of
- Nothing ->
- incomeRead loggedData account
- Just edition ->
- incomeEdition loggedData account edition
-
-incomeRead : LoggedData -> AccountModel.Model -> Html
-incomeRead loggedData account =
- div
- [ class "income" ]
- [ ( case AccountModel.getCurrentIncome loggedData.incomes loggedData.me account of
- Nothing ->
- text (getMessage "NoIncome" loggedData.translations)
- Just income ->
- text (getParamMessage [price loggedData.conf income] "Income" loggedData.translations)
- )
- , toggleIncomeEdition loggedData "editIncomeEdition" (getMessage "Edit" loggedData.translations)
- ]
-
-incomeEdition : LoggedData -> AccountModel.Model -> AccountModel.IncomeEdition -> Html
-incomeEdition loggedData account edition =
- H.form
- [ case AccountModel.validateIncome edition.income loggedData.translations of
- Ok validatedAmount ->
- onSubmitPrevDefault Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.UpdateIncome validatedAmount)
- Err error ->
- onSubmitPrevDefault Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount << AccountAction.UpdateEditionError <| error)
- , class "income"
- ]
- [ label
- [ for "incomeInput" ]
- [ text (getMessage "NewIncome" loggedData.translations) ]
- , input
- [ id "incomeInput"
- , value edition.income
- , on "input" targetValue (Signal.message Mailbox.address << Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount << AccountAction.UpdateIncomeEdition)
- , maxlength 10
- ]
- []
- , button
- [ type' "submit"
- , class "validateIncomeEdition"
- ]
- [ 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 : LoggedData -> String -> String -> Html
-toggleIncomeEdition loggedData className name =
- button
- [ type' "button"
- , class className
- , onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount <| AccountAction.ToggleIncomeEdition)
- ]
- [ text name ]
diff --git a/src/client/elm/LoggedIn/Home/Action.elm b/src/client/elm/LoggedIn/Home/Action.elm
index 7db705d..1590fb8 100644
--- a/src/client/elm/LoggedIn/Home/Action.elm
+++ b/src/client/elm/LoggedIn/Home/Action.elm
@@ -4,13 +4,11 @@ module LoggedIn.Home.Action
import Model.Payment exposing (PaymentId)
-import LoggedIn.Home.Account.Action as AccountAction
import LoggedIn.Home.AddPayment.Action as AddPaymentAction
type Action =
NoOp
| UpdateAdd AddPaymentAction.Action
- | UpdateAccount AccountAction.Action
| ToggleEdit PaymentId
| UpdatePage Int
| ShowMonthlyDetail
diff --git a/src/client/elm/LoggedIn/Home/Model.elm b/src/client/elm/LoggedIn/Home/Model.elm
index cd8b4d0..26af63c 100644
--- a/src/client/elm/LoggedIn/Home/Model.elm
+++ b/src/client/elm/LoggedIn/Home/Model.elm
@@ -8,12 +8,10 @@ import LoggedIn.Home.Model.Payer exposing (Payers)
import Model.User exposing (Users, UserId)
import Model.Payment exposing (PaymentId, Payments, Frequency(..))
-import LoggedIn.Home.Account.Model as AccountModel
import LoggedIn.Home.AddPayment.Model as AddPaymentModel
type alias Model =
{ add : AddPaymentModel.Model
- , account : AccountModel.Model
, paymentEdition : Maybe PaymentId
, currentPage : Int
, monthlyDetail : Bool
@@ -22,7 +20,6 @@ type alias Model =
init : Model
init =
{ add = AddPaymentModel.init Punctual
- , account = AccountModel.init
, paymentEdition = Nothing
, currentPage = 1
, monthlyDetail = False
diff --git a/src/client/elm/LoggedIn/Home/Update.elm b/src/client/elm/LoggedIn/Home/Update.elm
index b43ebb7..cebdc70 100644
--- a/src/client/elm/LoggedIn/Home/Update.elm
+++ b/src/client/elm/LoggedIn/Home/Update.elm
@@ -9,9 +9,6 @@ import LoggedData exposing (LoggedData)
import LoggedIn.Home.Action as HomeAction
import LoggedIn.Home.Model as HomeModel
-import LoggedIn.Home.Account.Action as AccountAction
-import LoggedIn.Home.Account.Update as AccountUpdate
-
import LoggedIn.Home.AddPayment.Update as AddPaymentUpdate
update : LoggedData -> HomeAction.Action -> HomeModel.Model -> (HomeModel.Model, Effects HomeAction.Action)
@@ -25,12 +22,6 @@ update loggedData action homeModel =
, Effects.none
)
- HomeAction.UpdateAccount accountAction ->
- let (newAccount, accountEffects) = AccountUpdate.update loggedData accountAction homeModel.account
- in ( { homeModel | account = newAccount }
- , Effects.map HomeAction.UpdateAccount accountEffects
- )
-
HomeAction.ToggleEdit id ->
( { homeModel | paymentEdition = if homeModel.paymentEdition == Just id then Nothing else Just id }
, Effects.none
diff --git a/src/client/elm/LoggedIn/Home/View/Date.elm b/src/client/elm/LoggedIn/Home/View/Date.elm
deleted file mode 100644
index 2cc55fe..0000000
--- a/src/client/elm/LoggedIn/Home/View/Date.elm
+++ /dev/null
@@ -1,59 +0,0 @@
-module LoggedIn.Home.View.Date
- ( renderShortDate
- , renderLongDate
- ) where
-
-import Date exposing (..)
-import String
-
-import Model.Translations exposing (..)
-
-renderShortDate : Date -> Translations -> String
-renderShortDate date translations =
- let params =
- [ String.pad 2 '0' (toString (Date.day date))
- , String.pad 2 '0' (toString (getMonthNumber (Date.month date)))
- , toString (Date.year date)
- ]
- in getParamMessage params "ShortDate" translations
-
-renderLongDate : Date -> Translations -> String
-renderLongDate date translations =
- let params =
- [ toString (Date.day date)
- , (getMessage (getMonthKey (Date.month date)) translations)
- , toString (Date.year date)
- ]
- in getParamMessage params "LongDate" translations
-
-getMonthNumber : Month -> Int
-getMonthNumber month =
- case month of
- Jan -> 1
- Feb -> 2
- Mar -> 3
- Apr -> 4
- May -> 5
- Jun -> 6
- Jul -> 7
- Aug -> 8
- Sep -> 9
- Oct -> 10
- Nov -> 11
- Dec -> 12
-
-getMonthKey : Month -> String
-getMonthKey month =
- case month of
- Jan -> "January"
- Feb -> "February"
- Mar -> "March"
- Apr -> "April"
- May -> "May"
- Jun -> "June"
- Jul -> "July"
- Aug -> "August"
- Sep -> "September"
- Oct -> "October"
- Nov -> "November"
- Dec -> "December"
diff --git a/src/client/elm/LoggedIn/Home/View/Monthly.elm b/src/client/elm/LoggedIn/Home/View/Monthly.elm
index aa0e3a5..c001331 100644
--- a/src/client/elm/LoggedIn/Home/View/Monthly.elm
+++ b/src/client/elm/LoggedIn/Home/View/Monthly.elm
@@ -12,7 +12,7 @@ import LoggedIn.Action as LoggedInAction
import LoggedIn.Home.Action as HomeAction
import LoggedIn.Home.Model as HomeModel
-import LoggedIn.Home.View.Price exposing (price)
+import LoggedIn.View.Price exposing (price)
import LoggedIn.Home.View.Expand exposing (..)
import Model.Payment as Payment exposing (Payments, Payment, monthly)
@@ -84,7 +84,7 @@ paymentLine loggedData homeModel payment =
[ text (price loggedData.conf payment.cost) ]
, div
[ class "cell delete"
- , onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeletePayment payment Payment.Monthly)
+ , onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeletePayment payment.id)
]
[ button [] [ renderIcon "times" ]
]
diff --git a/src/client/elm/LoggedIn/Home/View/Price.elm b/src/client/elm/LoggedIn/Home/View/Price.elm
deleted file mode 100644
index 2e208f9..0000000
--- a/src/client/elm/LoggedIn/Home/View/Price.elm
+++ /dev/null
@@ -1,37 +0,0 @@
-module LoggedIn.Home.View.Price
- ( price
- ) where
-
-import String exposing (..)
-
-import Model.Conf exposing (Conf)
-
-price : Conf -> Int -> String
-price conf amount =
- ( formatInt amount
- ++ " "
- ++ conf.currency
- )
-
-formatInt : Int -> String
-formatInt n =
- abs n
- |> toString
- |> toList
- |> List.reverse
- |> group 3
- |> List.intersperse [' ']
- |> List.concat
- |> List.reverse
- |> fromList
- |> append (if n < 0 then "-" else "")
-
-group : Int -> List a -> List (List a)
-group n xs =
- if List.length xs <= n
- then
- [xs]
- else
- let take = List.take n xs
- drop = List.drop n xs
- in take :: (group n drop)
diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm
index 1d69fb9..71aa4e5 100644
--- a/src/client/elm/LoggedIn/Home/View/Table.elm
+++ b/src/client/elm/LoggedIn/Home/View/Table.elm
@@ -16,8 +16,8 @@ import LoggedIn.Action as LoggedInAction
import LoggedIn.Home.Action as HomeAction
import LoggedIn.Home.Model as HomeModel
-import LoggedIn.Home.View.Date exposing (..)
-import LoggedIn.Home.View.Price exposing (price)
+import LoggedIn.View.Date exposing (..)
+import LoggedIn.View.Price exposing (price)
import Model.User exposing (getUserName)
import Model.Payment as Payment exposing (..)
@@ -90,7 +90,7 @@ paymentLine loggedData homeModel payment =
div
[ class "cell delete" ]
[ button
- [ onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeletePayment payment Punctual)]
+ [ onClick Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.DeletePayment payment.id)]
[ renderIcon "times" ]
]
else