View attachments from a share

This commit is contained in:
eikek 2021-10-06 01:14:30 +02:00
parent 9eb2f9c6fe
commit c62b8526be
5 changed files with 19 additions and 9 deletions

View File

@ -143,6 +143,7 @@ module Api exposing
, setTagsMultiple , setTagsMultiple
, setUnconfirmed , setUnconfirmed
, shareAttachmentPreviewURL , shareAttachmentPreviewURL
, shareFileURL
, shareItemBasePreviewURL , shareItemBasePreviewURL
, startClassifier , startClassifier
, startEmptyTrash , startEmptyTrash
@ -2311,6 +2312,11 @@ shareItemBasePreviewURL itemId =
"/api/v1/share/item/" ++ itemId ++ "/preview?withFallback=true" "/api/v1/share/item/" ++ itemId ++ "/preview?withFallback=true"
shareFileURL : String -> String
shareFileURL attachId =
"/api/v1/share/attachment/" ++ attachId
--- Helper --- Helper

View File

@ -58,6 +58,7 @@ type alias ViewConfig =
, extraClasses : String , extraClasses : String
, previewUrl : AttachmentLight -> String , previewUrl : AttachmentLight -> String
, previewUrlFallback : ItemLight -> String , previewUrlFallback : ItemLight -> String
, attachUrl : AttachmentLight -> String
} }
@ -219,7 +220,7 @@ view2 texts cfg settings model item =
, metaDataContent2 texts settings item , metaDataContent2 texts settings item
, notesContent2 settings item , notesContent2 settings item
, fulltextResultsContent2 item , fulltextResultsContent2 item
, previewMenu2 texts settings model item (currentAttachment model item) , previewMenu2 texts settings cfg model item (currentAttachment model item)
, selectedDimmer , selectedDimmer
] ]
) )
@ -473,8 +474,8 @@ previewImage2 cfg settings cardAction model item =
] ]
previewMenu2 : Texts -> UiSettings -> Model -> ItemLight -> Maybe AttachmentLight -> Html Msg previewMenu2 : Texts -> UiSettings -> ViewConfig -> Model -> ItemLight -> Maybe AttachmentLight -> Html Msg
previewMenu2 texts settings model item mainAttach = previewMenu2 texts settings cfg model item mainAttach =
let let
pageCount = pageCount =
Maybe.andThen .pageCount mainAttach Maybe.andThen .pageCount mainAttach
@ -486,16 +487,15 @@ previewMenu2 texts settings model item mainAttach =
fieldHidden f = fieldHidden f =
Data.UiSettings.fieldHidden settings f Data.UiSettings.fieldHidden settings f
mkAttachUrl id = mkAttachUrl attach =
if settings.nativePdfPreview then if settings.nativePdfPreview then
Api.fileURL id cfg.attachUrl attach
else else
Api.fileURL id ++ "/view" cfg.attachUrl attach ++ "/view"
attachUrl = attachUrl =
Maybe.map .id mainAttach Maybe.map mkAttachUrl mainAttach
|> Maybe.map mkAttachUrl
|> Maybe.withDefault "/api/v1/sec/attachment/none" |> Maybe.withDefault "/api/v1/sec/attachment/none"
dueDate = dueDate =

View File

@ -164,6 +164,7 @@ type alias ViewConfig =
, selection : ItemSelection , selection : ItemSelection
, previewUrl : AttachmentLight -> String , previewUrl : AttachmentLight -> String
, previewUrlFallback : ItemLight -> String , previewUrlFallback : ItemLight -> String
, attachUrl : AttachmentLight -> String
} }
@ -219,7 +220,7 @@ viewItem2 texts model cfg settings item =
"" ""
vvcfg = vvcfg =
Comp.ItemCard.ViewConfig cfg.selection currentClass cfg.previewUrl cfg.previewUrlFallback Comp.ItemCard.ViewConfig cfg.selection currentClass cfg.previewUrl cfg.previewUrlFallback cfg.attachUrl
cardModel = cardModel =
Dict.get item.id model.itemCards Dict.get item.id model.itemCards

View File

@ -476,6 +476,7 @@ itemCardList texts _ settings model =
(Data.ItemSelection.Active svm.ids) (Data.ItemSelection.Active svm.ids)
previewUrl previewUrl
previewUrlFallback previewUrlFallback
(.id >> Api.fileURL)
_ -> _ ->
Comp.ItemCardList.ViewConfig Comp.ItemCardList.ViewConfig
@ -483,6 +484,7 @@ itemCardList texts _ settings model =
Data.ItemSelection.Inactive Data.ItemSelection.Inactive
previewUrl previewUrl
previewUrlFallback previewUrlFallback
(.id >> Api.fileURL)
in in
[ Html.map ItemCardListMsg [ Html.map ItemCardListMsg
(Comp.ItemCardList.view2 texts.itemCardList (Comp.ItemCardList.view2 texts.itemCardList

View File

@ -25,6 +25,7 @@ view texts settings model =
, selection = Data.ItemSelection.Inactive , selection = Data.ItemSelection.Inactive
, previewUrl = \attach -> Api.shareAttachmentPreviewURL attach.id , previewUrl = \attach -> Api.shareAttachmentPreviewURL attach.id
, previewUrlFallback = \item -> Api.shareItemBasePreviewURL item.id , previewUrlFallback = \item -> Api.shareItemBasePreviewURL item.id
, attachUrl = .id >> Api.shareFileURL
} }
in in
div [] div []