From b96c16918b9bf0c58711044eed7df4a03196d086 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 29 May 2019 19:11:37 -0700 Subject: [PATCH] Only display certain views when they are useful. --- src/CacheSim/View.elm | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/CacheSim/View.elm b/src/CacheSim/View.elm index 3dd1425..f2e3710 100644 --- a/src/CacheSim/View.elm +++ b/src/CacheSim/View.elm @@ -151,13 +151,10 @@ viewCache level (cm, cs) = viewCacheHierarchy : CacheHierarchy -> Html Msg viewCacheHierarchy ch = let - levels = div [ class "cache-levels" ] + levels = div [] <| List.indexedMap viewCache ch in - div [] <| - [ h2 [] [ text <| "Cache State" ] - , levels - ] + levels viewAccessView : Model -> AccessView -> Html Msg viewAccessView m av = @@ -170,7 +167,9 @@ viewAccessView m av = [ primaryButton "Back" AccessViewBack , primaryButton "Forward" AccessViewForward ] + , h3 [] [ text "Access event log" ] , viewAccessLog av + , h3 [] [ text "Current cache state" ] , viewCacheHierarchy <| effectiveCacheHierarchy currentCache av ] @@ -194,23 +193,18 @@ viewAccessLog (aes, ap) = Up n -> List.indexedMap downEvent aes ++ (List.indexedMap upEvent <| List.drop n aes) in - div [ ] - [ h3 [] [ text "Simulation events" ] - , div [] events - ] + div [] events viewAccessInput : Model -> Html Msg viewAccessInput m = let accessButton = maybeButton (String.toInt m.accessInput) "Access address" Access + editHierarchyButton = button "Edit hierarchy" (UseHierarchy Nothing) in div [] [ h2 [] [ text "Run access simulation" ] - , div [ classList [("alert", True), ("alert-primary", True)] ] - [ text "Please make sure to click \"Use Hierarchy\" to load a hierarchy to simulate." - ] , labeledInput "Access address" m.accessInput ChangeAccessInput - , accessButton + , buttonWrapper [ accessButton, editHierarchyButton ] ] viewDescription : Html Msg @@ -234,9 +228,13 @@ viewBase : Model -> Html Msg viewBase m = let rawView = - case m.accessView of + case m.hierarchy of Nothing -> [ viewRawCacheModelHierarchy m.rawHierarchy ] Just _ -> [] + accessInputView = + case (m.hierarchy, m.accessView) of + (Just _, Nothing) -> [ viewAccessInput m ] + _ -> [] cacheView = case m.accessView of Nothing -> @@ -244,7 +242,6 @@ viewBase m = <| Maybe.map (List.singleton << viewCacheHierarchy) <| m.hierarchy Just _ -> [] accessView = Maybe.withDefault [] <| Maybe.map (List.singleton << viewAccessView m) <| m.accessView - accessInputView = [ viewAccessInput m ] in div [ class "container" ] - <| [ viewDescription] ++ rawView ++ cacheView ++ accessView ++ accessInputView + <| [ viewDescription] ++ rawView ++ accessInputView ++ accessView ++ cacheView