mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 18:39:33 +00:00
Using SelectViewModel, bulk deletion of item attachments
This commit is contained in:
parent
1db5eaf5ee
commit
decae84aec
@ -19,6 +19,7 @@ module Api exposing
|
||||
, createScanMailbox
|
||||
, deleteAllItems
|
||||
, deleteAttachment
|
||||
, deleteAttachments
|
||||
, deleteCustomField
|
||||
, deleteCustomValue
|
||||
, deleteCustomValueMultiple
|
||||
@ -609,6 +610,20 @@ deleteAttachment flags attachId receive =
|
||||
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||
}
|
||||
|
||||
--- Delete Attachments
|
||||
|
||||
deleteAttachments :
|
||||
Flags
|
||||
-> Set String
|
||||
-> (Result Http.Error BasicResult -> msg)
|
||||
-> Cmd msg
|
||||
deleteAttachments flags attachIds receive =
|
||||
Http2.authPost
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/attachments/delete"
|
||||
, account = getAccount flags
|
||||
, body = Http.jsonBody (Api.Model.IdList.encode (Set.toList attachIds |> IdList))
|
||||
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||
}
|
||||
|
||||
|
||||
--- Attachment Metadata
|
||||
|
@ -4,15 +4,16 @@ module Comp.ItemDetail.Model exposing
|
||||
, Msg(..)
|
||||
, NotesField(..)
|
||||
, SaveNameState(..)
|
||||
, SelectActionMode(..)
|
||||
, UpdateResult
|
||||
, ViewMode(..)
|
||||
, emptyModel
|
||||
, initSelectViewModel
|
||||
, isEditNotes
|
||||
, personMatchesOrg
|
||||
, resultModel
|
||||
, resultModelCmd
|
||||
, resultModelCmdSub
|
||||
, initSelectViewModel
|
||||
)
|
||||
|
||||
import Api.Model.BasicResult exposing (BasicResult)
|
||||
@ -108,7 +109,6 @@ type alias Model =
|
||||
, attachmentDropdownOpen : Bool
|
||||
, editMenuTabsOpen : Set String
|
||||
, viewMode : ViewMode
|
||||
, selectedAttachments: Set String
|
||||
}
|
||||
|
||||
type ViewMode
|
||||
@ -202,7 +202,6 @@ emptyModel =
|
||||
, attachmentDropdownOpen = False
|
||||
, editMenuTabsOpen = Set.empty
|
||||
, viewMode = SimpleView
|
||||
, selectedAttachments = Set.empty
|
||||
}
|
||||
|
||||
initSelectViewModel : SelectViewModel
|
||||
@ -264,6 +263,8 @@ type Msg
|
||||
| TogglePdfNativeView Bool
|
||||
| RequestDeleteAttachment String
|
||||
| DeleteAttachConfirmed String
|
||||
| RequestDeleteSelected
|
||||
| DeleteSelectedConfirmed
|
||||
| AttachModalCancelled
|
||||
| DeleteAttachResp (Result Http.Error BasicResult)
|
||||
| AddFilesToggle
|
||||
|
@ -182,6 +182,7 @@ attachHeader texts settings model _ attach =
|
||||
]
|
||||
, href "#"
|
||||
, title texts.deleteAttachments
|
||||
, onClick RequestDeleteSelected
|
||||
]
|
||||
[ i [ class "fa fa-trash" ] []
|
||||
]
|
||||
@ -352,8 +353,8 @@ menuItem texts model pos attach =
|
||||
|
||||
iconClass =
|
||||
case model.viewMode of
|
||||
SelectView _ ->
|
||||
if Set.member attach.id model.selectedAttachments then
|
||||
SelectView svm ->
|
||||
if Set.member attach.id svm.ids then
|
||||
"fa fa-check-circle ml-1"
|
||||
else
|
||||
"fa fa-circle ml-1"
|
||||
|
@ -24,19 +24,7 @@ import Comp.Dropdown exposing (isDropdownChangeMsg)
|
||||
import Comp.Dropzone
|
||||
import Comp.EquipmentForm
|
||||
import Comp.ItemDetail.FieldTabState as FTabState
|
||||
import Comp.ItemDetail.Model
|
||||
exposing
|
||||
( AttachmentRename
|
||||
, Model
|
||||
, Msg(..)
|
||||
, NotesField(..)
|
||||
, SaveNameState(..)
|
||||
, UpdateResult
|
||||
, isEditNotes
|
||||
, resultModel
|
||||
, resultModelCmd
|
||||
, resultModelCmdSub
|
||||
)
|
||||
import Comp.ItemDetail.Model exposing (AttachmentRename, Model, Msg(..), NotesField(..), SaveNameState(..), SelectActionMode(..), UpdateResult, isEditNotes, resultModel, resultModelCmd, resultModelCmdSub)
|
||||
import Comp.ItemMail
|
||||
import Comp.KeyInput
|
||||
import Comp.LinkTarget
|
||||
@ -281,16 +269,19 @@ update key flags inav settings msg model =
|
||||
}
|
||||
|
||||
ToggleAttachment id ->
|
||||
if Set.member id model.selectedAttachments then
|
||||
resultModel
|
||||
{ model
|
||||
| selectedAttachments = Set.remove id model.selectedAttachments
|
||||
}
|
||||
else
|
||||
resultModel
|
||||
{ model
|
||||
| selectedAttachments = Set.insert id model.selectedAttachments
|
||||
}
|
||||
case model.viewMode of
|
||||
SelectView svm ->
|
||||
let
|
||||
svm_ =
|
||||
if Set.member id svm.ids then
|
||||
{ svm | ids = Set.remove id svm.ids }
|
||||
else
|
||||
{ svm | ids = Set.insert id svm.ids }
|
||||
in
|
||||
resultModel
|
||||
{ model | viewMode = SelectView svm_ }
|
||||
_ ->
|
||||
resultModel model
|
||||
|
||||
ToggleMenu ->
|
||||
resultModel
|
||||
@ -948,6 +939,49 @@ update key flags inav settings msg model =
|
||||
in
|
||||
resultModel model_
|
||||
|
||||
RequestDeleteSelected ->
|
||||
case model.viewMode of
|
||||
SelectView svm ->
|
||||
if Set.isEmpty svm.ids then
|
||||
resultModel model
|
||||
|
||||
else
|
||||
let
|
||||
confirmModal =
|
||||
Comp.ConfirmModal.defaultSettings
|
||||
DeleteSelectedConfirmed
|
||||
AttachModalCancelled
|
||||
"Ok"
|
||||
"Cancel"
|
||||
"Really delete these files?"
|
||||
|
||||
model_ =
|
||||
{ model
|
||||
| viewMode =
|
||||
SelectView
|
||||
{ svm
|
||||
| action = DeleteSelected
|
||||
}
|
||||
, attachModal = Just confirmModal
|
||||
}
|
||||
in
|
||||
resultModel model_
|
||||
|
||||
_ ->
|
||||
resultModel model
|
||||
|
||||
DeleteSelectedConfirmed ->
|
||||
case model.viewMode of
|
||||
SelectView svm ->
|
||||
let
|
||||
cmd =
|
||||
Api.deleteAttachments flags svm.ids DeleteAttachResp
|
||||
in
|
||||
resultModelCmd ( { model | attachModal = Nothing, viewMode = SimpleView }, cmd )
|
||||
|
||||
_ ->
|
||||
resultModel model
|
||||
|
||||
AddFilesToggle ->
|
||||
resultModel
|
||||
{ model
|
||||
@ -1373,7 +1407,6 @@ update key flags inav settings msg model =
|
||||
resultModel { model
|
||||
| attachMenuOpen = not model.attachMenuOpen
|
||||
, viewMode = SimpleView
|
||||
, selectedAttachments = Set.empty
|
||||
}
|
||||
|
||||
UiSettingsUpdated ->
|
||||
@ -1598,7 +1631,6 @@ update key flags inav settings msg model =
|
||||
withSub
|
||||
( { model
|
||||
| viewMode = nextView
|
||||
, selectedAttachments = Set.empty
|
||||
}
|
||||
, cmd
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user