Enable power search for power users via ui settings

A different search bar is presented if enabled in ui settings that
allows to search via the new query language.
This commit is contained in:
Eike Kettner 2021-03-01 22:45:17 +01:00
parent 168f5a1a98
commit b4b5acde13
6 changed files with 102 additions and 33 deletions

View File

@ -58,6 +58,7 @@ type alias Model =
, showPatternHelp : Bool
, searchStatsVisible : Bool
, sideMenuVisible : Bool
, powerSearchEnabled : Bool
, openTabs : Set String
}
@ -151,6 +152,7 @@ init flags settings =
, showPatternHelp = False
, searchStatsVisible = settings.searchStatsVisible
, sideMenuVisible = settings.sideMenuVisible
, powerSearchEnabled = settings.powerSearchEnabled
, openTabs = Set.empty
}
, Api.getTags flags "" GetTagsResp
@ -178,6 +180,7 @@ type Msg
| ToggleSearchStatsVisible
| ToggleAkkordionTab String
| ToggleSideMenuVisible
| TogglePowerSearch
@ -460,6 +463,15 @@ update sett msg model =
, Just { sett | sideMenuVisible = next }
)
TogglePowerSearch ->
let
next =
not model.powerSearchEnabled
in
( { model | powerSearchEnabled = next }
, Just { sett | powerSearchEnabled = next }
)
--- View
@ -763,6 +775,15 @@ settingFormTabs flags _ model =
, label = "Show basic search statistics by default"
}
]
, div [ class "mb-4" ]
[ MB.viewItem <|
MB.Checkbox
{ id = "uisetting-powersearch-enabled"
, value = model.powerSearchEnabled
, tagger = \_ -> TogglePowerSearch
, label = "Enable power-user search bar"
}
]
]
}
, { title = "Item Cards"

View File

@ -52,6 +52,7 @@ type ItemQuery
| ItemName AttrMatch String
| AllNames String
| Contents String
| Fragment String
and : List (Maybe ItemQuery) -> Maybe ItemQuery
@ -176,6 +177,9 @@ render q =
Contents str ->
"content:" ++ quoteStr str
Fragment str ->
"(& " ++ str ++ " )"
attrMatch : AttrMatch -> String
attrMatch am =

View File

@ -62,6 +62,7 @@ type alias StoredUiSettings =
, cardPreviewFullWidth : Bool
, uiTheme : Maybe String
, sideMenuVisible : Bool
, powerSearchEnabled : Bool
}
@ -92,6 +93,7 @@ type alias UiSettings =
, cardPreviewFullWidth : Bool
, uiTheme : UiTheme
, sideMenuVisible : Bool
, powerSearchEnabled : Bool
}
@ -162,6 +164,7 @@ defaults =
, cardPreviewFullWidth = False
, uiTheme = Data.UiTheme.Light
, sideMenuVisible = True
, powerSearchEnabled = False
}
@ -213,6 +216,7 @@ merge given fallback =
Maybe.andThen Data.UiTheme.fromString given.uiTheme
|> Maybe.withDefault fallback.uiTheme
, sideMenuVisible = given.sideMenuVisible
, powerSearchEnabled = given.powerSearchEnabled
}
@ -249,6 +253,7 @@ toStoredUiSettings settings =
, cardPreviewFullWidth = settings.cardPreviewFullWidth
, uiTheme = Just (Data.UiTheme.toString settings.uiTheme)
, sideMenuVisible = settings.sideMenuVisible
, powerSearchEnabled = settings.powerSearchEnabled
}

View File

