Expose clicks on item cards

This commit is contained in:
Eike Kettner 2020-11-14 01:40:17 +01:00
parent b0bd7e417f
commit b1d0ae0cc8
2 changed files with 92 additions and 33 deletions

View File

@ -1,10 +1,19 @@
module Comp.ItemCard exposing (..) module Comp.ItemCard exposing
( LinkTarget(..)
, Model
, Msg
, UpdateResult
, ViewConfig
, init
, update
, view
)
import Api import Api
import Api.Model.AttachmentLight exposing (AttachmentLight) 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.ItemLight exposing (ItemLight) import Api.Model.ItemLight exposing (ItemLight)
import Data.BasicSize
import Data.Direction import Data.Direction
import Data.Fields import Data.Fields
import Data.Icons as Icons import Data.Icons as Icons
@ -16,7 +25,6 @@ import Html.Events exposing (onClick)
import Markdown import Markdown
import Page exposing (Page(..)) import Page exposing (Page(..))
import Set exposing (Set) import Set exposing (Set)
import Util.Html
import Util.ItemDragDrop as DD import Util.ItemDragDrop as DD
import Util.List import Util.List
import Util.Maybe import Util.Maybe
@ -33,6 +41,7 @@ type Msg
= CyclePreview ItemLight = CyclePreview ItemLight
| ToggleSelectItem (Set String) String | ToggleSelectItem (Set String) String
| ItemDDMsg DD.Msg | ItemDDMsg DD.Msg
| SetLinkTarget LinkTarget
type alias ViewConfig = type alias ViewConfig =
@ -41,10 +50,20 @@ 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
, selection : ItemSelection , selection : ItemSelection
, linkTarget : LinkTarget
} }
@ -89,7 +108,7 @@ update ddm msg model =
ddd = ddd =
DD.update lm ddm DD.update lm ddm
in in
UpdateResult model ddd.model Data.ItemSelection.Inactive UpdateResult model ddd.model Data.ItemSelection.Inactive LinkNone
ToggleSelectItem ids id -> ToggleSelectItem ids id ->
let let
@ -100,7 +119,7 @@ update ddm msg model =
else else
Set.insert id ids Set.insert id ids
in in
UpdateResult model ddm (Data.ItemSelection.Active newSet) UpdateResult model ddm (Data.ItemSelection.Active newSet) LinkNone
CyclePreview item -> CyclePreview item ->
let let
@ -113,6 +132,10 @@ update ddm msg model =
UpdateResult { model | previewAttach = next } UpdateResult { model | previewAttach = next }
ddm ddm
Data.ItemSelection.Inactive Data.ItemSelection.Inactive
LinkNone
SetLinkTarget target ->
UpdateResult model ddm Data.ItemSelection.Inactive target
view : ViewConfig -> UiSettings -> Model -> ItemLight -> Html Msg view : ViewConfig -> UiSettings -> Model -> ItemLight -> Html Msg
@ -204,31 +227,55 @@ metaDataContent settings item =
fieldHidden f = fieldHidden f =
Data.UiSettings.fieldHidden settings f Data.UiSettings.fieldHidden settings f
corr = default =
List.filterMap identity [ item.corrOrg, item.corrPerson ] text "-"
|> List.map .name
|> List.intersperse ", "
|> String.concat
conc = makeLink tagger idname =
List.filterMap identity [ item.concPerson, item.concEquip ] a
|> List.map .name [ onClick (tagger idname)
|> List.intersperse ", " , href "#"
|> String.concat ]
[ 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 = folder =
Maybe.map .name item.folder Maybe.map (makeLink (LinkFolder >> SetLinkTarget)) item.folder
|> Maybe.withDefault ""
dueDate = dueDate =
Maybe.map Util.Time.formatDateShort item.dueDate Maybe.map Util.Time.formatDateShort item.dueDate
|> Maybe.withDefault "" |> Maybe.withDefault ""
in in
div [ class "content" ] div [ class "content" ]
[ div [ class "ui horizontal list" ] [ div [ class "ui horizontal link list" ]
[ div [ div
[ classList [ classList
[ ( "item", True ) [ ( "link item", True )
, ( "invisible hidden" , ( "invisible hidden"
, fieldHidden Data.Fields.CorrOrg , fieldHidden Data.Fields.CorrOrg
&& fieldHidden Data.Fields.CorrPerson && fieldHidden Data.Fields.CorrPerson
@ -236,10 +283,9 @@ metaDataContent settings item =
] ]
, title "Correspondent" , title "Correspondent"
] ]
[ Icons.correspondentIcon "" (Icons.correspondentIcon ""
, text " " :: combine corrOrg corrPerson
, Util.String.withDefault "-" corr |> text )
]
, div , div
[ classList [ classList
[ ( "item", True ) [ ( "item", True )
@ -250,10 +296,9 @@ metaDataContent settings item =
] ]
, title "Concerning" , title "Concerning"
] ]
[ Icons.concernedIcon (Icons.concernedIcon
, text " " :: combine concPerson concEquip
, Util.String.withDefault "-" conc |> text )
]
, div , div
[ classList [ classList
[ ( "item", True ) [ ( "item", True )
@ -262,8 +307,7 @@ metaDataContent settings item =
, title "Folder" , title "Folder"
] ]
[ Icons.folderIcon "" [ Icons.folderIcon ""
, text " " , Maybe.withDefault default folder
, Util.String.withDefault "-" folder |> text
] ]
] ]
, div [ class "right floated meta" ] , div [ class "right floated meta" ]
@ -318,7 +362,7 @@ notesContent settings item =
mainContent : Attribute Msg -> String -> Bool -> UiSettings -> ViewConfig -> ItemLight -> Html Msg mainContent : Attribute Msg -> String -> Bool -> UiSettings -> ViewConfig -> ItemLight -> Html Msg
mainContent cardAction cardColor isConfirmed settings cfg item = mainContent cardAction cardColor isConfirmed settings _ item =
let let
dirIcon = dirIcon =
i [ class (Data.Direction.iconFromMaybe item.direction) ] [] i [ class (Data.Direction.iconFromMaybe item.direction) ] []
@ -429,6 +473,7 @@ previewMenu model item mainAttach =
[ class "ui compact basic icon button" [ class "ui compact basic icon button"
, href attachUrl , href attachUrl
, target "_self" , target "_self"
, title "Open attachment file"
] ]
[ i [ class "eye icon" ] [] [ i [ class "eye icon" ] []
] ]

View File

@ -75,6 +75,7 @@ type alias UpdateResult =
, cmd : Cmd Msg , cmd : Cmd Msg
, dragModel : DD.Model , dragModel : DD.Model
, selection : ItemSelection , selection : ItemSelection
, linkTarget : Comp.ItemCard.LinkTarget
} }
@ -91,18 +92,30 @@ updateDrag dm _ msg model =
newModel = newModel =
{ model | results = list } { model | results = list }
in in
UpdateResult newModel Cmd.none dm Data.ItemSelection.Inactive UpdateResult newModel
Cmd.none
dm
Data.ItemSelection.Inactive
Comp.ItemCard.LinkNone
AddResults list -> AddResults list ->
if list.groups == [] then if list.groups == [] then
UpdateResult model Cmd.none dm Data.ItemSelection.Inactive UpdateResult model
Cmd.none
dm
Data.ItemSelection.Inactive
Comp.ItemCard.LinkNone
else else
let let
newModel = newModel =
{ model | results = Data.Items.concat model.results list } { model | results = Data.Items.concat model.results list }
in in
UpdateResult newModel Cmd.none dm Data.ItemSelection.Inactive UpdateResult newModel
Cmd.none
dm
Data.ItemSelection.Inactive
Comp.ItemCard.LinkNone
ItemCardMsg item lm -> ItemCardMsg item lm ->
let let
@ -120,6 +133,7 @@ updateDrag dm _ msg model =
Cmd.none Cmd.none
result.dragModel result.dragModel
result.selection result.selection
result.linkTarget