Sow sent mails in item detail

This commit is contained in:
Eike Kettner 2020-01-11 01:51:38 +01:00
parent 88efe13209
commit 6e56aad251
4 changed files with 231 additions and 17 deletions

View File

@ -22,6 +22,7 @@ module Api exposing
, getOrganizations
, getPersons
, getPersonsLight
, getSentMails
, getSources
, getTags
, getUsers
@ -87,6 +88,7 @@ import Api.Model.Person exposing (Person)
import Api.Model.PersonList exposing (PersonList)
import Api.Model.ReferenceList exposing (ReferenceList)
import Api.Model.Registration exposing (Registration)
import Api.Model.SentMails exposing (SentMails)
import Api.Model.SimpleMail exposing (SimpleMail)
import Api.Model.Source exposing (Source)
import Api.Model.SourceList exposing (SourceList)
@ -107,6 +109,23 @@ import Util.Http as Http2
--- Get Sent Mails
getSentMails :
Flags
-> String
-> (Result Http.Error SentMails -> msg)
-> Cmd msg
getSentMails flags item receive =
Http2.authGet
{ url = flags.config.baseUrl ++ "/api/v1/sec/email/sent/item/" ++ item
, account = getAccount flags
, expect = Http.expectJson receive Api.Model.SentMails.decoder
}
--- Mail Send

View File

@ -17,12 +17,14 @@ import Api.Model.OptionalDate exposing (OptionalDate)
import Api.Model.OptionalId exposing (OptionalId)
import Api.Model.OptionalText exposing (OptionalText)
import Api.Model.ReferenceList exposing (ReferenceList)
import Api.Model.SentMails exposing (SentMails)
import Api.Model.Tag exposing (Tag)
import Api.Model.TagList exposing (TagList)
import Browser.Navigation as Nav
import Comp.DatePicker
import Comp.Dropdown exposing (isDropdownChangeMsg)
import Comp.ItemMail
import Comp.SentMails
import Comp.YesNoDimmer
import Data.Direction exposing (Direction)
import Data.Flags exposing (Flags)
@ -62,6 +64,8 @@ type alias Model =
, itemMail : Comp.ItemMail.Model
, mailOpen : Bool
, mailSendResult : Maybe BasicResult
, sentMails : Comp.SentMails.Model
, sentMailsOpen : Bool
}
@ -124,6 +128,8 @@ emptyModel =
, itemMail = Comp.ItemMail.emptyModel
, mailOpen = False
, mailSendResult = Nothing
, sentMails = Comp.SentMails.init
, sentMailsOpen = False
}
@ -169,6 +175,9 @@ type Msg
| ItemMailMsg Comp.ItemMail.Msg
| ToggleMail
| SendMailResp (Result Http.Error BasicResult)
| SentMailsMsg Comp.SentMails.Msg
| ToggleSentMails
| SentMailsResp (Result Http.Error SentMails)
@ -269,11 +278,7 @@ setNotes flags model =
text =
OptionalText model.notesModel
in
if model.notesModel == Nothing then
Cmd.none
else
Api.setItemNotes flags model.item.id text SaveResp
Api.setItemNotes flags model.item.id text SaveResp
setDate : Flags -> Model -> Maybe Int -> Cmd Msg
@ -303,6 +308,7 @@ update key flags next msg model =
, Cmd.map ItemDatePickerMsg dpc
, Cmd.map DueDatePickerMsg dpc
, Cmd.map ItemMailMsg ic
, Api.getSentMails flags model.item.id SentMailsResp
]
)
@ -381,11 +387,20 @@ update key flags next msg model =
, itemDate = item.itemDate
, dueDate = item.dueDate
}
, Cmd.batch [ c1, c2, c3, c4, c5, getOptions flags, proposalCmd ]
, Cmd.batch
[ c1
, c2
, c3
, c4
, c5
, getOptions flags
, proposalCmd
, Api.getSentMails flags item.id SentMailsResp
]
)
SetActiveAttachment pos ->
( { model | visibleAttach = pos }, Cmd.none )
( { model | visibleAttach = pos, sentMailsOpen = False }, Cmd.none )
ToggleMenu ->
( { model | menuOpen = not model.menuOpen }, Cmd.none )
@ -518,14 +533,7 @@ update key flags next msg model =
( model, setName flags model )
SetNotes str ->
( { model
| notesModel =
if str == "" then
Nothing
else
Just str
}
( { model | notesModel = Util.Maybe.fromString str }
, Cmd.none
)
@ -749,7 +757,11 @@ update key flags next msg model =
| itemMail = mm
, mailSendResult = Just br
}
, Cmd.none
, if br.success then
Api.itemDetail flags model.item.id GetItemResp
else
Cmd.none
)
SendMailResp (Err err) ->
@ -761,6 +773,26 @@ update key flags next msg model =
, Cmd.none
)
SentMailsMsg m ->
let
sm =
Comp.SentMails.update m model.sentMails
in
( { model | sentMails = sm }, Cmd.none )
ToggleSentMails ->
( { model | sentMailsOpen = not model.sentMailsOpen, visibleAttach = -1 }, Cmd.none )
SentMailsResp (Ok list) ->
let
sm =
Comp.SentMails.initMails list.items
in
( { model | sentMails = sm }, Cmd.none )
SentMailsResp (Err err) ->
( model, Cmd.none )
-- view
@ -911,7 +943,7 @@ renderNotes model =
, onClick ToggleNotes
, href "#"
]
[ i [ class "delete icon" ] []
[ i [ class "eye slash icon" ] []
]
]
]
@ -919,6 +951,23 @@ renderNotes model =
renderAttachmentsTabMenu : Model -> Html Msg
renderAttachmentsTabMenu model =
let
mailTab =
if Comp.SentMails.isEmpty model.sentMails then
[]
else
[ div
[ classList
[ ( "right item", True )
, ( "active", model.sentMailsOpen )
]
, onClick ToggleSentMails
]
[ text "E-Mails"
]
]
in
div [ class "ui top attached tabular menu" ]
(List.indexedMap
(\pos ->
@ -937,11 +986,31 @@ renderAttachmentsTabMenu model =
]
)
model.item.attachments
++ mailTab
)
renderAttachmentsTabBody : Model -> List (Html Msg)
renderAttachmentsTabBody model =
let
mailTab =
if Comp.SentMails.isEmpty model.sentMails then
[]
else
[ div
[ classList
[ ( "ui attached tab segment", True )
, ( "active", model.sentMailsOpen )
]
]
[ h3 [ class "ui header" ]
[ text "Sent E-Mails"
]
, Html.map SentMailsMsg (Comp.SentMails.view model.sentMails)
]
]
in
List.indexedMap
(\pos ->
\a ->
@ -958,6 +1027,7 @@ renderAttachmentsTabBody model =
]
)
model.item.attachments
++ mailTab
renderItemInfo : Model -> Html Msg

