From 0075abf51db5d1b54117525d7a7f9b06e31c9484 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Tue, 17 Mar 2015 21:26:40 +0100 Subject: Adding an edition mode for a timer --- src/View/ActivatedClasses.elm | 15 +++++++++++++++ src/View/Timer.elm | 28 +++++++++++++++++++++++----- src/View/View.elm | 8 ++++---- 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 src/View/ActivatedClasses.elm (limited to 'src/View') diff --git a/src/View/ActivatedClasses.elm b/src/View/ActivatedClasses.elm new file mode 100644 index 0000000..9594448 --- /dev/null +++ b/src/View/ActivatedClasses.elm @@ -0,0 +1,15 @@ +module View.ActivatedClasses + ( activatedClasses + ) where + +import Html +import Html.Attributes (..) +import List +import String + +activatedClasses : List (Bool, String) -> Html.Attribute +activatedClasses = + class + << String.concat + << List.intersperse " " + << List.filterMap (\(activated, str) -> if activated then Just str else Nothing) diff --git a/src/View/Timer.elm b/src/View/Timer.elm index 6925e42..5ec5d02 100644 --- a/src/View/Timer.elm +++ b/src/View/Timer.elm @@ -8,23 +8,41 @@ import Html.Events (..) import String import Time (Time) import Signal +import Maybe +import Model.Model (..) import Model.Timer (..) import Model.Id (..) import Update.Update (..) import Update.UpdateTimer (..) -timerView : (Id, Timer) -> Html -timerView (id, timer) = +import View.ActivatedClasses (..) + +timerView : Model -> (Id, Timer) -> Html +timerView model (id, timer) = div [ class <| "timer" ++ (if timer.isRunning then " isRunning" else "") ] [ button [ class "name block" ] [ text timer.name ] - , button - [ class <| "time block" ] - [ text (timeView timer.currentTime) ] + , let inEdition = + model.timerEdition + |> Maybe.map (\te -> te.id == id) + |> Maybe.withDefault False + in button + ( [ [ (True, "time block") + , (inEdition, "edition") + ] + |> activatedClasses + ] + ++ if inEdition + then + [] + else + [ onClick (Signal.send updates (EditTimer id)) ] + ) + [ text (timeView timer.currentTime) ] , button [ class <| "restart block" , onClick (Signal.send updates (UpdateTimer id Restart)) diff --git a/src/View/View.elm b/src/View/View.elm index f915952..8da1316 100644 --- a/src/View/View.elm +++ b/src/View/View.elm @@ -28,7 +28,7 @@ view model = |> Dict.toList |> List.sortBy (.creationTime << snd) |> List.reverse - |> timers + |> timers model ] title : Html @@ -56,8 +56,8 @@ is13 code = then Ok() else Err "Not the right key code" -timers : List (Id, Timer) -> Html -timers timers = +timers : Model -> List (Id, Timer) -> Html +timers model timers = div [ class "timers" ] - (List.map timerView timers) + (List.map (timerView model) timers) -- cgit v1.2.3