mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Allow simple search on share page
This commit is contained in:
@ -22,6 +22,9 @@ type alias Texts =
|
|||||||
, passwordForm : Messages.Comp.SharePasswordForm.Texts
|
, passwordForm : Messages.Comp.SharePasswordForm.Texts
|
||||||
, httpError : Http.Error -> String
|
, httpError : Http.Error -> String
|
||||||
, authFailed : String
|
, authFailed : String
|
||||||
|
, fulltextPlaceholder : String
|
||||||
|
, powerSearchPlaceholder : String
|
||||||
|
, extendedSearch : String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -33,6 +36,9 @@ gb =
|
|||||||
, passwordForm = Messages.Comp.SharePasswordForm.gb
|
, passwordForm = Messages.Comp.SharePasswordForm.gb
|
||||||
, authFailed = "This share does not exist."
|
, authFailed = "This share does not exist."
|
||||||
, httpError = Messages.Comp.HttpError.gb
|
, httpError = Messages.Comp.HttpError.gb
|
||||||
|
, fulltextPlaceholder = "Fulltext search…"
|
||||||
|
, powerSearchPlaceholder = "Extended search…"
|
||||||
|
, extendedSearch = "Extended search query"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -44,4 +50,7 @@ de =
|
|||||||
, passwordForm = Messages.Comp.SharePasswordForm.de
|
, passwordForm = Messages.Comp.SharePasswordForm.de
|
||||||
, authFailed = "Diese Freigabe existiert nicht."
|
, authFailed = "Diese Freigabe existiert nicht."
|
||||||
, httpError = Messages.Comp.HttpError.de
|
, httpError = Messages.Comp.HttpError.de
|
||||||
|
, fulltextPlaceholder = "Volltextsuche…"
|
||||||
|
, powerSearchPlaceholder = "Erweiterte Suche…"
|
||||||
|
, extendedSearch = "Erweiterte Suchanfrage"
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
-}
|
-}
|
||||||
|
|
||||||
|
|
||||||
module Page.Share.Data exposing (Mode(..), Model, Msg(..), PageError(..), init, initCmd)
|
module Page.Share.Data exposing (Mode(..), Model, Msg(..), PageError(..), SearchBarMode(..), init, initCmd)
|
||||||
|
|
||||||
import Api
|
import Api
|
||||||
import Api.Model.ItemLightList exposing (ItemLightList)
|
import Api.Model.ItemLightList exposing (ItemLightList)
|
||||||
@ -18,6 +18,7 @@ import Comp.SearchMenu
|
|||||||
import Comp.SharePasswordForm
|
import Comp.SharePasswordForm
|
||||||
import Data.Flags exposing (Flags)
|
import Data.Flags exposing (Flags)
|
||||||
import Http
|
import Http
|
||||||
|
import Util.Html exposing (KeyCode)
|
||||||
|
|
||||||
|
|
||||||
type Mode
|
type Mode
|
||||||
@ -32,6 +33,11 @@ type PageError
|
|||||||
| PageErrorAuthFail
|
| PageErrorAuthFail
|
||||||
|
|
||||||
|
|
||||||
|
type SearchBarMode
|
||||||
|
= SearchBarNormal
|
||||||
|
| SearchBarContent
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ mode : Mode
|
{ mode : Mode
|
||||||
, verifyResult : ShareVerifyResult
|
, verifyResult : ShareVerifyResult
|
||||||
@ -42,6 +48,8 @@ type alias Model =
|
|||||||
, searchInProgress : Bool
|
, searchInProgress : Bool
|
||||||
, itemListModel : Comp.ItemCardList.Model
|
, itemListModel : Comp.ItemCardList.Model
|
||||||
, initialized : Bool
|
, initialized : Bool
|
||||||
|
, contentSearch : Maybe String
|
||||||
|
, searchMode : SearchBarMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -56,6 +64,8 @@ emptyModel flags =
|
|||||||
, searchInProgress = False
|
, searchInProgress = False
|
||||||
, itemListModel = Comp.ItemCardList.init
|
, itemListModel = Comp.ItemCardList.init
|
||||||
, initialized = False
|
, initialized = False
|
||||||
|
, contentSearch = Nothing
|
||||||
|
, searchMode = SearchBarContent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -87,3 +97,6 @@ type Msg
|
|||||||
| PowerSearchMsg Comp.PowerSearchInput.Msg
|
| PowerSearchMsg Comp.PowerSearchInput.Msg
|
||||||
| ResetSearch
|
| ResetSearch
|
||||||
| ItemListMsg Comp.ItemCardList.Msg
|
| ItemListMsg Comp.ItemCardList.Msg
|
||||||
|
| ToggleSearchBar
|
||||||
|
| SetContentSearch String
|
||||||
|
| ContentSearchKey (Maybe KeyCode)
|
||||||
|
@ -13,10 +13,11 @@ import Comp.PowerSearchInput
|
|||||||
import Comp.SearchMenu
|
import Comp.SearchMenu
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (onClick)
|
import Html.Events exposing (onClick, onInput)
|
||||||
import Messages.Page.Share exposing (Texts)
|
import Messages.Page.Share exposing (Texts)
|
||||||
import Page.Share.Data exposing (Model, Msg(..))
|
import Page.Share.Data exposing (Model, Msg(..), SearchBarMode(..))
|
||||||
import Styles as S
|
import Styles as S
|
||||||
|
import Util.Html
|
||||||
|
|
||||||
|
|
||||||
view : Texts -> Model -> Html Msg
|
view : Texts -> Model -> Html Msg
|
||||||
@ -30,21 +31,73 @@ view texts model =
|
|||||||
model.searchMenuModel.textSearchModel
|
model.searchMenuModel.textSearchModel
|
||||||
|
|
||||||
powerSearchBar =
|
powerSearchBar =
|
||||||
div
|
div [ class "flex-grow flex flex-col relative" ]
|
||||||
[ class "relative flex flex-grow flex-row" ]
|
[ div
|
||||||
[ Html.map PowerSearchMsg
|
[ class "relative flex flex-grow flex-row" ]
|
||||||
(Comp.PowerSearchInput.viewInput
|
[ Html.map PowerSearchMsg
|
||||||
{ placeholder = texts.basics.searchPlaceholder
|
(Comp.PowerSearchInput.viewInput
|
||||||
, extraAttrs = []
|
{ placeholder = texts.powerSearchPlaceholder
|
||||||
}
|
, extraAttrs = []
|
||||||
model.powerSearchInput
|
}
|
||||||
)
|
model.powerSearchInput
|
||||||
, Html.map PowerSearchMsg
|
)
|
||||||
(Comp.PowerSearchInput.viewResult [] model.powerSearchInput)
|
, Html.map PowerSearchMsg
|
||||||
|
(Comp.PowerSearchInput.viewResult [] model.powerSearchInput)
|
||||||
|
]
|
||||||
|
, div
|
||||||
|
[ class "opacity-60 text-xs -mt-1.5 absolute -bottom-4"
|
||||||
|
]
|
||||||
|
[ text "Use an "
|
||||||
|
, a
|
||||||
|
[ href "https://docspell.org/docs/query/#structure"
|
||||||
|
, target "_new"
|
||||||
|
, class S.link
|
||||||
|
, class "mx-1"
|
||||||
|
]
|
||||||
|
[ i [ class "fa fa-external-link-alt mr-1" ] []
|
||||||
|
, text "extended search"
|
||||||
|
]
|
||||||
|
, text " syntax."
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
contentSearchBar =
|
||||||
|
div [ class "flex flex-grow" ]
|
||||||
|
[ input
|
||||||
|
[ type_ "text"
|
||||||
|
, class S.textInput
|
||||||
|
, class "text-sm"
|
||||||
|
, placeholder texts.fulltextPlaceholder
|
||||||
|
, onInput SetContentSearch
|
||||||
|
, value (Maybe.withDefault "" model.contentSearch)
|
||||||
|
, Util.Html.onKeyUpCode ContentSearchKey
|
||||||
|
]
|
||||||
|
[]
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
MB.view
|
MB.view
|
||||||
{ end =
|
{ start =
|
||||||
|
[ MB.CustomElement <|
|
||||||
|
case model.searchMode of
|
||||||
|
SearchBarContent ->
|
||||||
|
contentSearchBar
|
||||||
|
|
||||||
|
SearchBarNormal ->
|
||||||
|
powerSearchBar
|
||||||
|
, MB.CustomElement <|
|
||||||
|
B.secondaryBasicButton
|
||||||
|
{ label = ""
|
||||||
|
, icon = "fa fa-search-plus"
|
||||||
|
, disabled = False
|
||||||
|
, handler = onClick ToggleSearchBar
|
||||||
|
, attrs =
|
||||||
|
[ href "#"
|
||||||
|
, title texts.extendedSearch
|
||||||
|
, classList [ ( "bg-gray-200 dark:bg-bluegray-600", model.searchMode == SearchBarNormal ) ]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
, end =
|
||||||
[ MB.CustomElement <|
|
[ MB.CustomElement <|
|
||||||
B.secondaryBasicButton
|
B.secondaryBasicButton
|
||||||
{ label = ""
|
{ label = ""
|
||||||
@ -59,9 +112,5 @@ view texts model =
|
|||||||
, attrs = [ href "#" ]
|
, attrs = [ href "#" ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
, start =
|
|
||||||
[ MB.CustomElement <|
|
|
||||||
powerSearchBar
|
|
||||||
]
|
|
||||||
, rootClasses = "mb-2 pt-1 dark:bg-bluegray-700 items-center text-sm"
|
, rootClasses = "mb-2 pt-1 dark:bg-bluegray-700 items-center text-sm"
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ import Data.ItemQuery as Q
|
|||||||
import Data.SearchMode
|
import Data.SearchMode
|
||||||
import Data.UiSettings exposing (UiSettings)
|
import Data.UiSettings exposing (UiSettings)
|
||||||
import Page.Share.Data exposing (..)
|
import Page.Share.Data exposing (..)
|
||||||
|
import Util.Html
|
||||||
|
import Util.Maybe
|
||||||
import Util.Update
|
import Util.Update
|
||||||
|
|
||||||
|
|
||||||
@ -74,7 +76,7 @@ update flags settings shareId msg model =
|
|||||||
settings
|
settings
|
||||||
shareId
|
shareId
|
||||||
(ItemListMsg (Comp.ItemCardList.SetResults list))
|
(ItemListMsg (Comp.ItemCardList.SetResults list))
|
||||||
{ model | searchInProgress = False }
|
{ model | searchInProgress = False, pageError = PageErrorNone }
|
||||||
|
|
||||||
SearchResp (Err err) ->
|
SearchResp (Err err) ->
|
||||||
noSub ( { model | pageError = PageErrorHttp err, searchInProgress = False }, Cmd.none )
|
noSub ( { model | pageError = PageErrorHttp err, searchInProgress = False }, Cmd.none )
|
||||||
@ -149,7 +151,11 @@ update flags settings shareId msg model =
|
|||||||
ResetSearch ->
|
ResetSearch ->
|
||||||
let
|
let
|
||||||
nm =
|
nm =
|
||||||
{ model | powerSearchInput = Comp.PowerSearchInput.init }
|
{ model
|
||||||
|
| powerSearchInput = Comp.PowerSearchInput.init
|
||||||
|
, contentSearch = Nothing
|
||||||
|
, pageError = PageErrorNone
|
||||||
|
}
|
||||||
in
|
in
|
||||||
update flags settings shareId (SearchMenuMsg Comp.SearchMenu.ResetForm) nm
|
update flags settings shareId (SearchMenuMsg Comp.SearchMenu.ResetForm) nm
|
||||||
|
|
||||||
@ -167,6 +173,29 @@ update flags settings shareId msg model =
|
|||||||
, Cmd.batch [ Cmd.map ItemListMsg ic, searchMsg ]
|
, Cmd.batch [ Cmd.map ItemListMsg ic, searchMsg ]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ToggleSearchBar ->
|
||||||
|
noSub
|
||||||
|
( { model
|
||||||
|
| searchMode =
|
||||||
|
case model.searchMode of
|
||||||
|
SearchBarContent ->
|
||||||
|
SearchBarNormal
|
||||||
|
|
||||||
|
SearchBarNormal ->
|
||||||
|
SearchBarContent
|
||||||
|
}
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
|
SetContentSearch q ->
|
||||||
|
noSub ( { model | contentSearch = Util.Maybe.fromString q }, Cmd.none )
|
||||||
|
|
||||||
|
ContentSearchKey (Just Util.Html.Enter) ->
|
||||||
|
noSub ( model, makeSearchCmd flags model )
|
||||||
|
|
||||||
|
ContentSearchKey _ ->
|
||||||
|
noSub ( model, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
noSub : ( Model, Cmd Msg ) -> UpdateResult
|
noSub : ( Model, Cmd Msg ) -> UpdateResult
|
||||||
noSub ( m, c ) =
|
noSub ( m, c ) =
|
||||||
@ -179,7 +208,13 @@ makeSearchCmd flags model =
|
|||||||
xq =
|
xq =
|
||||||
Q.and
|
Q.and
|
||||||
[ Comp.SearchMenu.getItemQuery model.searchMenuModel
|
[ Comp.SearchMenu.getItemQuery model.searchMenuModel
|
||||||
, Maybe.map Q.Fragment model.powerSearchInput.input
|
, Maybe.map Q.Fragment <|
|
||||||
|
case model.searchMode of
|
||||||
|
SearchBarNormal ->
|
||||||
|
model.powerSearchInput.input
|
||||||
|
|
||||||
|
SearchBarContent ->
|
||||||
|
Maybe.map (Q.Contents >> Q.render) model.contentSearch
|
||||||
]
|
]
|
||||||
|
|
||||||
request mq =
|
request mq =
|
||||||
|
Reference in New Issue
Block a user