Allow to search in deleted items

This commit is contained in:
eikek 2021-08-14 15:35:17 +02:00
parent edb344314f
commit 3f1ff5c1ac
5 changed files with 98 additions and 8 deletions

View File

@ -45,6 +45,7 @@ import Data.Fields
import Data.Flags exposing (Flags) import Data.Flags exposing (Flags)
import Data.ItemQuery as Q exposing (ItemQuery) import Data.ItemQuery as Q exposing (ItemQuery)
import Data.PersonUse import Data.PersonUse
import Data.SearchMode exposing (SearchMode)
import Data.UiSettings exposing (UiSettings) import Data.UiSettings exposing (UiSettings)
import DatePicker exposing (DatePicker) import DatePicker exposing (DatePicker)
import Html exposing (..) import Html exposing (..)
@ -89,6 +90,7 @@ type alias Model =
, customValues : CustomFieldValueCollect , customValues : CustomFieldValueCollect
, sourceModel : Maybe String , sourceModel : Maybe String
, openTabs : Set String , openTabs : Set String
, searchMode : SearchMode
} }
@ -133,6 +135,7 @@ init flags =
, customValues = Data.CustomFieldChange.emptyCollect , customValues = Data.CustomFieldChange.emptyCollect
, sourceModel = Nothing , sourceModel = Nothing
, openTabs = Set.fromList [ "Tags", "Inbox" ] , openTabs = Set.fromList [ "Tags", "Inbox" ]
, searchMode = Data.SearchMode.Normal
} }
@ -323,6 +326,7 @@ resetModel model =
model.customFieldModel model.customFieldModel
, customValues = Data.CustomFieldChange.emptyCollect , customValues = Data.CustomFieldChange.emptyCollect
, sourceModel = Nothing , sourceModel = Nothing
, searchMode = Data.SearchMode.Normal
} }
@ -343,6 +347,7 @@ type Msg
| FromDueDateMsg Comp.DatePicker.Msg | FromDueDateMsg Comp.DatePicker.Msg
| UntilDueDateMsg Comp.DatePicker.Msg | UntilDueDateMsg Comp.DatePicker.Msg
| ToggleInbox | ToggleInbox
| ToggleSearchMode
| GetOrgResp (Result Http.Error ReferenceList) | GetOrgResp (Result Http.Error ReferenceList)
| GetEquipResp (Result Http.Error EquipmentList) | GetEquipResp (Result Http.Error EquipmentList)
| GetPersonResp (Result Http.Error PersonList) | GetPersonResp (Result Http.Error PersonList)
@ -683,6 +688,24 @@ updateDrop ddm flags settings msg model =
, dragDrop = DD.DragDropData ddm Nothing , dragDrop = DD.DragDropData ddm Nothing
} }
ToggleSearchMode ->
let
current =
model.searchMode
next =
if current == Data.SearchMode.Normal then
Data.SearchMode.Trashed
else
Data.SearchMode.Normal
in
{ model = { model | searchMode = next }
, cmd = Cmd.none
, stateChange = True
, dragDrop = DD.DragDropData ddm Nothing
}
FromDateMsg m -> FromDateMsg m ->
let let
( dp, event ) = ( dp, event ) =
@ -962,6 +985,7 @@ type SearchTab
| TabDueDate | TabDueDate
| TabSource | TabSource
| TabDirection | TabDirection
| TabTrashed
allTabs : List SearchTab allTabs : List SearchTab
@ -977,6 +1001,7 @@ allTabs =
, TabDueDate , TabDueDate
, TabSource , TabSource
, TabDirection , TabDirection
, TabTrashed
] ]
@ -1016,6 +1041,9 @@ tabName tab =
TabDirection -> TabDirection ->
"direction" "direction"
TabTrashed ->
"trashed"
findTab : Comp.Tabs.Tab msg -> Maybe SearchTab findTab : Comp.Tabs.Tab msg -> Maybe SearchTab
findTab tab = findTab tab =
@ -1053,6 +1081,9 @@ findTab tab =
"direction" -> "direction" ->
Just TabDirection Just TabDirection
"trashed" ->
Just TabTrashed
_ -> _ ->
Nothing Nothing
@ -1099,6 +1130,9 @@ searchTabState settings model tab =
Just TabInbox -> Just TabInbox ->
False False
Just TabTrashed ->
False
Nothing -> Nothing ->
False False
@ -1447,4 +1481,18 @@ searchTabs texts ddd flags settings model =
) )
] ]
} }
, { name = tabName TabTrashed
, title = texts.basics.deleted
, titleRight = []
, info = Nothing
, body =
[ MB.viewItem <|
MB.Checkbox
{ id = "trashed"
, value = model.searchMode == Data.SearchMode.Trashed
, label = texts.basics.deleted
, tagger = \_ -> ToggleSearchMode
}
]
}
] ]

