Implement reading from input.

This commit is contained in:
Danila Fedorin 2019-05-28 22:12:36 -07:00
parent 844888b28c
commit d3f34ac13c
3 changed files with 17 additions and 3 deletions

View File

@ -7,6 +7,7 @@ type alias Model =
{ rawHierarchy : RawCacheModelHierarchy
, hierarchy : Maybe CacheHierarchy
, accessView : Maybe AccessView
, accessInput : String
}
type alias Flags = ()
type Msg
@ -15,5 +16,6 @@ type Msg
| DeleteRawModel Int
| UseHierarchy (Maybe CacheModelHierarchy)
| Access Int
| ChangeAccessInput String
| AccessViewForward
| AccessViewBack

View File

@ -140,8 +140,18 @@ viewAccessView m av =
, viewCacheHierarchy <| effectiveCacheHierarchy currentCache av
]
viewAccessInput : Html Msg
viewAccessInput = input [ type_ "button", onClick (Access 128), value "Access me" ] []
viewAccessInput : Model -> Html Msg
viewAccessInput m =
let
accessButton =
case String.toInt m.accessInput of
Just i -> optionalButton True "Access address" (Access i)
Nothing -> optionalButton False "Access address" (Access -1)
in
div []
[ labeledInput "Access address" m.accessInput ChangeAccessInput
, accessButton
]
viewError : Bool -> String -> Html Msg
viewError hide e = span [ classList [ ("hidden", hide) ] ] [ text e ]
@ -153,4 +163,4 @@ viewBase m =
cacheView = Maybe.withDefault [] <| Maybe.map (List.singleton << viewCacheHierarchy) <| m.hierarchy
accessView = Maybe.withDefault [] <| Maybe.map (List.singleton << viewAccessView m) <| m.accessView
in
div [] <| [ rawView, viewAccessInput] ++ cacheView ++ accessView
div [] <| [ rawView, viewAccessInput m] ++ cacheView ++ accessView

View File

@ -19,6 +19,7 @@ init f =
{ rawHierarchy = testCacheModelHierarchy
, hierarchy = Nothing
, accessView = Nothing
, accessInput = ""
}
in
(initialModel, Cmd.none)
@ -37,6 +38,7 @@ update msg m =
DeleteRawModel i -> updateDeleteRawModel i m
UseHierarchy cmh -> updateUseHierarchy cmh m
Access i -> updateAccess i m
ChangeAccessInput s -> ({ m | accessInput = s }, Cmd.none)
AccessViewForward -> updateAccessViewForward m
AccessViewBack -> updateAccessViewBack m