Allow to hide search stats in user settings

This commit is contained in:
Eike Kettner 2021-01-02 10:20:18 +01:00
parent ae57881f2d
commit 2b8ef3c2f7
3 changed files with 38 additions and 4 deletions

View File

@ -51,6 +51,7 @@ type alias Model =
, cardTitlePattern : PatternModel
, cardSubtitlePattern : PatternModel
, showPatternHelp : Bool
, searchStatsVisible : Bool
}
@ -141,6 +142,7 @@ init flags settings =
, cardTitlePattern = initPatternModel settings.cardTitleTemplate
, cardSubtitlePattern = initPatternModel settings.cardSubtitleTemplate
, showPatternHelp = False
, searchStatsVisible = settings.searchStatsVisible
}
, Api.getTags flags "" GetTagsResp
)
@ -164,6 +166,7 @@ type Msg
| SetCardTitlePattern String
| SetCardSubtitlePattern String
| TogglePatternHelpMsg
| ToggleSearchStatsVisible
@ -415,6 +418,15 @@ update sett msg model =
TogglePatternHelpMsg ->
( { model | showPatternHelp = not model.showPatternHelp }, Nothing )
ToggleSearchStatsVisible ->
let
flag =
not model.searchStatsVisible
in
( { model | searchStatsVisible = flag }
, Just { sett | searchStatsVisible = flag }
)
--- View
@ -447,6 +459,19 @@ view flags _ model =
"field"
model.searchPageSizeModel
)
, div [ class "field" ]
[ div [ class "ui checkbox" ]
[ input
[ type_ "checkbox"
, onCheck (\_ -> ToggleSearchStatsVisible)
, checked model.searchStatsVisible
]
[]
, label []
[ text "Show basic search statistics by default"
]
]
]
, div [ class "ui dividing header" ]
[ text "Item Cards"
]

View File

@ -52,6 +52,7 @@ type alias StoredUiSettings =
, cardPreviewSize : Maybe String
, cardTitleTemplate : Maybe String
, cardSubtitleTemplate : Maybe String
, searchStatsVisible : Bool
}
@ -78,6 +79,7 @@ type alias UiSettings =
, cardPreviewSize : BasicSize
, cardTitleTemplate : ItemPattern
, cardSubtitleTemplate : ItemPattern
, searchStatsVisible : Bool
}
@ -144,6 +146,7 @@ defaults =
{ template = Data.ItemTemplate.dateLong
, pattern = "{{dateLong}}"
}
, searchStatsVisible = True
}
@ -189,6 +192,7 @@ merge given fallback =
, cardSubtitleTemplate =
Maybe.andThen readPattern given.cardSubtitleTemplate
|> Maybe.withDefault fallback.cardSubtitleTemplate
, searchStatsVisible = given.searchStatsVisible
}
@ -221,6 +225,7 @@ toStoredUiSettings settings =
|> Just
, cardTitleTemplate = settings.cardTitleTemplate.pattern |> Just
, cardSubtitleTemplate = settings.cardSubtitleTemplate.pattern |> Just
, searchStatsVisible = settings.searchStatsVisible
}

View File

@ -124,7 +124,7 @@ view flags settings model =
_ ->
[]
, viewStats flags model
, viewStats flags settings model
, [ Html.map ItemCardListMsg
(Comp.ItemCardList.view itemViewCfg settings model.itemListModel)
]
@ -163,9 +163,13 @@ view flags settings model =
]
viewStats : Flags -> Model -> List (Html Msg)
viewStats _ model =
Comp.SearchStatsView.view model.searchStats
viewStats : Flags -> UiSettings -> Model -> List (Html Msg)
viewStats _ settings model =
if settings.searchStatsVisible then
Comp.SearchStatsView.view model.searchStats
else
[]
viewLeftMenu : Flags -> UiSettings -> Model -> List (Html Msg)