Allow creating and deleting cache levels.

This commit is contained in:
Danila Fedorin 2019-05-28 19:49:48 -07:00
parent fed46241f1
commit 77bd953b95

View File

@ -1,9 +1,15 @@
module CacheSim.View exposing (..)
import CacheSim.Raw exposing (..)
import CacheSim.Model exposing (..)
import Html exposing (Html, input, text, div, label, span, h2)
import Html exposing (Html, input, text, div, label, span, h2, h3)
import Html.Attributes exposing (type_, class, value, for)
import Html.Events exposing (onInput)
import Html.Events exposing (onInput, onClick)
button : String -> Msg -> Html Msg
button s m = input [ type_ "button", onClick m, value s] []
buttonWrapper : List (Html Msg) -> Html Msg
buttonWrapper = div [ class "button-wrapper" ]
labeledInput : String -> String -> (String -> Msg) -> Html Msg
labeledInput s val f =
@ -20,6 +26,8 @@ viewRawCacheModel level rcm =
updateSetSize s cm = { cm | setSize = s}
wrapUpdate f s = ChangeRawModel level (f s)
deleteButton = button "Delete" (DeleteRawModel level)
params = div [ class "cache-model-params" ]
[ labeledInput "Block size" rcm.blockSize (wrapUpdate updateBlockSize)
, labeledInput "Set count" rcm.setCount (wrapUpdate updateSetCount)
@ -27,10 +35,21 @@ viewRawCacheModel level rcm =
]
in
div [ class "cache-model" ]
[ h2 [] [ text <| "L" ++ String.fromInt (level + 1) ++ " Cache" ]
[ h3 [] [ text <| "L" ++ String.fromInt (level + 1) ++ " Cache" ]
, buttonWrapper [ deleteButton ]
, params
]
viewRawCacheModelHierarchy : RawCacheModelHierarchy -> Html Msg
viewRawCacheModelHierarchy rcmh =
div [ class "cache-model-hierarchy" ] <| List.indexedMap viewRawCacheModel rcmh
let
models = div [ class "cache-model-levels" ]
<|List.indexedMap viewRawCacheModel rcmh
newButton = button "Add level" CreateRawModel
in
div [ class "cache-model-hierarchy" ]
[ h2 [] [ text "Cache hierarchy" ]
, buttonWrapper [ newButton ]
, models
]