mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-25 16:45:05 +00:00
Refactor link-target in a separate module
This commit is contained in:
parent
4b700fb249
commit
23391ef41c
@ -1,6 +1,5 @@
|
|||||||
module Comp.ItemCard exposing
|
module Comp.ItemCard exposing
|
||||||
( LinkTarget(..)
|
( Model
|
||||||
, Model
|
|
||||||
, Msg
|
, Msg
|
||||||
, UpdateResult
|
, UpdateResult
|
||||||
, ViewConfig
|
, ViewConfig
|
||||||
@ -14,6 +13,7 @@ import Api.Model.AttachmentLight exposing (AttachmentLight)
|
|||||||
import Api.Model.HighlightEntry exposing (HighlightEntry)
|
import Api.Model.HighlightEntry exposing (HighlightEntry)
|
||||||
import Api.Model.IdName exposing (IdName)
|
import Api.Model.IdName exposing (IdName)
|
||||||
import Api.Model.ItemLight exposing (ItemLight)
|
import Api.Model.ItemLight exposing (ItemLight)
|
||||||
|
import Comp.LinkTarget exposing (LinkTarget(..))
|
||||||
import Data.Direction
|
import Data.Direction
|
||||||
import Data.Fields
|
import Data.Fields
|
||||||
import Data.Icons as Icons
|
import Data.Icons as Icons
|
||||||
@ -50,15 +50,6 @@ type alias ViewConfig =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type LinkTarget
|
|
||||||
= LinkCorrOrg IdName
|
|
||||||
| LinkCorrPerson IdName
|
|
||||||
| LinkConcPerson IdName
|
|
||||||
| LinkConcEquip IdName
|
|
||||||
| LinkFolder IdName
|
|
||||||
| LinkNone
|
|
||||||
|
|
||||||
|
|
||||||
type alias UpdateResult =
|
type alias UpdateResult =
|
||||||
{ model : Model
|
{ model : Model
|
||||||
, dragModel : DD.Model
|
, dragModel : DD.Model
|
||||||
@ -227,46 +218,6 @@ metaDataContent settings item =
|
|||||||
fieldHidden f =
|
fieldHidden f =
|
||||||
Data.UiSettings.fieldHidden settings f
|
Data.UiSettings.fieldHidden settings f
|
||||||
|
|
||||||
default =
|
|
||||||
text "-"
|
|
||||||
|
|
||||||
makeLink tagger idname =
|
|
||||||
a
|
|
||||||
[ onClick (tagger idname)
|
|
||||||
, href "#"
|
|
||||||
]
|
|
||||||
[ text idname.name
|
|
||||||
]
|
|
||||||
|
|
||||||
combine ma mb =
|
|
||||||
case ( ma, mb ) of
|
|
||||||
( Just a, Just b ) ->
|
|
||||||
[ a, text ", ", b ]
|
|
||||||
|
|
||||||
( Just a, Nothing ) ->
|
|
||||||
[ a ]
|
|
||||||
|
|
||||||
( Nothing, Just b ) ->
|
|
||||||
[ b ]
|
|
||||||
|
|
||||||
( Nothing, Nothing ) ->
|
|
||||||
[ default ]
|
|
||||||
|
|
||||||
corrOrg =
|
|
||||||
Maybe.map (makeLink (LinkCorrOrg >> SetLinkTarget)) item.corrOrg
|
|
||||||
|
|
||||||
corrPerson =
|
|
||||||
Maybe.map (makeLink (LinkCorrPerson >> SetLinkTarget)) item.corrPerson
|
|
||||||
|
|
||||||
concPerson =
|
|
||||||
Maybe.map (makeLink (LinkConcPerson >> SetLinkTarget)) item.concPerson
|
|
||||||
|
|
||||||
concEquip =
|
|
||||||
Maybe.map (makeLink (LinkConcEquip >> SetLinkTarget)) item.concEquip
|
|
||||||
|
|
||||||
folder =
|
|
||||||
Maybe.map (makeLink (LinkFolder >> SetLinkTarget)) item.folder
|
|
||||||
|
|
||||||
dueDate =
|
dueDate =
|
||||||
Maybe.map Util.Time.formatDateShort item.dueDate
|
Maybe.map Util.Time.formatDateShort item.dueDate
|
||||||
|> Maybe.withDefault ""
|
|> Maybe.withDefault ""
|
||||||
@ -284,7 +235,7 @@ metaDataContent settings item =
|
|||||||
, title "Correspondent"
|
, title "Correspondent"
|
||||||
]
|
]
|
||||||
(Icons.correspondentIcon ""
|
(Icons.correspondentIcon ""
|
||||||
:: combine corrOrg corrPerson
|
:: Comp.LinkTarget.makeCorrLink item SetLinkTarget
|
||||||
)
|
)
|
||||||
, div
|
, div
|
||||||
[ classList
|
[ classList
|
||||||
@ -297,7 +248,7 @@ metaDataContent settings item =
|
|||||||
, title "Concerning"
|
, title "Concerning"
|
||||||
]
|
]
|
||||||
(Icons.concernedIcon
|
(Icons.concernedIcon
|
||||||
:: combine concPerson concEquip
|
:: Comp.LinkTarget.makeConcLink item SetLinkTarget
|
||||||
)
|
)
|
||||||
, div
|
, div
|
||||||
[ classList
|
[ classList
|
||||||
@ -307,7 +258,7 @@ metaDataContent settings item =
|
|||||||
, title "Folder"
|
, title "Folder"
|
||||||
]
|
]
|
||||||
[ Icons.folderIcon ""
|
[ Icons.folderIcon ""
|
||||||
, Maybe.withDefault default folder
|
, Comp.LinkTarget.makeFolderLink item SetLinkTarget
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
, div [ class "right floated meta" ]
|
, div [ class "right floated meta" ]
|
||||||
|
@ -14,6 +14,7 @@ import Api.Model.ItemLight exposing (ItemLight)
|
|||||||
import Api.Model.ItemLightGroup exposing (ItemLightGroup)
|
import Api.Model.ItemLightGroup exposing (ItemLightGroup)
|
||||||
import Api.Model.ItemLightList exposing (ItemLightList)
|
import Api.Model.ItemLightList exposing (ItemLightList)
|
||||||
import Comp.ItemCard
|
import Comp.ItemCard
|
||||||
|
import Comp.LinkTarget exposing (LinkTarget)
|
||||||
import Data.Flags exposing (Flags)
|
import Data.Flags exposing (Flags)
|
||||||
import Data.ItemSelection exposing (ItemSelection)
|
import Data.ItemSelection exposing (ItemSelection)
|
||||||
import Data.Items
|
import Data.Items
|
||||||
@ -75,7 +76,7 @@ type alias UpdateResult =
|
|||||||
, cmd : Cmd Msg
|
, cmd : Cmd Msg
|
||||||
, dragModel : DD.Model
|
, dragModel : DD.Model
|
||||||
, selection : ItemSelection
|
, selection : ItemSelection
|
||||||
, linkTarget : Comp.ItemCard.LinkTarget
|
, linkTarget : LinkTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ updateDrag dm _ msg model =
|
|||||||
Cmd.none
|
Cmd.none
|
||||||
dm
|
dm
|
||||||
Data.ItemSelection.Inactive
|
Data.ItemSelection.Inactive
|
||||||
Comp.ItemCard.LinkNone
|
Comp.LinkTarget.LinkNone
|
||||||
|
|
||||||
AddResults list ->
|
AddResults list ->
|
||||||
if list.groups == [] then
|
if list.groups == [] then
|
||||||
@ -104,7 +105,7 @@ updateDrag dm _ msg model =
|
|||||||
Cmd.none
|
Cmd.none
|
||||||
dm
|
dm
|
||||||
Data.ItemSelection.Inactive
|
Data.ItemSelection.Inactive
|
||||||
Comp.ItemCard.LinkNone
|
Comp.LinkTarget.LinkNone
|
||||||
|
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
@ -115,7 +116,7 @@ updateDrag dm _ msg model =
|
|||||||
Cmd.none
|
Cmd.none
|
||||||
dm
|
dm
|
||||||
Data.ItemSelection.Inactive
|
Data.ItemSelection.Inactive
|
||||||
Comp.ItemCard.LinkNone
|
Comp.LinkTarget.LinkNone
|
||||||
|
|
||||||
ItemCardMsg item lm ->
|
ItemCardMsg item lm ->
|
||||||
let
|
let
|
||||||
|
93
modules/webapp/src/main/elm/Comp/LinkTarget.elm
Normal file
93
modules/webapp/src/main/elm/Comp/LinkTarget.elm
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
module Comp.LinkTarget exposing
|
||||||
|
( LinkTarget(..)
|
||||||
|
, makeConcLink
|
||||||
|
, makeCorrLink
|
||||||
|
, makeFolderLink
|
||||||
|
)
|
||||||
|
|
||||||
|
import Api.Model.IdName exposing (IdName)
|
||||||
|
import Html exposing (..)
|
||||||
|
import Html.Attributes exposing (..)
|
||||||
|
import Html.Events exposing (onClick)
|
||||||
|
|
||||||
|
|
||||||
|
type LinkTarget
|
||||||
|
= LinkCorrOrg IdName
|
||||||
|
| LinkCorrPerson IdName
|
||||||
|
| LinkConcPerson IdName
|
||||||
|
| LinkConcEquip IdName
|
||||||
|
| LinkFolder IdName
|
||||||
|
| LinkNone
|
||||||
|
|
||||||
|
|
||||||
|
makeCorrLink :
|
||||||
|
{ a | corrOrg : Maybe IdName, corrPerson : Maybe IdName }
|
||||||
|
-> (LinkTarget -> msg)
|
||||||
|
-> List (Html msg)
|
||||||
|
makeCorrLink item tagger =
|
||||||
|
let
|
||||||
|
makeOrg idname =
|
||||||
|
makeLink (LinkCorrOrg >> tagger) idname
|
||||||
|
|
||||||
|
makePerson idname =
|
||||||
|
makeLink (LinkCorrPerson >> tagger) idname
|
||||||
|
in
|
||||||
|
combine (Maybe.map makeOrg item.corrOrg) (Maybe.map makePerson item.corrPerson)
|
||||||
|
|
||||||
|
|
||||||
|
makeConcLink :
|
||||||
|
{ a | concPerson : Maybe IdName, concEquip : Maybe IdName }
|
||||||
|
-> (LinkTarget -> msg)
|
||||||
|
-> List (Html msg)
|
||||||
|
makeConcLink item tagger =
|
||||||
|
let
|
||||||
|
makePerson idname =
|
||||||
|
makeLink (LinkConcPerson >> tagger) idname
|
||||||
|
|
||||||
|
makeEquip idname =
|
||||||
|
makeLink (LinkConcEquip >> tagger) idname
|
||||||
|
in
|
||||||
|
combine (Maybe.map makePerson item.concPerson) (Maybe.map makeEquip item.concEquip)
|
||||||
|
|
||||||
|
|
||||||
|
makeFolderLink :
|
||||||
|
{ a | folder : Maybe IdName }
|
||||||
|
-> (LinkTarget -> msg)
|
||||||
|
-> Html msg
|
||||||
|
makeFolderLink item tagger =
|
||||||
|
let
|
||||||
|
makeFolder idname =
|
||||||
|
makeLink (LinkFolder >> tagger) idname
|
||||||
|
in
|
||||||
|
Maybe.map makeFolder item.folder
|
||||||
|
|> Maybe.withDefault (text "-")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- Helpers
|
||||||
|
|
||||||
|
|
||||||
|
combine : Maybe (Html msg) -> Maybe (Html msg) -> List (Html msg)
|
||||||
|
combine ma mb =
|
||||||
|
case ( ma, mb ) of
|
||||||
|
( Just a, Just b ) ->
|
||||||
|
[ a, text ", ", b ]
|
||||||
|
|
||||||
|
( Just a, Nothing ) ->
|
||||||
|
[ a ]
|
||||||
|
|
||||||
|
( Nothing, Just b ) ->
|
||||||
|
[ b ]
|
||||||
|
|
||||||
|
( Nothing, Nothing ) ->
|
||||||
|
[ text "-" ]
|
||||||
|
|
||||||
|
|
||||||
|
makeLink : (IdName -> msg) -> IdName -> Html msg
|
||||||
|
makeLink tagger idname =
|
||||||
|
a
|
||||||
|
[ onClick (tagger idname)
|
||||||
|
, href "#"
|
||||||
|
]
|
||||||
|
[ text idname.name
|
||||||
|
]
|
@ -10,6 +10,7 @@ import Comp.ItemCard
|
|||||||
import Comp.ItemCardList
|
import Comp.ItemCardList
|
||||||
import Comp.ItemDetail.EditMenu exposing (SaveNameState(..))
|
import Comp.ItemDetail.EditMenu exposing (SaveNameState(..))
|
||||||
import Comp.ItemDetail.FormChange exposing (FormChange(..))
|
import Comp.ItemDetail.FormChange exposing (FormChange(..))
|
||||||
|
import Comp.LinkTarget
|
||||||
import Comp.SearchMenu
|
import Comp.SearchMenu
|
||||||
import Comp.YesNoDimmer
|
import Comp.YesNoDimmer
|
||||||
import Data.Flags exposing (Flags)
|
import Data.Flags exposing (Flags)
|
||||||
@ -97,22 +98,22 @@ update mId key flags settings msg model =
|
|||||||
|
|
||||||
searchMsg =
|
searchMsg =
|
||||||
case result.linkTarget of
|
case result.linkTarget of
|
||||||
Comp.ItemCard.LinkNone ->
|
Comp.LinkTarget.LinkNone ->
|
||||||
Cmd.none
|
Cmd.none
|
||||||
|
|
||||||
Comp.ItemCard.LinkCorrOrg id ->
|
Comp.LinkTarget.LinkCorrOrg id ->
|
||||||
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetCorrOrg id))
|
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetCorrOrg id))
|
||||||
|
|
||||||
Comp.ItemCard.LinkCorrPerson id ->
|
Comp.LinkTarget.LinkCorrPerson id ->
|
||||||
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetCorrPerson id))
|
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetCorrPerson id))
|
||||||
|
|
||||||
Comp.ItemCard.LinkConcPerson id ->
|
Comp.LinkTarget.LinkConcPerson id ->
|
||||||
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetConcPerson id))
|
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetConcPerson id))
|
||||||
|
|
||||||
Comp.ItemCard.LinkConcEquip id ->
|
Comp.LinkTarget.LinkConcEquip id ->
|
||||||
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetConcEquip id))
|
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetConcEquip id))
|
||||||
|
|
||||||
Comp.ItemCard.LinkFolder id ->
|
Comp.LinkTarget.LinkFolder id ->
|
||||||
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetFolder id))
|
Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetFolder id))
|
||||||
|
|
||||||
nextView =
|
nextView =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user