-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathViews.elm
134 lines (115 loc) · 3.59 KB
/
Views.elm
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module Client.StartTakeHome.Views (..) where
import Html exposing (..)
import Html.Attributes exposing (src, for, id, type', name, action, method, enctype, attribute, href)
import Html.Tags exposing (style, stylesheetLink)
import String
import Client.Components exposing (..)
import Shared.Test exposing (..)
import Shared.User exposing (..)
import Shared.Routes exposing (..)
import Client.Styles exposing (..)
import Client.StartTakeHome.Update exposing (Action)
import Client.StartTakeHome.Model exposing (Model)
import Moment exposing (emptyMoment, Moment)
beforeTestWelcome : User -> TestEntry -> Html
beforeTestWelcome user test =
div
[]
[ stylesheetLink assets.start.route
, img
[ src assets.noredinkLogo.route ]
[]
, form
[ class Welcome
, action routes.startTest
, method "POST"
, enctype "multipart/form-data"
]
[ div
[ class WelcomeMessageName ]
[ text user.name ]
, div
[ class WelcomeTestName ]
[ text <| test.name ]
, hiddenTokenField user.token
, button
[ class Button ]
[ text "Start the take home" ]
]
]
viewTestLink : TestEntry -> Html
viewTestLink test =
div
[]
[ a
[ href test.item ]
[ text "Click here to read the test contents!" ]
]
viewTestFile : TestEntry -> Html
viewTestFile test =
let
justFileName =
case List.reverse (String.indexes "/" test.item) of
[] ->
test.item
x :: _ ->
String.dropLeft (x + 1) test.item
in
div
[]
[ a
[ href test.item
, attribute "download" justFileName
]
[ text "Click here to download the test content!" ]
]
viewUploadSolution : User -> Html
viewUploadSolution user =
form
[ action routes.apply
, method "POST"
, enctype "multipart/form-data"
]
[ fileField
, hiddenTokenField <| Debug.log "user token" user.token
, submitField
]
viewTimeStarted : Moment -> User -> Html
viewTimeStarted currentTime user =
case user.startTime of
Nothing ->
div [] [ text "Not started yet!" ]
Just time ->
let
withTwoHours =
{ emptyMoment | hours = 2 }
endTime =
Moment.add time withTwoHours
timeLeft =
Moment.from endTime currentTime
in
div
[]
[ text <| "Started at " ++ (Moment.formatString "h:mm:ss a" time)
, text <| "End time" ++ (Moment.formatString "h:mm:ss a" endTime)
, text <| "You should submit your solution " ++ timeLeft
]
viewTakeHome : Signal.Address Action -> Model -> Html
viewTakeHome address model =
let
testView =
case model.test.itemType of
TestLink ->
viewTestLink model.test
TestFile ->
viewTestFile model.test
NoTest ->
text "Failed to find your test"
in
div
[]
[ stylesheetLink assets.main.route
, testView
, viewUploadSolution model.user
, viewTimeStarted model.currentTime model.user
]