View File

@ -0,0 +1,121 @@
module Comp.SentMails exposing (..)
import Api.Model.SentMail exposing (SentMail)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Util.Time
type alias Model =
{ mails : List SentMail
, selected : Maybe SentMail
}
init : Model
init =
{ mails = []
, selected = Nothing
}
initMails : List SentMail -> Model
initMails mails =
{ init | mails = mails }
isEmpty : Model -> Bool
isEmpty model =
List.isEmpty model.mails
type Msg
= Show SentMail
| Hide
update : Msg -> Model -> Model
update msg model =
case msg of
Hide ->
{ model | selected = Nothing }
Show m ->
{ model | selected = Just m }
view : Model -> Html Msg
view model =
case model.selected of
Just mail ->
div [ class "ui blue basic segment" ]
[ div [ class "ui list" ]
[ div [ class "item" ]
[ text "From"
, div [ class "header" ]
[ text mail.sender
, text " ("
, text mail.connection
, text ")"
]
]
, div [ class "item" ]
[ text "Date"
, div [ class "header" ]
[ Util.Time.formatDateTime mail.created |> text
]
]
, div [ class "item" ]
[ text "Recipients"
, div [ class "header" ]
[ String.join ", " mail.recipients |> text
]
]
, div [ class "item" ]
[ text "Subject"
, div [ class "header" ]
[ text mail.subject
]
]
]
, div [ class "ui horizontal divider" ] []
, div [ class "mail-body" ]
[ text mail.body
]
, a
[ class "ui right corner label"
, onClick Hide
, href "#"
]
[ i [ class "close icon" ] []
]
]
Nothing ->
table [ class "ui selectable pointer very basic table" ]
[ thead []
[ th [ class "collapsing" ] [ text "Recipients" ]
, th [] [ text "Subject" ]
, th [ class "collapsible" ] [ text "Sent" ]
, th [ class "collapsible" ] [ text "Sender" ]
]
, tbody [] <|
List.map
renderLine
model.mails
]
renderLine : SentMail -> Html Msg
renderLine mail =
tr [ onClick (Show mail) ]
[ td [ class "collapsing" ]
[ String.join ", " mail.recipients |> text
]
, td [] [ text mail.subject ]
, td [ class "collapsing" ]
[ Util.Time.formatDateTime mail.created |> text
]
, td [ class "collapsing" ] [ text mail.sender ]
]

View File

@ -107,6 +107,10 @@ span.small-info {
color: rgba(0,0,0,0.4);
}
.mail-body {
white-space: pre;
}
.login-layout, .register-layout, .newinvite-layout {
background: #708090;
height: 101vh;