mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 19:08:26 +00:00
Simplify search bar and search menu
The functionality of the search bar is now in the search menu, too. The search menu shows one input field for "textual search", which is either the fulltext search (if enabled) or a basic search in various names.
This commit is contained in:
@ -6,7 +6,6 @@ module Page.Home.Data exposing
|
||||
, SelectActionMode(..)
|
||||
, SelectViewModel
|
||||
, ViewMode(..)
|
||||
, defaultSearchType
|
||||
, doSearchCmd
|
||||
, init
|
||||
, initSelectViewModel
|
||||
@ -20,7 +19,6 @@ module Page.Home.Data exposing
|
||||
import Api
|
||||
import Api.Model.BasicResult exposing (BasicResult)
|
||||
import Api.Model.ItemLightList exposing (ItemLightList)
|
||||
import Api.Model.ItemSearch
|
||||
import Browser.Dom as Dom
|
||||
import Comp.FixedDropdown
|
||||
import Comp.ItemCardList
|
||||
@ -52,7 +50,6 @@ type alias Model =
|
||||
, searchTypeDropdown : Comp.FixedDropdown.Model SearchType
|
||||
, searchTypeDropdownValue : SearchType
|
||||
, lastSearchType : SearchType
|
||||
, contentOnlySearch : Maybe String
|
||||
, dragDropData : DD.DragDropData
|
||||
, scrollToCard : Maybe String
|
||||
}
|
||||
@ -88,6 +85,9 @@ type ViewMode
|
||||
init : Flags -> ViewMode -> Model
|
||||
init flags viewMode =
|
||||
let
|
||||
searchMenuModel =
|
||||
Comp.SearchMenu.init flags
|
||||
|
||||
searchTypeOptions =
|
||||
if flags.config.fullTextSearchEnabled then
|
||||
[ BasicSearch, ContentOnlySearch ]
|
||||
@ -95,7 +95,7 @@ init flags viewMode =
|
||||
else
|
||||
[ BasicSearch ]
|
||||
in
|
||||
{ searchMenuModel = Comp.SearchMenu.init
|
||||
{ searchMenuModel = searchMenuModel
|
||||
, itemListModel = Comp.ItemCardList.init
|
||||
, searchInProgress = False
|
||||
, searchOffset = 0
|
||||
@ -105,9 +105,13 @@ init flags viewMode =
|
||||
, searchTypeDropdown =
|
||||
Comp.FixedDropdown.initMap searchTypeString
|
||||
searchTypeOptions
|
||||
, searchTypeDropdownValue = defaultSearchType flags
|
||||
, searchTypeDropdownValue =
|
||||
if Comp.SearchMenu.isFulltextSearch searchMenuModel then
|
||||
ContentOnlySearch
|
||||
|
||||
else
|
||||
BasicSearch
|
||||
, lastSearchType = BasicSearch
|
||||
, contentOnlySearch = Nothing
|
||||
, dragDropData =
|
||||
DD.DragDropData DD.init Nothing
|
||||
, scrollToCard = Nothing
|
||||
@ -115,15 +119,6 @@ init flags viewMode =
|
||||
}
|
||||
|
||||
|
||||
defaultSearchType : Flags -> SearchType
|
||||
defaultSearchType flags =
|
||||
if flags.config.fullTextSearchEnabled then
|
||||
ContentOnlySearch
|
||||
|
||||
else
|
||||
BasicSearch
|
||||
|
||||
|
||||
menuCollapsed : Model -> Bool
|
||||
menuCollapsed model =
|
||||
case model.viewMode of
|
||||
@ -165,7 +160,6 @@ type Msg
|
||||
| SetBasicSearch String
|
||||
| SearchTypeMsg (Comp.FixedDropdown.Msg SearchType)
|
||||
| KeyUpSearchbarMsg (Maybe KeyCode)
|
||||
| SetContentOnly String
|
||||
| ScrollResult (Result Dom.Error ())
|
||||
| ClearItemDetailId
|
||||
| SelectAllItems
|
||||
@ -227,12 +221,7 @@ itemNav id model =
|
||||
|
||||
doSearchCmd : SearchParam -> Model -> Cmd Msg
|
||||
doSearchCmd param model =
|
||||
case param.searchType of
|
||||
BasicSearch ->
|
||||
doSearchDefaultCmd param model
|
||||
|
||||
ContentOnlySearch ->
|
||||
doSearchIndexCmd param model
|
||||
doSearchDefaultCmd param model
|
||||
|
||||
|
||||
doSearchDefaultCmd : SearchParam -> Model -> Cmd Msg
|
||||
@ -254,36 +243,6 @@ doSearchDefaultCmd param model =
|
||||
Api.itemSearch param.flags mask ItemSearchAddResp
|
||||
|
||||
|
||||
doSearchIndexCmd : SearchParam -> Model -> Cmd Msg
|
||||
doSearchIndexCmd param model =
|
||||
case model.contentOnlySearch of
|
||||
Just q ->
|
||||
let
|
||||
mask =
|
||||
{ query = q
|
||||
, limit = param.pageSize
|
||||
, offset = param.offset
|
||||
}
|
||||
in
|
||||
if param.offset == 0 then
|
||||
Api.itemIndexSearch param.flags mask (ItemSearchResp param.scroll)
|
||||
|
||||
else
|
||||
Api.itemIndexSearch param.flags mask ItemSearchAddResp
|
||||
|
||||
Nothing ->
|
||||
-- If there is no fulltext query, render simply the most
|
||||
-- current ones
|
||||
let
|
||||
emptyMask =
|
||||
Api.Model.ItemSearch.empty
|
||||
|
||||
mask =
|
||||
{ emptyMask | limit = param.pageSize }
|
||||
in
|
||||
Api.itemSearch param.flags mask (ItemSearchResp param.scroll)
|
||||
|
||||
|
||||
resultsBelowLimit : UiSettings -> Model -> Bool
|
||||
resultsBelowLimit settings model =
|
||||
let
|
||||
|
@ -52,10 +52,7 @@ update mId key flags settings msg model =
|
||||
ResetSearch ->
|
||||
let
|
||||
nm =
|
||||
{ model
|
||||
| searchOffset = 0
|
||||
, contentOnlySearch = Nothing
|
||||
}
|
||||
{ model | searchOffset = 0 }
|
||||
in
|
||||
update mId key flags settings (SearchMenuMsg Comp.SearchMenu.ResetForm) nm
|
||||
|
||||
@ -76,6 +73,12 @@ update mId key flags settings msg model =
|
||||
{ model
|
||||
| searchMenuModel = nextState.model
|
||||
, dragDropData = nextState.dragDrop
|
||||
, searchTypeDropdownValue =
|
||||
if Comp.SearchMenu.isFulltextSearch nextState.model then
|
||||
ContentOnlySearch
|
||||
|
||||
else
|
||||
BasicSearch
|
||||
}
|
||||
|
||||
( m2, c2, s2 ) =
|
||||
@ -261,21 +264,10 @@ update mId key flags settings msg model =
|
||||
SetBasicSearch str ->
|
||||
let
|
||||
smMsg =
|
||||
case model.searchTypeDropdownValue of
|
||||
BasicSearch ->
|
||||
SearchMenuMsg (Comp.SearchMenu.SetAllName str)
|
||||
|
||||
ContentOnlySearch ->
|
||||
SetContentOnly str
|
||||
SearchMenuMsg (Comp.SearchMenu.SetTextSearch str)
|
||||
in
|
||||
update mId key flags settings smMsg model
|
||||
|
||||
SetContentOnly str ->
|
||||
withSub
|
||||
( { model | contentOnlySearch = Util.Maybe.fromString str }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
SearchTypeMsg lm ->
|
||||
let
|
||||
( sm, mv ) =
|
||||
@ -293,23 +285,17 @@ update mId key flags settings msg model =
|
||||
next =
|
||||
case mvChange of
|
||||
Just BasicSearch ->
|
||||
Just
|
||||
( { m0 | contentOnlySearch = Nothing }
|
||||
, Maybe.withDefault "" model.contentOnlySearch
|
||||
)
|
||||
Just Comp.SearchMenu.SetNamesSearch
|
||||
|
||||
Just ContentOnlySearch ->
|
||||
Just
|
||||
( { m0 | contentOnlySearch = model.searchMenuModel.allNameModel }
|
||||
, ""
|
||||
)
|
||||
Just Comp.SearchMenu.SetFulltextSearch
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
in
|
||||
case next of
|
||||
Just ( m_, nstr ) ->
|
||||
update mId key flags settings (SearchMenuMsg (Comp.SearchMenu.SetAllName nstr)) m_
|
||||
Just lm_ ->
|
||||
update mId key flags settings (SearchMenuMsg lm_) m0
|
||||
|
||||
Nothing ->
|
||||
withSub ( m0, Cmd.none )
|
||||
|
@ -285,12 +285,8 @@ viewSearchBar flags model =
|
||||
(searchTypeString model.searchTypeDropdownValue)
|
||||
|
||||
searchInput =
|
||||
case model.searchTypeDropdownValue of
|
||||
BasicSearch ->
|
||||
model.searchMenuModel.allNameModel
|
||||
|
||||
ContentOnlySearch ->
|
||||
model.contentOnlySearch
|
||||
Comp.SearchMenu.textSearchString
|
||||
model.searchMenuModel.textSearchModel
|
||||
|
||||
searchTypeClass =
|
||||
if flags.config.fullTextSearchEnabled then
|
||||
@ -328,7 +324,7 @@ viewSearchBar flags model =
|
||||
, href "#"
|
||||
, onClick (DoSearch model.searchTypeDropdownValue)
|
||||
]
|
||||
(if hasMoreSearch model && model.searchTypeDropdownValue == BasicSearch then
|
||||
(if hasMoreSearch model then
|
||||
[ i [ class "icons search-corner-icons" ]
|
||||
[ i [ class "tiny blue circle icon" ] []
|
||||
]
|
||||
@ -339,7 +335,14 @@ viewSearchBar flags model =
|
||||
)
|
||||
, input
|
||||
[ type_ "text"
|
||||
, placeholder "Quick Search …"
|
||||
, placeholder
|
||||
(case model.searchTypeDropdownValue of
|
||||
ContentOnlySearch ->
|
||||
"Content search…"
|
||||
|
||||
BasicSearch ->
|
||||
"Search in names…"
|
||||
)
|
||||
, onInput SetBasicSearch
|
||||
, Util.Html.onKeyUpCode KeyUpSearchbarMsg
|
||||
, Maybe.map value searchInput
|
||||
@ -381,12 +384,7 @@ hasMoreSearch model =
|
||||
Comp.SearchMenu.getItemSearch model.searchMenuModel
|
||||
|
||||
is_ =
|
||||
case model.lastSearchType of
|
||||
BasicSearch ->
|
||||
{ is | allNames = Nothing }
|
||||
|
||||
ContentOnlySearch ->
|
||||
Api.Model.ItemSearch.empty
|
||||
{ is | allNames = Nothing, fullText = Nothing }
|
||||
in
|
||||
is_ /= Api.Model.ItemSearch.empty
|
||||
|
||||
|
Reference in New Issue
Block a user