Refactor to allow internal card links into search menu

Also allows to exchange the preview-url in the item card
This commit is contained in:
eikek 2021-10-05 01:44:50 +02:00
parent 83dd675e4f
commit 7b0f378558
10 changed files with 111 additions and 39 deletions

View File

@ -141,6 +141,8 @@ module Api exposing
, setTags
, setTagsMultiple
, setUnconfirmed
, shareAttachmentPreviewURL
, shareItemBasePreviewURL
, startClassifier
, startEmptyTrash
, startOnceNotifyDueItems
@ -2288,6 +2290,16 @@ searchShare flags token search receive =
}
shareAttachmentPreviewURL : String -> String
shareAttachmentPreviewURL id =
"/api/v1/share/attachment/" ++ id ++ "/preview?withFallback=true"
shareItemBasePreviewURL : String -> String
shareItemBasePreviewURL itemId =
"/api/v1/share/item/" ++ itemId ++ "/preview?withFallback=true"
--- Helper

View File

@ -56,6 +56,8 @@ type Msg
type alias ViewConfig =
{ selection : ItemSelection
, extraClasses : String
, previewUrl : AttachmentLight -> String
, previewUrlFallback : ItemLight -> String
}
@ -160,7 +162,7 @@ view2 texts cfg settings model item =
"text-blue-500 dark:text-lightblue-500"
else if isDeleted then
"text-red-600 dark:text-orange-600"
"text-red-600 dark:text-orange-600"
else
""
@ -210,7 +212,7 @@ view2 texts cfg settings model item =
[]
else
[ previewImage2 settings cardAction model item
[ previewImage2 cfg settings cardAction model item
]
)
++ [ mainContent2 texts cardAction cardColor isCreated isDeleted settings cfg item
@ -443,16 +445,15 @@ mainTagsAndFields2 settings item =
(renderFields ++ renderTags)
previewImage2 : UiSettings -> List (Attribute Msg) -> Model -> ItemLight -> Html Msg
previewImage2 settings cardAction model item =
previewImage2 : ViewConfig -> UiSettings -> List (Attribute Msg) -> Model -> ItemLight -> Html Msg
previewImage2 cfg settings cardAction model item =
let
mainAttach =
currentAttachment model item
previewUrl =
Maybe.map .id mainAttach
|> Maybe.map Api.attachmentPreviewURL
|> Maybe.withDefault (Api.itemBasePreviewURL item.id)
Maybe.map cfg.previewUrl mainAttach
|> Maybe.withDefault (cfg.previewUrlFallback item)
in
a
([ class "overflow-hidden block bg-gray-50 dark:bg-bluegray-700 dark:bg-opacity-40 border-gray-400 dark:hover:border-bluegray-500 rounded-t-lg"

View File

@ -17,6 +17,7 @@ module Comp.ItemCardList exposing
, view2
)
import Api.Model.AttachmentLight exposing (AttachmentLight)
import Api.Model.ItemLight exposing (ItemLight)
import Api.Model.ItemLightGroup exposing (ItemLightGroup)
import Api.Model.ItemLightList exposing (ItemLightList)
@ -72,13 +73,13 @@ prevItem model id =
--- Update
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
update : Flags -> Msg -> Model -> ( Model, Cmd Msg, LinkTarget )
update flags msg model =
let
res =
updateDrag DD.init flags msg model
in
( res.model, res.cmd )
( res.model, res.cmd, res.linkTarget )
type alias UpdateResult =
@ -161,6 +162,8 @@ updateDrag dm _ msg model =
type alias ViewConfig =
{ current : Maybe String
, selection : ItemSelection
, previewUrl : AttachmentLight -> String
, previewUrlFallback : ItemLight -> String
}
@ -216,7 +219,7 @@ viewItem2 texts model cfg settings item =
""
vvcfg =
Comp.ItemCard.ViewConfig cfg.selection currentClass
Comp.ItemCard.ViewConfig cfg.selection currentClass cfg.previewUrl cfg.previewUrlFallback
cardModel =
Dict.get item.id model.itemCards

View File

@ -14,6 +14,7 @@ module Comp.SearchMenu exposing
, init
, isFulltextSearch
, isNamesSearch
, linkTargetMsg
, textSearchString
, update
, updateDrop
@ -34,6 +35,7 @@ import Comp.CustomFieldMultiInput
import Comp.DatePicker
import Comp.Dropdown exposing (isDropdownChangeMsg)
import Comp.FolderSelect
import Comp.LinkTarget exposing (LinkTarget)
import Comp.MenuBar as MB
import Comp.Tabs
import Comp.TagSelect
@ -377,6 +379,37 @@ type Msg
| ToggleOpenAllAkkordionTabs
linkTargetMsg : LinkTarget -> Maybe Msg
linkTargetMsg linkTarget =
case linkTarget of
Comp.LinkTarget.LinkNone ->
Nothing
Comp.LinkTarget.LinkCorrOrg id ->
Just <| SetCorrOrg id
Comp.LinkTarget.LinkCorrPerson id ->
Just <| SetCorrPerson id
Comp.LinkTarget.LinkConcPerson id ->
Just <| SetConcPerson id
Comp.LinkTarget.LinkConcEquip id ->
Just <| SetConcEquip id
Comp.LinkTarget.LinkFolder id ->
Just <| SetFolder id
Comp.LinkTarget.LinkTag id ->
Just <| SetTag id.id
Comp.LinkTarget.LinkCustomField id ->
Just <| SetCustomField id
Comp.LinkTarget.LinkSource str ->
Just <| ResetToSource str
type alias NextState =
{ model : Model
, cmd : Cmd Msg

View File

@ -1035,33 +1035,7 @@ doSearch param model =
linkTargetMsg : LinkTarget -> Maybe Msg
linkTargetMsg linkTarget =
case linkTarget of
Comp.LinkTarget.LinkNone ->
Nothing
Comp.LinkTarget.LinkCorrOrg id ->
Just <| SearchMenuMsg (Comp.SearchMenu.SetCorrOrg id)
Comp.LinkTarget.LinkCorrPerson id ->
Just <| SearchMenuMsg (Comp.SearchMenu.SetCorrPerson id)
Comp.LinkTarget.LinkConcPerson id ->
Just <| SearchMenuMsg (Comp.SearchMenu.SetConcPerson id)
Comp.LinkTarget.LinkConcEquip id ->
Just <| SearchMenuMsg (Comp.SearchMenu.SetConcEquip id)
Comp.LinkTarget.LinkFolder id ->
Just <| SearchMenuMsg (Comp.SearchMenu.SetFolder id)
Comp.LinkTarget.LinkTag id ->
Just <| SearchMenuMsg (Comp.SearchMenu.SetTag id.id)
Comp.LinkTarget.LinkCustomField id ->
Just <| SearchMenuMsg (Comp.SearchMenu.SetCustomField id)
Comp.LinkTarget.LinkSource str ->
Just <| SearchMenuMsg (Comp.SearchMenu.ResetToSource str)
Maybe.map SearchMenuMsg (Comp.SearchMenu.linkTargetMsg linkTarget)
doSearchMore : Flags -> UiSettings -> Model -> ( Model, Cmd Msg )

View File

@ -7,6 +7,7 @@
module Page.Home.View2 exposing (viewContent, viewSidebar)
import Api
import Comp.Basic as B
import Comp.ConfirmModal
import Comp.ItemCardList
@ -461,17 +462,27 @@ searchStats texts _ settings model =
itemCardList : Texts -> Flags -> UiSettings -> Model -> List (Html Msg)
itemCardList texts _ settings model =
let
previewUrl attach =
Api.attachmentPreviewURL attach.id
previewUrlFallback item =
Api.itemBasePreviewURL item.id
itemViewCfg =
case model.viewMode of
SelectView svm ->
Comp.ItemCardList.ViewConfig
model.scrollToCard
(Data.ItemSelection.Active svm.ids)
previewUrl
previewUrlFallback
_ ->
Comp.ItemCardList.ViewConfig
model.scrollToCard
Data.ItemSelection.Inactive
previewUrl
previewUrlFallback
in
[ Html.map ItemCardListMsg
(Comp.ItemCardList.view2 texts.itemCardList

View File

@ -1,3 +1,10 @@
{-
Copyright 2020 Eike K. & Contributors
SPDX-License-Identifier: AGPL-3.0-or-later
-}
module Page.Share.Menubar exposing (view)
import Comp.Basic as B

View File

@ -1,5 +1,13 @@
{-
Copyright 2020 Eike K. & Contributors
SPDX-License-Identifier: AGPL-3.0-or-later
-}
module Page.Share.Results exposing (view)
import Api
import Comp.ItemCardList
import Data.ItemSelection
import Data.UiSettings exposing (UiSettings)
@ -15,6 +23,8 @@ view texts settings model =
viewCfg =
{ current = Nothing
, selection = Data.ItemSelection.Inactive
, previewUrl = \attach -> Api.shareAttachmentPreviewURL attach.id
, previewUrlFallback = \item -> Api.shareItemBasePreviewURL item.id
}
in
div []

View File

@ -1,3 +1,10 @@
{-
Copyright 2020 Eike K. & Contributors
SPDX-License-Identifier: AGPL-3.0-or-later
-}
module Page.Share.Sidebar exposing (..)
import Comp.SearchMenu

View File

@ -10,6 +10,7 @@ module Page.Share.Update exposing (UpdateResult, update)
import Api
import Api.Model.ItemQuery
import Comp.ItemCardList
import Comp.LinkTarget exposing (LinkTarget)
import Comp.PowerSearchInput
import Comp.SearchMenu
import Data.Flags exposing (Flags)
@ -17,6 +18,7 @@ import Data.ItemQuery as Q
import Data.SearchMode
import Data.UiSettings exposing (UiSettings)
import Page.Share.Data exposing (..)
import Util.Update
type alias UpdateResult =
@ -155,10 +157,17 @@ update flags settings shareId msg model =
ItemListMsg lm ->
let
( im, ic ) =
( im, ic, linkTarget ) =
Comp.ItemCardList.update flags lm model.itemListModel
searchMsg =
Maybe.map Util.Update.cmdUnit (linkTargetMsg linkTarget)
|> Maybe.withDefault Cmd.none
in
noSub ( { model | itemListModel = im }, Cmd.map ItemListMsg ic )
noSub
( { model | itemListModel = im }
, Cmd.batch [ Cmd.map ItemListMsg ic, searchMsg ]
)
noSub : ( Model, Cmd Msg ) -> UpdateResult
@ -184,3 +193,8 @@ makeSearchCmd flags model =
}
in
Api.searchShare flags model.verifyResult.token (request xq) SearchResp
linkTargetMsg : LinkTarget -> Maybe Msg
linkTargetMsg linkTarget =
Maybe.map SearchMenuMsg (Comp.SearchMenu.linkTargetMsg linkTarget)