aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home/View
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/LoggedIn/Home/View')
-rw-r--r--src/client/elm/LoggedIn/Home/View/Paging.elm74
-rw-r--r--src/client/elm/LoggedIn/Home/View/Table.elm42
2 files changed, 67 insertions, 49 deletions
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" ]