Allow to restore deleted items in webui

This commit is contained in:
eikek 2021-08-14 16:46:04 +02:00
parent f999662905
commit 828e5cf703
8 changed files with 105 additions and 7 deletions

View File

@ -99,6 +99,8 @@ module Api exposing
, removeTagsMultiple , removeTagsMultiple
, reprocessItem , reprocessItem
, reprocessMultiple , reprocessMultiple
, restoreAllItems
, restoreItem
, saveClientSettings , saveClientSettings
, sendMail , sendMail
, setAttachmentName , setAttachmentName
@ -1676,6 +1678,20 @@ deleteAllItems flags ids receive =
} }
restoreAllItems :
Flags
-> Set String
-> (Result Http.Error BasicResult -> msg)
-> Cmd msg
restoreAllItems flags ids receive =
Http2.authPost
{ url = flags.config.baseUrl ++ "/api/v1/sec/items/restoreAll"
, account = getAccount flags
, body = Http.jsonBody (Api.Model.IdList.encode (IdList (Set.toList ids)))
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
}
--- Item --- Item
@ -1973,6 +1989,16 @@ setUnconfirmed flags item receive =
} }
restoreItem : Flags -> String -> (Result Http.Error BasicResult -> msg) -> Cmd msg
restoreItem flags item receive =
Http2.authPost
{ url = flags.config.baseUrl ++ "/api/v1/sec/item/" ++ item ++ "/restore"
, account = getAccount flags
, body = Http.emptyBody
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
}
deleteItem : Flags -> String -> (Result Http.Error BasicResult -> msg) -> Cmd msg deleteItem : Flags -> String -> (Result Http.Error BasicResult -> msg) -> Cmd msg
deleteItem flags item receive = deleteItem flags item receive =
Http2.authDelete Http2.authDelete

View File

@ -1605,11 +1605,7 @@ update key flags inav settings msg model =
) )
RestoreItem -> RestoreItem ->
let resultModelCmd ( model, Api.restoreItem flags model.item.id SaveResp )
_ =
Debug.todo "implement"
in
resultModelCmd ( model, Cmd.none )

View File

@ -1482,7 +1482,7 @@ searchTabs texts ddd flags settings model =
] ]
} }
, { name = tabName TabTrashed , { name = tabName TabTrashed
, title = texts.basics.deleted , title = texts.trashcan
, titleRight = [] , titleRight = []
, info = Nothing , info = Nothing
, body = , body =
@ -1490,7 +1490,7 @@ searchTabs texts ddd flags settings model =
MB.Checkbox MB.Checkbox
{ id = "trashed" { id = "trashed"
, value = model.searchMode == Data.SearchMode.Trashed , value = model.searchMode == Data.SearchMode.Trashed
, label = texts.basics.deleted , label = texts.trashcan
, tagger = \_ -> ToggleSearchMode , tagger = \_ -> ToggleSearchMode
} }
] ]

View File

@ -46,6 +46,7 @@ type alias Texts =
, sourceTab : String , sourceTab : String
, searchInItemSource : String , searchInItemSource : String
, direction : Direction -> String , direction : Direction -> String
, trashcan : String
} }
@ -77,6 +78,7 @@ gb =
, sourceTab = "Source" , sourceTab = "Source"
, searchInItemSource = "Search in item source" , searchInItemSource = "Search in item source"
, direction = Messages.Data.Direction.gb , direction = Messages.Data.Direction.gb
, trashcan = "Trash"
} }
@ -108,4 +110,5 @@ de =
, sourceTab = "Quelle" , sourceTab = "Quelle"
, searchInItemSource = "Suche in Dokumentquelle" , searchInItemSource = "Suche in Dokumentquelle"
, direction = Messages.Data.Direction.de , direction = Messages.Data.Direction.de
, trashcan = "Papierkorb"
} }

View File

