Commit 3a4c4ee1 authored by André Espaze's avatar André Espaze
Browse files

View error message on Plot

parent fdfcb05adae4
......@@ -169,6 +169,7 @@ view model =
model.searchString
model.searchedSeries
model.selectedSeries
Nothing
in
article [ classes [ T.center, T.pt4, T.w_90 ] ]
[ KeywordMultiSelector.view selectorConfig ctx ]
......
......@@ -16,14 +16,15 @@ type alias Config msg =
}
type alias Context =
type alias Context msg =
{ searchString : String
, searchedItems : List String
, selectedItems : List String
, errorMessage : Maybe (Html msg)
}
view : Config msg -> Context -> Html msg
view : Config msg -> Context msg -> Html msg
view cfg ctx =
let
searchInput =
......@@ -56,10 +57,26 @@ view cfg ctx =
, ( cfg.actionSelector, ctx.selectedItems )
]
)
addErr mess =
let
cls =
classes
[ T.flex
, T.items_center
, T.pa4
, T.bg_washed_red
, T.navy
]
in
[ div [ cls ] [ mess ] ]
checkErr xs =
Common.maybe xs (addErr >> List.append xs) ctx.errorMessage
in
div cfg.divAttrs
[ searchInput
-- XXX w_90 should not be there but how to fix it ?
, div [ classes [ T.w_90, T.absolute, T.z_2, T.bg_white_80 ] ] [ cols ]
, div [ classes [ T.w_90, T.absolute, T.z_2, T.bg_white_80 ] ] <| checkErr [ cols ]
]
......@@ -9,15 +9,19 @@ type alias Config msg =
KeywordMultiSelector.Config msg
type alias Context =
type alias Context msg =
{ searchString : String
, searchedItems : List String
, selectedItem : Maybe String
, errorMessage : Maybe (Html msg)
}
view : Config msg -> Context -> Html msg
view : Config msg -> Context msg -> Html msg
view cfg ctx =
KeywordMultiSelector.view cfg <|
KeywordMultiSelector.Context ctx.searchString ctx.searchedItems <|
Common.maybe [] (\x -> [ x ]) ctx.selectedItem
KeywordMultiSelector.Context
ctx.searchString
ctx.searchedItems
(Common.maybe [] List.singleton ctx.selectedItem)
ctx.errorMessage
......@@ -28,9 +28,16 @@ type alias Model =
, selectedNamedSeries : List NamedSerie
, activeSelection : Bool
, cache : SeriesCache
, error : Maybe Error
}
type Error
= CatalogError String
| SelectionError (List NamedError)
| RenderError String
type alias SeriesCatalog =
Dict.Dict String String
......@@ -243,11 +250,7 @@ update msg model =
)
CatalogReceived (Err x) ->
let
_ =
Debug.log "Error on CatalogReceived" x
in
newModel model
newModel { model | error = Just <| CatalogError "Nothing receive" }
ToggleSelection ->
newModel { model | activeSelection = not model.activeSelection }
......@@ -269,17 +272,26 @@ update msg model =
RenderPlot (Ok ( cache, namedSeries, namedErrors )) ->
let
_ =
Debug.log "Named errors" namedErrors
in
( { model | cache = cache, selectedNamedSeries = namedSeries }, Cmd.none )
error =
case namedErrors of
[] ->
Nothing
RenderPlot (Err x) ->
let
_ =
Debug.log "Error on RenderPlot" x
xs ->
Just <| SelectionError xs
in
newModel model
newModel
{ model
| cache = cache
, selectedNamedSeries = namedSeries
, error = error
}
RenderPlot (Err xs) ->
newModel
{ model
| error = Just <| RenderError <| String.join " " xs
}
selectorConfig : KeywordMultiSelector.Config Msg
......@@ -301,6 +313,27 @@ selectorConfig =
}
viewError : Error -> Html Msg
viewError error =
let
bold x =
b [] [ text x ]
in
case error of
CatalogError x ->
div [] [ bold "Catalog error", text x ]
RenderError x ->
text x
SelectionError namedErrors ->
ul []
(List.map
(\( name, mess ) -> li [] [ bold name, text mess ])
namedErrors
)
view : Model -> Html Msg
view model =
let
......@@ -335,6 +368,7 @@ view model =
model.searchString
model.searchedSeries
model.selectedSeries
(Maybe.map viewError model.error)
in
form [ classes [ T.center, T.pt4, T.w_90 ] ]
(if model.activeSelection then
......@@ -412,7 +446,7 @@ main =
s =
flags.selectedSeries
in
( Model p [] "" [] s [] (List.isEmpty s) c
( Model p [] "" [] s [] (List.isEmpty s) c Nothing
, initialGet p
)
......
......@@ -299,6 +299,7 @@ view model =
model.searchString
model.searchedSeries
model.selectedSerie
Nothing
content =
case model.state of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment