mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Finish mail settings
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
module Api exposing
|
||||
( cancelJob
|
||||
, changePassword
|
||||
, createMailSettings
|
||||
, deleteEquip
|
||||
, deleteItem
|
||||
, deleteMailSettings
|
||||
, deleteOrg
|
||||
, deletePerson
|
||||
, deleteSource
|
||||
@ -15,6 +17,7 @@ module Api exposing
|
||||
, getItemProposals
|
||||
, getJobQueueState
|
||||
, getJobQueueStateIn
|
||||
, getMailSettings
|
||||
, getOrgLight
|
||||
, getOrganizations
|
||||
, getPersons
|
||||
@ -60,6 +63,8 @@ import Api.Model.BasicResult exposing (BasicResult)
|
||||
import Api.Model.Collective exposing (Collective)
|
||||
import Api.Model.CollectiveSettings exposing (CollectiveSettings)
|
||||
import Api.Model.DirectionValue exposing (DirectionValue)
|
||||
import Api.Model.EmailSettings exposing (EmailSettings)
|
||||
import Api.Model.EmailSettingsList exposing (EmailSettingsList)
|
||||
import Api.Model.Equipment exposing (Equipment)
|
||||
import Api.Model.EquipmentList exposing (EquipmentList)
|
||||
import Api.Model.GenInvite exposing (GenInvite)
|
||||
@ -99,6 +104,57 @@ import Util.File
|
||||
import Util.Http as Http2
|
||||
|
||||
|
||||
|
||||
--- Mail Settings
|
||||
|
||||
|
||||
deleteMailSettings : Flags -> String -> (Result Http.Error BasicResult -> msg) -> Cmd msg
|
||||
deleteMailSettings flags name receive =
|
||||
Http2.authDelete
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/email/settings/" ++ name
|
||||
, account = getAccount flags
|
||||
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||
}
|
||||
|
||||
|
||||
getMailSettings : Flags -> String -> (Result Http.Error EmailSettingsList -> msg) -> Cmd msg
|
||||
getMailSettings flags query receive =
|
||||
Http2.authGet
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/email/settings?q=" ++ Url.percentEncode query
|
||||
, account = getAccount flags
|
||||
, expect = Http.expectJson receive Api.Model.EmailSettingsList.decoder
|
||||
}
|
||||
|
||||
|
||||
createMailSettings :
|
||||
Flags
|
||||
-> Maybe String
|
||||
-> EmailSettings
|
||||
-> (Result Http.Error BasicResult -> msg)
|
||||
-> Cmd msg
|
||||
createMailSettings flags mname ems receive =
|
||||
case mname of
|
||||
Just en ->
|
||||
Http2.authPut
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/email/settings/" ++ en
|
||||
, account = getAccount flags
|
||||
, body = Http.jsonBody (Api.Model.EmailSettings.encode ems)
|
||||
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||
}
|
||||
|
||||
Nothing ->
|
||||
Http2.authPost
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/email/settings"
|
||||
, account = getAccount flags
|
||||
, body = Http.jsonBody (Api.Model.EmailSettings.encode ems)
|
||||
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Upload
|
||||
|
||||
|
||||
upload : Flags -> Maybe String -> ItemUploadMeta -> List File -> (String -> Result Http.Error BasicResult -> msg) -> List (Cmd msg)
|
||||
upload flags sourceId meta files receive =
|
||||
let
|
||||
|
@ -4,6 +4,7 @@ module Comp.EmailSettingsForm exposing
|
||||
, emptyModel
|
||||
, getSettings
|
||||
, init
|
||||
, isValid
|
||||
, update
|
||||
, view
|
||||
)
|
||||
@ -40,7 +41,7 @@ emptyModel =
|
||||
{ settings = Api.Model.EmailSettings.empty
|
||||
, name = ""
|
||||
, host = ""
|
||||
, portField = Comp.IntField.init (Just 0) Nothing "SMTP Port"
|
||||
, portField = Comp.IntField.init (Just 0) Nothing True "SMTP Port"
|
||||
, portNum = Nothing
|
||||
, user = Nothing
|
||||
, passField = Comp.PasswordInput.init
|
||||
@ -63,7 +64,7 @@ init ems =
|
||||
{ settings = ems
|
||||
, name = ems.name
|
||||
, host = ems.smtpHost
|
||||
, portField = Comp.IntField.init (Just 0) Nothing "SMTP Port"
|
||||
, portField = Comp.IntField.init (Just 0) Nothing True "SMTP Port"
|
||||
, portNum = ems.smtpPort
|
||||
, user = ems.smtpUser
|
||||
, passField = Comp.PasswordInput.init
|
||||
@ -184,7 +185,7 @@ view model =
|
||||
]
|
||||
]
|
||||
, div [ class "fields" ]
|
||||
[ div [ class "fifteen wide required field" ]
|
||||
[ div [ class "thirteen wide required field" ]
|
||||
[ label [] [ text "SMTP Host" ]
|
||||
, input
|
||||
[ type_ "text"
|
||||
@ -194,7 +195,11 @@ view model =
|
||||
]
|
||||
[]
|
||||
]
|
||||
, Html.map PortMsg (Comp.IntField.view model.portNum model.portField)
|
||||
, Html.map PortMsg
|
||||
(Comp.IntField.view model.portNum
|
||||
"three wide field"
|
||||
model.portField
|
||||
)
|
||||
]
|
||||
, div [ class "two fields" ]
|
||||
[ div [ class "field" ]
|
||||
|
@ -18,6 +18,8 @@ import Data.Flags exposing (Flags)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick, onInput)
|
||||
import Http
|
||||
import Util.Http
|
||||
|
||||
|
||||
type alias Model =
|
||||
@ -43,9 +45,9 @@ emptyModel =
|
||||
}
|
||||
|
||||
|
||||
init : ( Model, Cmd Msg )
|
||||
init =
|
||||
( emptyModel, Cmd.none )
|
||||
init : Flags -> ( Model, Cmd Msg )
|
||||
init flags =
|
||||
( emptyModel, Api.getMailSettings flags "" MailSettingsResp )
|
||||
|
||||
|
||||
type ViewMode
|
||||
@ -61,6 +63,10 @@ type Msg
|
||||
| YesNoMsg Comp.YesNoDimmer.Msg
|
||||
| RequestDelete
|
||||
| SetViewMode ViewMode
|
||||
| Submit
|
||||
| SubmitResp (Result Http.Error BasicResult)
|
||||
| LoadSettings
|
||||
| MailSettingsResp (Result Http.Error EmailSettingsList)
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
@ -84,8 +90,27 @@ update flags msg model =
|
||||
let
|
||||
( tm, tc ) =
|
||||
Comp.EmailSettingsTable.update m model.tableModel
|
||||
|
||||
m2 =
|
||||
{ model
|
||||
| tableModel = tm
|
||||
, viewMode = Maybe.map (\_ -> Form) tm.selected |> Maybe.withDefault Table
|
||||
, formError =
|
||||
if tm.selected /= Nothing then
|
||||
Nothing
|
||||
|
||||
else
|
||||
model.formError
|
||||
, formModel =
|
||||
case tm.selected of
|
||||
Just ems ->
|
||||
Comp.EmailSettingsForm.init ems
|
||||
|
||||
Nothing ->
|
||||
model.formModel
|
||||
}
|
||||
in
|
||||
( { model | tableModel = tm }, Cmd.map TableMsg tc )
|
||||
( m2, Cmd.map TableMsg tc )
|
||||
|
||||
FormMsg m ->
|
||||
let
|
||||
@ -95,21 +120,84 @@ update flags msg model =
|
||||
( { model | formModel = fm }, Cmd.map FormMsg fc )
|
||||
|
||||
SetQuery str ->
|
||||
( { model | query = str }, Cmd.none )
|
||||
let
|
||||
m =
|
||||
{ model | query = str }
|
||||
in
|
||||
( m, Api.getMailSettings flags str MailSettingsResp )
|
||||
|
||||
YesNoMsg m ->
|
||||
let
|
||||
( dm, flag ) =
|
||||
Comp.YesNoDimmer.update m model.deleteConfirm
|
||||
|
||||
( mid, _ ) =
|
||||
Comp.EmailSettingsForm.getSettings model.formModel
|
||||
|
||||
cmd =
|
||||
case ( flag, mid ) of
|
||||
( True, Just name ) ->
|
||||
Api.deleteMailSettings flags name SubmitResp
|
||||
|
||||
_ ->
|
||||
Cmd.none
|
||||
in
|
||||
( { model | deleteConfirm = dm }, Cmd.none )
|
||||
( { model | deleteConfirm = dm }, cmd )
|
||||
|
||||
RequestDelete ->
|
||||
( model, Cmd.none )
|
||||
update flags (YesNoMsg Comp.YesNoDimmer.activate) model
|
||||
|
||||
SetViewMode m ->
|
||||
( { model | viewMode = m }, Cmd.none )
|
||||
|
||||
Submit ->
|
||||
let
|
||||
( mid, ems ) =
|
||||
Comp.EmailSettingsForm.getSettings model.formModel
|
||||
|
||||
valid =
|
||||
Comp.EmailSettingsForm.isValid model.formModel
|
||||
in
|
||||
if valid then
|
||||
( { model | loading = True }, Api.createMailSettings flags mid ems SubmitResp )
|
||||
|
||||
else
|
||||
( { model | formError = Just "Please fill required fields." }, Cmd.none )
|
||||
|
||||
LoadSettings ->
|
||||
( { model | loading = True }, Api.getMailSettings flags model.query MailSettingsResp )
|
||||
|
||||
SubmitResp (Ok res) ->
|
||||
if res.success then
|
||||
let
|
||||
( m2, c2 ) =
|
||||
update flags (SetViewMode Table) model
|
||||
|
||||
( m3, c3 ) =
|
||||
update flags LoadSettings m2
|
||||
in
|
||||
( { m3 | loading = False }, Cmd.batch [ c2, c3 ] )
|
||||
|
||||
else
|
||||
( { model | formError = Just res.message, loading = False }, Cmd.none )
|
||||
|
||||
SubmitResp (Err err) ->
|
||||
( { model | formError = Just (Util.Http.errorToString err), loading = False }, Cmd.none )
|
||||
|
||||
MailSettingsResp (Ok ems) ->
|
||||
let
|
||||
m2 =
|
||||
{ model
|
||||
| viewMode = Table
|
||||
, loading = False
|
||||
, tableModel = Comp.EmailSettingsTable.init ems.items
|
||||
}
|
||||
in
|
||||
( m2, Cmd.none )
|
||||
|
||||
MailSettingsResp (Err _) ->
|
||||
( { model | loading = False }, Cmd.none )
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
@ -171,10 +259,18 @@ viewForm model =
|
||||
[ Maybe.withDefault "" model.formError |> text
|
||||
]
|
||||
, div [ class "ui divider" ] []
|
||||
, button [ class "ui primary button" ]
|
||||
, button
|
||||
[ class "ui primary button"
|
||||
, onClick Submit
|
||||
, href "#"
|
||||
]
|
||||
[ text "Submit"
|
||||
]
|
||||
, a [ class "ui secondary button", onClick (SetViewMode Table), href "" ]
|
||||
, a
|
||||
[ class "ui secondary button"
|
||||
, onClick (SetViewMode Table)
|
||||
, href ""
|
||||
]
|
||||
[ text "Cancel"
|
||||
]
|
||||
, if model.formModel.settings.name /= "" then
|
||||
|
@ -2,6 +2,7 @@ module Comp.EmailSettingsTable exposing
|
||||
( Model
|
||||
, Msg
|
||||
, emptyModel
|
||||
, init
|
||||
, update
|
||||
, view
|
||||
)
|
||||
@ -9,10 +10,12 @@ module Comp.EmailSettingsTable exposing
|
||||
import Api.Model.EmailSettings exposing (EmailSettings)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ emailSettings : List EmailSettings
|
||||
, selected : Maybe EmailSettings
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +27,7 @@ emptyModel =
|
||||
init : List EmailSettings -> Model
|
||||
init ems =
|
||||
{ emailSettings = ems
|
||||
, selected = Nothing
|
||||
}
|
||||
|
||||
|
||||
@ -33,17 +37,40 @@ type Msg
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
( model, Cmd.none )
|
||||
case msg of
|
||||
Select ems ->
|
||||
( { model | selected = Just ems }, Cmd.none )
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
table [ class "ui table" ]
|
||||
table [ class "ui selectable pointer table" ]
|
||||
[ thead []
|
||||
[ th [] [ text "Name" ]
|
||||
[ th [ class "collapsible" ] [ text "Name" ]
|
||||
, th [] [ text "Host/Port" ]
|
||||
, th [] [ text "From" ]
|
||||
]
|
||||
, tbody []
|
||||
[]
|
||||
(List.map (renderLine model) model.emailSettings)
|
||||
]
|
||||
|
||||
|
||||
renderLine : Model -> EmailSettings -> Html Msg
|
||||
renderLine model ems =
|
||||
let
|
||||
hostport =
|
||||
case ems.smtpPort of
|
||||
Just p ->
|
||||
ems.smtpHost ++ ":" ++ String.fromInt p
|
||||
|
||||
Nothing ->
|
||||
ems.smtpHost
|
||||
in
|
||||
tr
|
||||
[ classList [ ( "active", model.selected == Just ems ) ]
|
||||
, onClick (Select ems)
|
||||
]
|
||||
[ td [ class "collapsible" ] [ text ems.name ]
|
||||
, td [] [ text hostport ]
|
||||
, td [] [ text ems.from ]
|
||||
]
|
||||
|
@ -11,6 +11,7 @@ type alias Model =
|
||||
, label : String
|
||||
, error : Maybe String
|
||||
, lastInput : String
|
||||
, optional : Bool
|
||||
}
|
||||
|
||||
|
||||
@ -18,26 +19,27 @@ type Msg
|
||||
= SetValue String
|
||||
|
||||
|
||||
init : Maybe Int -> Maybe Int -> String -> Model
|
||||
init min max label =
|
||||
init : Maybe Int -> Maybe Int -> Bool -> String -> Model
|
||||
init min max opt label =
|
||||
{ min = min
|
||||
, max = max
|
||||
, label = label
|
||||
, error = Nothing
|
||||
, lastInput = ""
|
||||
, optional = opt
|
||||
}
|
||||
|
||||
|
||||
tooLow : Model -> Int -> Bool
|
||||
tooLow model n =
|
||||
Maybe.map ((<) n) model.min
|
||||
|> Maybe.withDefault False
|
||||
|> Maybe.withDefault (not model.optional)
|
||||
|
||||
|
||||
tooHigh : Model -> Int -> Bool
|
||||
tooHigh model n =
|
||||
Maybe.map ((>) n) model.max
|
||||
|> Maybe.withDefault False
|
||||
|> Maybe.withDefault (not model.optional)
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Maybe Int )
|
||||
@ -75,16 +77,20 @@ update msg model =
|
||||
( { m | error = Nothing }, Just n )
|
||||
|
||||
Nothing ->
|
||||
( { m | error = Just ("'" ++ str ++ "' is not a valid number!") }
|
||||
, Nothing
|
||||
)
|
||||
if model.optional && String.trim str == "" then
|
||||
( { m | error = Nothing }, Nothing )
|
||||
|
||||
else
|
||||
( { m | error = Just ("'" ++ str ++ "' is not a valid number!") }
|
||||
, Nothing
|
||||
)
|
||||
|
||||
|
||||
view : Maybe Int -> Model -> Html Msg
|
||||
view nval model =
|
||||
view : Maybe Int -> String -> Model -> Html Msg
|
||||
view nval classes model =
|
||||
div
|
||||
[ classList
|
||||
[ ( "field", True )
|
||||
[ ( classes, True )
|
||||
, ( "error", model.error /= Nothing )
|
||||
]
|
||||
]
|
||||
|
@ -13,8 +13,20 @@ update flags msg model =
|
||||
let
|
||||
m =
|
||||
{ model | currentTab = Just t }
|
||||
|
||||
( m2, cmd ) =
|
||||
case t of
|
||||
EmailSettingsTab ->
|
||||
let
|
||||
( em, c ) =
|
||||
Comp.EmailSettingsManage.init flags
|
||||
in
|
||||
( { m | emailSettingsModel = em }, Cmd.map EmailSettingsMsg c )
|
||||
|
||||
ChangePassTab ->
|
||||
( m, Cmd.none )
|
||||
in
|
||||
( m, Cmd.none )
|
||||
( m2, cmd )
|
||||
|
||||
ChangePassMsg m ->
|
||||
let
|
||||
|
@ -88,6 +88,10 @@
|
||||
background-color: #d8dfe5;
|
||||
}
|
||||
|
||||
.ui.selectable.pointer.table tr {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
span.small-info {
|
||||
font-size: smaller;
|
||||
color: rgba(0,0,0,0.6);
|
||||
|
Reference in New Issue
Block a user