diff options
author | Joris Guyonvarch | 2015-03-21 12:33:58 +0100 |
---|---|---|
committer | Joris Guyonvarch | 2015-03-21 12:33:58 +0100 |
commit | 9e6cf2f2f15b3fef1f99a2fcf980eb96945dc936 (patch) | |
tree | 3e460acb675bf1511baaaa603d1478f6464bba8a | |
parent | 11403e9e7a07494d72df0b225216c15724386aa8 (diff) |
Cannot delete a timer if it is the last one
-rw-r--r-- | design/design.css | 4 | ||||
-rw-r--r-- | src/Model/Model.elm | 5 | ||||
-rw-r--r-- | src/Update/Update.elm | 6 | ||||
-rw-r--r-- | src/View/Timer.elm | 20 |
4 files changed, 26 insertions, 9 deletions
diff --git a/design/design.css b/design/design.css index 681e770..159353c 100644 --- a/design/design.css +++ b/design/design.css @@ -87,6 +87,10 @@ color: #AA2222; } +.timers button.singleRemove { + color: grey; +} + .timer:not(last-child) { margin-bottom: 20px; } diff --git a/src/Model/Model.elm b/src/Model/Model.elm index b7ac48a..ad1e9da 100644 --- a/src/Model/Model.elm +++ b/src/Model/Model.elm @@ -2,11 +2,13 @@ module Model.Model ( Model , initialModel , substractTimersTime + , numberOfTimers ) where import Dict (Dict) import Dict import Time (Time) +import List import Model.Timer (..) import Model.TimerEdition (..) @@ -33,3 +35,6 @@ initialModel initialTime = substractTimersTime : Time -> Dict Id Timer -> Dict Id Timer substractTimersTime t timers = Dict.map (\id timer -> substractTimerTime t timer) timers + +numberOfTimers : Model -> Int +numberOfTimers = List.length << Dict.toList << .timers diff --git a/src/Update/Update.elm b/src/Update/Update.elm index c6c5f32..2cb45cb 100644 --- a/src/Update/Update.elm +++ b/src/Update/Update.elm @@ -76,7 +76,11 @@ update action model = Nothing -> { model | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers } RemoveTimer id -> - { model | timers <- Dict.remove id model.timers } + if numberOfTimers model > 1 + then + { model | timers <- Dict.remove id model.timers } + else + model EditTimer id -> { model | timerEdition <- Just (newTimerEdition id) diff --git a/src/View/Timer.elm b/src/View/Timer.elm index 2325d3a..9c302a4 100644 --- a/src/View/Timer.elm +++ b/src/View/Timer.elm @@ -37,7 +37,7 @@ timerView model (id, timer) = , restartBlock (id, timer) , playPauseBlock (id, timer) , stopBlock (id, timer) - , removeBlock (id, timer) + , removeBlock model (id, timer) ] nameBlock : (Id, Timer) -> Html @@ -105,13 +105,17 @@ stopBlock (id, timer) = ] [ i [ class "fa fa-fw fa-stop" ] [] ] -removeBlock : (Id, Timer) -> Html -removeBlock (id, timer) = - button - [ class <| "remove block" - , onClick (Signal.send updates (RemoveTimer id)) - ] - [ i [ class "fa fa-fw fa-remove" ] [] ] +removeBlock : Model -> (Id, Timer) -> Html +removeBlock model (id, timer) = + let removeClass = + if numberOfTimers model > 1 + then "remove" + else "singleRemove" + in button + [ class <| "block " ++ removeClass + , onClick (Signal.send updates (RemoveTimer id)) + ] + [ i [ class "fa fa-fw fa-remove" ] [] ] stopIfRinging : (Id, Timer) -> Signal.Message -> Signal.Message stopIfRinging (id, timer) message = |