@ -30,9 +30,11 @@ type alias Texts =
, powerSearchPlaceholder : String , powerSearchPlaceholder : String
, reallyReprocessQuestion : String , reallyReprocessQuestion : String
, reallyDeleteQuestion : String , reallyDeleteQuestion : String
, reallyRestoreQuestion : String
, editSelectedItems : Int -> String , editSelectedItems : Int -> String
, reprocessSelectedItems : Int -> String , reprocessSelectedItems : Int -> String
, deleteSelectedItems : Int -> String , deleteSelectedItems : Int -> String
, undeleteSelectedItems : Int -> String
, selectAllVisible : String , selectAllVisible : String
, selectNone : String , selectNone : String
, resetSearchForm : String , resetSearchForm : String
@ -54,9 +56,11 @@ gb =
, powerSearchPlaceholder = "Search query " , powerSearchPlaceholder = "Search query "
, reallyReprocessQuestion = "Really reprocess all selected items? Metadata of unconfirmed items may change." , reallyReprocessQuestion = "Really reprocess all selected items? Metadata of unconfirmed items may change."
, reallyDeleteQuestion = "Really delete all selected items?" , reallyDeleteQuestion = "Really delete all selected items?"
, reallyRestoreQuestion = "Really restore all selected items?"
, editSelectedItems = \n -> "Edit " ++ String.fromInt n ++ " selected items" , editSelectedItems = \n -> "Edit " ++ String.fromInt n ++ " selected items"
, reprocessSelectedItems = \n -> "Reprocess " ++ String.fromInt n ++ " selected items" , reprocessSelectedItems = \n -> "Reprocess " ++ String.fromInt n ++ " selected items"
, deleteSelectedItems = \n -> "Delete " ++ String.fromInt n ++ " selected items" , deleteSelectedItems = \n -> "Delete " ++ String.fromInt n ++ " selected items"
, undeleteSelectedItems = \n -> "Restore " ++ String.fromInt n ++ " selected items"
, selectAllVisible = "Select all visible" , selectAllVisible = "Select all visible"
, selectNone = "Select none" , selectNone = "Select none"
, resetSearchForm = "Reset search form" , resetSearchForm = "Reset search form"
@ -78,9 +82,11 @@ de =
, powerSearchPlaceholder = "Suchanfrage" , powerSearchPlaceholder = "Suchanfrage"
, reallyReprocessQuestion = "Wirklich die gewählten Dokumente neu verarbeiten? Die Metadaten von nicht bestätigten Dokumenten können sich dabei ändern." , reallyReprocessQuestion = "Wirklich die gewählten Dokumente neu verarbeiten? Die Metadaten von nicht bestätigten Dokumenten können sich dabei ändern."
, reallyDeleteQuestion = "Wirklich alle gewählten Dokumente löschen?" , reallyDeleteQuestion = "Wirklich alle gewählten Dokumente löschen?"
, reallyRestoreQuestion = "Wirklich alle gewählten Dokumente wiederherstellen?"
, editSelectedItems = \n -> "Ändere " ++ String.fromInt n ++ " gewählte Dokumente" , editSelectedItems = \n -> "Ändere " ++ String.fromInt n ++ " gewählte Dokumente"
, reprocessSelectedItems = \n -> "Erneute Verarbeitung von " ++ String.fromInt n ++ " gewählten Dokumenten" , reprocessSelectedItems = \n -> "Erneute Verarbeitung von " ++ String.fromInt n ++ " gewählten Dokumenten"
, deleteSelectedItems = \n -> "Lösche " ++ String.fromInt n ++ " gewählte Dokumente" , deleteSelectedItems = \n -> "Lösche " ++ String.fromInt n ++ " gewählte Dokumente"
, undeleteSelectedItems = \n -> "Stelle " ++ String.fromInt n ++ " gewählte Dokumente wieder her"
, selectAllVisible = "Wähle alle Dokumente in der Liste" , selectAllVisible = "Wähle alle Dokumente in der Liste"
, selectNone = "Wähle alle Dokumente ab" , selectNone = "Wähle alle Dokumente ab"
, resetSearchForm = "Suchformular zurücksetzen" , resetSearchForm = "Suchformular zurücksetzen"

