module View.Timer ( timerView ) where import Html (..) import Html.Attributes (..) import Html.Events (..) import String import Time (Time) import Signal import Maybe import Model.Model (..) import Model.Timer (..) import Model.TimerEdition (..) import Model.Id (..) import Update.Update (..) import Update.UpdateTimer (..) import View.ActivatedClasses (..) import Utils.Maybe (..) 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 ] , let maybeEdition = filterMaybe (\te -> te.id == id) model.timerEdition in case maybeEdition of Just edition -> button [ class "time block edition" , onClick (Signal.send updates ValidTimerEdition) ] [ text (editionView edition.numbers) ] Nothing -> button [ class "time block" , onClick (Signal.send updates (EditTimer id)) ] [ text (timeView timer.currentTime) ] , button [ class <| "restart block" , onClick (Signal.send updates (UpdateTimer id Restart)) ] [ i [ class "fa fa-fw fa-backward" ] [] ] , button [ class <| "playPause block" , onClick (Signal.send updates (UpdateTimer id ToggleRunning)) ] [ let icon = if timer.isRunning then "fa-pause" else "fa-play" in i [ class <| "fa fa-fw " ++ icon ] [] ] , button [ class <| "stop block" , onClick (Signal.send updates (UpdateTimer id Stop)) ] [ i [ class "fa fa-fw fa-stop" ] [] ] , button [ class <| "remove block" , onClick (Signal.send updates (RemoveTimer id)) ] [ i [ class "fa fa-fw fa-remove" ] [] ] ] editionView : Numbers -> String editionView numbers = let (minutes, seconds) = toMinutesAndSeconds numbers in minutes ++ " : " ++ seconds 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))