mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Check for existing bookmarks
This commit is contained in:
@ -16,6 +16,7 @@ module Api exposing
|
|||||||
, addTag
|
, addTag
|
||||||
, addTagsMultiple
|
, addTagsMultiple
|
||||||
, attachmentPreviewURL
|
, attachmentPreviewURL
|
||||||
|
, bookmarkNameExists
|
||||||
, cancelJob
|
, cancelJob
|
||||||
, changeFolderName
|
, changeFolderName
|
||||||
, changePassword
|
, changePassword
|
||||||
@ -2371,6 +2372,23 @@ addBookmark flags model receive =
|
|||||||
Task.andThen add load |> Task.attempt receive
|
Task.andThen add load |> Task.attempt receive
|
||||||
|
|
||||||
|
|
||||||
|
bookmarkNameExistsTask : Flags -> BookmarkLocation -> String -> Task.Task Http.Error Bool
|
||||||
|
bookmarkNameExistsTask flags loc name =
|
||||||
|
let
|
||||||
|
load =
|
||||||
|
getBookmarksTask flags loc
|
||||||
|
|
||||||
|
exists current =
|
||||||
|
Data.BookmarkedQuery.exists name current
|
||||||
|
in
|
||||||
|
Task.map exists load
|
||||||
|
|
||||||
|
|
||||||
|
bookmarkNameExists : Flags -> BookmarkLocation -> String -> (Result Http.Error Bool -> msg) -> Cmd msg
|
||||||
|
bookmarkNameExists flags loc name receive =
|
||||||
|
bookmarkNameExistsTask flags loc name |> Task.attempt receive
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- OTP
|
--- OTP
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
module Comp.BookmarkQueryForm exposing (Model, Msg, get, init, initQuery, update, view)
|
module Comp.BookmarkQueryForm exposing (Model, Msg, get, init, initQuery, update, view)
|
||||||
|
|
||||||
|
import Api
|
||||||
import Comp.Basic as B
|
import Comp.Basic as B
|
||||||
import Comp.PowerSearchInput
|
import Comp.PowerSearchInput
|
||||||
import Data.BookmarkedQuery exposing (BookmarkedQueryDef, Location(..))
|
import Data.BookmarkedQuery exposing (BookmarkedQueryDef, Location(..))
|
||||||
@ -14,15 +15,20 @@ import Data.Flags exposing (Flags)
|
|||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (onCheck, onInput)
|
import Html.Events exposing (onCheck, onInput)
|
||||||
|
import Http
|
||||||
import Messages.Comp.BookmarkQueryForm exposing (Texts)
|
import Messages.Comp.BookmarkQueryForm exposing (Texts)
|
||||||
import Styles as S
|
import Styles as S
|
||||||
|
import Throttle exposing (Throttle)
|
||||||
|
import Time
|
||||||
import Util.Maybe
|
import Util.Maybe
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ name : Maybe String
|
{ name : Maybe String
|
||||||
|
, nameExists : Bool
|
||||||
, queryModel : Comp.PowerSearchInput.Model
|
, queryModel : Comp.PowerSearchInput.Model
|
||||||
, location : Location
|
, location : Location
|
||||||
|
, nameExistsThrottle : Throttle Msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -35,8 +41,10 @@ initQuery q =
|
|||||||
Comp.PowerSearchInput.init
|
Comp.PowerSearchInput.init
|
||||||
in
|
in
|
||||||
( { name = Nothing
|
( { name = Nothing
|
||||||
|
, nameExists = False
|
||||||
, queryModel = res.model
|
, queryModel = res.model
|
||||||
, location = User
|
, location = User
|
||||||
|
, nameExistsThrottle = Throttle.create 1
|
||||||
}
|
}
|
||||||
, Cmd.batch
|
, Cmd.batch
|
||||||
[ Cmd.map QueryMsg res.cmd
|
[ Cmd.map QueryMsg res.cmd
|
||||||
@ -79,16 +87,46 @@ type Msg
|
|||||||
= SetName String
|
= SetName String
|
||||||
| QueryMsg Comp.PowerSearchInput.Msg
|
| QueryMsg Comp.PowerSearchInput.Msg
|
||||||
| SetLocation Location
|
| SetLocation Location
|
||||||
|
| NameExistsResp (Result Http.Error Bool)
|
||||||
|
| UpdateThrottle
|
||||||
|
|
||||||
|
|
||||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
|
update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Sub Msg )
|
||||||
update _ msg model =
|
update flags msg model =
|
||||||
|
let
|
||||||
|
nameCheck1 name =
|
||||||
|
Api.bookmarkNameExists flags model.location name NameExistsResp
|
||||||
|
|
||||||
|
nameCheck2 loc =
|
||||||
|
case model.name of
|
||||||
|
Just n ->
|
||||||
|
Api.bookmarkNameExists flags loc n NameExistsResp
|
||||||
|
|
||||||
|
Nothing ->
|
||||||
|
Cmd.none
|
||||||
|
|
||||||
|
throttleSub =
|
||||||
|
Throttle.ifNeeded
|
||||||
|
(Time.every 150 (\_ -> UpdateThrottle))
|
||||||
|
model.nameExistsThrottle
|
||||||
|
in
|
||||||
case msg of
|
case msg of
|
||||||
SetName n ->
|
SetName n ->
|
||||||
( { model | name = Util.Maybe.fromString n }, Cmd.none, Sub.none )
|
let
|
||||||
|
( newThrottle, cmd ) =
|
||||||
|
Throttle.try (nameCheck1 n) model.nameExistsThrottle
|
||||||
|
in
|
||||||
|
( { model | name = Util.Maybe.fromString n, nameExistsThrottle = newThrottle }
|
||||||
|
, cmd
|
||||||
|
, throttleSub
|
||||||
|
)
|
||||||
|
|
||||||
SetLocation loc ->
|
SetLocation loc ->
|
||||||
( { model | location = loc }, Cmd.none, Sub.none )
|
let
|
||||||
|
( newThrottle, cmd ) =
|
||||||
|
Throttle.try (nameCheck2 loc) model.nameExistsThrottle
|
||||||
|
in
|
||||||
|
( { model | location = loc, nameExistsThrottle = newThrottle }, cmd, throttleSub )
|
||||||
|
|
||||||
QueryMsg lm ->
|
QueryMsg lm ->
|
||||||
let
|
let
|
||||||
@ -100,6 +138,25 @@ update _ msg model =
|
|||||||
, Sub.map QueryMsg res.subs
|
, Sub.map QueryMsg res.subs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
NameExistsResp (Ok flag) ->
|
||||||
|
( { model | nameExists = flag }
|
||||||
|
, Cmd.none
|
||||||
|
, Sub.none
|
||||||
|
)
|
||||||
|
|
||||||
|
NameExistsResp (Err err) ->
|
||||||
|
( model, Cmd.none, Sub.none )
|
||||||
|
|
||||||
|
UpdateThrottle ->
|
||||||
|
let
|
||||||
|
( newThrottle, cmd ) =
|
||||||
|
Throttle.update model.nameExistsThrottle
|
||||||
|
in
|
||||||
|
( { model | nameExistsThrottle = newThrottle }
|
||||||
|
, cmd
|
||||||
|
, throttleSub
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- View
|
--- View
|
||||||
@ -124,9 +181,9 @@ view texts model =
|
|||||||
in
|
in
|
||||||
div
|
div
|
||||||
[ class "flex flex-col" ]
|
[ class "flex flex-col" ]
|
||||||
[ div [ class "mb-4" ]
|
[ div [ class "mb-2" ]
|
||||||
[ label
|
[ label
|
||||||
[ for "sharename"
|
[ for "bookmark-name"
|
||||||
, class S.inputLabel
|
, class S.inputLabel
|
||||||
]
|
]
|
||||||
[ text texts.basics.name
|
[ text texts.basics.name
|
||||||
@ -137,10 +194,17 @@ view texts model =
|
|||||||
, onInput SetName
|
, onInput SetName
|
||||||
, placeholder texts.basics.name
|
, placeholder texts.basics.name
|
||||||
, value <| Maybe.withDefault "" model.name
|
, value <| Maybe.withDefault "" model.name
|
||||||
, id "sharename"
|
, id "bookmark-name"
|
||||||
, class S.textInput
|
, class S.textInput
|
||||||
]
|
]
|
||||||
[]
|
[]
|
||||||
|
, span
|
||||||
|
[ class S.infoMessagePlain
|
||||||
|
, class "font-medium text-sm"
|
||||||
|
, classList [ ( "invisible", not model.nameExists ) ]
|
||||||
|
]
|
||||||
|
[ text texts.nameExistsWarning
|
||||||
|
]
|
||||||
]
|
]
|
||||||
, div [ class "flex flex-col mb-4 " ]
|
, div [ class "flex flex-col mb-4 " ]
|
||||||
[ label [ class "inline-flex items-center" ]
|
[ label [ class "inline-flex items-center" ]
|
||||||
|
@ -21,6 +21,7 @@ type alias Texts =
|
|||||||
, userLocationText : String
|
, userLocationText : String
|
||||||
, collectiveLocation : String
|
, collectiveLocation : String
|
||||||
, collectiveLocationText : String
|
, collectiveLocationText : String
|
||||||
|
, nameExistsWarning : String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ gb =
|
|||||||
, userLocationText = "The bookmarked query is just for you"
|
, userLocationText = "The bookmarked query is just for you"
|
||||||
, collectiveLocation = "Collective scope"
|
, collectiveLocation = "Collective scope"
|
||||||
, collectiveLocationText = "The bookmarked query can be used and edited by all users"
|
, collectiveLocationText = "The bookmarked query can be used and edited by all users"
|
||||||
|
, nameExistsWarning = "A bookmark with this name exists, it is overwritten on save!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,4 +45,5 @@ de =
|
|||||||
, userLocationText = "Der Bookmark ist nur für dich"
|
, userLocationText = "Der Bookmark ist nur für dich"
|
||||||
, collectiveLocation = "Kollektiv-Bookmark"
|
, collectiveLocation = "Kollektiv-Bookmark"
|
||||||
, collectiveLocationText = "Der Bookmark kann von allen Benutzer verwendet werden"
|
, collectiveLocationText = "Der Bookmark kann von allen Benutzer verwendet werden"
|
||||||
|
, nameExistsWarning = "Der Bookmark existiert bereits. Er wird beim Speichern überschrieben."
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,11 @@ errorText =
|
|||||||
" text-red-600 dark:text-orange-800 "
|
" text-red-600 dark:text-orange-800 "
|
||||||
|
|
||||||
|
|
||||||
|
warnMessagePlain : String
|
||||||
|
warnMessagePlain =
|
||||||
|
" text-yellow-800 dark:text-amber-200 "
|
||||||
|
|
||||||
|
|
||||||
warnMessage : String
|
warnMessage : String
|
||||||
warnMessage =
|
warnMessage =
|
||||||
warnMessageColors ++ " border dark:bg-opacity-25 px-2 py-2 rounded "
|
warnMessageColors ++ " border dark:bg-opacity-25 px-2 py-2 rounded "
|
||||||
@ -62,12 +67,17 @@ warnMessage =
|
|||||||
|
|
||||||
warnMessageColors : String
|
warnMessageColors : String
|
||||||
warnMessageColors =
|
warnMessageColors =
|
||||||
" border-yellow-800 bg-yellow-50 text-yellow-800 dark:border-amber-200 dark:bg-amber-800 dark:text-amber-200 "
|
warnMessagePlain ++ " border-yellow-800 bg-yellow-50 dark:border-amber-200 dark:bg-amber-800 "
|
||||||
|
|
||||||
|
|
||||||
|
infoMessagePlain : String
|
||||||
|
infoMessagePlain =
|
||||||
|
" text-blue-800 dark:text-sky-200 "
|
||||||
|
|
||||||
|
|
||||||
infoMessageBase : String
|
infoMessageBase : String
|
||||||
infoMessageBase =
|
infoMessageBase =
|
||||||
" border border-blue-800 bg-blue-100 text-blue-800 dark:border-sky-200 dark:bg-sky-800 dark:text-sky-200 dark:bg-opacity-25 "
|
infoMessagePlain ++ " border border-blue-800 bg-blue-100 dark:border-sky-200 dark:bg-sky-800 dark:bg-opacity-25 "
|
||||||
|
|
||||||
|
|
||||||
infoMessage : String
|
infoMessage : String
|
||||||
|
Reference in New Issue
Block a user