aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home
diff options
context:
space:
mode:
authorJoris2017-03-24 09:21:06 +0000
committerJoris2017-03-24 09:21:06 +0000
commitc0ac16a713c4e53cf6af8e72a6d5f6b8ac5d6456 (patch)
tree8a438430cee7411259fc395d8f3898488e85d750 /src/client/elm/LoggedIn/Home
parent293eb8295162bf0a038f488237db9c9d1316c04d (diff)
parentcfca18262c1ff48dcb683ddab7d03cf8e55573ff (diff)
Merge branch 'features/categories' into 'master'
Features/categories See merge request !1
Diffstat (limited to 'src/client/elm/LoggedIn/Home')
-rw-r--r--src/client/elm/LoggedIn/Home/Header/View.elm7
-rw-r--r--src/client/elm/LoggedIn/Home/Model.elm15
-rw-r--r--src/client/elm/LoggedIn/Home/Update.elm4
-rw-r--r--src/client/elm/LoggedIn/Home/View.elm21
-rw-r--r--src/client/elm/LoggedIn/Home/View/Paging.elm74
-rw-r--r--src/client/elm/LoggedIn/Home/View/Table.elm42
6 files changed, 91 insertions, 72 deletions
diff --git a/src/client/elm/LoggedIn/Home/Header/View.elm b/src/client/elm/LoggedIn/Home/Header/View.elm
index b67fb3b..3f8a320 100644
--- a/src/client/elm/LoggedIn/Home/Header/View.elm
+++ b/src/client/elm/LoggedIn/Home/Header/View.elm
@@ -5,7 +5,6 @@ module LoggedIn.Home.Header.View exposing
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
-import Html.App as Html
import String
import Dict
import Date
@@ -32,8 +31,6 @@ import LoggedIn.Home.View.ExceedingPayers as ExceedingPayers
import LoggedIn.View.Format as Format
import View.Plural exposing (plural)
-import Utils.Tuple as Tuple
-
view : LoggedData -> Home.Model -> Payments -> Frequency -> Html Msg
view loggedData { search } payments frequency =
let currentDate = Date.fromTime loggedData.currentTime
@@ -90,9 +87,9 @@ paymentsPartition loggedData payments =
", "
( loggedData.users
|> Dict.toList
- |> List.map (Tuple.mapFst (\userId -> Payment.totalPayments (always True) userId payments))
+ |> List.map (Tuple.mapFirst (\userId -> Payment.totalPayments (always True) userId payments))
|> List.filter (\(sum, _) -> sum > 0)
- |> List.sortBy fst
+ |> List.sortBy Tuple.first
|> List.reverse
|> List.map (\(sum, user) ->
getParamMessage [ user.name, Format.price loggedData.conf sum ] loggedData.translations "By"
diff --git a/src/client/elm/LoggedIn/Home/Model.elm b/src/client/elm/LoggedIn/Home/Model.elm
index caedc29..ace1593 100644
--- a/src/client/elm/LoggedIn/Home/Model.elm
+++ b/src/client/elm/LoggedIn/Home/Model.elm
@@ -3,6 +3,7 @@ module LoggedIn.Home.Model exposing
, Search
, init
, searchInitial
+ , validation
)
import Form exposing (Form)
@@ -26,14 +27,14 @@ type alias Search =
init : Model
init =
{ currentPage = 1
- , search = Form.initial (searchInitial Punctual) searchValidation
+ , search = Form.initial (searchInitial Punctual) validation
}
searchInitial : Frequency -> List (String, Field)
-searchInitial frequency = [ ("frequency", Field.Radio (toString frequency)) ]
+searchInitial frequency = [ ("frequency", Field.string (toString frequency)) ]
-searchValidation : Validation String Search
-searchValidation =
- Validate.form2 Search
- (Validate.get "name" (Validate.maybe Validate.string))
- (Validate.get "frequency" Payment.validateFrequency)
+validation : Validation String Search
+validation =
+ Validate.map2 Search
+ (Validate.field "name" (Validate.maybe Validate.string))
+ (Validate.field "frequency" Payment.validateFrequency)
diff --git a/src/client/elm/LoggedIn/Home/Update.elm b/src/client/elm/LoggedIn/Home/Update.elm
index d1a3239..b0ce256 100644
--- a/src/client/elm/LoggedIn/Home/Update.elm
+++ b/src/client/elm/LoggedIn/Home/Update.elm
@@ -25,10 +25,10 @@ update loggedData msg model =
Home.SearchMsg formMsg ->
( { model
- | search = Form.update formMsg model.search
+ | search = Form.update Home.validation formMsg model.search
, currentPage =
case formMsg of
- Form.Input "name" _ -> 1
+ Form.Input "name" _ _ -> 1
_ -> model.currentPage
}
, Cmd.none
diff --git a/src/client/elm/LoggedIn/Home/View.elm b/src/client/elm/LoggedIn/Home/View.elm
index 0def64e..0b90e67 100644
--- a/src/client/elm/LoggedIn/Home/View.elm
+++ b/src/client/elm/LoggedIn/Home/View.elm
@@ -2,23 +2,22 @@ module LoggedIn.Home.View exposing
( view
)
+import Date
import Html exposing (..)
import Html.Attributes exposing (..)
-import Date
import Form
import Utils.Form as Form
-import Msg exposing (Msg)
-
import LoggedData exposing (LoggedData)
-import Model.Payment as Payment exposing (Frequency(..))
-
-import LoggedIn.Home.Model as Home
import LoggedIn.Home.Header.View as Header
-
-import LoggedIn.Home.View.Table as Table
+import LoggedIn.Home.Model as Home
+import LoggedIn.Home.Msg as HomeMsg
import LoggedIn.Home.View.Paging as Paging
+import LoggedIn.Home.View.Table as Table
+import LoggedIn.Msg as LoggedInMsg
+import Model.Payment as Payment exposing (Frequency(..))
+import Msg exposing (Msg)
view : LoggedData -> Home.Model -> Html Msg
view loggedData home =
@@ -31,5 +30,9 @@ view loggedData home =
[ class "home" ]
[ Header.view loggedData home payments frequency
, Table.view loggedData home payments frequency
- , Paging.view home payments
+ , Paging.view
+ home.currentPage
+ (List.length payments)
+ Msg.NoOp
+ (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage)
]
diff --git a/src/client/elm/LoggedIn/Home/View/Paging.elm b/src/client/elm/LoggedIn/Home/View/Paging.elm
index 5bcb827..dffe061 100644
--- a/src/client/elm/LoggedIn/Home/View/Paging.elm
+++ b/src/client/elm/LoggedIn/Home/View/Paging.elm
@@ -10,31 +10,29 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
-import LoggedIn.Msg as LoggedInMsg
-
-import LoggedIn.Home.Msg as HomeMsg
-import LoggedIn.Home.Model as HomeModel
-
-import Msg exposing (Msg)
import LoggedData exposing (LoggedData)
import Model.Payment as Payment exposing (Payments, perPage)
showedPages : Int
showedPages = 5
-view : HomeModel.Model -> Payments -> Html Msg
-view homeModel payments =
- let maxPage = ceiling (toFloat (List.length payments) / toFloat perPage)
- pages = truncatePages homeModel.currentPage [1..maxPage]
+view : Int -> Int -> msg -> (Int -> msg) -> Html msg
+view currentPage payments noOp pageMsg =
+ let maxPage = ceiling (toFloat payments / toFloat perPage)
+ pages = truncatePages currentPage (List.range 1 maxPage)
in if maxPage <= 1
then
text ""
else
div
[ class "pages" ]
- ( [ firstPage homeModel, previousPage homeModel ]
- ++ ( List.map (paymentsPage homeModel) pages)
- ++ [ nextPage homeModel maxPage, lastPage homeModel maxPage ]
+ ( [ firstPage currentPage pageMsg
+ , previousPage currentPage noOp pageMsg
+ ]
+ ++ ( List.map (paymentsPage currentPage noOp pageMsg) pages)
+ ++ [ nextPage currentPage maxPage noOp pageMsg
+ , lastPage currentPage maxPage pageMsg
+ ]
)
truncatePages : Int -> List Int -> List Int
@@ -44,57 +42,57 @@ truncatePages currentPage pages =
showedRightPages = floor ((toFloat showedPages - 1) / 2)
truncatedPages =
if currentPage <= showedLeftPages then
- [1..showedPages]
+ (List.range 1 showedPages)
else if currentPage > totalPages - showedRightPages then
- [(totalPages - showedPages + 1)..totalPages]
+ (List.range (totalPages - showedPages + 1) totalPages)
else
- [(currentPage - showedLeftPages)..(currentPage + showedRightPages)]
+ (List.range (currentPage - showedLeftPages) (currentPage + showedRightPages))
in List.filter (flip List.member pages) truncatedPages
-firstPage : HomeModel.Model -> Html Msg
-firstPage homeModel =
+firstPage : Int -> (Int -> msg) -> Html msg
+firstPage currentPage pageMsg =
button
[ classList
[ ("page", True)
- , ("disable", homeModel.currentPage <= 1)
+ , ("disable", currentPage <= 1)
]
- , onClick (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| 1)
+ , onClick (pageMsg 1)
]
[ FontAwesome.fast_backward grey 13 ]
-previousPage : HomeModel.Model -> Html Msg
-previousPage homeModel =
+previousPage : Int -> msg -> (Int -> msg) -> Html msg
+previousPage currentPage noOp pageMsg =
button
[ class "page"
, onClick <|
- if homeModel.currentPage > 1
- then (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| homeModel.currentPage - 1)
- else Msg.NoOp
+ if currentPage > 1
+ then (pageMsg <| currentPage - 1)
+ else noOp
]
[ FontAwesome.backward grey 13 ]
-nextPage : HomeModel.Model -> Int -> Html Msg
-nextPage homeModel maxPage =
+nextPage : Int -> Int -> msg -> (Int -> msg) -> Html msg
+nextPage currentPage maxPage noOp pageMsg =
button
[ class "page"
, onClick <|
- if homeModel.currentPage < maxPage
- then (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| homeModel.currentPage + 1)
- else Msg.NoOp
+ if currentPage < maxPage
+ then (pageMsg <| currentPage + 1)
+ else noOp
]
[ FontAwesome.forward grey 13 ]
-lastPage : HomeModel.Model -> Int -> Html Msg
-lastPage homeModel maxPage =
+lastPage : Int -> Int -> (Int -> msg) -> Html msg
+lastPage currentPage maxPage pageMsg =
button
[ class "page"
- , onClick (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| maxPage)
+ , onClick (pageMsg maxPage)
]
[ FontAwesome.fast_forward grey 13 ]
-paymentsPage : HomeModel.Model -> Int -> Html Msg
-paymentsPage homeModel page =
- let onCurrentPage = page == homeModel.currentPage
+paymentsPage : Int -> msg -> (Int -> msg) -> Int -> Html msg
+paymentsPage currentPage noOp pageMsg page =
+ let onCurrentPage = page == currentPage
in button
[ classList
[ ("page", True)
@@ -102,8 +100,8 @@ paymentsPage homeModel page =
]
, onClick <|
if onCurrentPage
- then Msg.NoOp
- else Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage <| page
+ then noOp
+ else pageMsg page
]
[ text (toString page) ]
diff --git a/src/client/elm/LoggedIn/Home/View/Table.elm b/src/client/elm/LoggedIn/Home/View/Table.elm
index 6423bf9..8828488 100644
--- a/src/client/elm/LoggedIn/Home/View/Table.elm
+++ b/src/client/elm/LoggedIn/Home/View/Table.elm
@@ -2,8 +2,8 @@ module LoggedIn.Home.View.Table exposing
( view
)
-import Dict exposing (..)
import Date exposing (Date)
+import Dict exposing (..)
import String exposing (append)
import FontAwesome
@@ -26,12 +26,13 @@ import LoggedData exposing (LoggedData)
import LoggedIn.Msg as LoggedInMsg
import LoggedIn.Home.Model as Home
-import View.Date as Date
import LoggedIn.View.Format as Format
+import View.Date as Date
-import Model.User exposing (getUserName)
import Model.Payment as Payment exposing (..)
+import Model.PaymentCategory as PaymentCategory
import Model.Translations exposing (getMessage)
+import Model.User exposing (getUserName)
view : LoggedData -> Home.Model -> Payments -> Frequency -> Html Msg
view loggedData homeModel payments frequency =
@@ -60,6 +61,7 @@ headerLine loggedData frequency =
[ div [ class "cell category" ] [ text <| getMessage loggedData.translations "Name" ]
, div [ class "cell cost" ] [ text <| getMessage loggedData.translations "Cost" ]
, div [ class "cell user" ] [ text <| getMessage loggedData.translations "Payer" ]
+ , div [ class "cell user" ] [ text <| getMessage loggedData.translations "PaymentCategory" ]
, case frequency of
Punctual -> div [ class "cell date" ] [ text <| getMessage loggedData.translations "Date" ]
Monthly -> text ""
@@ -72,7 +74,7 @@ paymentLine : LoggedData -> Home.Model -> Frequency -> Payment -> Html Msg
paymentLine loggedData homeModel frequency payment =
div
[ class "row" ]
- [ div [ class "cell category" ] [ text payment.name ]
+ [ div [ class "cell name" ] [ text payment.name ]
, div
[ classList
[ ("cell cost", True)
@@ -87,6 +89,22 @@ paymentLine loggedData homeModel frequency payment =
|> Maybe.withDefault "−"
|> text
]
+ , div
+ [ class "cell category" ]
+ ( let mbCategory =
+ PaymentCategory.search payment.name loggedData.paymentCategories
+ |> Maybe.andThen (\category -> Dict.get category loggedData.categories)
+ in case mbCategory of
+ Just category ->
+ [ span
+ [ class "tag"
+ , style [("background-color", category.color)]
+ ]
+ [ text category.name ]
+ ]
+ Nothing ->
+ []
+ )
, case frequency of
Punctual ->
div
@@ -103,9 +121,10 @@ paymentLine loggedData homeModel frequency payment =
, div
[ class "cell button" ]
[ let currentDate = Date.fromTime loggedData.currentTime
+ category = PaymentCategory.search payment.name loggedData.paymentCategories
in AddPayment.button
loggedData
- (AddPayment.initialClone loggedData.translations currentDate payment)
+ (AddPayment.initialClone loggedData.translations currentDate category payment)
"ClonePayment"
(FontAwesome.clone Color.chestnutRose 18)
(Just (getMessage loggedData.translations "Clone"))
@@ -116,12 +135,13 @@ paymentLine loggedData homeModel frequency payment =
then
text ""
else
- AddPayment.button
- loggedData
- (AddPayment.initialEdit loggedData.translations payment)
- "EditPayment"
- (FontAwesome.pencil Color.chestnutRose 18)
- (Just (getMessage loggedData.translations "Edit"))
+ let category = PaymentCategory.search payment.name loggedData.paymentCategories
+ in AddPayment.button
+ loggedData
+ (AddPayment.initialEdit loggedData.translations category payment)
+ "EditPayment"
+ (FontAwesome.pencil Color.chestnutRose 18)
+ (Just (getMessage loggedData.translations "Edit"))
]
, div
[ class "cell button" ]