diff --git a/modules/webapp/src/main/elm/Comp/ItemCard.elm b/modules/webapp/src/main/elm/Comp/ItemCard.elm index d7b92f2d..6b3a1938 100644 --- a/modules/webapp/src/main/elm/Comp/ItemCard.elm +++ b/modules/webapp/src/main/elm/Comp/ItemCard.elm @@ -1,6 +1,5 @@ module Comp.ItemCard exposing - ( LinkTarget(..) - , Model + ( Model , Msg , UpdateResult , ViewConfig @@ -14,6 +13,7 @@ import Api.Model.AttachmentLight exposing (AttachmentLight) import Api.Model.HighlightEntry exposing (HighlightEntry) import Api.Model.IdName exposing (IdName) import Api.Model.ItemLight exposing (ItemLight) +import Comp.LinkTarget exposing (LinkTarget(..)) import Data.Direction import Data.Fields 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 = { model : Model , dragModel : DD.Model @@ -227,46 +218,6 @@ metaDataContent settings item = fieldHidden 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 = Maybe.map Util.Time.formatDateShort item.dueDate |> Maybe.withDefault "" @@ -284,7 +235,7 @@ metaDataContent settings item = , title "Correspondent" ] (Icons.correspondentIcon "" - :: combine corrOrg corrPerson + :: Comp.LinkTarget.makeCorrLink item SetLinkTarget ) , div [ classList @@ -297,7 +248,7 @@ metaDataContent settings item = , title "Concerning" ] (Icons.concernedIcon - :: combine concPerson concEquip + :: Comp.LinkTarget.makeConcLink item SetLinkTarget ) , div [ classList @@ -307,7 +258,7 @@ metaDataContent settings item = , title "Folder" ] [ Icons.folderIcon "" - , Maybe.withDefault default folder + , Comp.LinkTarget.makeFolderLink item SetLinkTarget ] ] , div [ class "right floated meta" ] diff --git a/modules/webapp/src/main/elm/Comp/ItemCardList.elm b/modules/webapp/src/main/elm/Comp/ItemCardList.elm index 220bb692..50df7c86 100644 --- a/modules/webapp/src/main/elm/Comp/ItemCardList.elm +++ b/modules/webapp/src/main/elm/Comp/ItemCardList.elm @@ -14,6 +14,7 @@ import Api.Model.ItemLight exposing (ItemLight) import Api.Model.ItemLightGroup exposing (ItemLightGroup) import Api.Model.ItemLightList exposing (ItemLightList) import Comp.ItemCard +import Comp.LinkTarget exposing (LinkTarget) import Data.Flags exposing (Flags) import Data.ItemSelection exposing (ItemSelection) import Data.Items @@ -75,7 +76,7 @@ type alias UpdateResult = , cmd : Cmd Msg , dragModel : DD.Model , selection : ItemSelection - , linkTarget : Comp.ItemCard.LinkTarget + , linkTarget : LinkTarget } @@ -96,7 +97,7 @@ updateDrag dm _ msg model = Cmd.none dm Data.ItemSelection.Inactive - Comp.ItemCard.LinkNone + Comp.LinkTarget.LinkNone AddResults list -> if list.groups == [] then @@ -104,7 +105,7 @@ updateDrag dm _ msg model = Cmd.none dm Data.ItemSelection.Inactive - Comp.ItemCard.LinkNone + Comp.LinkTarget.LinkNone else let @@ -115,7 +116,7 @@ updateDrag dm _ msg model = Cmd.none dm Data.ItemSelection.Inactive - Comp.ItemCard.LinkNone + Comp.LinkTarget.LinkNone ItemCardMsg item lm -> let diff --git a/modules/webapp/src/main/elm/Comp/LinkTarget.elm b/modules/webapp/src/main/elm/Comp/LinkTarget.elm new file mode 100644 index 00000000..625a276c --- /dev/null +++ b/modules/webapp/src/main/elm/Comp/LinkTarget.elm @@ -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 + ] diff --git a/modules/webapp/src/main/elm/Page/Home/Update.elm b/modules/webapp/src/main/elm/Page/Home/Update.elm index 46505ee1..f5b674a8 100644 --- a/modules/webapp/src/main/elm/Page/Home/Update.elm +++ b/modules/webapp/src/main/elm/Page/Home/Update.elm @@ -10,6 +10,7 @@ import Comp.ItemCard import Comp.ItemCardList import Comp.ItemDetail.EditMenu exposing (SaveNameState(..)) import Comp.ItemDetail.FormChange exposing (FormChange(..)) +import Comp.LinkTarget import Comp.SearchMenu import Comp.YesNoDimmer import Data.Flags exposing (Flags) @@ -97,22 +98,22 @@ update mId key flags settings msg model = searchMsg = case result.linkTarget of - Comp.ItemCard.LinkNone -> + Comp.LinkTarget.LinkNone -> Cmd.none - Comp.ItemCard.LinkCorrOrg id -> + Comp.LinkTarget.LinkCorrOrg 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)) - Comp.ItemCard.LinkConcPerson id -> + Comp.LinkTarget.LinkConcPerson 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)) - Comp.ItemCard.LinkFolder id -> + Comp.LinkTarget.LinkFolder id -> Util.Update.cmdUnit (SearchMenuMsg (Comp.SearchMenu.SetFolder id)) nextView =