diff --git a/modules/webapp/src/main/elm/Api.elm b/modules/webapp/src/main/elm/Api.elm index abba1ebc..1ea82fbe 100644 --- a/modules/webapp/src/main/elm/Api.elm +++ b/modules/webapp/src/main/elm/Api.elm @@ -99,6 +99,8 @@ module Api exposing , removeTagsMultiple , reprocessItem , reprocessMultiple + , restoreAllItems + , restoreItem , saveClientSettings , sendMail , 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 @@ -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 item receive = Http2.authDelete diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm index b0905241..d3574835 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm @@ -1605,11 +1605,7 @@ update key flags inav settings msg model = ) RestoreItem -> - let - _ = - Debug.todo "implement" - in - resultModelCmd ( model, Cmd.none ) + resultModelCmd ( model, Api.restoreItem flags model.item.id SaveResp ) diff --git a/modules/webapp/src/main/elm/Comp/SearchMenu.elm b/modules/webapp/src/main/elm/Comp/SearchMenu.elm index 1374f0b9..a4a00daf 100644 --- a/modules/webapp/src/main/elm/Comp/SearchMenu.elm +++ b/modules/webapp/src/main/elm/Comp/SearchMenu.elm @@ -1482,7 +1482,7 @@ searchTabs texts ddd flags settings model = ] } , { name = tabName TabTrashed - , title = texts.basics.deleted + , title = texts.trashcan , titleRight = [] , info = Nothing , body = @@ -1490,7 +1490,7 @@ searchTabs texts ddd flags settings model = MB.Checkbox { id = "trashed" , value = model.searchMode == Data.SearchMode.Trashed - , label = texts.basics.deleted + , label = texts.trashcan , tagger = \_ -> ToggleSearchMode } ] diff --git a/modules/webapp/src/main/elm/Messages/Comp/SearchMenu.elm b/modules/webapp/src/main/elm/Messages/Comp/SearchMenu.elm index 27be0496..02f13091 100644 --- a/modules/webapp/src/main/elm/Messages/Comp/SearchMenu.elm +++ b/modules/webapp/src/main/elm/Messages/Comp/SearchMenu.elm @@ -46,6 +46,7 @@ type alias Texts = , sourceTab : String , searchInItemSource : String , direction : Direction -> String + , trashcan : String } @@ -77,6 +78,7 @@ gb = , sourceTab = "Source" , searchInItemSource = "Search in item source…" , direction = Messages.Data.Direction.gb + , trashcan = "Trash" } @@ -108,4 +110,5 @@ de = , sourceTab = "Quelle" , searchInItemSource = "Suche in Dokumentquelle…" , direction = Messages.Data.Direction.de + , trashcan = "Papierkorb" } diff --git a/modules/webapp/src/main/elm/Messages/Page/Home.elm b/modules/webapp/src/main/elm/Messages/Page/Home.elm index 27c875d0..5aa8ecbf 100644 --- a/modules/webapp/src/main/elm/Messages/Page/Home.elm +++ b/modules/webapp/src/main/elm/Messages/Page/Home.elm @@ -30,9 +30,11 @@ type alias Texts = , powerSearchPlaceholder : String , reallyReprocessQuestion : String , reallyDeleteQuestion : String + , reallyRestoreQuestion : String , editSelectedItems : Int -> String , reprocessSelectedItems : Int -> String , deleteSelectedItems : Int -> String + , undeleteSelectedItems : Int -> String , selectAllVisible : String , selectNone : String , resetSearchForm : String @@ -54,9 +56,11 @@ gb = , powerSearchPlaceholder = "Search query …" , reallyReprocessQuestion = "Really reprocess all selected items? Metadata of unconfirmed items may change." , reallyDeleteQuestion = "Really delete all selected items?" + , reallyRestoreQuestion = "Really restore all selected items?" , editSelectedItems = \n -> "Edit " ++ String.fromInt n ++ " selected items" , reprocessSelectedItems = \n -> "Reprocess " ++ 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" , selectNone = "Select none" , resetSearchForm = "Reset search form" @@ -78,9 +82,11 @@ de = , powerSearchPlaceholder = "Suchanfrage…" , 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?" + , reallyRestoreQuestion = "Wirklich alle gewählten Dokumente wiederherstellen?" , editSelectedItems = \n -> "Ändere " ++ String.fromInt n ++ " gewählte Dokumente" , reprocessSelectedItems = \n -> "Erneute Verarbeitung von " ++ String.fromInt n ++ " gewählten Dokumenten" , 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" , selectNone = "Wähle alle Dokumente ab" , resetSearchForm = "Suchformular zurücksetzen" diff --git a/modules/webapp/src/main/elm/Page/Home/Data.elm b/modules/webapp/src/main/elm/Page/Home/Data.elm index 46318790..8d8455f9 100644 --- a/modules/webapp/src/main/elm/Page/Home/Data.elm +++ b/modules/webapp/src/main/elm/Page/Home/Data.elm @@ -68,6 +68,7 @@ type alias Model = type ConfirmModalValue = ConfirmReprocessItems | ConfirmDelete + | ConfirmRestore type alias SelectViewModel = @@ -185,7 +186,9 @@ type Msg | SelectAllItems | SelectNoItems | RequestDeleteSelected + | RequestRestoreSelected | DeleteSelectedConfirmed + | RestoreSelectedConfirmed | CloseConfirmModal | EditSelectedItems | EditMenuMsg Comp.ItemDetail.MultiEditMenu.Msg @@ -214,6 +217,7 @@ type SelectActionMode | DeleteSelected | EditSelected | ReprocessSelected + | RestoreSelected type alias SearchParam = diff --git a/modules/webapp/src/main/elm/Page/Home/Update.elm b/modules/webapp/src/main/elm/Page/Home/Update.elm index 9ddfb8b7..7c68f082 100644 --- a/modules/webapp/src/main/elm/Page/Home/Update.elm +++ b/modules/webapp/src/main/elm/Page/Home/Update.elm @@ -361,6 +361,28 @@ update mId key flags settings msg model = _ -> 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) -> if res.success then @@ -469,6 +491,29 @@ update mId key flags settings msg model = _ -> 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 -> case model.viewMode of SelectView svm -> diff --git a/modules/webapp/src/main/elm/Page/Home/View2.elm b/modules/webapp/src/main/elm/Page/Home/View2.elm index ad464746..dbbff10f 100644 --- a/modules/webapp/src/main/elm/Page/Home/View2.elm +++ b/modules/webapp/src/main/elm/Page/Home/View2.elm @@ -78,6 +78,14 @@ confirmModal texts model = texts.basics.yes texts.basics.no texts.reallyDeleteQuestion + ConfirmRestore -> + Comp.ConfirmModal.defaultSettings + RestoreSelectedConfirmed + CloseConfirmModal + texts.basics.yes + texts.basics.no + texts.reallyRestoreQuestion + in case model.viewMode of SelectView svm -> @@ -264,6 +272,16 @@ editMenuBar texts model svm = , ( "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 = [ MB.CustomButton