View File

@ -68,6 +68,7 @@ type alias Model =
type ConfirmModalValue type ConfirmModalValue
= ConfirmReprocessItems = ConfirmReprocessItems
| ConfirmDelete | ConfirmDelete
| ConfirmRestore
type alias SelectViewModel = type alias SelectViewModel =
@ -185,7 +186,9 @@ type Msg
| SelectAllItems | SelectAllItems
| SelectNoItems | SelectNoItems
| RequestDeleteSelected | RequestDeleteSelected
| RequestRestoreSelected
| DeleteSelectedConfirmed | DeleteSelectedConfirmed
| RestoreSelectedConfirmed
| CloseConfirmModal | CloseConfirmModal
| EditSelectedItems | EditSelectedItems
| EditMenuMsg Comp.ItemDetail.MultiEditMenu.Msg | EditMenuMsg Comp.ItemDetail.MultiEditMenu.Msg
@ -214,6 +217,7 @@ type SelectActionMode
| DeleteSelected | DeleteSelected
| EditSelected | EditSelected
| ReprocessSelected | ReprocessSelected
| RestoreSelected
type alias SearchParam = type alias SearchParam =

View File

@ -361,6 +361,28 @@ update mId key flags settings msg model =
_ -> _ ->
noSub ( model, Cmd.none ) noSub ( model, Cmd.none )
RestoreSelectedConfirmed ->
case model.viewMode of
SelectView svm ->
let
cmd =
Api.restoreAllItems flags svm.ids DeleteAllResp
in
noSub
( { model
| viewMode =
SelectView
{ svm
| confirmModal = Nothing
, action = RestoreSelected
}
}
, cmd
)
_ ->
noSub ( model, Cmd.none )
DeleteAllResp (Ok res) -> DeleteAllResp (Ok res) ->
if res.success then if res.success then
@ -469,6 +491,29 @@ update mId key flags settings msg model =
_ -> _ ->
noSub ( model, Cmd.none ) noSub ( model, Cmd.none )
RequestRestoreSelected ->
case model.viewMode of
SelectView svm ->
if svm.ids == Set.empty then
noSub ( model, Cmd.none )
else
let
model_ =
{ model
| viewMode =
SelectView
{ svm
| action = RestoreSelected
, confirmModal = Just ConfirmRestore
}
}
in
noSub ( model_, Cmd.none )
_ ->
noSub ( model, Cmd.none )
EditSelectedItems -> EditSelectedItems ->
case model.viewMode of case model.viewMode of
SelectView svm -> SelectView svm ->

View File

@ -78,6 +78,14 @@ confirmModal texts model =
texts.basics.yes texts.basics.yes
texts.basics.no texts.basics.no
texts.reallyDeleteQuestion texts.reallyDeleteQuestion
ConfirmRestore ->
Comp.ConfirmModal.defaultSettings
RestoreSelectedConfirmed
CloseConfirmModal
texts.basics.yes
texts.basics.no
texts.reallyRestoreQuestion
in in
case model.viewMode of case model.viewMode of
SelectView svm -> SelectView svm ->
@ -264,6 +272,16 @@ editMenuBar texts model svm =
, ( "bg-gray-200 dark:bg-bluegray-600", svm.action == DeleteSelected ) , ( "bg-gray-200 dark:bg-bluegray-600", svm.action == DeleteSelected )
] ]
} }
, MB.CustomButton
{ tagger = RequestRestoreSelected
, label = ""
, icon = Just "fa fa-trash-restore"
, title = texts.undeleteSelectedItems selectCount
, inputClass =
[ ( btnStyle, True )
, ( "bg-gray-200 dark:bg-bluegray-600", svm.action == RestoreSelected )
]
}
] ]
, end = , end =
[ MB.CustomButton [ MB.CustomButton