diff --git a/modules/webapp/src/main/elm/Comp/ItemCard.elm b/modules/webapp/src/main/elm/Comp/ItemCard.elm index 95e758cc..a1e00fbd 100644 --- a/modules/webapp/src/main/elm/Comp/ItemCard.elm +++ b/modules/webapp/src/main/elm/Comp/ItemCard.elm @@ -4,6 +4,7 @@ import Api import Api.Model.AttachmentLight exposing (AttachmentLight) import Api.Model.HighlightEntry exposing (HighlightEntry) import Api.Model.ItemLight exposing (ItemLight) +import Data.BasicSize import Data.Direction import Data.Fields import Data.Icons as Icons @@ -117,29 +118,6 @@ update ddm msg model = view : ViewConfig -> UiSettings -> Model -> ItemLight -> Html Msg view cfg settings model item = let - dirIcon = - i [ class (Data.Direction.iconFromMaybe item.direction) ] [] - - corr = - List.filterMap identity [ item.corrOrg, item.corrPerson ] - |> List.map .name - |> List.intersperse ", " - |> String.concat - - conc = - List.filterMap identity [ item.concPerson, item.concEquip ] - |> List.map .name - |> List.intersperse ", " - |> String.concat - - folder = - Maybe.map .name item.folder - |> Maybe.withDefault "" - - dueDate = - Maybe.map Util.Time.formatDateShort item.dueDate - |> Maybe.withDefault "" - isConfirmed = item.state /= "created" @@ -163,55 +141,6 @@ view cfg settings model item = Data.ItemSelection.Active ids -> onClick (ToggleSelectItem ids item.id) - - mainAttach = - currentAttachment model item - - previewUrl = - Maybe.map .id mainAttach - |> Maybe.map Api.attachmentPreviewURL - |> Maybe.withDefault (Api.itemBasePreviewURL item.id) - - pageCount = - Maybe.andThen .pageCount mainAttach - |> Maybe.withDefault 0 - - pageCountLabel = - div - [ classList - [ ( "card-attachment-nav top", True ) - , ( "invisible", pageCount == 0 || (item.fileCount == 1 && pageCount == 1) ) - ] - ] - [ if item.fileCount == 1 then - div - [ class "ui secondary basic mini label" - , title "Number of pages" - ] - [ text "p." - , text (String.fromInt pageCount) - ] - - else - div [ class "ui left labeled mini button" ] - [ div [ class "ui basic right pointing mini label" ] - [ currentPosition model item - |> String.fromInt - |> text - , text "/" - , text (String.fromInt item.fileCount) - , text " p." - , text (String.fromInt pageCount) - ] - , a - [ class "ui mini icon secondary button" - , href "#" - , onClick (CyclePreview item) - ] - [ i [ class "arrow right icon" ] [] - ] - ] - ] in div ([ classList @@ -227,183 +156,292 @@ view cfg settings model item = span [ class "invisible" ] [] else - div - [ class "image ds-card-image" - , Data.UiSettings.cardPreviewSize settings - ] - [ img - [ class "preview-image" - , src previewUrl - , Data.UiSettings.cardPreviewSize settings - ] - [] - , pageCountLabel - ] - , a - [ class "link content" - , href "#" - , cardAction + previewImage settings model item + , mainContent cardAction cardColor isConfirmed settings cfg item + , notesContent settings item + , metaDataContent settings item + , fulltextResultsContent item + ] + + +fulltextResultsContent : ItemLight -> Html Msg +fulltextResultsContent item = + div + [ classList + [ ( "content search-highlight", True ) + , ( "invisible hidden", item.highlighting == [] ) ] - [ case cfg.selection of - Data.ItemSelection.Active ids -> + ] + [ div [ class "ui list" ] + (List.map renderHighlightEntry item.highlighting) + ] + + +metaDataContent : UiSettings -> ItemLight -> Html Msg +metaDataContent settings item = + let + fieldHidden f = + Data.UiSettings.fieldHidden settings f + + corr = + List.filterMap identity [ item.corrOrg, item.corrPerson ] + |> List.map .name + |> List.intersperse ", " + |> String.concat + + conc = + List.filterMap identity [ item.concPerson, item.concEquip ] + |> List.map .name + |> List.intersperse ", " + |> String.concat + + folder = + Maybe.map .name item.folder + |> Maybe.withDefault "" + + dueDate = + Maybe.map Util.Time.formatDateShort item.dueDate + |> Maybe.withDefault "" + in + div [ class "content" ] + [ div [ class "ui horizontal list" ] + [ div + [ classList + [ ( "item", True ) + , ( "invisible hidden" + , fieldHidden Data.Fields.CorrOrg + && fieldHidden Data.Fields.CorrPerson + ) + ] + , title "Correspondent" + ] + [ Icons.correspondentIcon "" + , text " " + , Util.String.withDefault "-" corr |> text + ] + , div + [ classList + [ ( "item", True ) + , ( "invisible hidden" + , fieldHidden Data.Fields.ConcPerson + && fieldHidden Data.Fields.ConcEquip + ) + ] + , title "Concerning" + ] + [ Icons.concernedIcon + , text " " + , Util.String.withDefault "-" conc |> text + ] + , div + [ classList + [ ( "item", True ) + , ( "invisible hidden", fieldHidden Data.Fields.Folder ) + ] + , title "Folder" + ] + [ Icons.folderIcon "" + , text " " + , Util.String.withDefault "-" folder |> text + ] + ] + , div [ class "right floated meta" ] + [ div [ class "ui horizontal list" ] + [ div + [ class "item" + , title "Source" + ] + [ text item.source + ] + , div + [ classList + [ ( "item", True ) + , ( "invisible hidden" + , item.dueDate + == Nothing + || fieldHidden Data.Fields.DueDate + ) + ] + , title ("Due on " ++ dueDate) + ] + [ div + [ class "ui basic grey label" + ] + [ Icons.dueDateIcon "" + , text (" " ++ dueDate) + ] + ] + ] + ] + ] + + +notesContent : UiSettings -> ItemLight -> Html Msg +notesContent settings item = + div + [ classList + [ ( "content", True ) + , ( "invisible hidden" + , settings.itemSearchNoteLength + <= 0 + || Util.String.isNothingOrBlank item.notes + ) + ] + ] + [ span [ class "small-info" ] + [ Maybe.withDefault "" item.notes + |> Util.String.ellipsis settings.itemSearchNoteLength + |> text + ] + ] + + +mainContent : Attribute Msg -> String -> Bool -> UiSettings -> ViewConfig -> ItemLight -> Html Msg +mainContent cardAction cardColor isConfirmed settings cfg item = + let + dirIcon = + i [ class (Data.Direction.iconFromMaybe item.direction) ] [] + + fieldHidden f = + Data.UiSettings.fieldHidden settings f + in + a + [ class "link content" + , href "#" + , cardAction + ] + [ case cfg.selection of + Data.ItemSelection.Active ids -> + div [ class "header" ] + [ Util.Html.checkbox (Set.member item.id ids) + , dirIcon + , Util.String.underscoreToSpace item.name + |> text + ] + + Data.ItemSelection.Inactive -> + if fieldHidden Data.Fields.Direction then div [ class "header" ] - [ Util.Html.checkbox (Set.member item.id ids) - , dirIcon + [ Util.String.underscoreToSpace item.name |> text + ] + + else + div + [ class "header" + , Data.Direction.labelFromMaybe item.direction + |> title + ] + [ dirIcon , Util.String.underscoreToSpace item.name |> text ] - - Data.ItemSelection.Inactive -> - if fieldHidden Data.Fields.Direction then - div [ class "header" ] - [ Util.String.underscoreToSpace item.name |> text - ] - - else + , div + [ classList + [ ( "ui right corner label", True ) + , ( cardColor, True ) + , ( "invisible", isConfirmed ) + ] + , title "New" + ] + [ i [ class "exclamation icon" ] [] + ] + , div + [ classList + [ ( "meta", True ) + , ( "invisible hidden", fieldHidden Data.Fields.Date ) + ] + ] + [ Util.Time.formatDate item.date |> text + ] + , div [ class "meta description" ] + [ div + [ classList + [ ( "ui right floated tiny labels", True ) + , ( "invisible hidden", item.tags == [] || fieldHidden Data.Fields.Tag ) + ] + ] + (List.map + (\tag -> div - [ class "header" - , Data.Direction.labelFromMaybe item.direction - |> title - ] - [ dirIcon - , Util.String.underscoreToSpace item.name - |> text - ] - , div - [ classList - [ ( "ui right corner label", True ) - , ( cardColor, True ) - , ( "invisible", isConfirmed ) - ] - , title "New" - ] - [ i [ class "exclamation icon" ] [] - ] - , div - [ classList - [ ( "meta", True ) - , ( "invisible hidden", fieldHidden Data.Fields.Date ) - ] - ] - [ Util.Time.formatDate item.date |> text - ] - , div [ class "meta description" ] - [ div - [ classList - [ ( "ui right floated tiny labels", True ) - , ( "invisible hidden", item.tags == [] || fieldHidden Data.Fields.Tag ) - ] - ] - (List.map - (\tag -> - div - [ classList - [ ( "ui basic label", True ) - , ( Data.UiSettings.tagColorString tag settings, True ) - ] + [ classList + [ ( "ui basic label", True ) + , ( Data.UiSettings.tagColorString tag settings, True ) ] - [ text tag.name ] - ) - item.tags + ] + [ text tag.name ] ) - ] + item.tags + ) ] - , div - [ classList - [ ( "content", True ) - , ( "invisible hidden" - , settings.itemSearchNoteLength - <= 0 - || Util.String.isNothingOrBlank item.notes - ) - ] + ] + + +previewImage : UiSettings -> Model -> ItemLight -> Html Msg +previewImage settings model item = + let + previewUrl = + Maybe.map .id mainAttach + |> Maybe.map Api.attachmentPreviewURL + |> Maybe.withDefault (Api.itemBasePreviewURL item.id) + + mainAttach = + currentAttachment model item + in + div + [ class "image ds-card-image" + , Data.UiSettings.cardPreviewSize settings + ] + [ img + [ class "preview-image" + , src previewUrl + , Data.UiSettings.cardPreviewSize settings ] - [ span [ class "small-info" ] - [ Maybe.withDefault "" item.notes - |> Util.String.ellipsis settings.itemSearchNoteLength - |> text - ] + [] + , pageCountLabel model item mainAttach + ] + + +pageCountLabel : Model -> ItemLight -> Maybe AttachmentLight -> Html Msg +pageCountLabel model item mainAttach = + let + pageCount = + Maybe.andThen .pageCount mainAttach + |> Maybe.withDefault 0 + in + div + [ classList + [ ( "card-attachment-nav top", True ) + , ( "invisible", pageCount == 0 || (item.fileCount == 1 && pageCount == 1) ) ] - , div [ class "content" ] - [ div [ class "ui horizontal list" ] - [ div - [ classList - [ ( "item", True ) - , ( "invisible hidden" - , fieldHidden Data.Fields.CorrOrg - && fieldHidden Data.Fields.CorrPerson - ) - ] - , title "Correspondent" + ] + [ if item.fileCount == 1 then + div + [ class "ui secondary basic mini label" + , title "Number of pages" + ] + [ text "p." + , text (String.fromInt pageCount) + ] + + else + div [ class "ui left labeled mini button" ] + [ div [ class "ui basic right pointing mini label" ] + [ currentPosition model item + |> String.fromInt + |> text + , text "/" + , text (String.fromInt item.fileCount) + , text " p." + , text (String.fromInt pageCount) ] - [ Icons.correspondentIcon "" - , text " " - , Util.String.withDefault "-" corr |> text + , a + [ class "ui mini icon secondary button" + , href "#" + , onClick (CyclePreview item) ] - , div - [ classList - [ ( "item", True ) - , ( "invisible hidden" - , fieldHidden Data.Fields.ConcPerson - && fieldHidden Data.Fields.ConcEquip - ) - ] - , title "Concerning" - ] - [ Icons.concernedIcon - , text " " - , Util.String.withDefault "-" conc |> text - ] - , div - [ classList - [ ( "item", True ) - , ( "invisible hidden", fieldHidden Data.Fields.Folder ) - ] - , title "Folder" - ] - [ Icons.folderIcon "" - , text " " - , Util.String.withDefault "-" folder |> text + [ i [ class "arrow right icon" ] [] ] ] - , div [ class "right floated meta" ] - [ div [ class "ui horizontal list" ] - [ div - [ class "item" - , title "Source" - ] - [ text item.source - ] - , div - [ classList - [ ( "item", True ) - , ( "invisible hidden" - , item.dueDate - == Nothing - || fieldHidden Data.Fields.DueDate - ) - ] - , title ("Due on " ++ dueDate) - ] - [ div - [ class "ui basic grey label" - ] - [ Icons.dueDateIcon "" - , text (" " ++ dueDate) - ] - ] - ] - ] - ] - , div - [ classList - [ ( "content search-highlight", True ) - , ( "invisible hidden", item.highlighting == [] ) - ] - ] - [ div [ class "ui list" ] - (List.map renderHighlightEntry item.highlighting) - ] ]