diff options
author | Joris Guyonvarch | 2015-03-16 00:15:05 +0100 |
---|---|---|
committer | Joris Guyonvarch | 2015-03-16 00:15:05 +0100 |
commit | cd3b37adebca99138fad1acca37908183036ace9 (patch) | |
tree | d566ae0564d82ab94901e4deda98f36abd22ad2d /src/View |
Initial commit, can create and name 5 minute timers, can toggle running state
Diffstat (limited to 'src/View')
-rw-r--r-- | src/View/Timer.elm | 37 | ||||
-rw-r--r-- | src/View/View.elm | 71 |
2 files changed, 108 insertions, 0 deletions
diff --git a/src/View/Timer.elm b/src/View/Timer.elm new file mode 100644 index 0000000..668bf08 --- /dev/null +++ b/src/View/Timer.elm @@ -0,0 +1,37 @@ +module View.Timer + ( timerView + ) where + +import Html (..) +import Html.Attributes (..) +import Html.Events (..) +import String +import Time (Time) +import Signal + +import Model.Timer (..) +import Model.Id (..) + +import Update.Update (..) +import Update.UpdateTimer (..) + +timerView : (Id, Timer) -> Html +timerView (id, timer) = + div + [ class "timer" ] + [ div + [ class "block" ] + [ text timer.name ] + , div + [ class <| "timerTime block" ++ (if timer.isRunning then " isRunning" else "") + , onClick (Signal.send updates (UpdateTimer id ToggleRunning)) + ] + [ text (timeView timer.time) ] + ] + +timeView : Time -> String +timeView time = + let totalSeconds = truncate (time / 1000) + totalMinutes = totalSeconds // 60 + restSeconds = totalSeconds `rem` 60 + in (toString totalMinutes) ++ ":" ++ (String.padLeft 2 '0' (toString restSeconds)) diff --git a/src/View/View.elm b/src/View/View.elm new file mode 100644 index 0000000..ae60807 --- /dev/null +++ b/src/View/View.elm @@ -0,0 +1,71 @@ +module View.View + ( view + ) where + +import Html (..) +import Html.Attributes (..) +import Html.Events (..) +import Signal +import List +import Dict +import Json.Decode as Json +import Debug + +import Model.Model (..) +import Model.Timer (..) +import Model.Id (..) + +import Update.Update (..) + +import View.Timer (timerView) + +view : Model -> Html +view model = + div + [] + [ h1 [] [ text "Timer" ] + , addTimer model.newTimerName + , model.timers + |> Dict.toList + |> List.sortBy (.creationTime << snd) + |> List.reverse + |> timers + ] + +addTimer : String -> Html +addTimer name = + div + [ class "addTimer" ] + [ input + [ placeholder "Name" + , value name + , on "input" targetValue (Signal.send updates << RenameNewTimer) + , onEnter (Signal.send updates AddNewTimer) + , autofocus True + ] + [] + , button + [ onClick (Signal.send updates AddNewTimer) ] + [ i + [ class "fa fa-fw fa-plus" ] + [] + ] + ] + +onEnter : Signal.Message -> Attribute +onEnter message = + on "keydown" + (Json.customDecoder keyCode is13) + (always message) + +is13 : Int -> Result String () +is13 code = + if code == 13 + then Ok() + else Err "Not the right key code" + +timers : List (Id, Timer) -> Html +timers timers = + div + [ class "timers" ] + (List.map timerView timers) |