blob: 777655c7b1111aac345d8f93499f9486b6b72f9c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
module View.Page
( renderPage
) where
import Html exposing (..)
import Html as H
import Html.Attributes exposing (..)
import Html.Attributes as A
import Html.Events exposing (..)
import Date
import Date exposing (Date)
import String exposing (append)
import Model exposing (Model)
import Model.Payment exposing (Payments, Payment)
renderPage : Model -> Html
renderPage model =
div
[]
[ renderHeader
, renderMain model
]
renderHeader : Html
renderHeader =
header
[]
[ h1
[]
[ text "Payments" ]
]
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
paymentLine : Payment -> Html
paymentLine payment =
tr
[]
[ td [] [ text payment.name ]
, td [] [ text payment.userName ]
, td [] [ text (toString payment.cost) ]
, td [] [ text (renderDate payment.creation) ]
]
renderDate : Date -> String
renderDate date =
toString (Date.day date)
|> flip append (" " ++ (toString (Date.month date)))
|> flip append (" " ++ (toString (Date.year date)))
|