diff --git a/modules/webapp/src/main/elm/Messages/Page/Share.elm b/modules/webapp/src/main/elm/Messages/Page/Share.elm index 20884777..53061b7d 100644 --- a/modules/webapp/src/main/elm/Messages/Page/Share.elm +++ b/modules/webapp/src/main/elm/Messages/Page/Share.elm @@ -22,6 +22,9 @@ type alias Texts = , passwordForm : Messages.Comp.SharePasswordForm.Texts , httpError : Http.Error -> String , authFailed : String + , fulltextPlaceholder : String + , powerSearchPlaceholder : String + , extendedSearch : String } @@ -33,6 +36,9 @@ gb = , passwordForm = Messages.Comp.SharePasswordForm.gb , authFailed = "This share does not exist." , 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 , authFailed = "Diese Freigabe existiert nicht." , httpError = Messages.Comp.HttpError.de + , fulltextPlaceholder = "Volltextsuche…" + , powerSearchPlaceholder = "Erweiterte Suche…" + , extendedSearch = "Erweiterte Suchanfrage" } diff --git a/modules/webapp/src/main/elm/Page/Share/Data.elm b/modules/webapp/src/main/elm/Page/Share/Data.elm index 505f4908..bea33497 100644 --- a/modules/webapp/src/main/elm/Page/Share/Data.elm +++ b/modules/webapp/src/main/elm/Page/Share/Data.elm @@ -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.Model.ItemLightList exposing (ItemLightList) @@ -18,6 +18,7 @@ import Comp.SearchMenu import Comp.SharePasswordForm import Data.Flags exposing (Flags) import Http +import Util.Html exposing (KeyCode) type Mode @@ -32,6 +33,11 @@ type PageError | PageErrorAuthFail +type SearchBarMode + = SearchBarNormal + | SearchBarContent + + type alias Model = { mode : Mode , verifyResult : ShareVerifyResult @@ -42,6 +48,8 @@ type alias Model = , searchInProgress : Bool , itemListModel : Comp.ItemCardList.Model , initialized : Bool + , contentSearch : Maybe String + , searchMode : SearchBarMode } @@ -56,6 +64,8 @@ emptyModel flags = , searchInProgress = False , itemListModel = Comp.ItemCardList.init , initialized = False + , contentSearch = Nothing + , searchMode = SearchBarContent } @@ -87,3 +97,6 @@ type Msg | PowerSearchMsg Comp.PowerSearchInput.Msg | ResetSearch | ItemListMsg Comp.ItemCardList.Msg + | ToggleSearchBar + | SetContentSearch String + | ContentSearchKey (Maybe KeyCode) diff --git a/modules/webapp/src/main/elm/Page/Share/Menubar.elm b/modules/webapp/src/main/elm/Page/Share/Menubar.elm index eb490c37..1bfcc08c 100644 --- a/modules/webapp/src/main/elm/Page/Share/Menubar.elm +++ b/modules/webapp/src/main/elm/Page/Share/Menubar.elm @@ -13,10 +13,11 @@ import Comp.PowerSearchInput import Comp.SearchMenu import Html exposing (..) import Html.Attributes exposing (..) -import Html.Events exposing (onClick) +import Html.Events exposing (onClick, onInput) 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 Util.Html view : Texts -> Model -> Html Msg @@ -30,21 +31,73 @@ view texts model = model.searchMenuModel.textSearchModel powerSearchBar = - div - [ class "relative flex flex-grow flex-row" ] - [ Html.map PowerSearchMsg - (Comp.PowerSearchInput.viewInput - { placeholder = texts.basics.searchPlaceholder - , extraAttrs = [] - } - model.powerSearchInput - ) - , Html.map PowerSearchMsg - (Comp.PowerSearchInput.viewResult [] model.powerSearchInput) + div [ class "flex-grow flex flex-col relative" ] + [ div + [ class "relative flex flex-grow flex-row" ] + [ Html.map PowerSearchMsg + (Comp.PowerSearchInput.viewInput + { placeholder = texts.powerSearchPlaceholder + , extraAttrs = [] + } + 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 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 <| B.secondaryBasicButton { label = "" @@ -59,9 +112,5 @@ view texts model = , attrs = [ href "#" ] } ] - , start = - [ MB.CustomElement <| - powerSearchBar - ] , rootClasses = "mb-2 pt-1 dark:bg-bluegray-700 items-center text-sm" } diff --git a/modules/webapp/src/main/elm/Page/Share/Update.elm b/modules/webapp/src/main/elm/Page/Share/Update.elm index c37a9776..e7f6c852 100644 --- a/modules/webapp/src/main/elm/Page/Share/Update.elm +++ b/modules/webapp/src/main/elm/Page/Share/Update.elm @@ -19,6 +19,8 @@ import Data.ItemQuery as Q import Data.SearchMode import Data.UiSettings exposing (UiSettings) import Page.Share.Data exposing (..) +import Util.Html +import Util.Maybe import Util.Update @@ -74,7 +76,7 @@ update flags settings shareId msg model = settings shareId (ItemListMsg (Comp.ItemCardList.SetResults list)) - { model | searchInProgress = False } + { model | searchInProgress = False, pageError = PageErrorNone } SearchResp (Err err) -> noSub ( { model | pageError = PageErrorHttp err, searchInProgress = False }, Cmd.none ) @@ -149,7 +151,11 @@ update flags settings shareId msg model = ResetSearch -> let nm = - { model | powerSearchInput = Comp.PowerSearchInput.init } + { model + | powerSearchInput = Comp.PowerSearchInput.init + , contentSearch = Nothing + , pageError = PageErrorNone + } in 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 ] ) + 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 ( m, c ) = @@ -179,7 +208,13 @@ makeSearchCmd flags model = xq = Q.and [ 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 =