mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-11-03 18:00:11 +00:00 
			
		
		
		
	SearchMenu uses query string instead of json form
This commit is contained in:
		@@ -10,7 +10,6 @@ module Data.CustomFieldChange exposing
 | 
			
		||||
 | 
			
		||||
import Api.Model.CustomField exposing (CustomField)
 | 
			
		||||
import Api.Model.CustomFieldValue exposing (CustomFieldValue)
 | 
			
		||||
import Api.Model.ItemFieldValue exposing (ItemFieldValue)
 | 
			
		||||
import Dict exposing (Dict)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										202
									
								
								modules/webapp/src/main/elm/Data/ItemQuery.elm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										202
									
								
								modules/webapp/src/main/elm/Data/ItemQuery.elm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,202 @@
 | 
			
		||||
module Data.ItemQuery exposing
 | 
			
		||||
    ( AttrMatch(..)
 | 
			
		||||
    , ItemQuery(..)
 | 
			
		||||
    , TagMatch(..)
 | 
			
		||||
    , and
 | 
			
		||||
    , render
 | 
			
		||||
    , renderMaybe
 | 
			
		||||
    , request
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
{-| Models the query language for the purpose of generating a query string.
 | 
			
		||||
-}
 | 
			
		||||
 | 
			
		||||
import Api.Model.CustomFieldValue exposing (CustomFieldValue)
 | 
			
		||||
import Api.Model.ItemQuery as RQ
 | 
			
		||||
import Data.Direction exposing (Direction)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
type TagMatch
 | 
			
		||||
    = AnyMatch
 | 
			
		||||
    | AllMatch
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
type AttrMatch
 | 
			
		||||
    = Eq
 | 
			
		||||
    | Neq
 | 
			
		||||
    | Lt
 | 
			
		||||
    | Gt
 | 
			
		||||
    | Lte
 | 
			
		||||
    | Gte
 | 
			
		||||
    | Like
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
type ItemQuery
 | 
			
		||||
    = Inbox Bool
 | 
			
		||||
    | And (List ItemQuery)
 | 
			
		||||
    | Or (List ItemQuery)
 | 
			
		||||
    | Not ItemQuery
 | 
			
		||||
    | TagIds TagMatch (List String)
 | 
			
		||||
    | CatNames TagMatch (List String)
 | 
			
		||||
    | FolderId AttrMatch String
 | 
			
		||||
    | CorrOrgId AttrMatch String
 | 
			
		||||
    | CorrPersId AttrMatch String
 | 
			
		||||
    | ConcPersId AttrMatch String
 | 
			
		||||
    | ConcEquipId AttrMatch String
 | 
			
		||||
    | CustomField AttrMatch CustomFieldValue
 | 
			
		||||
    | DateMs AttrMatch Int
 | 
			
		||||
    | DueDateMs AttrMatch Int
 | 
			
		||||
    | Source AttrMatch String
 | 
			
		||||
    | Dir Direction
 | 
			
		||||
    | ItemIdIn (List String)
 | 
			
		||||
    | ItemName AttrMatch String
 | 
			
		||||
    | AllNames String
 | 
			
		||||
    | Contents String
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
and : List (Maybe ItemQuery) -> Maybe ItemQuery
 | 
			
		||||
and list =
 | 
			
		||||
    case List.filterMap identity list of
 | 
			
		||||
        [] ->
 | 
			
		||||
            Nothing
 | 
			
		||||
 | 
			
		||||
        es ->
 | 
			
		||||
            Just (And es)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
request : Maybe ItemQuery -> RQ.ItemQuery
 | 
			
		||||
request mq =
 | 
			
		||||
    { offset = Nothing
 | 
			
		||||
    , limit = Nothing
 | 
			
		||||
    , withDetails = Just True
 | 
			
		||||
    , query = renderMaybe mq
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
renderMaybe : Maybe ItemQuery -> String
 | 
			
		||||
renderMaybe mq =
 | 
			
		||||
    Maybe.map render mq
 | 
			
		||||
        |> Maybe.withDefault ""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
render : ItemQuery -> String
 | 
			
		||||
render q =
 | 
			
		||||
    let
 | 
			
		||||
        boolStr flag =
 | 
			
		||||
            if flag then
 | 
			
		||||
                "yes"
 | 
			
		||||
 | 
			
		||||
            else
 | 
			
		||||
                "no"
 | 
			
		||||
 | 
			
		||||
        between left right str =
 | 
			
		||||
            left ++ str ++ right
 | 
			
		||||
 | 
			
		||||
        surround lr str =
 | 
			
		||||
            between lr lr str
 | 
			
		||||
 | 
			
		||||
        tagMatchStr tm =
 | 
			
		||||
            case tm of
 | 
			
		||||
                AnyMatch ->
 | 
			
		||||
                    ":"
 | 
			
		||||
 | 
			
		||||
                AllMatch ->
 | 
			
		||||
                    "="
 | 
			
		||||
 | 
			
		||||
        quoteStr =
 | 
			
		||||
            --TODO escape quotes
 | 
			
		||||
            surround "\""
 | 
			
		||||
    in
 | 
			
		||||
    case q of
 | 
			
		||||
        And inner ->
 | 
			
		||||
            List.map render inner
 | 
			
		||||
                |> String.join " "
 | 
			
		||||
                |> between "(& " " )"
 | 
			
		||||
 | 
			
		||||
        Or inner ->
 | 
			
		||||
            List.map render inner
 | 
			
		||||
                |> String.join " "
 | 
			
		||||
                |> between "(| " " )"
 | 
			
		||||
 | 
			
		||||
        Not inner ->
 | 
			
		||||
            "!" ++ render inner
 | 
			
		||||
 | 
			
		||||
        Inbox flag ->
 | 
			
		||||
            "inbox:" ++ boolStr flag
 | 
			
		||||
 | 
			
		||||
        TagIds m ids ->
 | 
			
		||||
            List.map quoteStr ids
 | 
			
		||||
                |> String.join ","
 | 
			
		||||
                |> between ("tag.id" ++ tagMatchStr m) ""
 | 
			
		||||
 | 
			
		||||
        CatNames m ids ->
 | 
			
		||||
            List.map quoteStr ids
 | 
			
		||||
                |> String.join ","
 | 
			
		||||
                |> between ("cat" ++ tagMatchStr m) ""
 | 
			
		||||
 | 
			
		||||
        FolderId m id ->
 | 
			
		||||
            "folder.id" ++ attrMatch m ++ quoteStr id
 | 
			
		||||
 | 
			
		||||
        CorrOrgId m id ->
 | 
			
		||||
            "correspondent.org.id" ++ attrMatch m ++ quoteStr id
 | 
			
		||||
 | 
			
		||||
        CorrPersId m id ->
 | 
			
		||||
            "correspondent.person.id" ++ attrMatch m ++ quoteStr id
 | 
			
		||||
 | 
			
		||||
        ConcPersId m id ->
 | 
			
		||||
            "concerning.person.id" ++ attrMatch m ++ quoteStr id
 | 
			
		||||
 | 
			
		||||
        ConcEquipId m id ->
 | 
			
		||||
            "concerning.equip.id" ++ attrMatch m ++ quoteStr id
 | 
			
		||||
 | 
			
		||||
        CustomField m kv ->
 | 
			
		||||
            "f:" ++ kv.field ++ attrMatch m ++ quoteStr kv.value
 | 
			
		||||
 | 
			
		||||
        DateMs m ms ->
 | 
			
		||||
            "date" ++ attrMatch m ++ "ms" ++ String.fromInt ms
 | 
			
		||||
 | 
			
		||||
        DueDateMs m ms ->
 | 
			
		||||
            "due" ++ attrMatch m ++ "ms" ++ String.fromInt ms
 | 
			
		||||
 | 
			
		||||
        Source m str ->
 | 
			
		||||
            "source" ++ attrMatch m ++ quoteStr str
 | 
			
		||||
 | 
			
		||||
        Dir dir ->
 | 
			
		||||
            "incoming:" ++ boolStr (dir == Data.Direction.Incoming)
 | 
			
		||||
 | 
			
		||||
        ItemIdIn ids ->
 | 
			
		||||
            "id~=" ++ String.join "," ids
 | 
			
		||||
 | 
			
		||||
        ItemName m str ->
 | 
			
		||||
            "name" ++ attrMatch m ++ quoteStr str
 | 
			
		||||
 | 
			
		||||
        AllNames str ->
 | 
			
		||||
            "$names:" ++ quoteStr str
 | 
			
		||||
 | 
			
		||||
        Contents str ->
 | 
			
		||||
            "content:" ++ quoteStr str
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
attrMatch : AttrMatch -> String
 | 
			
		||||
attrMatch am =
 | 
			
		||||
    case am of
 | 
			
		||||
        Eq ->
 | 
			
		||||
            "="
 | 
			
		||||
 | 
			
		||||
        Neq ->
 | 
			
		||||
            "!="
 | 
			
		||||
 | 
			
		||||
        Like ->
 | 
			
		||||
            ":"
 | 
			
		||||
 | 
			
		||||
        Gt ->
 | 
			
		||||
            ">"
 | 
			
		||||
 | 
			
		||||
        Gte ->
 | 
			
		||||
            ">="
 | 
			
		||||
 | 
			
		||||
        Lt ->
 | 
			
		||||
            "<"
 | 
			
		||||
 | 
			
		||||
        Lte ->
 | 
			
		||||
            "<="
 | 
			
		||||
		Reference in New Issue
	
	Block a user