aboutsummaryrefslogtreecommitdiff
path: root/src/Update
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
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')
-rw-r--r--src/Update/Update.elm35
-rw-r--r--src/Update/UpdateTimer.elm18
-rw-r--r--src/Update/UpdateTimerEdition.elm20
3 files changed, 69 insertions, 4 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
diff --git a/src/Update/UpdateTimer.elm b/src/Update/UpdateTimer.elm
index 3eba549..e4671d9 100644
--- a/src/Update/UpdateTimer.elm
+++ b/src/Update/UpdateTimer.elm
@@ -3,26 +3,40 @@ module Update.UpdateTimer
, updateTimer
) where
+import Time (Time)
+
import Model.Timer (..)
import Model.Id (..)
type TimerAction =
Restart
+ | Pause
| ToggleRunning
| Stop
+ | SetTime Time
updateTimer : TimerAction -> Timer -> Timer
updateTimer action timer =
case action of
- ToggleRunning ->
- { timer | isRunning <- timer.currentTime > 0.0 && not timer.isRunning }
Restart ->
{ timer
| isRunning <- True
, currentTime <- initTime timer.initialTime
}
+ Pause ->
+ { timer
+ | isRunning <- False
+ }
+ ToggleRunning ->
+ { timer | isRunning <- timer.currentTime > 0.0 && not timer.isRunning }
Stop ->
{ timer
| isRunning <- False
, currentTime <- initTime timer.initialTime
}
+ SetTime time ->
+ let augmentedTime = time + 999
+ in { timer
+ | initialTime <- augmentedTime
+ , currentTime <- augmentedTime
+ }
diff --git a/src/Update/UpdateTimerEdition.elm b/src/Update/UpdateTimerEdition.elm
new file mode 100644
index 0000000..da12ed0
--- /dev/null
+++ b/src/Update/UpdateTimerEdition.elm
@@ -0,0 +1,20 @@
+module Update.UpdateTimerEdition
+ ( updateTimerEdition
+ ) where
+
+import Char (..)
+import Debug
+
+import Model.TimerEdition (..)
+
+updateTimerEdition : Maybe Char -> TimerEdition -> TimerEdition
+updateTimerEdition maybeChar timerEdition =
+ case maybeChar of
+ Just char ->
+ if isDigit char
+ then
+ { timerEdition | numbers <- char :: timerEdition.numbers }
+ else
+ timerEdition
+ Nothing ->
+ timerEdition