View File

@ -21,6 +21,7 @@ module Data.ItemQuery exposing
import Api.Model.CustomFieldValue exposing (CustomFieldValue) import Api.Model.CustomFieldValue exposing (CustomFieldValue)
import Api.Model.ItemQuery as RQ import Api.Model.ItemQuery as RQ
import Data.Direction exposing (Direction) import Data.Direction exposing (Direction)
import Data.SearchMode exposing (SearchMode)
type TagMatch type TagMatch
@ -73,13 +74,13 @@ and list =
Just (And es) Just (And es)
request : Maybe ItemQuery -> RQ.ItemQuery request : SearchMode -> Maybe ItemQuery -> RQ.ItemQuery
request mq = request smode mq =
{ offset = Nothing { offset = Nothing
, limit = Nothing , limit = Nothing
, withDetails = Just True , withDetails = Just True
, query = renderMaybe mq , query = renderMaybe mq
, searchMode = Nothing , searchMode = Data.SearchMode.asString smode |> Just
} }

View File

@ -0,0 +1,40 @@
{-
Copyright 2020 Docspell Contributors
SPDX-License-Identifier: GPL-3.0-or-later
-}
module Data.SearchMode exposing
( SearchMode(..)
, asString
, fromString
)
type SearchMode
= Normal
| Trashed
fromString : String -> Maybe SearchMode
fromString str =
case String.toLower str of
"normal" ->
Just Normal
"trashed" ->
Just Trashed
_ ->
Nothing
asString : SearchMode -> String
asString smode =
case smode of
Normal ->
"normal"
Trashed ->
"trashed"

View File

@ -239,7 +239,7 @@ doSearchDefaultCmd : SearchParam -> Model -> Cmd Msg
doSearchDefaultCmd param model = doSearchDefaultCmd param model =
let let
smask = smask =
Q.request <| Q.request model.searchMenuModel.searchMode <|
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 model.powerSearchInput.input

View File

@ -23,6 +23,7 @@ import Data.Flags exposing (Flags)
import Data.ItemQuery as Q import Data.ItemQuery as Q
import Data.ItemSelection import Data.ItemSelection
import Data.Items import Data.Items
import Data.SearchMode exposing (SearchMode)
import Data.UiSettings exposing (UiSettings) import Data.UiSettings exposing (UiSettings)
import Page exposing (Page(..)) import Page exposing (Page(..))
import Page.Home.Data exposing (..) import Page.Home.Data exposing (..)
@ -548,7 +549,7 @@ update mId key flags settings msg model =
case model.viewMode of case model.viewMode of
SelectView svm -> SelectView svm ->
-- replace changed items in the view -- replace changed items in the view
noSub ( nm, loadChangedItems flags svm.ids ) noSub ( nm, loadChangedItems flags model.searchMenuModel.searchMode svm.ids )
_ -> _ ->
noSub ( nm, Cmd.none ) noSub ( nm, Cmd.none )
@ -717,8 +718,8 @@ replaceItems model newItems =
{ model | itemListModel = newList } { model | itemListModel = newList }
loadChangedItems : Flags -> Set String -> Cmd Msg loadChangedItems : Flags -> SearchMode -> Set String -> Cmd Msg
loadChangedItems flags ids = loadChangedItems flags smode ids =
if Set.isEmpty ids then if Set.isEmpty ids then
Cmd.none Cmd.none
@ -728,7 +729,7 @@ loadChangedItems flags ids =
Set.toList ids Set.toList ids
searchInit = searchInit =
Q.request (Just <| Q.ItemIdIn idList) Q.request smode (Just <| Q.ItemIdIn idList)
search = search =
{ searchInit { searchInit