diff options
Diffstat (limited to 'src/View/Timer.elm')
-rw-r--r-- | src/View/Timer.elm | 120 |
1 files changed, 78 insertions, 42 deletions
diff --git a/src/View/Timer.elm b/src/View/Timer.elm index 604b045..100514a 100644 --- a/src/View/Timer.elm +++ b/src/View/Timer.elm @@ -5,15 +5,17 @@ module View.Timer import Html (..) import Html.Attributes (..) import Html.Events (..) -import String import Time (Time) import Signal import Maybe import List +import String import Model.Model (..) import Model.Timer (..) -import Model.TimerEdition (..) +import Model.Edition.Edition (..) +import Model.Edition.NameEdition (..) +import Model.Edition.TimeEdition (..) import Model.TimerState (..) import Model.Id (..) @@ -28,54 +30,75 @@ timerView : Model -> (Id, Timer) -> Html timerView model (id, timer) = div [ class "timer" ] - [ nameBlock (id, timer) - , timeBlock model (id, timer) + [ renderMaybeEdition model id Name (nameBlockReadOnly id timer) (nameBlockEdition id timer) + , renderMaybeEdition model id Time (timeBlockReadOnly id timer) (timeBlockEdition timer) , playPauseBlock (id, timer) , stopBlock (id, timer) , removeBlock (id, timer) ] -nameBlock : (Id, Timer) -> Html -nameBlock (id, timer) = +nameBlockReadOnly : Id -> Timer -> Html +nameBlockReadOnly id timer = button - [ class "name block" ] - [ text timer.name ] + [ class "name block" + , onClick (Signal.send updates (Edit id Name)) + ] + [ text (timerName id timer) ] -timeBlock : Model -> (Id, Timer) -> Html -timeBlock model (id, timer) = - let maybeEdition = filterMaybe (\te -> te.id == id) model.timerEdition - in case maybeEdition of - Just edition -> - let isEmptyEdition = List.isEmpty edition.numbers - in button - [ [ (True, "time block edition") - , (isEmptyEdition, "empty") - ] - |> activatedClasses - , onClick (Signal.send updates ValidTimerEdition) - ] - [ if isEmptyEdition - then - timeWithProgressBar timer - else - text (editionView edition.numbers) - ] +nameBlockEdition : Id -> Timer -> Edition -> Html +nameBlockEdition id timer edition = + button + [ [ (True, "name block edition") + , (List.isEmpty edition.chars, "empty") + ] + |> activatedClasses + , onClick (Signal.send updates ValidEdition) + ] + [ if List.isEmpty edition.chars + then + text (timerName id timer) + else + edition.chars + |> renderNameEdition + |> text + ] - Nothing -> - button - [ [ (True, "time block") - , (timer.state == Ringing, "isRinging") - , (timer.state == Running, "isRunning") - ] - |> activatedClasses - , onClick - <| if timer.state == Ringing - then Signal.send updates (UpdateTimer id Stop) - else Signal.send updates (EditTimer id) - ] - [ timeWithProgressBar timer ] - -editionView : Numbers -> String +timerName : Id -> Timer -> String +timerName id = Maybe.withDefault ("Timer " ++ toString id) << .name + +timeBlockReadOnly : Id -> Timer -> Html +timeBlockReadOnly id timer = + button + [ [ (True, "time block") + , (timer.state == Ringing, "isRinging") + , (timer.state == Running, "isRunning") + ] + |> activatedClasses + , onClick + <| if timer.state == Ringing + then Signal.send updates (UpdateTimer id Stop) + else Signal.send updates (Edit id Time) + ] + [ timeWithProgressBar timer ] + +timeBlockEdition : Timer -> Edition -> Html +timeBlockEdition timer edition = + let isEmptyEdition = List.isEmpty edition.chars + in button + [ [ (True, "time block edition") + , (isEmptyEdition, "empty") + ] + |> activatedClasses + , onClick (Signal.send updates ValidEdition) + ] + [ if isEmptyEdition + then + timeWithProgressBar timer + else + text (editionView edition.chars) + ] + +editionView : List Char -> String editionView numbers = let (minutes, seconds) = toMinutesAndSeconds numbers in minutes ++ " : " ++ seconds @@ -134,3 +157,16 @@ removeBlock (id, timer) = , onClick (Signal.send updates (RemoveTimer id)) ] [ i [ class "fa fa-fw fa-remove" ] [] ] + +renderMaybeEdition : Model -> Id -> Kind -> Html -> (Edition -> Html) -> Html +renderMaybeEdition model id kind readOnlyView editionView = + let maybeEdition = filterMaybe (\edition -> edition.id == id) model.edition + in case maybeEdition of + Just edition -> + if edition.kind == kind + then + editionView edition + else + readOnlyView + Nothing -> + readOnlyView |