diff options
-rw-r--r-- | design/design.css | 4 | ||||
-rw-r--r-- | index.html | 15 | ||||
-rw-r--r-- | src/Main.elm | 13 | ||||
-rw-r--r-- | src/Model/Model.elm | 3 | ||||
-rw-r--r-- | src/Model/Position.elm | 12 | ||||
-rw-r--r-- | src/Model/TimerEdition.elm | 16 | ||||
-rw-r--r-- | src/Update/Update.elm | 7 | ||||
-rw-r--r-- | src/View/ActivatedClasses.elm | 15 | ||||
-rw-r--r-- | src/View/Timer.elm | 28 | ||||
-rw-r--r-- | src/View/View.elm | 8 |
10 files changed, 109 insertions, 12 deletions
diff --git a/design/design.css b/design/design.css index a2bf160..ac34f6f 100644 --- a/design/design.css +++ b/design/design.css @@ -56,6 +56,10 @@ width: 200px; } +.timer > .edition { + color: #DDDDDD; +} + .timer > button { border: none; width: 100px; @@ -16,9 +16,18 @@ </body> <script> - Elm.fullscreen(Elm.Main, { - initialTime: new Date().getTime() - }); + var timer = Elm.fullscreen(Elm.Main, { + initialTime: new Date().getTime(), + clickAway: [] + }); + + timer.ports.clickPosition.subscribe(function(pos) { + const element = document.elementFromPoint(pos.x, pos.y); + if(element.nodeName != 'BUTTON') { + timer.ports.clickAway.send([]); + } + }); + </script> </html> diff --git a/src/Main.elm b/src/Main.elm index c2a7519..c2a327b 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -5,8 +5,12 @@ module Main import Signal import Html (Html) import Time (..) +import Mouse +import Debug +import Json.Encode (Value) import Model.Model (..) +import Model.Position (..) import Update.Update (..) import View.View (view) @@ -21,6 +25,15 @@ input = Signal.mergeMany [ Signal.subscribe updates , Signal.map DeltaTime (fps 30) + , Signal.map (\_ -> ReadOnly) clickAway ] +port clickPosition : Signal Value +port clickPosition = + Signal.sampleOn + Mouse.clicks + (Signal.map positionEncoder Mouse.position) + +port clickAway : Signal () + port initialTime : Time diff --git a/src/Model/Model.elm b/src/Model/Model.elm index 9a20219..b7ac48a 100644 --- a/src/Model/Model.elm +++ b/src/Model/Model.elm @@ -9,6 +9,7 @@ import Dict import Time (Time) import Model.Timer (..) +import Model.TimerEdition (..) import Model.Id (..) import Model.IdGenerator (..) @@ -16,6 +17,7 @@ type alias Model = { currentTime : Time , timers : Dict Id Timer , timerIdGenerator : IdGenerator + , timerEdition : Maybe TimerEdition } initialModel : Time -> Model @@ -25,6 +27,7 @@ initialModel initialTime = in { currentTime = initialTime , timers = Dict.insert id (initialTimer initialTime timerName) Dict.empty , timerIdGenerator = idGenerator + , timerEdition = Nothing } substractTimersTime : Time -> Dict Id Timer -> Dict Id Timer diff --git a/src/Model/Position.elm b/src/Model/Position.elm new file mode 100644 index 0000000..b73a3d9 --- /dev/null +++ b/src/Model/Position.elm @@ -0,0 +1,12 @@ +module Model.Position + ( positionEncoder + ) where + +import Json.Encode (..) + +positionEncoder : (Int, Int) -> Value +positionEncoder (x, y) = + object + [ ("x", int x) + , ("y", int y) + ] diff --git a/src/Model/TimerEdition.elm b/src/Model/TimerEdition.elm new file mode 100644 index 0000000..c7b90c5 --- /dev/null +++ b/src/Model/TimerEdition.elm @@ -0,0 +1,16 @@ +module Model.TimerEdition + ( TimerEdition + , newTimerEdition + ) where + +import Model.Id (..) + +type alias TimerEdition = + { id : Id + , numbers : List Int + } + +newTimerEdition id = + { id = id + , numbers = [] + } diff --git a/src/Update/Update.elm b/src/Update/Update.elm index aa31a84..fa11921 100644 --- a/src/Update/Update.elm +++ b/src/Update/Update.elm @@ -11,6 +11,7 @@ import Maybe import Model.Model (..) import Model.Timer (..) +import Model.TimerEdition (..) import Model.Id (..) import Model.IdGenerator (..) @@ -22,6 +23,8 @@ type Action = | DeltaTime Time | UpdateTimer Id TimerAction | RemoveTimer Id + | EditTimer Id + | ReadOnly updates : Signal.Channel Action updates = Signal.channel NoOp @@ -46,3 +49,7 @@ update action model = { 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) } + ReadOnly -> + { model | timerEdition <- Nothing } diff --git a/src/View/ActivatedClasses.elm b/src/View/ActivatedClasses.elm new file mode 100644 index 0000000..9594448 --- /dev/null +++ b/src/View/ActivatedClasses.elm @@ -0,0 +1,15 @@ +module View.ActivatedClasses + ( activatedClasses + ) where + +import Html +import Html.Attributes (..) +import List +import String + +activatedClasses : List (Bool, String) -> Html.Attribute +activatedClasses = + class + << String.concat + << List.intersperse " " + << List.filterMap (\(activated, str) -> if activated then Just str else Nothing) diff --git a/src/View/Timer.elm b/src/View/Timer.elm index 6925e42..5ec5d02 100644 --- a/src/View/Timer.elm +++ b/src/View/Timer.elm @@ -8,23 +8,41 @@ import Html.Events (..) import String import Time (Time) import Signal +import Maybe +import Model.Model (..) import Model.Timer (..) import Model.Id (..) import Update.Update (..) import Update.UpdateTimer (..) -timerView : (Id, Timer) -> Html -timerView (id, timer) = +import View.ActivatedClasses (..) + +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 ] - , button - [ class <| "time block" ] - [ text (timeView timer.currentTime) ] + , let inEdition = + model.timerEdition + |> Maybe.map (\te -> te.id == id) + |> Maybe.withDefault False + in button + ( [ [ (True, "time block") + , (inEdition, "edition") + ] + |> activatedClasses + ] + ++ if inEdition + then + [] + else + [ onClick (Signal.send updates (EditTimer id)) ] + ) + [ text (timeView timer.currentTime) ] , button [ class <| "restart block" , onClick (Signal.send updates (UpdateTimer id Restart)) diff --git a/src/View/View.elm b/src/View/View.elm index f915952..8da1316 100644 --- a/src/View/View.elm +++ b/src/View/View.elm @@ -28,7 +28,7 @@ view model = |> Dict.toList |> List.sortBy (.creationTime << snd) |> List.reverse - |> timers + |> timers model ] title : Html @@ -56,8 +56,8 @@ is13 code = then Ok() else Err "Not the right key code" -timers : List (Id, Timer) -> Html -timers timers = +timers : Model -> List (Id, Timer) -> Html +timers model timers = div [ class "timers" ] - (List.map timerView timers) + (List.map (timerView model) timers) |