@ -56,6 +56,7 @@ type alias Model =
, dragDropData : DD.DragDropData
, scrollToCard : Maybe String
, searchStats : SearchStats
, powerSearchInput : Maybe String
}
@ -121,6 +122,7 @@ init flags viewMode =
, scrollToCard = Nothing
, viewMode = viewMode
, searchStats = Api.Model.SearchStats.empty
, powerSearchInput = Nothing
}
@ -194,6 +196,8 @@ type Msg
| SetLinkTarget LinkTarget
| SearchStatsResp (Result Http.Error SearchStats)
| TogglePreviewFullWidth
| SetPowerSearch String
| KeyUpPowerSearchbarMsg (Maybe KeyCode)
type SearchType
@ -240,8 +244,11 @@ doSearchDefaultCmd : SearchParam -> Model -> Cmd Msg
doSearchDefaultCmd param model =
let
smask =
Q.request
(Comp.SearchMenu.getItemQuery model.searchMenuModel)
Q.request <|
Q.and
[ Comp.SearchMenu.getItemQuery model.searchMenuModel
, Maybe.map Q.Fragment model.powerSearchInput
]
mask =
{ smask

View File

@ -54,7 +54,7 @@ update mId key flags settings msg model =
ResetSearch ->
let
nm =
{ model | searchOffset = 0 }
{ model | searchOffset = 0, powerSearchInput = Nothing }
in
update mId key flags settings (SearchMenuMsg Comp.SearchMenu.ResetForm) nm
@ -580,6 +580,15 @@ update mId key flags settings msg model =
in
noSub ( model, cmd )
SetPowerSearch str ->
noSub ( { model | powerSearchInput = Util.Maybe.fromString str }, Cmd.none )
KeyUpPowerSearchbarMsg (Just Enter) ->
update mId key flags settings (DoSearch model.searchTypeDropdownValue) model
KeyUpPowerSearchbarMsg _ ->
withSub ( model, Cmd.none )
--- Helpers

View File

@ -92,7 +92,7 @@ itemsBar flags settings model =
defaultMenuBar : Flags -> UiSettings -> Model -> Html Msg
defaultMenuBar flags settings model =
defaultMenuBar _ settings model =
let
btnStyle =
S.secondaryBasicButton ++ " text-sm"
@ -100,6 +100,53 @@ defaultMenuBar flags settings model =
searchInput =
Comp.SearchMenu.textSearchString
model.searchMenuModel.textSearchModel
simpleSearchBar =
div
[ class "relative flex flex-row" ]
[ input
[ type_ "text"
, placeholder
(case model.searchTypeDropdownValue of
ContentOnlySearch ->
"Content search"
BasicSearch ->
"Search in names"
)
, onInput SetBasicSearch
, Util.Html.onKeyUpCode KeyUpSearchbarMsg
, Maybe.map value searchInput
|> Maybe.withDefault (value "")
, class (String.replace "rounded" "" S.textInput)
, class "py-1 text-sm border-r-0 rounded-l"
]
[]
, a
[ class S.secondaryBasicButtonPlain
, class "text-sm px-4 py-2 border rounded-r"
, href "#"
, onClick ToggleSearchType
]
[ i [ class "fa fa-exchange-alt" ] []
]
]
powerSearchBar =
div
[ class "relative flex flex-grow flex-row" ]
[ input
[ type_ "text"
, placeholder "Search query "
, onInput SetPowerSearch
, Util.Html.onKeyUpCode KeyUpPowerSearchbarMsg
, Maybe.map value model.powerSearchInput
|> Maybe.withDefault (value "")
, class S.textInput
, class "text-sm "
]
[]
]
in
MB.view
{ end =
@ -129,35 +176,11 @@ defaultMenuBar flags settings model =
]
, start =
[ MB.CustomElement <|
div
[ class "relative flex flex-row" ]
[ input
[ type_ "text"
, placeholder
(case model.searchTypeDropdownValue of
ContentOnlySearch ->
"Content search"
if settings.powerSearchEnabled then
powerSearchBar
BasicSearch ->
"Search in names"
)
, onInput SetBasicSearch
, Util.Html.onKeyUpCode KeyUpSearchbarMsg
, Maybe.map value searchInput
|> Maybe.withDefault (value "")
, class (String.replace "rounded" "" S.textInput)
, class "py-1 text-sm border-r-0 rounded-l"
]
[]
, a
[ class S.secondaryBasicButtonPlain
, class "text-sm px-4 py-2 border rounded-r"
, href "#"
, onClick ToggleSearchType
]
[ i [ class "fa fa-exchange-alt" ] []
]
]
else
simpleSearchBar
, MB.CustomButton
{ tagger = TogglePreviewFullWidth
, label = ""
@ -271,7 +294,7 @@ searchStats _ settings model =
itemCardList : Flags -> UiSettings -> Model -> List (Html Msg)
itemCardList flags settings model =
itemCardList _ settings model =
let
itemViewCfg =
case model.viewMode of