aboutsummaryrefslogtreecommitdiff
path: root/src/client/View/Page.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-07-18 18:29:46 +0200
committerJoris Guyonvarch2015-07-18 18:29:46 +0200
commit3486644b442a0800f645ec9ae7f3ce8fe2b3c9cd (patch)
tree07cf31c37b09a2cb8bcb04380b91a640727888df /src/client/View/Page.elm
parentb27a7914993f5a5a87160dc33431a6fa1f4ad323 (diff)
downloadbudget-3486644b442a0800f645ec9ae7f3ce8fe2b3c9cd.tar.gz
budget-3486644b442a0800f645ec9ae7f3ce8fe2b3c9cd.tar.bz2
budget-3486644b442a0800f645ec9ae7f3ce8fe2b3c9cd.zip
Showing either the payment table or a forbidden message in the UI
Diffstat (limited to 'src/client/View/Page.elm')
-rw-r--r--src/client/View/Page.elm62
1 files changed, 45 insertions, 17 deletions
diff --git a/src/client/View/Page.elm b/src/client/View/Page.elm
index 73afed9..777655c 100644
--- a/src/client/View/Page.elm
+++ b/src/client/View/Page.elm
@@ -18,31 +18,59 @@ import Model.Payment exposing (Payments, Payment)
renderPage : Model -> Html
renderPage model =
+ div
+ []
+ [ renderHeader
+ , renderMain model
+ ]
+
+renderHeader : Html
+renderHeader =
header
[]
[ h1
[]
[ text "Payments" ]
- , table
- []
- ([ tr
- []
- [ th [] [ text "Utilisateur" ]
- , th [] [ text "Nom" ]
- , th [] [ text "Prix" ]
- , th [] [ text "Date" ]
- ]
- ] ++ (List.map renderPayment model.payments))
]
-renderPayments : Payments -> List Html
-renderPayments =
- List.map renderPayment
- << List.reverse
- << List.sortBy (Date.toTime << .creation)
+renderMain : Model -> Html
+renderMain model =
+ if model.forbiddenAccess
+ then
+ forbiddenAccess
+ else
+ model.payments
+ |> Maybe.map paymentTable
+ |> Maybe.withDefault loadingTable
+
+forbiddenAccess : Html
+forbiddenAccess = text "Forbidden access"
+
+loadingTable : Html
+loadingTable = text ""
+
+paymentTable : Payments -> Html
+paymentTable payments =
+ table
+ []
+ ([ tr
+ []
+ [ th [] [ text "Utilisateur" ]
+ , th [] [ text "Nom" ]
+ , th [] [ text "Prix" ]
+ , th [] [ text "Date" ]
+ ]
+ ] ++ (paymentLines payments))
+
+paymentLines : Payments -> List Html
+paymentLines payments =
+ payments
+ |> List.sortBy (Date.toTime << .creation)
+ |> List.reverse
+ |> List.map paymentLine
-renderPayment : Payment -> Html
-renderPayment payment =
+paymentLine : Payment -> Html
+paymentLine payment =
tr
[]
[ td [] [ text payment.name ]