aboutsummaryrefslogtreecommitdiff
path: root/src/Update/Update.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-18 00:32:17 +0100
committerJoris Guyonvarch2015-03-18 00:32:17 +0100
commit2613aeeae0f4de44842ff0e796603d0316a61a14 (patch)
tree722a21c69597e6d2547ad9f991e7c73afae78058 /src/Update/Update.elm
parent0075abf51db5d1b54117525d7a7f9b06e31c9484 (diff)
Can edit the time, unfortunately the enter key is overriden so the '+' key of the numpad is used instead
Diffstat (limited to 'src/Update/Update.elm')
-rw-r--r--src/Update/Update.elm35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/Update/Update.elm b/src/Update/Update.elm
index fa11921..4725970 100644
--- a/src/Update/Update.elm
+++ b/src/Update/Update.elm
@@ -8,6 +8,8 @@ import Signal
import Dict
import Time (Time)
import Maybe
+import Keyboard (KeyCode)
+import Char
import Model.Model (..)
import Model.Timer (..)
@@ -16,6 +18,7 @@ import Model.Id (..)
import Model.IdGenerator (..)
import Update.UpdateTimer (..)
+import Update.UpdateTimerEdition (..)
type Action =
NoOp
@@ -25,6 +28,7 @@ type Action =
| RemoveTimer Id
| EditTimer Id
| ReadOnly
+ | KeyPressed KeyCode
updates : Signal.Channel Action
updates = Signal.channel NoOp
@@ -46,10 +50,37 @@ update action model =
, timers <- substractTimersTime delta model.timers
}
UpdateTimer id action ->
- { model | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers }
+ let inEdition =
+ model.timerEdition
+ |> Maybe.map (\timerEdition -> timerEdition.id == id)
+ |> Maybe.withDefault False
+ in if inEdition
+ then
+ model
+ else
+ { model | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers }
RemoveTimer id ->
{ model | timers <- Dict.remove id model.timers }
EditTimer id ->
- { model | timerEdition <- Just (newTimerEdition id) }
+ { model
+ | timerEdition <- Just (newTimerEdition id)
+ , timers <- Dict.update id (Maybe.map (updateTimer Pause)) model.timers
+ }
ReadOnly ->
{ model | timerEdition <- Nothing }
+ KeyPressed keyCode ->
+ if isEnter keyCode
+ then
+ case model.timerEdition of
+ Just timerEdition ->
+ { model
+ | timers <- Dict.update timerEdition.id (Maybe.map (updateTimer (SetTime (toTime timerEdition.numbers)))) model.timers
+ , timerEdition <- Nothing
+ }
+ Nothing ->
+ { model | timerEdition <- Nothing }
+ else
+ { model | timerEdition <- Maybe.map (updateTimerEdition (keyCodeToChar keyCode)) model.timerEdition }
+
+isEnter : KeyCode -> Bool
+isEnter = (==) 107