mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
@ -159,6 +159,7 @@ module Api exposing
|
||||
, searchShare
|
||||
, searchShareStats
|
||||
, sendMail
|
||||
, setAttachmentExtractedText
|
||||
, setAttachmentName
|
||||
, setCollectiveSettings
|
||||
, setConcEquip
|
||||
@ -2049,6 +2050,21 @@ setAttachmentName flags attachId newName receive =
|
||||
}
|
||||
|
||||
|
||||
setAttachmentExtractedText :
|
||||
Flags
|
||||
-> String
|
||||
-> Maybe String
|
||||
-> (Result Http.Error BasicResult -> msg)
|
||||
-> Cmd msg
|
||||
setAttachmentExtractedText flags attachId newName receive =
|
||||
Http2.authPost
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/attachment/" ++ attachId ++ "/extracted-text"
|
||||
, account = getAccount flags
|
||||
, body = Http.jsonBody (Api.Model.OptionalText.encode (OptionalText newName))
|
||||
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||
}
|
||||
|
||||
|
||||
moveAttachmentBefore :
|
||||
Flags
|
||||
-> String
|
||||
|
@ -15,12 +15,14 @@ module Comp.AttachmentMeta exposing
|
||||
|
||||
import Api
|
||||
import Api.Model.AttachmentMeta exposing (AttachmentMeta)
|
||||
import Api.Model.BasicResult exposing (BasicResult)
|
||||
import Api.Model.ItemProposals exposing (ItemProposals)
|
||||
import Api.Model.Label exposing (Label)
|
||||
import Comp.Basic as B
|
||||
import Data.Flags exposing (Flags)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick, onInput)
|
||||
import Http
|
||||
import Messages.Comp.AttachmentMeta exposing (Texts)
|
||||
import Styles as S
|
||||
@ -28,13 +30,20 @@ import Styles as S
|
||||
|
||||
type alias Model =
|
||||
{ id : String
|
||||
, meta : DataResult AttachmentMeta
|
||||
, meta : DataResult
|
||||
}
|
||||
|
||||
|
||||
type DataResult a
|
||||
type alias EditModel =
|
||||
{ meta : AttachmentMeta
|
||||
, text : String
|
||||
}
|
||||
|
||||
|
||||
type DataResult
|
||||
= NotAvailable
|
||||
| Success a
|
||||
| Success AttachmentMeta
|
||||
| Editing EditModel
|
||||
| HttpFailure Http.Error
|
||||
|
||||
|
||||
@ -54,16 +63,64 @@ init flags id =
|
||||
|
||||
type Msg
|
||||
= MetaResp (Result Http.Error AttachmentMeta)
|
||||
| SaveResp String (Result Http.Error BasicResult)
|
||||
| ToggleEdit
|
||||
| SaveExtractedText
|
||||
| SetExtractedText String
|
||||
|
||||
|
||||
update : Msg -> Model -> Model
|
||||
update msg model =
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update flags msg model =
|
||||
case msg of
|
||||
MetaResp (Ok am) ->
|
||||
{ model | meta = Success am }
|
||||
( { model | meta = Success am }, Cmd.none )
|
||||
|
||||
MetaResp (Err err) ->
|
||||
{ model | meta = HttpFailure err }
|
||||
( { model | meta = HttpFailure err }, Cmd.none )
|
||||
|
||||
SaveResp newText (Ok result) ->
|
||||
if result.success then
|
||||
case model.meta of
|
||||
Editing { meta } ->
|
||||
( { model | meta = Success { meta | content = newText } }, Cmd.none )
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
else
|
||||
( model, Cmd.none )
|
||||
|
||||
SaveResp _ (Err err) ->
|
||||
( { model | meta = HttpFailure err }, Cmd.none )
|
||||
|
||||
ToggleEdit ->
|
||||
case model.meta of
|
||||
Editing m ->
|
||||
( { model | meta = Success m.meta }, Cmd.none )
|
||||
|
||||
Success m ->
|
||||
( { model | meta = Editing { meta = m, text = m.content } }, Cmd.none )
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
SaveExtractedText ->
|
||||
case model.meta of
|
||||
Editing em ->
|
||||
( model
|
||||
, Api.setAttachmentExtractedText flags model.id (Just em.text) (SaveResp em.text)
|
||||
)
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
SetExtractedText txt ->
|
||||
case model.meta of
|
||||
Editing em ->
|
||||
( { model | meta = Editing { em | text = txt } }, Cmd.none )
|
||||
|
||||
_ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
|
||||
@ -89,19 +146,55 @@ view2 texts attrs model =
|
||||
]
|
||||
|
||||
Success data ->
|
||||
viewData2 texts data
|
||||
viewData2 texts data Nothing
|
||||
|
||||
Editing em ->
|
||||
viewData2 texts em.meta (Just em.text)
|
||||
]
|
||||
|
||||
|
||||
viewData2 : Texts -> AttachmentMeta -> Html Msg
|
||||
viewData2 texts meta =
|
||||
viewData2 : Texts -> AttachmentMeta -> Maybe String -> Html Msg
|
||||
viewData2 texts meta maybeText =
|
||||
div [ class "flex flex-col" ]
|
||||
[ div [ class "text-lg font-bold" ]
|
||||
[ text texts.content
|
||||
]
|
||||
, div [ class "px-2 py-2 text-sm bg-yellow-50 dark:bg-stone-800 break-words whitespace-pre max-h-80 overflow-auto" ]
|
||||
[ text meta.content
|
||||
[ div [ class "flex flex-row items-center" ]
|
||||
[ div [ class "text-lg font-bold flex flex-grow" ]
|
||||
[ text texts.content
|
||||
]
|
||||
, case maybeText of
|
||||
Nothing ->
|
||||
div [ class "flex text-sm" ]
|
||||
[ a [ href "#", class S.link, onClick ToggleEdit ]
|
||||
[ i [ class "fa fa-edit pr-1" ] []
|
||||
, text texts.basics.edit
|
||||
]
|
||||
]
|
||||
|
||||
Just _ ->
|
||||
div [ class "flex text-sm" ]
|
||||
[ a [ href "#", class S.link, onClick ToggleEdit ]
|
||||
[ text texts.basics.cancel
|
||||
]
|
||||
, span [ class "px-2" ] [ text "•" ]
|
||||
, a [ href "#", class S.link, onClick SaveExtractedText ]
|
||||
[ i [ class "fa fa-save pr-1" ] []
|
||||
, text texts.basics.submit
|
||||
]
|
||||
]
|
||||
]
|
||||
, case maybeText of
|
||||
Nothing ->
|
||||
div [ class "px-2 py-2 text-sm bg-yellow-50 dark:bg-stone-800 break-words whitespace-pre max-h-80 overflow-auto" ]
|
||||
[ text meta.content
|
||||
]
|
||||
|
||||
Just em ->
|
||||
textarea
|
||||
[ class "px-2 py-2 text-sm bg-yellow-50 dark:bg-stone-800 break-words whitespace-pre h-80 overflow-auto"
|
||||
, value em
|
||||
, onInput SetExtractedText
|
||||
, rows 10
|
||||
]
|
||||
[]
|
||||
, div [ class "text-lg font-bold mt-2" ]
|
||||
[ text texts.labels
|
||||
]
|
||||
|
@ -991,11 +991,13 @@ update inav env msg model =
|
||||
case Dict.get id model.attachMeta of
|
||||
Just cm ->
|
||||
let
|
||||
am =
|
||||
Comp.AttachmentMeta.update lmsg cm
|
||||
( am, ac ) =
|
||||
Comp.AttachmentMeta.update env.flags lmsg cm
|
||||
in
|
||||
resultModel
|
||||
{ model | attachMeta = Dict.insert id am model.attachMeta }
|
||||
resultModelCmd
|
||||
( { model | attachMeta = Dict.insert id am model.attachMeta }
|
||||
, Cmd.map (AttachMetaMsg id) ac
|
||||
)
|
||||
|
||||
Nothing ->
|
||||
resultModel model
|
||||
|
Reference in New Issue
Block a user