From e3053549b31d6507118a08f955085660283bad2f Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Mon, 26 Apr 2021 22:02:45 +0200 Subject: [PATCH] Extract strings in item detail modals --- .../elm/Comp/ItemDetail/ConfirmModalView.elm | 60 +++++++++++++++ .../src/main/elm/Comp/ItemDetail/Model.elm | 13 +++- .../elm/Comp/ItemDetail/SingleAttachment.elm | 12 +-- .../src/main/elm/Comp/ItemDetail/Update.elm | 73 ++----------------- .../src/main/elm/Comp/ItemDetail/View2.elm | 11 ++- .../src/main/elm/Messages/Comp/ItemDetail.elm | 3 + .../Messages/Comp/ItemDetail/ConfirmModal.elm | 44 +++++++++++ .../Comp/ItemDetail/SingleAttachment.elm | 3 + 8 files changed, 138 insertions(+), 81 deletions(-) create mode 100644 modules/webapp/src/main/elm/Comp/ItemDetail/ConfirmModalView.elm create mode 100644 modules/webapp/src/main/elm/Messages/Comp/ItemDetail/ConfirmModal.elm diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/ConfirmModalView.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/ConfirmModalView.elm new file mode 100644 index 00000000..9703b70f --- /dev/null +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/ConfirmModalView.elm @@ -0,0 +1,60 @@ +module Comp.ItemDetail.ConfirmModalView exposing (view) + +import Comp.ConfirmModal +import Comp.ItemDetail.Model exposing (..) +import Html exposing (..) +import Messages.Comp.ItemDetail.ConfirmModal exposing (Texts) + + +view : Texts -> ConfirmModalValue -> Model -> Html Msg +view texts modal itemModel = + case modal of + ConfirmModalReprocessItem msg -> + Comp.ConfirmModal.view + (makeSettings texts + msg + ItemModalCancelled + (texts.confirmReprocessItem itemModel.item.state) + ) + + ConfirmModalReprocessFile msg -> + Comp.ConfirmModal.view + (makeSettings texts + msg + AttachModalCancelled + (texts.confirmReprocessFile itemModel.item.state) + ) + + ConfirmModalDeleteItem msg -> + Comp.ConfirmModal.view + (makeSettings texts + msg + ItemModalCancelled + texts.confirmDeleteItem + ) + + ConfirmModalDeleteFile msg -> + Comp.ConfirmModal.view + (makeSettings texts + msg + AttachModalCancelled + texts.confirmDeleteFile + ) + + ConfirmModalDeleteAllFiles msg -> + Comp.ConfirmModal.view + (makeSettings texts + msg + AttachModalCancelled + texts.confirmDeleteAllFiles + ) + + +makeSettings : Texts -> Msg -> Msg -> String -> Comp.ConfirmModal.Settings Msg +makeSettings texts confirm cancel confirmMsg = + Comp.ConfirmModal.defaultSettings + confirm + cancel + texts.basics.ok + texts.basics.cancel + confirmMsg diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm index e7c930e3..1a944942 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm @@ -1,5 +1,6 @@ module Comp.ItemDetail.Model exposing ( AttachmentRename + , ConfirmModalValue(..) , MailSendResult(..) , Model , Msg(..) @@ -76,7 +77,7 @@ type alias Model = , nameSaveThrottle : Throttle Msg , notesModel : Maybe String , notesField : NotesField - , itemModal : Maybe (Comp.ConfirmModal.Settings Msg) + , itemModal : Maybe ConfirmModalValue , itemDatePicker : DatePicker , itemDate : Maybe Int , itemProposals : ItemProposals @@ -91,7 +92,7 @@ type alias Model = , attachMeta : Dict String Comp.AttachmentMeta.Model , attachMetaOpen : Bool , pdfNativeView : Maybe Bool - , attachModal : Maybe (Comp.ConfirmModal.Settings Msg) + , attachModal : Maybe ConfirmModalValue , addFilesOpen : Bool , addFilesModel : Comp.Dropzone.Model , selectedFiles : List File @@ -113,6 +114,14 @@ type alias Model = } +type ConfirmModalValue + = ConfirmModalReprocessItem Msg + | ConfirmModalReprocessFile Msg + | ConfirmModalDeleteItem Msg + | ConfirmModalDeleteFile Msg + | ConfirmModalDeleteAllFiles Msg + + type ViewMode = SimpleView | SelectView SelectViewModel diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm index 046a36f8..792ea53a 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/SingleAttachment.elm @@ -3,7 +3,7 @@ module Comp.ItemDetail.SingleAttachment exposing (view) import Api import Api.Model.Attachment exposing (Attachment) import Comp.AttachmentMeta -import Comp.ConfirmModal +import Comp.ItemDetail.ConfirmModalView import Comp.ItemDetail.Model exposing (Model, Msg(..), NotesField(..), SaveNameState(..), ViewMode(..)) import Comp.MenuBar as MB import Data.UiSettings exposing (UiSettings) @@ -32,7 +32,7 @@ view texts settings model pos attach = [ ( "hidden", not (attachmentVisible model pos) ) ] ] - [ renderModal model + [ renderModal texts model , div [ class "flex flex-row px-2 py-2 text-sm" , class S.border @@ -420,11 +420,11 @@ menuItem texts model pos attach = ] -renderModal : Model -> Html Msg -renderModal model = +renderModal : Texts -> Model -> Html Msg +renderModal texts model = case model.attachModal of - Just confirmModal -> - Comp.ConfirmModal.view confirmModal + Just mm -> + Comp.ItemDetail.ConfirmModalView.view texts.confirmModal mm model Nothing -> span [ class "hidden" ] [] diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm index 13a7399b..ea47c6d6 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm @@ -27,6 +27,7 @@ import Comp.ItemDetail.FieldTabState as FTabState import Comp.ItemDetail.Model exposing ( AttachmentRename + , ConfirmModalValue(..) , MailSendResult(..) , Model , Msg(..) @@ -560,19 +561,7 @@ update key flags inav settings msg model = resultModel { model | itemModal = Nothing } RequestDelete -> - let - confirmMsg = - "Really delete this item? This cannot be undone." - - confirm = - Comp.ConfirmModal.defaultSettings - DeleteItemConfirmed - ItemModalCancelled - "Ok" - "Cancel" - confirmMsg - in - resultModel { model | itemModal = Just confirm } + resultModel { model | itemModal = Just (ConfirmModalDeleteItem DeleteItemConfirmed) } SetCorrOrgSuggestion idname -> resultModelCmd ( model, setCorrOrg flags model (Just idname) ) @@ -940,18 +929,10 @@ update key flags inav settings msg model = RequestDeleteAttachment id -> let - confirmModal = - Comp.ConfirmModal.defaultSettings - (DeleteAttachConfirmed id) - AttachModalCancelled - "Ok" - "Cancel" - "Really delete this file?" - model_ = { model | attachmentDropdownOpen = False - , attachModal = Just confirmModal + , attachModal = Just (ConfirmModalDeleteFile (DeleteAttachConfirmed id)) } in resultModel model_ @@ -964,14 +945,6 @@ update key flags inav settings msg model = else let - confirmModal = - Comp.ConfirmModal.defaultSettings - DeleteSelectedConfirmed - AttachModalCancelled - "Ok" - "Cancel" - "Really delete these files?" - model_ = { model | viewMode = @@ -979,7 +952,7 @@ update key flags inav settings msg model = { svm | action = DeleteSelected } - , attachModal = Just confirmModal + , attachModal = Just (ConfirmModalDeleteAllFiles DeleteSelectedConfirmed) } in resultModel model_ @@ -1567,27 +1540,10 @@ update key flags inav settings msg model = RequestReprocessFile id -> let - confirmMsg = - if model.item.state == "created" then - "Reprocessing this file may change metadata of " - ++ "this item, since it is unconfirmed. Do you want to proceed?" - - else - "Reprocessing this file will not change metadata of " - ++ "this item, since it has been confirmed. Do you want to proceed?" - - confirmModal = - Comp.ConfirmModal.defaultSettings - (ReprocessFileConfirmed id) - AttachModalCancelled - "Ok" - "Cancel" - confirmMsg - model_ = { model | attachmentDropdownOpen = False - , attachModal = Just confirmModal + , attachModal = Just (ConfirmModalReprocessFile (ReprocessFileConfirmed id)) } in resultModel model_ @@ -1604,27 +1560,10 @@ update key flags inav settings msg model = RequestReprocessItem -> let - confirmMsg = - if model.item.state == "created" then - "Reprocessing this item may change its metadata, " - ++ "since it is unconfirmed. Do you want to proceed?" - - else - "Reprocessing this item will not change its metadata, " - ++ "since it has been confirmed. Do you want to proceed?" - - confirmModal = - Comp.ConfirmModal.defaultSettings - ReprocessItemConfirmed - ItemModalCancelled - "Ok" - "Cancel" - confirmMsg - model_ = { model | attachmentDropdownOpen = False - , itemModal = Just confirmModal + , itemModal = Just (ConfirmModalReprocessItem ReprocessItemConfirmed) } in resultModel model_ diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/View2.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/View2.elm index 068e7774..864d3b8f 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/View2.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/View2.elm @@ -1,9 +1,9 @@ module Comp.ItemDetail.View2 exposing (view) import Comp.Basic as B -import Comp.ConfirmModal import Comp.DetailEdit import Comp.ItemDetail.AddFilesForm +import Comp.ItemDetail.ConfirmModalView import Comp.ItemDetail.ItemInfoHeader import Comp.ItemDetail.Model exposing @@ -27,7 +27,6 @@ import Html.Events exposing (onClick) import Messages.Comp.ItemDetail exposing (Texts) import Page exposing (Page(..)) import Styles as S -import Util.Time view : Texts -> ItemNav -> UiSettings -> Model -> Html Msg @@ -36,15 +35,15 @@ view texts inav settings model = [ header texts settings model , menuBar texts inav settings model , body texts inav settings model - , itemModal model + , itemModal texts model ] -itemModal : Model -> Html Msg -itemModal model = +itemModal : Texts -> Model -> Html Msg +itemModal texts model = case model.itemModal of Just confirm -> - Comp.ConfirmModal.view confirm + Comp.ItemDetail.ConfirmModalView.view texts.confirmModal confirm model Nothing -> span [ class "hidden" ] [] diff --git a/modules/webapp/src/main/elm/Messages/Comp/ItemDetail.elm b/modules/webapp/src/main/elm/Messages/Comp/ItemDetail.elm index f48daaa5..333f5afd 100644 --- a/modules/webapp/src/main/elm/Messages/Comp/ItemDetail.elm +++ b/modules/webapp/src/main/elm/Messages/Comp/ItemDetail.elm @@ -4,6 +4,7 @@ import Http import Messages.Comp.DetailEdit import Messages.Comp.HttpError import Messages.Comp.ItemDetail.AddFilesForm +import Messages.Comp.ItemDetail.ConfirmModal import Messages.Comp.ItemDetail.ItemInfoHeader import Messages.Comp.ItemDetail.Notes import Messages.Comp.ItemDetail.SingleAttachment @@ -21,6 +22,7 @@ type alias Texts = , notes : Messages.Comp.ItemDetail.Notes.Texts , itemMail : Messages.Comp.ItemMail.Texts , detailEdit : Messages.Comp.DetailEdit.Texts + , confirmModal : Messages.Comp.ItemDetail.ConfirmModal.Texts , httpError : Http.Error -> String , key : String , backToSearchResults : String @@ -53,6 +55,7 @@ gb = , notes = Messages.Comp.ItemDetail.Notes.gb , itemMail = Messages.Comp.ItemMail.gb , detailEdit = Messages.Comp.DetailEdit.gb + , confirmModal = Messages.Comp.ItemDetail.ConfirmModal.gb , httpError = Messages.Comp.HttpError.gb , key = "Key" , backToSearchResults = "Back to search results" diff --git a/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/ConfirmModal.elm b/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/ConfirmModal.elm new file mode 100644 index 00000000..39cea759 --- /dev/null +++ b/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/ConfirmModal.elm @@ -0,0 +1,44 @@ +module Messages.Comp.ItemDetail.ConfirmModal exposing + ( Texts + , gb + ) + +import Messages.Basics + + +type alias Texts = + { basics : Messages.Basics.Texts + , confirmReprocessItem : String -> String + , confirmReprocessFile : String -> String + , confirmDeleteItem : String + , confirmDeleteFile : String + , confirmDeleteAllFiles : String + } + + +gb : Texts +gb = + { basics = Messages.Basics.gb + , confirmReprocessItem = + \state -> + if state == "created" then + "Reprocessing this item may change its metadata, " + ++ "since it is unconfirmed. Do you want to proceed?" + + else + "Reprocessing this item will not change its metadata, " + ++ "since it has been confirmed. Do you want to proceed?" + , confirmReprocessFile = + \state -> + if state == "created" then + "Reprocessing this file may change metadata of " + ++ "this item, since it is unconfirmed. Do you want to proceed?" + + else + "Reprocessing this file will not change metadata of " + ++ "this item, since it has been confirmed. Do you want to proceed?" + , confirmDeleteItem = + "Really delete this item? This cannot be undone." + , confirmDeleteFile = "Really delete this file?" + , confirmDeleteAllFiles = "Really delete these files?" + } diff --git a/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/SingleAttachment.elm b/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/SingleAttachment.elm index d7e12583..53422230 100644 --- a/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/SingleAttachment.elm +++ b/modules/webapp/src/main/elm/Messages/Comp/ItemDetail/SingleAttachment.elm @@ -1,10 +1,12 @@ module Messages.Comp.ItemDetail.SingleAttachment exposing (Texts, gb) import Messages.Comp.AttachmentMeta +import Messages.Comp.ItemDetail.ConfirmModal type alias Texts = { attachmentMeta : Messages.Comp.AttachmentMeta.Texts + , confirmModal : Messages.Comp.ItemDetail.ConfirmModal.Texts , noName : String , openFileInNewTab : String , downloadFile : String @@ -24,6 +26,7 @@ type alias Texts = gb : Texts gb = { attachmentMeta = Messages.Comp.AttachmentMeta.gb + , confirmModal = Messages.Comp.ItemDetail.ConfirmModal.gb , noName = "No name" , openFileInNewTab = "Open file in new tab" , downloadFile = "Download file"