Externalize error messages

This commit is contained in:
Eike Kettner
2021-04-17 11:14:29 +02:00
parent c9b54e80b7
commit b2cffb22ef
65 changed files with 1518 additions and 683 deletions

View File

@ -17,7 +17,6 @@ import Html.Attributes exposing (..)
import Http
import Messages.Comp.AttachmentMeta exposing (Texts)
import Styles as S
import Util.Http
type alias Model =
@ -29,7 +28,7 @@ type alias Model =
type DataResult a
= NotAvailable
| Success a
| Failure String
| HttpFailure Http.Error
emptyModel : Model
@ -57,7 +56,7 @@ update msg model =
{ model | meta = Success am }
MetaResp (Err err) ->
{ model | meta = Failure (Util.Http.errorToString err) }
{ model | meta = HttpFailure err }
@ -77,9 +76,9 @@ view2 texts attrs model =
, label = texts.basics.loading
}
Failure msg ->
HttpFailure err ->
div [ class S.errorMessage ]
[ text msg
[ text (texts.httpError err)
]
Success data ->

View File

@ -18,7 +18,6 @@ import Html.Events exposing (onClick)
import Http
import Messages.Comp.ChangePasswordForm exposing (Texts)
import Styles as S
import Util.Http
type alias Model =
@ -28,12 +27,20 @@ type alias Model =
, newPass1 : Maybe String
, pass2Model : Comp.PasswordInput.Model
, newPass2 : Maybe String
, errors : List String
, formState : FormState
, loading : Bool
, successMsg : String
}
type FormState
= FormStateNone
| FormStateHttpError Http.Error
| FormStateSubmitOk
| FormStateRequiredMissing
| FormStatePasswordMismatch
| FormStateSubmitError String
emptyModel : Model
emptyModel =
validateModel
@ -43,9 +50,8 @@ emptyModel =
, pass1Model = Comp.PasswordInput.init
, newPass2 = Nothing
, pass2Model = Comp.PasswordInput.init
, errors = []
, loading = False
, successMsg = ""
, formState = FormStateNone
}
@ -57,37 +63,21 @@ type Msg
| SubmitResp (Result Http.Error BasicResult)
validate : Model -> List String
validate : Model -> FormState
validate model =
List.concat
[ if model.newPass1 /= Nothing && model.newPass2 /= Nothing && model.newPass1 /= model.newPass2 then
[ "New passwords do not match." ]
if model.newPass1 /= Nothing && model.newPass2 /= Nothing && model.newPass1 /= model.newPass2 then
FormStatePasswordMismatch
else
[]
, if model.newPass1 == Nothing || model.newPass2 == Nothing || model.current == Nothing then
[ "Please fill in required fields." ]
else if model.newPass1 == Nothing || model.newPass2 == Nothing || model.current == Nothing then
FormStateRequiredMissing
else
[]
]
else
FormStateNone
validateModel : Model -> Model
validateModel model =
let
err =
validate model
in
{ model
| errors = err
, successMsg =
if err == [] then
model.successMsg
else
""
}
{ model | formState = validate model }
@ -126,7 +116,7 @@ update flags msg model =
Submit ->
let
valid =
state =
validate model
cp =
@ -134,43 +124,34 @@ update flags msg model =
(Maybe.withDefault "" model.current)
(Maybe.withDefault "" model.newPass1)
in
if List.isEmpty valid then
( { model | loading = True, errors = [], successMsg = "" }
if state == FormStateNone then
( { model | loading = True, formState = state }
, Api.changePassword flags cp SubmitResp
)
else
( model, Cmd.none )
( { model | formState = state }, Cmd.none )
SubmitResp (Ok res) ->
let
em =
{ emptyModel
| errors = []
, successMsg = "Password has been changed."
}
{ emptyModel | formState = FormStateSubmitOk }
in
if res.success then
( em, Cmd.none )
else
( { model
| errors = [ res.message ]
| formState = FormStateSubmitError res.message
, loading = False
, successMsg = ""
}
, Cmd.none
)
SubmitResp (Err err) ->
let
str =
Util.Http.errorToString err
in
( { model
| errors = [ str ]
| formState = FormStateHttpError err
, loading = False
, successMsg = ""
}
, Cmd.none
)
@ -235,29 +216,7 @@ view2 texts model =
model.pass2Model
)
]
, div
[ class S.successMessage
, classList [ ( "hidden", model.successMsg == "" ) ]
]
[ text model.successMsg
]
, div
[ class S.errorMessage
, classList
[ ( "hidden"
, List.isEmpty model.errors
|| (currentEmpty && pass1Empty && pass2Empty)
)
]
]
[ case model.errors of
a :: [] ->
text a
_ ->
ul [ class "list-disc" ]
(List.map (\em -> li [] [ text em ]) model.errors)
]
, renderResultMessage texts model
, div [ class "flex flex-row" ]
[ button
[ class S.primaryButton
@ -272,3 +231,33 @@ view2 texts model =
, label = texts.basics.loading
}
]
renderResultMessage : Texts -> Model -> Html msg
renderResultMessage texts model =
div
[ classList
[ ( S.errorMessage, model.formState /= FormStateSubmitOk )
, ( S.successMessage, model.formState == FormStateSubmitOk )
, ( "hidden", model.formState == FormStateNone )
]
]
[ case model.formState of
FormStateNone ->
text ""
FormStateHttpError err ->
text (texts.httpError err)
FormStateSubmitError m ->
text m
FormStatePasswordMismatch ->
text texts.passwordMismatch
FormStateRequiredMissing ->
text texts.fillRequiredFields
FormStateSubmitOk ->
text texts.passwordChangeSuccessful
]

View File

@ -25,7 +25,6 @@ import Html.Events exposing (onCheck, onClick, onInput)
import Http
import Messages.Comp.CollectiveSettingsForm exposing (Texts)
import Styles as S
import Util.Http
type alias Model =
@ -33,12 +32,27 @@ type alias Model =
, intEnabled : Bool
, initSettings : CollectiveSettings
, fullTextConfirmText : String
, fullTextReIndexResult : Maybe BasicResult
, fullTextReIndexResult : FulltextReindexResult
, classifierModel : Comp.ClassifierSettingsForm.Model
, startClassifierResult : Maybe BasicResult
, startClassifierResult : ClassifierResult
}
type ClassifierResult
= ClassifierResultInitial
| ClassifierResultHttpError Http.Error
| ClassifierResultSubmitError String
| ClassifierResultOk
type FulltextReindexResult
= FulltextReindexInitial
| FulltextReindexHttpError Http.Error
| FulltextReindexSubmitError String
| FulltextReindexSubmitOk
| FulltextReindexOKMissing
init : Flags -> CollectiveSettings -> ( Model, Cmd Msg )
init flags settings =
let
@ -57,9 +71,9 @@ init flags settings =
, intEnabled = settings.integrationEnabled
, initSettings = settings
, fullTextConfirmText = ""
, fullTextReIndexResult = Nothing
, fullTextReIndexResult = FulltextReindexInitial
, classifierModel = cm
, startClassifierResult = Nothing
, startClassifierResult = ClassifierResultInitial
}
, Cmd.map ClassifierSettingMsg cc
)
@ -121,31 +135,36 @@ update flags msg model =
TriggerReIndex ->
case String.toLower model.fullTextConfirmText of
"ok" ->
( { model | fullTextReIndexResult = Nothing }
( { model | fullTextReIndexResult = FulltextReindexInitial }
, Api.startReIndex flags TriggerReIndexResult
, Nothing
)
_ ->
( { model
| fullTextReIndexResult =
Just
(BasicResult False <|
"Please type OK in the field if you really "
++ "want to start re-indexing your data."
)
| fullTextReIndexResult = FulltextReindexOKMissing
}
, Cmd.none
, Nothing
)
TriggerReIndexResult (Ok br) ->
( { model | fullTextReIndexResult = Just br }, Cmd.none, Nothing )
( { model
| fullTextReIndexResult =
if br.success then
FulltextReindexSubmitOk
else
FulltextReindexSubmitError br.message
}
, Cmd.none
, Nothing
)
TriggerReIndexResult (Err err) ->
( { model
| fullTextReIndexResult =
Just (BasicResult False (Util.Http.errorToString err))
FulltextReindexHttpError err
}
, Cmd.none
, Nothing
@ -175,16 +194,20 @@ update flags msg model =
( model, Api.startClassifier flags StartClassifierResp, Nothing )
StartClassifierResp (Ok br) ->
( { model | startClassifierResult = Just br }
( { model
| startClassifierResult =
if br.success then
ClassifierResultOk
else
ClassifierResultSubmitError br.message
}
, Cmd.none
, Nothing
)
StartClassifierResp (Err err) ->
( { model
| startClassifierResult =
Just (BasicResult False (Util.Http.errorToString err))
}
( { model | startClassifierResult = ClassifierResultHttpError err }
, Cmd.none
, Nothing
)
@ -209,12 +232,7 @@ view2 flags texts settings model =
}
in
div
[ classList
[ ( "ui form error success", True )
, ( "error", Maybe.map .success model.fullTextReIndexResult == Just False )
, ( "success", Maybe.map .success model.fullTextReIndexResult == Just True )
]
, class "flex flex-col relative"
[ class "flex flex-col relative"
]
[ MB.view
{ start =
@ -263,13 +281,13 @@ view2 flags texts settings model =
, div [ class "mb-4" ]
[ label
[ class "inline-flex items-center"
, for "intendpoint-enabled"
, for "int-endpoint-enabled"
]
[ input
[ type_ "checkbox"
, onCheck (\_ -> ToggleIntegrationEndpoint)
, checked model.intEnabled
, id "intendpoint-enabled"
, id "int-endpoint-enabled"
, class S.checkboxInput
]
[]
@ -316,7 +334,7 @@ view2 flags texts settings model =
, div [ class "opacity-50 text-sm" ]
[ text texts.reindexAllDataHelp
]
, renderResultMessage2 model.fullTextReIndexResult
, renderFulltextReindexResultMessage texts model.fullTextReIndexResult
]
]
, div
@ -343,23 +361,63 @@ view2 flags texts settings model =
, disabled = Data.Validated.isInvalid model.classifierModel.schedule
, attrs = [ href "#" ]
}
, renderResultMessage2 model.startClassifierResult
, renderClassifierResultMessage texts model.startClassifierResult
]
]
]
]
renderResultMessage2 : Maybe BasicResult -> Html msg
renderResultMessage2 result =
renderClassifierResultMessage : Texts -> ClassifierResult -> Html msg
renderClassifierResultMessage texts result =
let
isSuccess =
case result of
ClassifierResultOk ->
True
_ ->
False
isError =
not isSuccess
in
div
[ classList
[ ( S.errorMessage, Maybe.map .success result == Just False )
, ( S.successMessage, Maybe.map .success result == Just True )
, ( "hidden", result == Nothing )
[ ( S.errorMessage, isError )
, ( S.successMessage, isSuccess )
, ( "hidden", result == ClassifierResultInitial )
]
]
[ Maybe.map .message result
|> Maybe.withDefault ""
|> text
[ case result of
ClassifierResultInitial ->
text ""
ClassifierResultOk ->
text texts.classifierTaskStarted
ClassifierResultHttpError err ->
text (texts.httpError err)
ClassifierResultSubmitError m ->
text m
]
renderFulltextReindexResultMessage : Texts -> FulltextReindexResult -> Html msg
renderFulltextReindexResultMessage texts result =
case result of
FulltextReindexInitial ->
text ""
FulltextReindexSubmitOk ->
text texts.fulltextReindexSubmitted
FulltextReindexHttpError err ->
text (texts.httpError err)
FulltextReindexOKMissing ->
text texts.fulltextReindexOkMissing
FulltextReindexSubmitError m ->
text m

View File

@ -20,19 +20,17 @@ import Comp.YesNoDimmer
import Data.CustomFieldType exposing (CustomFieldType)
import Data.DropdownStyle as DS
import Data.Flags exposing (Flags)
import Data.Validated exposing (Validated)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
import Http
import Messages.Comp.CustomFieldForm exposing (Texts)
import Styles as S
import Util.Http
import Util.Maybe
type alias Model =
{ result : Maybe BasicResult
{ formState : FormState
, field : CustomField
, name : Maybe String
, label : Maybe String
@ -43,20 +41,67 @@ type alias Model =
}
type FormState
= FormStateInitial
| FormStateHttp Http.Error
| FormStateNameRequired
| FormStateTypeRequired
| FormStateUpdateFailed UpdateType String
| FormStateUpdateOk UpdateType
type UpdateType
= UpdateCreate
| UpdateChange
| UpdateDelete
isFormError : FormState -> Bool
isFormError state =
case state of
FormStateInitial ->
False
FormStateHttp _ ->
True
FormStateNameRequired ->
True
FormStateTypeRequired ->
True
FormStateUpdateFailed _ _ ->
True
FormStateUpdateOk _ ->
False
isFormSuccess : FormState -> Bool
isFormSuccess state =
case state of
FormStateInitial ->
False
_ ->
not (isFormError state)
type Msg
= SetName String
| SetLabel String
| FTypeMsg (Comp.FixedDropdown.Msg CustomFieldType)
| RequestDelete
| DeleteMsg Comp.YesNoDimmer.Msg
| UpdateResp (Result Http.Error BasicResult)
| UpdateResp UpdateType (Result Http.Error BasicResult)
| GoBack
| SubmitForm
init : CustomField -> Model
init field =
{ result = Nothing
{ formState = FormStateInitial
, field = field
, name = Util.Maybe.fromString field.name
, label = field.label
@ -77,22 +122,22 @@ initEmpty =
--- Update
makeField : Model -> Validated NewCustomField
makeField : Model -> Result FormState NewCustomField
makeField model =
let
name =
Maybe.map Data.Validated.Valid model.name
|> Maybe.withDefault (Data.Validated.Invalid [ "A name is required." ] "")
Maybe.map Ok model.name
|> Maybe.withDefault (Err FormStateNameRequired)
ftype =
Maybe.map Data.CustomFieldType.asString model.ftype
|> Maybe.map Data.Validated.Valid
|> Maybe.withDefault (Data.Validated.Invalid [ "A field type is required." ] "")
|> Maybe.map Ok
|> Maybe.withDefault (Err FormStateTypeRequired)
make n ft =
NewCustomField n model.label ft
in
Data.Validated.map2 make name ftype
Result.map2 make name ftype
update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Bool )
@ -129,29 +174,22 @@ update flags msg model =
makeField model
in
case newField of
Data.Validated.Valid f ->
Ok f ->
( model
, if model.field.id == "" then
Api.postCustomField flags f UpdateResp
Api.postCustomField flags f (UpdateResp UpdateCreate)
else
Api.putCustomField flags model.field.id f UpdateResp
Api.putCustomField flags model.field.id f (UpdateResp UpdateChange)
, False
)
Data.Validated.Invalid msgs _ ->
let
combined =
String.join "; " msgs
in
( { model | result = Just (BasicResult False combined) }
Err fe ->
( { model | formState = fe }
, Cmd.none
, False
)
Data.Validated.Unknown _ ->
( model, Cmd.none, False )
RequestDelete ->
let
( dm, _ ) =
@ -166,18 +204,28 @@ update flags msg model =
cmd =
if flag then
Api.deleteCustomField flags model.field.id UpdateResp
Api.deleteCustomField flags model.field.id (UpdateResp UpdateDelete)
else
Cmd.none
in
( { model | deleteDimmer = dm }, cmd, False )
UpdateResp (Ok r) ->
( { model | result = Just r }, Cmd.none, r.success )
UpdateResp updateType (Ok r) ->
( { model
| formState =
if r.success then
FormStateUpdateOk updateType
UpdateResp (Err err) ->
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
else
FormStateUpdateFailed updateType r.message
}
, Cmd.none
, r.success
)
UpdateResp _ (Err err) ->
( { model | formState = FormStateHttp err }
, Cmd.none
, False
)
@ -230,15 +278,30 @@ view2 texts viewSettings model =
)
, div
[ classList
[ ( "hidden", model.result == Nothing )
, ( S.errorMessage, Maybe.map .success model.result == Just False )
, ( S.successMessage, Maybe.map .success model.result == Just True )
[ ( "hidden", model.formState == FormStateInitial )
, ( S.errorMessage, isFormError model.formState )
, ( S.successMessage, isFormSuccess model.formState )
]
, class "my-2"
]
[ Maybe.map .message model.result
|> Maybe.withDefault ""
|> text
[ case model.formState of
FormStateInitial ->
text ""
FormStateHttp err ->
text (texts.httpError err)
FormStateNameRequired ->
text texts.fieldNameRequired
FormStateTypeRequired ->
text texts.fieldTypeRequired
FormStateUpdateFailed _ m ->
text m
FormStateUpdateOk _ ->
text texts.updateSuccessful
]
, if model.field.id == "" then
div [ class "py-2 text-lg opacity-75" ]

View File

@ -42,14 +42,12 @@ import Comp.TagForm
import Data.Flags exposing (Flags)
import Data.Icons as Icons
import Data.UiSettings exposing (UiSettings)
import Data.Validated
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Http
import Messages.Comp.DetailEdit exposing (Texts)
import Styles as S
import Util.Http
type alias Model =
@ -57,10 +55,47 @@ type alias Model =
, itemId : String
, submitting : Bool
, loading : Bool
, result : Maybe BasicResult
, formState : FormState
}
type FormState
= FormStateInitial
| FormStateHttpError Http.Error
| FormStateSubmitSuccessful
| FormStateSubmitError String
| FormStateMissingRequiredFields
isError : FormState -> Bool
isError state =
case state of
FormStateInitial ->
False
FormStateHttpError _ ->
True
FormStateSubmitSuccessful ->
False
FormStateSubmitError _ ->
True
FormStateMissingRequiredFields ->
True
isSuccess : FormState -> Bool
isSuccess state =
case state of
FormStateInitial ->
False
_ ->
not (isError state)
type FormModel
= TM Comp.TagForm.Model
| PMR Comp.PersonForm.Model
@ -105,7 +140,7 @@ init itemId fm =
, itemId = itemId
, submitting = False
, loading = False
, result = Nothing
, formState = FormStateInitial
}
@ -125,7 +160,7 @@ editOrg flags orgId om =
, itemId = ""
, submitting = False
, loading = True
, result = Nothing
, formState = FormStateInitial
}
, Api.getOrgFull orgId flags GetOrgResp
)
@ -137,7 +172,7 @@ editPerson flags persId pm =
, itemId = ""
, submitting = False
, loading = True
, result = Nothing
, formState = FormStateInitial
}
, Cmd.batch
[ Api.getPersonFull persId flags GetPersonResp
@ -152,7 +187,7 @@ editEquip flags equipId em =
, itemId = ""
, submitting = False
, loading = True
, result = Nothing
, formState = FormStateInitial
}
, Api.getEquipment flags equipId GetEquipResp
)
@ -246,10 +281,10 @@ makeValue fm =
Comp.CustomFieldForm.makeField fieldModel
in
case cfield of
Data.Validated.Valid field ->
Ok field ->
SubmitCustomField field
_ ->
Err _ ->
CancelForm
@ -285,7 +320,10 @@ update flags msg model =
)
GetOrgResp (Err err) ->
( { model | loading = False, result = Just (BasicResult False (Util.Http.errorToString err)) }
( { model
| loading = False
, formState = FormStateHttpError err
}
, Cmd.none
, Nothing
)
@ -312,7 +350,10 @@ update flags msg model =
)
GetPersonResp (Err err) ->
( { model | loading = False, result = Just (BasicResult False (Util.Http.errorToString err)) }
( { model
| loading = False
, formState = FormStateHttpError err
}
, Cmd.none
, Nothing
)
@ -349,7 +390,10 @@ update flags msg model =
( { model | loading = False }, Cmd.none, Nothing )
GetOrgsResp (Err err) ->
( { model | loading = False, result = Just (BasicResult False (Util.Http.errorToString err)) }
( { model
| loading = False
, formState = FormStateHttpError err
}
, Cmd.none
, Nothing
)
@ -376,7 +420,10 @@ update flags msg model =
)
GetEquipResp (Err err) ->
( { model | loading = False, result = Just (BasicResult False (Util.Http.errorToString err)) }
( { model
| loading = False
, formState = FormStateHttpError err
}
, Cmd.none
, Nothing
)
@ -391,7 +438,12 @@ update flags msg model =
Nothing
in
( { model
| result = Just res
| formState =
if res.success then
FormStateSubmitSuccessful
else
FormStateSubmitError res.message
, submitting = False
}
, Cmd.none
@ -400,7 +452,7 @@ update flags msg model =
SubmitResp (Err err) ->
( { model
| result = Just (BasicResult False (Util.Http.errorToString err))
| formState = FormStateHttpError err
, submitting = False
}
, Cmd.none
@ -408,10 +460,6 @@ update flags msg model =
)
Submit ->
let
failMsg =
Just (BasicResult False "Please fill required fields.")
in
case model.form of
TM tm ->
let
@ -425,7 +473,7 @@ update flags msg model =
)
else
( { model | result = failMsg }
( { model | formState = FormStateMissingRequiredFields }
, Cmd.none
, Nothing
)
@ -446,7 +494,7 @@ update flags msg model =
)
else
( { model | result = failMsg }
( { model | formState = FormStateMissingRequiredFields }
, Cmd.none
, Nothing
)
@ -467,7 +515,7 @@ update flags msg model =
)
else
( { model | result = failMsg }
( { model | formState = FormStateMissingRequiredFields }
, Cmd.none
, Nothing
)
@ -488,7 +536,7 @@ update flags msg model =
)
else
( { model | result = failMsg }
( { model | formState = FormStateMissingRequiredFields }
, Cmd.none
, Nothing
)
@ -509,7 +557,7 @@ update flags msg model =
)
else
( { model | result = failMsg }
( { model | formState = FormStateMissingRequiredFields }
, Cmd.none
, Nothing
)
@ -520,14 +568,14 @@ update flags msg model =
Comp.CustomFieldForm.makeField fm
in
case cfield of
Data.Validated.Valid newField ->
Ok newField ->
( { model | submitting = True }
, Api.postCustomField flags newField SubmitResp
, Nothing
)
_ ->
( { model | result = failMsg }
Err _ ->
( { model | formState = FormStateMissingRequiredFields }
, Cmd.none
, Nothing
)
@ -541,7 +589,7 @@ update flags msg model =
in
( { model
| form = TM tm_
, result = Nothing
, formState = FormStateInitial
}
, Cmd.map TagMsg tc_
, Nothing
@ -559,7 +607,7 @@ update flags msg model =
in
( { model
| form = PMR pm_
, result = Nothing
, formState = FormStateInitial
}
, Cmd.map PersonMsg pc_
, Nothing
@ -572,7 +620,7 @@ update flags msg model =
in
( { model
| form = PMC pm_
, result = Nothing
, formState = FormStateInitial
}
, Cmd.map PersonMsg pc_
, Nothing
@ -590,7 +638,7 @@ update flags msg model =
in
( { model
| form = OM om_
, result = Nothing
, formState = FormStateInitial
}
, Cmd.map OrgMsg oc_
, Nothing
@ -608,7 +656,7 @@ update flags msg model =
in
( { model
| form = EM em_
, result = Nothing
, formState = FormStateInitial
}
, Cmd.map EquipMsg ec_
, Nothing
@ -626,7 +674,7 @@ update flags msg model =
in
( { model
| form = CFM fm_
, result = Nothing
, formState = FormStateInitial
}
, Cmd.map CustomFieldMsg fc_
, Nothing
@ -756,14 +804,26 @@ viewIntern2 : Texts -> UiSettings -> Bool -> Model -> List (Html Msg)
viewIntern2 texts settings withButtons model =
[ div
[ classList
[ ( S.errorMessage, Maybe.map .success model.result == Just False )
, ( S.successMessage, Maybe.map .success model.result == Just True )
, ( "hidden", model.result == Nothing )
[ ( S.errorMessage, isError model.formState )
, ( S.successMessage, isSuccess model.formState )
, ( "hidden", model.formState == FormStateInitial )
]
]
[ Maybe.map .message model.result
|> Maybe.withDefault ""
|> text
[ case model.formState of
FormStateInitial ->
text ""
FormStateHttpError err ->
text (texts.httpError err)
FormStateSubmitSuccessful ->
text texts.submitSuccessful
FormStateSubmitError m ->
text m
FormStateMissingRequiredFields ->
text texts.missingRequiredFields
]
, case model.form of
TM tm ->

View File

@ -23,26 +23,32 @@ import Html.Attributes exposing (..)
import Http
import Messages.Comp.EmailSettingsManage exposing (Texts)
import Styles as S
import Util.Http
type alias Model =
{ tableModel : Comp.EmailSettingsTable.Model
, formModel : Comp.EmailSettingsForm.Model
, viewMode : ViewMode
, formError : Maybe String
, formError : FormError
, loading : Bool
, query : String
, deleteConfirm : Comp.YesNoDimmer.Model
}
type FormError
= FormErrorNone
| FormErrorHttp Http.Error
| FormErrorSubmit String
| FormErrorFillRequired
emptyModel : Model
emptyModel =
{ tableModel = Comp.EmailSettingsTable.emptyModel
, formModel = Comp.EmailSettingsForm.emptyModel
, viewMode = Table
, formError = Nothing
, formError = FormErrorNone
, loading = False
, query = ""
, deleteConfirm = Comp.YesNoDimmer.emptyModel
@ -84,7 +90,7 @@ update flags msg model =
nm =
{ model
| viewMode = Form
, formError = Nothing
, formError = FormErrorNone
, formModel = Comp.EmailSettingsForm.init ems
}
in
@ -101,7 +107,7 @@ update flags msg model =
, viewMode = Maybe.map (\_ -> Form) tm.selected |> Maybe.withDefault Table
, formError =
if tm.selected /= Nothing then
Nothing
FormErrorNone
else
model.formError
@ -166,7 +172,7 @@ update flags msg model =
( { model | loading = True }, Api.createMailSettings flags mid ems SubmitResp )
else
( { model | formError = Just "Please fill required fields." }, Cmd.none )
( { model | formError = FormErrorFillRequired }, Cmd.none )
LoadSettings ->
( { model | loading = True }, Api.getMailSettings flags model.query MailSettingsResp )
@ -183,10 +189,10 @@ update flags msg model =
( { m3 | loading = False }, Cmd.batch [ c2, c3 ] )
else
( { model | formError = Just res.message, loading = False }, Cmd.none )
( { model | formError = FormErrorSubmit res.message, loading = False }, Cmd.none )
SubmitResp (Err err) ->
( { model | formError = Just (Util.Http.errorToString err), loading = False }, Cmd.none )
( { model | formError = FormErrorHttp err, loading = False }, Cmd.none )
MailSettingsResp (Ok ems) ->
let
@ -286,12 +292,23 @@ viewForm2 texts settings model =
}
, div
[ classList
[ ( "hidden", model.formError == Nothing )
[ ( "hidden", model.formError == FormErrorNone )
]
, class "my-2"
, class S.errorMessage
]
[ Maybe.withDefault "" model.formError |> text
[ case model.formError of
FormErrorNone ->
text ""
FormErrorHttp err ->
text (texts.httpError err)
FormErrorFillRequired ->
text texts.fillRequiredFields
FormErrorSubmit m ->
text m
]
, Html.map FormMsg
(Comp.EmailSettingsForm.view2 texts.settingsForm

View File

@ -22,7 +22,6 @@ import Html.Events exposing (onSubmit)
import Http
import Messages.Comp.EquipmentManage exposing (Texts)
import Styles as S
import Util.Http
import Util.Maybe
@ -30,13 +29,20 @@ type alias Model =
{ tableModel : Comp.EquipmentTable.Model
, formModel : Comp.EquipmentForm.Model
, viewMode : ViewMode
, formError : Maybe String
, formError : FormError
, loading : Bool
, deleteConfirm : Comp.YesNoDimmer.Model
, query : String
}
type FormError
= FormErrorNone
| FormErrorHttp Http.Error
| FormErrorSubmit String
| FormErrorInvalid
type ViewMode
= Table
| Form
@ -47,7 +53,7 @@ emptyModel =
{ tableModel = Comp.EquipmentTable.emptyModel
, formModel = Comp.EquipmentForm.emptyModel
, viewMode = Table
, formError = Nothing
, formError = FormErrorNone
, loading = False
, deleteConfirm = Comp.YesNoDimmer.emptyModel
, query = ""
@ -82,7 +88,7 @@ update flags msg model =
, viewMode = Maybe.map (\_ -> Form) tm.selected |> Maybe.withDefault Table
, formError =
if Util.Maybe.nonEmpty tm.selected then
Nothing
FormErrorNone
else
model.formError
@ -135,7 +141,7 @@ update flags msg model =
InitNewEquipment ->
let
nm =
{ model | viewMode = Form, formError = Nothing }
{ model | viewMode = Form, formError = FormErrorNone }
equipment =
Api.Model.Equipment.empty
@ -154,7 +160,7 @@ update flags msg model =
( { model | loading = True }, Api.postEquipment flags equipment SubmitResp )
else
( { model | formError = Just "Please correct the errors in the form." }, Cmd.none )
( { model | formError = FormErrorInvalid }, Cmd.none )
SubmitResp (Ok res) ->
if res.success then
@ -168,10 +174,10 @@ update flags msg model =
( { m3 | loading = False }, Cmd.batch [ c2, c3 ] )
else
( { model | formError = Just res.message, loading = False }, Cmd.none )
( { model | formError = FormErrorSubmit res.message, loading = False }, Cmd.none )
SubmitResp (Err err) ->
( { model | formError = Just (Util.Http.errorToString err), loading = False }, Cmd.none )
( { model | formError = FormErrorHttp err, loading = False }, Cmd.none )
RequestDelete ->
update flags (YesNoMsg Comp.YesNoDimmer.activate) model
@ -316,12 +322,23 @@ viewForm2 texts model =
}
, div
[ classList
[ ( "hidden", Util.Maybe.isEmpty model.formError )
[ ( "hidden", model.formError == FormErrorNone )
]
, class S.errorMessage
, class "my-2"
]
[ Maybe.withDefault "" model.formError |> text
[ case model.formError of
FormErrorNone ->
text ""
FormErrorSubmit m ->
text m
FormErrorInvalid ->
text texts.correctFormErrors
FormErrorHttp err ->
text (texts.httpError err)
]
, Html.map FormMsg (Comp.EquipmentForm.view2 texts.equipmentForm model.formModel)
, B.loadingDimmer

View File

@ -26,12 +26,11 @@ import Html.Events exposing (onClick, onInput)
import Http
import Messages.Comp.FolderDetail exposing (Texts)
import Styles as S
import Util.Http
import Util.Maybe
type alias Model =
{ result : Maybe BasicResult
{ formState : FormState
, folder : FolderDetail
, name : Maybe String
, members : List IdName
@ -43,6 +42,59 @@ type alias Model =
}
type FormState
= FormStateInitial
| FormStateHttpError Http.Error
| FormStateFolderCreated
| FormStateGenericError String
| FormStateNameChangeSuccessful
| FormStateDeleteSuccessful
isError : FormState -> Bool
isError state =
case state of
FormStateInitial ->
False
FormStateHttpError _ ->
True
FormStateGenericError _ ->
True
FormStateFolderCreated ->
False
FormStateNameChangeSuccessful ->
False
FormStateDeleteSuccessful ->
False
isSuccess : FormState -> Bool
isSuccess state =
case state of
FormStateInitial ->
False
FormStateHttpError _ ->
False
FormStateGenericError _ ->
False
FormStateFolderCreated ->
True
FormStateNameChangeSuccessful ->
True
FormStateDeleteSuccessful ->
True
type Msg
= SetName String
| MemberDropdownMsg (Comp.FixedDropdown.Msg IdName)
@ -61,7 +113,7 @@ type Msg
init : List User -> FolderDetail -> Model
init users folder =
{ result = Nothing
{ formState = FormStateInitial
, folder = folder
, name = Util.Maybe.fromString folder.name
, members = folder.members
@ -143,7 +195,7 @@ update flags msg model =
in
( { model
| loading = True
, result = Nothing
, formState = FormStateInitial
}
, cmd
, False
@ -159,7 +211,12 @@ update flags msg model =
else
( { model
| loading = False
, result = Just (BasicResult ir.success ir.message)
, formState =
if ir.success then
FormStateFolderCreated
else
FormStateGenericError ir.message
}
, Cmd.none
, False
@ -168,7 +225,7 @@ update flags msg model =
NewFolderResp (Err err) ->
( { model
| loading = False
, result = Just (BasicResult False (Util.Http.errorToString err))
, formState = FormStateHttpError err
}
, Cmd.none
, False
@ -182,7 +239,7 @@ update flags msg model =
)
else
( { model | loading = False, result = Just r }
( { model | loading = False, formState = FormStateGenericError r.message }
, Cmd.none
, False
)
@ -190,7 +247,7 @@ update flags msg model =
ChangeFolderResp (Err err) ->
( { model
| loading = False
, result = Just (BasicResult False (Util.Http.errorToString err))
, formState = FormStateHttpError err
}
, Cmd.none
, False
@ -199,13 +256,21 @@ update flags msg model =
ChangeNameResp (Ok r) ->
let
model_ =
{ model | result = Just r, loading = False }
{ model
| formState =
if r.success then
FormStateNameChangeSuccessful
else
FormStateGenericError r.message
, loading = False
}
in
( model_, Cmd.none, False )
ChangeNameResp (Err err) ->
( { model
| result = Just (BasicResult False (Util.Http.errorToString err))
| formState = FormStateHttpError err
, loading = False
}
, Cmd.none
@ -218,7 +283,7 @@ update flags msg model =
FolderDetailResp (Err err) ->
( { model
| loading = False
, result = Just (BasicResult False (Util.Http.errorToString err))
, formState = FormStateHttpError err
}
, Cmd.none
, False
@ -263,10 +328,20 @@ update flags msg model =
( { model | deleteDimmer = dm }, cmd, False )
DeleteResp (Ok r) ->
( { model | result = Just r }, Cmd.none, r.success )
( { model
| formState =
if r.success then
FormStateDeleteSuccessful
else
FormStateGenericError r.message
}
, Cmd.none
, r.success
)
DeleteResp (Err err) ->
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
( { model | formState = FormStateHttpError err }
, Cmd.none
, False
)
@ -350,15 +425,30 @@ view2 texts flags model =
]
, div
[ classList
[ ( "hidden", model.result == Nothing )
, ( S.errorMessage, Maybe.map .success model.result == Just False )
, ( S.successMessage, Maybe.map .success model.result == Just True )
[ ( "hidden", model.formState == FormStateInitial )
, ( S.errorMessage, isError model.formState )
, ( S.successMessage, isSuccess model.formState )
]
, class "my-4"
]
[ Maybe.map .message model.result
|> Maybe.withDefault ""
|> text
[ case model.formState of
FormStateInitial ->
text ""
FormStateHttpError err ->
text (texts.httpError err)
FormStateGenericError m ->
text m
FormStateFolderCreated ->
text texts.folderCreated
FormStateNameChangeSuccessful ->
text texts.nameChangeSuccessful
FormStateDeleteSuccessful ->
text texts.deleteSuccessful
]
]
++ viewMembers2 texts model

View File

@ -23,26 +23,32 @@ import Html.Attributes exposing (..)
import Http
import Messages.Comp.ImapSettingsManage exposing (Texts)
import Styles as S
import Util.Http
type alias Model =
{ tableModel : Comp.ImapSettingsTable.Model
, formModel : Comp.ImapSettingsForm.Model
, viewMode : ViewMode
, formError : Maybe String
, formError : FormError
, loading : Bool
, query : String
, deleteConfirm : Comp.YesNoDimmer.Model
}
type FormError
= FormErrorNone
| FormErrorHttp Http.Error
| FormErrorSubmit String
| FormErrorFillRequired
emptyModel : Model
emptyModel =
{ tableModel = Comp.ImapSettingsTable.emptyModel
, formModel = Comp.ImapSettingsForm.emptyModel
, viewMode = Table
, formError = Nothing
, formError = FormErrorNone
, loading = False
, query = ""
, deleteConfirm = Comp.YesNoDimmer.emptyModel
@ -84,7 +90,7 @@ update flags msg model =
nm =
{ model
| viewMode = Form
, formError = Nothing
, formError = FormErrorNone
, formModel = Comp.ImapSettingsForm.init ems
}
in
@ -101,7 +107,7 @@ update flags msg model =
, viewMode = Maybe.map (\_ -> Form) tm.selected |> Maybe.withDefault Table
, formError =
if tm.selected /= Nothing then
Nothing
FormErrorNone
else
model.formError
@ -166,7 +172,7 @@ update flags msg model =
( { model | loading = True }, Api.createImapSettings flags mid ems SubmitResp )
else
( { model | formError = Just "Please fill required fields." }, Cmd.none )
( { model | formError = FormErrorFillRequired }, Cmd.none )
LoadSettings ->
( { model | loading = True }, Api.getImapSettings flags model.query MailSettingsResp )
@ -183,10 +189,10 @@ update flags msg model =
( { m3 | loading = False }, Cmd.batch [ c2, c3 ] )
else
( { model | formError = Just res.message, loading = False }, Cmd.none )
( { model | formError = FormErrorSubmit res.message, loading = False }, Cmd.none )
SubmitResp (Err err) ->
( { model | formError = Just (Util.Http.errorToString err), loading = False }, Cmd.none )
( { model | formError = FormErrorHttp err, loading = False }, Cmd.none )
MailSettingsResp (Ok ems) ->
let
@ -287,12 +293,23 @@ viewForm2 texts settings model =
}
, div
[ classList
[ ( "hidden", model.formError == Nothing )
[ ( "hidden", model.formError == FormErrorNone )
]
, class "my-2"
, class S.errorMessage
]
[ Maybe.withDefault "" model.formError |> text
[ case model.formError of
FormErrorNone ->
text ""
FormErrorHttp err ->
text (texts.httpError err)
FormErrorFillRequired ->
text texts.fillRequiredFields
FormErrorSubmit m ->
text m
]
, Html.map FormMsg
(Comp.ImapSettingsForm.view2

View File

@ -1,5 +1,6 @@
module Comp.ItemDetail.Model exposing
( AttachmentRename
, MailSendResult(..)
, Model
, Msg(..)
, NotesField(..)
@ -84,7 +85,7 @@ type alias Model =
, itemMail : Comp.ItemMail.Model
, mailOpen : Bool
, mailSending : Bool
, mailSendResult : Maybe BasicResult
, mailSendResult : MailSendResult
, sentMails : Comp.SentMails.Model
, sentMailsOpen : Bool
, attachMeta : Dict String Comp.AttachmentMeta.Model
@ -128,6 +129,13 @@ type SelectActionMode
| DeleteSelected
type MailSendResult
= MailSendSuccessful
| MailSendHttpError Http.Error
| MailSendFailed String
| MailSendResultInitial
type NotesField
= ViewNotes
| EditNotes Comp.MarkdownInput.Model
@ -181,7 +189,7 @@ emptyModel =
, itemMail = Comp.ItemMail.emptyModel
, mailOpen = False
, mailSending = False
, mailSendResult = Nothing
, mailSendResult = MailSendResultInitial
, sentMails = Comp.SentMails.init
, sentMailsOpen = False
, attachMeta = Dict.empty

View File

@ -24,7 +24,23 @@ import Comp.Dropdown exposing (isDropdownChangeMsg)
import Comp.Dropzone
import Comp.EquipmentForm
import Comp.ItemDetail.FieldTabState as FTabState
import Comp.ItemDetail.Model exposing (AttachmentRename, Model, Msg(..), NotesField(..), SaveNameState(..), SelectActionMode(..), UpdateResult, ViewMode(..), initSelectViewModel, isEditNotes, resultModel, resultModelCmd, resultModelCmdSub)
import Comp.ItemDetail.Model
exposing
( AttachmentRename
, MailSendResult(..)
, Model
, Msg(..)
, NotesField(..)
, SaveNameState(..)
, SelectActionMode(..)
, UpdateResult
, ViewMode(..)
, initSelectViewModel
, isEditNotes
, resultModel
, resultModelCmd
, resultModelCmdSub
)
import Comp.ItemMail
import Comp.KeyInput
import Comp.LinkTarget
@ -48,7 +64,6 @@ import Set exposing (Set)
import Throttle
import Time
import Util.File exposing (makeFileId)
import Util.Http
import Util.List
import Util.Maybe
import Util.String
@ -750,7 +765,7 @@ update key flags inav settings msg model =
( { model
| itemMail = Comp.ItemMail.clear im
, mailOpen = False
, mailSendResult = Nothing
, mailSendResult = MailSendResultInitial
}
, Cmd.map ItemMailMsg ic
)
@ -788,7 +803,7 @@ update key flags inav settings msg model =
model.mailSendResult
else
Nothing
MailSendResultInitial
in
resultModel
{ model
@ -810,7 +825,12 @@ update key flags inav settings msg model =
( { model
| itemMail = mm
, mailSending = False
, mailSendResult = Just br
, mailSendResult =
if br.success then
MailSendSuccessful
else
MailSendFailed br.message
}
, if br.success then
Api.itemDetail flags model.item.id GetItemResp
@ -820,13 +840,9 @@ update key flags inav settings msg model =
)
SendMailResp (Err err) ->
let
errmsg =
Util.Http.errorToString err
in
resultModel
{ model
| mailSendResult = Just (BasicResult False errmsg)
| mailSendResult = MailSendHttpError err
, mailSending = False
}

View File

@ -7,7 +7,8 @@ import Comp.ItemDetail.AddFilesForm
import Comp.ItemDetail.ItemInfoHeader
import Comp.ItemDetail.Model
exposing
( Model
( MailSendResult(..)
, Model
, Msg(..)
, NotesField(..)
, SaveNameState(..)
@ -257,22 +258,24 @@ sendMailForm texts settings model =
, Html.map ItemMailMsg (Comp.ItemMail.view2 texts.itemMail settings model.itemMail)
, div
[ classList
[ ( S.errorMessage
, Maybe.map .success model.mailSendResult
|> Maybe.map not
|> Maybe.withDefault False
)
, ( S.successMessage
, Maybe.map .success model.mailSendResult
|> Maybe.withDefault False
)
, ( "hidden", model.mailSendResult == Nothing )
[ ( S.errorMessage, model.mailSendResult /= MailSendSuccessful )
, ( S.successMessage, model.mailSendResult == MailSendSuccessful )
, ( "hidden", model.mailSendResult == MailSendResultInitial )
]
, class "mt-2"
]
[ Maybe.map .message model.mailSendResult
|> Maybe.withDefault ""
|> text
[ case model.mailSendResult of
MailSendSuccessful ->
text texts.mailSendSuccessful
MailSendHttpError err ->
text (texts.httpError err)
MailSendFailed m ->
text m
MailSendResultInitial ->
text ""
]
]

View File

@ -25,7 +25,6 @@ import Html.Events exposing (onClick, onInput)
import Http
import Messages.Comp.ItemMail exposing (Texts)
import Styles as S
import Util.Http
type alias Model =
@ -39,10 +38,16 @@ type alias Model =
, bccRecipientsModel : Comp.EmailInput.Model
, body : String
, attachAll : Bool
, formError : Maybe String
, formError : FormError
}
type FormError
= FormErrorNone
| FormErrorNoConnection
| FormErrorHttp Http.Error
type Msg
= SetSubject String
| RecipientMsg Comp.EmailInput.Msg
@ -80,7 +85,7 @@ emptyModel =
, bccRecipientsModel = Comp.EmailInput.init
, body = ""
, attachAll = True
, formError = Nothing
, formError = FormErrorNone
}
@ -111,7 +116,10 @@ update flags msg model =
( em, ec, rec ) =
Comp.EmailInput.update flags model.recipients m model.recipientsModel
in
( { model | recipients = rec, recipientsModel = em }
( { model
| recipients = rec
, recipientsModel = em
}
, Cmd.map RecipientMsg ec
, FormNone
)
@ -121,7 +129,10 @@ update flags msg model =
( em, ec, rec ) =
Comp.EmailInput.update flags model.ccRecipients m model.ccRecipientsModel
in
( { model | ccRecipients = rec, ccRecipientsModel = em }
( { model
| ccRecipients = rec
, ccRecipientsModel = em
}
, Cmd.map CCRecipientMsg ec
, FormNone
)
@ -165,24 +176,24 @@ update flags msg model =
| connectionModel = cm
, formError =
if names == [] then
Just "No E-Mail connections configured. Goto user settings to add one."
FormErrorNoConnection
else
Nothing
FormErrorNone
}
, Cmd.none
, FormNone
)
ConnResp (Err err) ->
( { model | formError = Just (Util.Http.errorToString err) }, Cmd.none, FormNone )
( { model | formError = FormErrorHttp err }, Cmd.none, FormNone )
Cancel ->
( model, Cmd.none, FormCancel )
Send ->
case ( model.formError, Comp.Dropdown.getSelected model.connectionModel ) of
( Nothing, conn :: [] ) ->
( FormErrorNone, conn :: [] ) ->
let
emptyMail =
Api.Model.SimpleMail.empty
@ -212,7 +223,9 @@ isValid model =
&& model.body
/= ""
&& model.formError
== Nothing
== FormErrorNone
&& Comp.Dropdown.getSelected model.connectionModel
/= []
@ -249,9 +262,17 @@ view2 texts settings model =
]
, div
[ class S.errorMessage
, classList [ ( "hidden", model.formError == Nothing ) ]
, classList [ ( "hidden", model.formError == FormErrorNone ) ]
]
[ Maybe.withDefault "" model.formError |> text
[ case model.formError of
FormErrorNone ->
text ""
FormErrorHttp err ->
text (texts.httpError err)
FormErrorNoConnection ->
text texts.connectionMissing
]
, div [ class "mb-4" ]
[ label
@ -320,7 +341,7 @@ view2 texts settings model =
}
, div [ class "flex flex-row space-x-2" ]
[ B.primaryButton
{ label = "Send"
{ label = texts.sendLabel
, icon = "fa fa-paper-plane font-thin"
, handler = onClick Send
, attrs = [ href "#" ]

View File

@ -33,8 +33,8 @@ import Http
import Markdown
import Messages.Comp.NotificationForm exposing (Texts)
import Styles as S
import Util.Http
import Util.Maybe
import Util.Result
import Util.Tag
import Util.Update
@ -50,15 +50,28 @@ type alias Model =
, remindDaysModel : Comp.IntField.Model
, capOverdue : Bool
, enabled : Bool
, schedule : Validated CalEvent
, schedule : Result CalEvent CalEvent
, scheduleModel : Comp.CalEventInput.Model
, formMsg : Maybe BasicResult
, formState : FormState
, loading : Int
, yesNoDelete : Comp.YesNoDimmer.Model
, summary : Maybe String
}
type FormState
= FormStateInitial
| FormStateHttpError Http.Error
| FormStateInvalid ValidateError
type ValidateError
= ValidateConnectionMissing
| ValidateRemindDaysRequired
| ValidateRecipientsRequired
| ValidateCalEventInvalid
type Action
= SubmitAction NotificationSettings
| StartOnceAction NotificationSettings
@ -121,9 +134,9 @@ initWith flags s =
, remindDays = Just s.remindDays
, enabled = s.enabled
, capOverdue = s.capOverdue
, schedule = Data.Validated.Unknown newSchedule
, schedule = Ok newSchedule
, scheduleModel = sm
, formMsg = Nothing
, formState = FormStateInitial
, loading = im.loading
, yesNoDelete = Comp.YesNoDimmer.emptyModel
, summary = s.summary
@ -140,7 +153,7 @@ init : Flags -> ( Model, Cmd Msg )
init flags =
let
initialSchedule =
Data.Validated.Valid Data.CalEvent.everyMonth
Ok Data.CalEvent.everyMonth
sm =
Comp.CalEventInput.initDefault
@ -157,7 +170,7 @@ init flags =
, capOverdue = False
, schedule = initialSchedule
, scheduleModel = sm
, formMsg = Nothing
, formState = FormStateInitial
, loading = 2
, yesNoDelete = Comp.YesNoDimmer.emptyModel
, summary = Nothing
@ -173,7 +186,7 @@ init flags =
--- Update
makeSettings : Model -> Validated NotificationSettings
makeSettings : Model -> Result ValidateError NotificationSettings
makeSettings model =
let
prev =
@ -182,19 +195,22 @@ makeSettings model =
conn =
Comp.Dropdown.getSelected model.connectionModel
|> List.head
|> Maybe.map Valid
|> Maybe.withDefault (Invalid [ "Connection missing" ] "")
|> Maybe.map Ok
|> Maybe.withDefault (Err ValidateConnectionMissing)
recp =
if List.isEmpty model.recipients then
Invalid [ "No recipients" ] []
Err ValidateRecipientsRequired
else
Valid model.recipients
Ok model.recipients
rmdays =
Maybe.map Valid model.remindDays
|> Maybe.withDefault (Invalid [ "Remind Days is required" ] 0)
Maybe.map Ok model.remindDays
|> Maybe.withDefault (Err ValidateRemindDaysRequired)
schedule_ =
Result.mapError (\_ -> ValidateCalEventInvalid) model.schedule
make smtp rec days timer =
{ prev
@ -209,34 +225,24 @@ makeSettings model =
, summary = model.summary
}
in
Data.Validated.map4 make
Result.map4 make
conn
recp
rmdays
model.schedule
schedule_
withValidSettings : (NotificationSettings -> Action) -> Model -> ( Model, Action, Cmd Msg )
withValidSettings mkcmd model =
case makeSettings model of
Valid set ->
( { model | formMsg = Nothing }
Ok set ->
( { model | formState = FormStateInitial }
, mkcmd set
, Cmd.none
)
Invalid errs _ ->
let
errMsg =
String.join ", " errs
in
( { model | formMsg = Just (BasicResult False errMsg) }
, NoAction
, Cmd.none
)
Unknown _ ->
( { model | formMsg = Just (BasicResult False "An unknown error occured") }
Err errs ->
( { model | formState = FormStateInvalid errs }
, NoAction
, Cmd.none
)
@ -249,14 +255,23 @@ update flags msg model =
let
( cm, cc, cs ) =
Comp.CalEventInput.update flags
(Data.Validated.value model.schedule)
(Util.Result.fold identity identity model.schedule)
lmsg
model.scheduleModel
in
( { model
| schedule = cs
| schedule =
case cs of
Data.Validated.Valid e ->
Ok e
Data.Validated.Invalid _ e ->
Err e
Data.Validated.Unknown e ->
Ok e
, scheduleModel = cm
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.map CalEventMsg cc
@ -270,7 +285,7 @@ update flags msg model =
( { model
| recipients = rec
, recipientsModel = em
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.map RecipientMsg ec
@ -283,7 +298,7 @@ update flags msg model =
in
( { model
| connectionModel = cm
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.map ConnMsg cc
@ -303,15 +318,12 @@ update flags msg model =
( { model
| connectionModel = cm
, loading = model.loading - 1
, formMsg =
, formState =
if names == [] then
Just
(BasicResult False
"No E-Mail connections configured. Goto E-Mail Settings to add one."
)
FormStateInvalid ValidateConnectionMissing
else
Nothing
FormStateInitial
}
, NoAction
, Cmd.none
@ -319,7 +331,7 @@ update flags msg model =
ConnResp (Err err) ->
( { model
| formMsg = Just (BasicResult False (Util.Http.errorToString err))
| formState = FormStateHttpError err
, loading = model.loading - 1
}
, NoAction
@ -333,7 +345,7 @@ update flags msg model =
in
( { model
| tagInclModel = m2
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.map TagIncMsg c2
@ -346,7 +358,7 @@ update flags msg model =
in
( { model
| tagExclModel = m2
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.map TagExcMsg c2
@ -372,7 +384,7 @@ update flags msg model =
GetTagsResp (Err err) ->
( { model
| loading = model.loading - 1
, formMsg = Just (BasicResult False (Util.Http.errorToString err))
, formState = FormStateHttpError err
}
, NoAction
, Cmd.none
@ -386,7 +398,7 @@ update flags msg model =
( { model
| remindDaysModel = pm
, remindDays = val
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.none
@ -395,7 +407,7 @@ update flags msg model =
ToggleEnabled ->
( { model
| enabled = not model.enabled
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.none
@ -404,7 +416,7 @@ update flags msg model =
ToggleCapOverdue ->
( { model
| capOverdue = not model.capOverdue
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.none
@ -465,15 +477,17 @@ update flags msg model =
isFormError : Model -> Bool
isFormError model =
Maybe.map .success model.formMsg
|> Maybe.map not
|> Maybe.withDefault False
case model.formState of
FormStateInitial ->
False
_ ->
True
isFormSuccess : Model -> Bool
isFormSuccess model =
Maybe.map .success model.formMsg
|> Maybe.withDefault False
not (isFormError model)
view2 : Texts -> String -> UiSettings -> Model -> Html Msg
@ -547,13 +561,28 @@ view2 texts extraClasses settings model =
[ classList
[ ( S.successMessage, isFormSuccess model )
, ( S.errorMessage, isFormError model )
, ( "hidden", model.formMsg == Nothing )
, ( "hidden", model.formState == FormStateInitial )
]
, class "mb-4"
]
[ Maybe.map .message model.formMsg
|> Maybe.withDefault ""
|> text
[ case model.formState of
FormStateInitial ->
text ""
FormStateHttpError err ->
text (texts.httpError err)
FormStateInvalid ValidateConnectionMissing ->
text texts.connectionMissing
FormStateInvalid ValidateCalEventInvalid ->
text texts.invalidCalEvent
FormStateInvalid ValidateRemindDaysRequired ->
text texts.remindDaysRequired
FormStateInvalid ValidateRecipientsRequired ->
text texts.recipientsRequired
]
, div [ class "mb-4" ]
[ MB.viewItem <|
@ -678,7 +707,7 @@ view2 texts extraClasses settings model =
(Comp.CalEventInput.view2
texts.calEventInput
""
(Data.Validated.value model.schedule)
(Util.Result.fold identity identity model.schedule)
model.scheduleModel
)
, span [ class "opacity-50 text-sm" ]

View File

@ -20,24 +20,36 @@ import Html.Attributes exposing (..)
import Http
import Messages.Comp.NotificationManage exposing (Texts)
import Styles as S
import Util.Http
type alias Model =
{ listModel : Comp.NotificationList.Model
, detailModel : Maybe Comp.NotificationForm.Model
, items : List NotificationSettings
, result : Maybe BasicResult
, formState : FormState
}
type SubmitType
= SubmitDelete
| SubmitUpdate
| SubmitCreate
| SubmitStartOnce
type FormState
= FormStateInitial
| FormHttpError Http.Error
| FormSubmitSuccessful SubmitType
| FormSubmitFailed String
type Msg
= ListMsg Comp.NotificationList.Msg
| DetailMsg Comp.NotificationForm.Msg
| GetDataResp (Result Http.Error NotificationSettingsList)
| NewTask
| SubmitResp Bool (Result Http.Error BasicResult)
| DeleteResp (Result Http.Error BasicResult)
| SubmitResp SubmitType (Result Http.Error BasicResult)
initModel : Model
@ -45,7 +57,7 @@ initModel =
{ listModel = Comp.NotificationList.init
, detailModel = Nothing
, items = []
, result = Nothing
, formState = FormStateInitial
}
@ -69,13 +81,13 @@ update flags msg model =
GetDataResp (Ok res) ->
( { model
| items = res.items
, result = Nothing
, formState = FormStateInitial
}
, Cmd.none
)
GetDataResp (Err err) ->
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
( { model | formState = FormHttpError err }
, Cmd.none
)
@ -113,26 +125,29 @@ update flags msg model =
( model_, cmd_ ) =
case action of
Comp.NotificationForm.NoAction ->
( { model | detailModel = Just mm }
( { model
| detailModel = Just mm
, formState = FormStateInitial
}
, Cmd.none
)
Comp.NotificationForm.SubmitAction settings ->
( { model
| detailModel = Just mm
, result = Nothing
, formState = FormStateInitial
}
, if settings.id == "" then
Api.createNotifyDueItems flags settings (SubmitResp True)
Api.createNotifyDueItems flags settings (SubmitResp SubmitCreate)
else
Api.updateNotifyDueItems flags settings (SubmitResp True)
Api.updateNotifyDueItems flags settings (SubmitResp SubmitUpdate)
)
Comp.NotificationForm.CancelAction ->
( { model
| detailModel = Nothing
, result = Nothing
, formState = FormStateInitial
}
, initCmd flags
)
@ -140,17 +155,17 @@ update flags msg model =
Comp.NotificationForm.StartOnceAction settings ->
( { model
| detailModel = Just mm
, result = Nothing
, formState = FormStateInitial
}
, Api.startOnceNotifyDueItems flags settings (SubmitResp False)
, Api.startOnceNotifyDueItems flags settings (SubmitResp SubmitStartOnce)
)
Comp.NotificationForm.DeleteAction id ->
( { model
| detailModel = Just mm
, result = Nothing
, formState = FormStateInitial
}
, Api.deleteNotifyDueItems flags id DeleteResp
, Api.deleteNotifyDueItems flags id (SubmitResp SubmitDelete)
)
in
( model_
@ -170,17 +185,22 @@ update flags msg model =
in
( { model | detailModel = Just mm }, Cmd.map DetailMsg mc )
SubmitResp close (Ok res) ->
SubmitResp submitType (Ok res) ->
( { model
| result = Just res
| formState =
if res.success then
FormSubmitSuccessful submitType
else
FormSubmitFailed res.message
, detailModel =
if close then
if submitType == SubmitDelete then
Nothing
else
model.detailModel
}
, if close then
, if submitType == SubmitDelete then
initCmd flags
else
@ -188,23 +208,7 @@ update flags msg model =
)
SubmitResp _ (Err err) ->
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
, Cmd.none
)
DeleteResp (Ok res) ->
if res.success then
( { model | result = Nothing, detailModel = Nothing }
, initCmd flags
)
else
( { model | result = Just res }
, Cmd.none
)
DeleteResp (Err err) ->
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
( { model | formState = FormHttpError err }
, Cmd.none
)
@ -218,15 +222,33 @@ view2 texts settings model =
div [ class "flex flex-col" ]
(div
[ classList
[ ( S.errorMessage, Maybe.map .success model.result == Just False )
, ( S.successMessage, Maybe.map .success model.result == Just True )
, ( "hidden", model.result == Nothing )
[ ( S.errorMessage, model.formState /= FormStateInitial )
, ( S.successMessage, isSuccess model.formState )
, ( "hidden", model.formState == FormStateInitial )
]
, class "mb-2"
]
[ Maybe.map .message model.result
|> Maybe.withDefault ""
|> text
[ case model.formState of
FormStateInitial ->
text ""
FormSubmitSuccessful SubmitCreate ->
text texts.taskCreated
FormSubmitSuccessful SubmitUpdate ->
text texts.taskUpdated
FormSubmitSuccessful SubmitStartOnce ->
text texts.taskStarted
FormSubmitSuccessful SubmitDelete ->
text texts.taskDeleted
FormSubmitFailed m ->
text m
FormHttpError err ->
text (texts.httpError err)
]
:: (case model.detailModel of
Just msett ->
@ -238,6 +260,16 @@ view2 texts settings model =
)
isSuccess : FormState -> Bool
isSuccess state =
case state of
FormSubmitSuccessful _ ->
True
_ ->
False
viewForm2 : Texts -> UiSettings -> Comp.NotificationForm.Model -> List (Html Msg)
viewForm2 texts settings model =
[ Html.map DetailMsg

View File

@ -23,7 +23,6 @@ import Html.Events exposing (onSubmit)
import Http
import Messages.Comp.OrgManage exposing (Texts)
import Styles as S
import Util.Http
import Util.Maybe
@ -31,13 +30,20 @@ type alias Model =
{ tableModel : Comp.OrgTable.Model
, formModel : Comp.OrgForm.Model
, viewMode : ViewMode
, formError : Maybe String
, formError : FormError
, loading : Bool
, deleteConfirm : Comp.YesNoDimmer.Model
, query : String
}
type FormError
= FormErrorNone
| FormErrorHttp Http.Error
| FormErrorSubmit String
| FormErrorInvalid
type ViewMode
= Table
| Form
@ -48,7 +54,7 @@ emptyModel =
{ tableModel = Comp.OrgTable.emptyModel
, formModel = Comp.OrgForm.emptyModel
, viewMode = Table
, formError = Nothing
, formError = FormErrorNone
, loading = False
, deleteConfirm = Comp.YesNoDimmer.emptyModel
, query = ""
@ -83,7 +89,7 @@ update flags msg model =
, viewMode = Maybe.map (\_ -> Form) tm.selected |> Maybe.withDefault Table
, formError =
if Util.Maybe.nonEmpty tm.selected then
Nothing
FormErrorNone
else
model.formError
@ -136,7 +142,7 @@ update flags msg model =
InitNewOrg ->
let
nm =
{ model | viewMode = Form, formError = Nothing }
{ model | viewMode = Form, formError = FormErrorNone }
org =
Api.Model.Organization.empty
@ -155,7 +161,7 @@ update flags msg model =
( { model | loading = True }, Api.postOrg flags org SubmitResp )
else
( { model | formError = Just "Please correct the errors in the form." }, Cmd.none )
( { model | formError = FormErrorInvalid }, Cmd.none )
SubmitResp (Ok res) ->
if res.success then
@ -169,10 +175,10 @@ update flags msg model =
( { m3 | loading = False }, Cmd.batch [ c2, c3 ] )
else
( { model | formError = Just res.message, loading = False }, Cmd.none )
( { model | formError = FormErrorSubmit res.message, loading = False }, Cmd.none )
SubmitResp (Err err) ->
( { model | formError = Just (Util.Http.errorToString err), loading = False }, Cmd.none )
( { model | formError = FormErrorHttp err, loading = False }, Cmd.none )
RequestDelete ->
update flags (YesNoMsg Comp.YesNoDimmer.activate) model
@ -310,12 +316,23 @@ viewForm2 texts settings model =
}
, div
[ classList
[ ( "hidden", Util.Maybe.isEmpty model.formError )
[ ( "hidden", model.formError == FormErrorNone )
]
, class S.errorMessage
, class "my-2"
]
[ Maybe.withDefault "" model.formError |> text
[ case model.formError of
FormErrorNone ->
text ""
FormErrorSubmit m ->
text m
FormErrorHttp err ->
text (texts.httpError err)
FormErrorInvalid ->
text texts.correctFormErrors
]
, Html.map FormMsg
(Comp.OrgForm.view2

View File

@ -24,7 +24,6 @@ import Html.Events exposing (onSubmit)
import Http
import Messages.Comp.PersonManage exposing (Texts)
import Styles as S
import Util.Http
import Util.Maybe
@ -32,13 +31,20 @@ type alias Model =
{ tableModel : Comp.PersonTable.Model
, formModel : Comp.PersonForm.Model
, viewMode : ViewMode
, formError : Maybe String
, formError : FormError
, loading : Int
, deleteConfirm : Comp.YesNoDimmer.Model
, query : String
}
type FormError
= FormErrorNone
| FormErrorHttp Http.Error
| FormErrorSubmit String
| FormErrorInvalid
type ViewMode
= Table
| Form
@ -49,7 +55,7 @@ emptyModel =
{ tableModel = Comp.PersonTable.emptyModel
, formModel = Comp.PersonForm.emptyModel
, viewMode = Table
, formError = Nothing
, formError = FormErrorNone
, loading = 0
, deleteConfirm = Comp.YesNoDimmer.emptyModel
, query = ""
@ -85,7 +91,7 @@ update flags msg model =
, viewMode = Maybe.map (\_ -> Form) tm.selected |> Maybe.withDefault Table
, formError =
if Util.Maybe.nonEmpty tm.selected then
Nothing
FormErrorNone
else
model.formError
@ -156,7 +162,7 @@ update flags msg model =
InitNewPerson ->
let
nm =
{ model | viewMode = Form, formError = Nothing }
{ model | viewMode = Form, formError = FormErrorNone }
org =
Api.Model.Person.empty
@ -177,7 +183,7 @@ update flags msg model =
)
else
( { model | formError = Just "Please correct the errors in the form." }, Cmd.none )
( { model | formError = FormErrorInvalid }, Cmd.none )
SubmitResp (Ok res) ->
if res.success then
@ -192,7 +198,7 @@ update flags msg model =
else
( { model
| formError = Just res.message
| formError = FormErrorSubmit res.message
, loading = Basics.max 0 (model.loading - 1)
}
, Cmd.none
@ -200,7 +206,7 @@ update flags msg model =
SubmitResp (Err err) ->
( { model
| formError = Just (Util.Http.errorToString err)
| formError = FormErrorHttp err
, loading = Basics.max 0 (model.loading - 1)
}
, Cmd.none
@ -347,12 +353,23 @@ viewForm2 texts settings model =
}
, div
[ classList
[ ( "hidden", Util.Maybe.isEmpty model.formError )
[ ( "hidden", model.formError == FormErrorNone )
]
, class S.errorMessage
, class "my-2"
]
[ Maybe.withDefault "" model.formError |> text
[ case model.formError of
FormErrorNone ->
text ""
FormErrorSubmit m ->
text m
FormErrorHttp err ->
text (texts.httpError err)
FormErrorInvalid ->
text texts.correctFormErrors
]
, Html.map FormMsg
(Comp.PersonForm.view2 texts.personForm

View File

@ -9,7 +9,6 @@ module Comp.ScanMailboxForm exposing
)
import Api
import Api.Model.BasicResult exposing (BasicResult)
import Api.Model.FolderItem exposing (FolderItem)
import Api.Model.FolderList exposing (FolderList)
import Api.Model.IdName exposing (IdName)
@ -44,9 +43,9 @@ import Messages.Data.Language
import Set exposing (Set)
import Styles as S
import Util.Folder exposing (mkFolderOption)
import Util.Http
import Util.List
import Util.Maybe
import Util.Result
import Util.Tag
import Util.Update
@ -62,9 +61,9 @@ type alias Model =
, foldersModel : Comp.StringListInput.Model
, folders : List String
, direction : Maybe Direction
, schedule : Validated CalEvent
, schedule : Result CalEvent CalEvent
, scheduleModel : Comp.CalEventInput.Model
, formMsg : Maybe BasicResult
, formState : FormState
, loading : Int
, yesNoDelete : Comp.YesNoDimmer.Model
, folderModel : Comp.Dropdown.Model IdName
@ -82,6 +81,18 @@ type alias Model =
}
type FormState
= FormStateInitial
| FormStateHttpError Http.Error
| FormStateInvalid ValidateError
type ValidateError
= ValidateNoProcessingFolders
| ValidateConnectionMissing
| ValidateCalEventInvalid
type Action
= SubmitAction ScanMailboxSettings
| StartOnceAction ScanMailboxSettings
@ -179,10 +190,10 @@ initWith flags s =
, receivedHours = s.receivedSinceHours
, targetFolder = s.targetFolder
, folders = s.folders
, schedule = Data.Validated.Unknown newSchedule
, schedule = Ok newSchedule
, direction = Maybe.andThen Data.Direction.fromString s.direction
, scheduleModel = sm
, formMsg = Nothing
, formState = FormStateInitial
, yesNoDelete = Comp.YesNoDimmer.emptyModel
, itemFolderId = s.itemFolder
, tagModel = Util.Tag.makeDropdownModel
@ -211,7 +222,7 @@ init : Flags -> ( Model, Cmd Msg )
init flags =
let
initialSchedule =
Data.Validated.Valid Data.CalEvent.everyMonth
Ok Data.CalEvent.everyMonth
sm =
Comp.CalEventInput.initDefault
@ -228,7 +239,7 @@ init flags =
, direction = Nothing
, schedule = initialSchedule
, scheduleModel = sm
, formMsg = Nothing
, formState = FormStateInitial
, loading = 3
, yesNoDelete = Comp.YesNoDimmer.emptyModel
, folderModel = Comp.Dropdown.makeSingle
@ -257,7 +268,7 @@ init flags =
--- Update
makeSettings : Model -> Validated ScanMailboxSettings
makeSettings : Model -> Result ValidateError ScanMailboxSettings
makeSettings model =
let
prev =
@ -266,15 +277,18 @@ makeSettings model =
conn =
Comp.Dropdown.getSelected model.connectionModel
|> List.head
|> Maybe.map Valid
|> Maybe.withDefault (Invalid [ "Connection missing" ] "")
|> Maybe.map Ok
|> Maybe.withDefault (Err ValidateConnectionMissing)
infolders =
if model.folders == [] then
Invalid [ "No processing folders given" ] []
Err ValidateNoProcessingFolders
else
Valid model.folders
Ok model.folders
schedule_ =
Result.mapError (\_ -> ValidateCalEventInvalid) model.schedule
make imap timer folders =
{ prev
@ -303,33 +317,20 @@ makeSettings model =
, summary = model.summary
}
in
Data.Validated.map3 make
conn
model.schedule
infolders
Result.map3 make conn schedule_ infolders
withValidSettings : (ScanMailboxSettings -> Action) -> Model -> ( Model, Action, Cmd Msg )
withValidSettings mkAction model =
case makeSettings model of
Valid set ->
( { model | formMsg = Nothing }
Ok set ->
( { model | formState = FormStateInitial }
, mkAction set
, Cmd.none
)
Invalid errs _ ->
let
errMsg =
String.join ", " errs
in
( { model | formMsg = Just (BasicResult False errMsg) }
, NoAction
, Cmd.none
)
Unknown _ ->
( { model | formMsg = Just (BasicResult False "An unknown error occured") }
Err errs ->
( { model | formState = FormStateInvalid errs }
, NoAction
, Cmd.none
)
@ -342,14 +343,23 @@ update flags msg model =
let
( cm, cc, cs ) =
Comp.CalEventInput.update flags
(Data.Validated.value model.schedule)
(Util.Result.fold identity identity model.schedule)
lmsg
model.scheduleModel
in
( { model
| schedule = cs
| schedule =
case cs of
Data.Validated.Valid e ->
Ok e
Data.Validated.Invalid _ e ->
Err e
Data.Validated.Unknown e ->
Ok e
, scheduleModel = cm
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.map CalEventMsg cc
@ -362,7 +372,7 @@ update flags msg model =
in
( { model
| connectionModel = cm
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.map ConnMsg cc
@ -394,15 +404,12 @@ update flags msg model =
( { model
| connectionModel = cm
, loading = model.loading - 1
, formMsg =
, formState =
if names == [] then
Just
(BasicResult False
"No E-Mail connections configured. Goto E-Mail Settings to add one."
)
FormStateInvalid ValidateConnectionMissing
else
Nothing
FormStateInitial
}
, NoAction
, Cmd.none
@ -410,7 +417,7 @@ update flags msg model =
ConnResp (Err err) ->
( { model
| formMsg = Just (BasicResult False (Util.Http.errorToString err))
| formState = FormStateHttpError err
, loading = model.loading - 1
}
, NoAction
@ -420,7 +427,7 @@ update flags msg model =
ToggleEnabled ->
( { model
| enabled = not model.enabled
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.none
@ -429,7 +436,7 @@ update flags msg model =
ToggleDeleteMail ->
( { model
| deleteMail = not model.deleteMail
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.none
@ -443,7 +450,7 @@ update flags msg model =
( { model
| receivedHoursModel = pm
, receivedHours = val
, formMsg = Nothing
, formState = FormStateInitial
}
, NoAction
, Cmd.none
@ -714,15 +721,17 @@ update flags msg model =
isFormError : Model -> Bool
isFormError model =
Maybe.map .success model.formMsg
|> Maybe.map not
|> Maybe.withDefault False
case model.formState of
FormStateInitial ->
False
_ ->
True
isFormSuccess : Model -> Bool
isFormSuccess model =
Maybe.map .success model.formMsg
|> Maybe.withDefault False
not (isFormError model)
isFolderMember : Model -> Bool
@ -796,12 +805,24 @@ view2 texts flags extraClasses settings model =
[ classList
[ ( S.successMessage, isFormSuccess model )
, ( S.errorMessage, isFormError model )
, ( "hidden", model.formMsg == Nothing )
, ( "hidden", model.formState == FormStateInitial )
]
]
[ Maybe.map .message model.formMsg
|> Maybe.withDefault ""
|> text
[ case model.formState of
FormStateInitial ->
text ""
FormStateHttpError err ->
text (texts.httpError err)
FormStateInvalid ValidateConnectionMissing ->
text texts.connectionMissing
FormStateInvalid ValidateNoProcessingFolders ->
text texts.noProcessingFolders
FormStateInvalid ValidateCalEventInvalid ->
text texts.invalidCalEvent
]
, Comp.Tabs.akkordion
Comp.Tabs.defaultStyle
@ -1172,7 +1193,7 @@ viewSchedule2 texts model =
(Comp.CalEventInput.view2
texts.calEventInput
""
(Data.Validated.value model.schedule)
(Util.Result.fold identity identity model.schedule)
model.scheduleModel
)
, span [ class "opacity-50 text-sm" ]

View File

@ -20,24 +20,36 @@ import Html.Attributes exposing (..)
import Http
import Messages.Comp.ScanMailboxManage exposing (Texts)
import Styles as S
import Util.Http
type alias Model =
{ listModel : Comp.ScanMailboxList.Model
, detailModel : Maybe Comp.ScanMailboxForm.Model
, items : List ScanMailboxSettings
, result : Maybe BasicResult
, formState : FormState
}
type SubmitType
= SubmitDelete
| SubmitUpdate
| SubmitCreate
| SubmitStartOnce
type FormState
= FormStateInitial
| FormHttpError Http.Error
| FormSubmitSuccessful SubmitType
| FormSubmitFailed String
type Msg
= ListMsg Comp.ScanMailboxList.Msg
| DetailMsg Comp.ScanMailboxForm.Msg
| GetDataResp (Result Http.Error ScanMailboxSettingsList)
| NewTask
| SubmitResp Bool (Result Http.Error BasicResult)
| DeleteResp (Result Http.Error BasicResult)
| SubmitResp SubmitType (Result Http.Error BasicResult)
initModel : Model
@ -45,7 +57,7 @@ initModel =
{ listModel = Comp.ScanMailboxList.init
, detailModel = Nothing
, items = []
, result = Nothing
, formState = FormStateInitial
}
@ -69,13 +81,13 @@ update flags msg model =
GetDataResp (Ok res) ->
( { model
| items = res.items
, result = Nothing
, formState = FormStateInitial
}
, Cmd.none
)
GetDataResp (Err err) ->
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
( { model | formState = FormHttpError err }
, Cmd.none
)
@ -113,26 +125,29 @@ update flags msg model =
( model_, cmd_ ) =
case action of
Comp.ScanMailboxForm.NoAction ->
( { model | detailModel = Just mm }
( { model
| detailModel = Just mm
, formState = FormStateInitial
}
, Cmd.none
)
Comp.ScanMailboxForm.SubmitAction settings ->
( { model
| detailModel = Just mm
, result = Nothing
, formState = FormStateInitial
}
, if settings.id == "" then
Api.createScanMailbox flags settings (SubmitResp True)
Api.createScanMailbox flags settings (SubmitResp SubmitCreate)
else
Api.updateScanMailbox flags settings (SubmitResp True)
Api.updateScanMailbox flags settings (SubmitResp SubmitUpdate)
)
Comp.ScanMailboxForm.CancelAction ->
( { model
| detailModel = Nothing
, result = Nothing
, formState = FormStateInitial
}
, initCmd flags
)
@ -140,17 +155,17 @@ update flags msg model =
Comp.ScanMailboxForm.StartOnceAction settings ->
( { model
| detailModel = Just mm
, result = Nothing
, formState = FormStateInitial
}
, Api.startOnceScanMailbox flags settings (SubmitResp False)
, Api.startOnceScanMailbox flags settings (SubmitResp SubmitStartOnce)
)
Comp.ScanMailboxForm.DeleteAction id ->
( { model
| detailModel = Just mm
, result = Nothing
, formState = FormStateInitial
}
, Api.deleteScanMailbox flags id DeleteResp
, Api.deleteScanMailbox flags id (SubmitResp SubmitDelete)
)
in
( model_
@ -170,17 +185,22 @@ update flags msg model =
in
( { model | detailModel = Just mm }, Cmd.map DetailMsg mc )
SubmitResp close (Ok res) ->
SubmitResp submitType (Ok res) ->
( { model
| result = Just res
| formState =
if res.success then
FormSubmitSuccessful submitType
else
FormSubmitFailed res.message
, detailModel =
if close then
if submitType == SubmitDelete then
Nothing
else
model.detailModel
}
, if close then
, if submitType == SubmitDelete then
initCmd flags
else
@ -188,23 +208,7 @@ update flags msg model =
)
SubmitResp _ (Err err) ->
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
, Cmd.none
)
DeleteResp (Ok res) ->
if res.success then
( { model | result = Nothing, detailModel = Nothing }
, initCmd flags
)
else
( { model | result = Just res }
, Cmd.none
)
DeleteResp (Err err) ->
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
( { model | formState = FormHttpError err }
, Cmd.none
)
@ -218,14 +222,33 @@ view2 texts flags settings model =
div [ class "flex flex-col" ]
(div
[ classList
[ ( S.errorMessage, Maybe.map .success model.result == Just False )
, ( S.successMessage, Maybe.map .success model.result == Just True )
, ( "hidden", model.result == Nothing )
[ ( S.errorMessage, model.formState /= FormStateInitial )
, ( S.successMessage, isSuccess model.formState )
, ( "hidden", model.formState == FormStateInitial )
]
, class "mb-2"
]
[ Maybe.map .message model.result
|> Maybe.withDefault ""
|> text
[ case model.formState of
FormStateInitial ->
text ""
FormSubmitSuccessful SubmitCreate ->
text texts.taskCreated
FormSubmitSuccessful SubmitUpdate ->
text texts.taskUpdated
FormSubmitSuccessful SubmitStartOnce ->
text texts.taskStarted
FormSubmitSuccessful SubmitDelete ->
text texts.taskDeleted
FormSubmitFailed m ->
text m
FormHttpError err ->
text (texts.httpError err)
]
:: (case model.detailModel of
Just msett ->
@ -237,6 +260,16 @@ view2 texts flags settings model =
)
isSuccess : FormState -> Bool
isSuccess state =
case state of
FormSubmitSuccessful _ ->
True
_ ->
False
viewForm2 : Texts -> Flags -> UiSettings -> Comp.ScanMailboxForm.Model -> List (Html Msg)
viewForm2 texts flags settings model =
[ Html.map DetailMsg

View File

@ -25,20 +25,25 @@ import Messages.Comp.SourceManage exposing (Texts)
import Ports
import QRCode
import Styles as S
import Util.Http
import Util.Maybe
type alias Model =
{ formModel : Comp.SourceForm.Model
, viewMode : SelectMode
, formError : Maybe String
, formError : FormError
, loading : Bool
, deleteConfirm : Comp.YesNoDimmer.Model
, sources : List SourceAndTags
}
type FormError
= FormErrorNone
| FormErrorHttp Http.Error
| FormErrorInvalid
| FormErrorSubmit String
init : Flags -> ( Model, Cmd Msg )
init flags =
let
@ -47,7 +52,7 @@ init flags =
in
( { formModel = fm
, viewMode = None
, formError = Nothing
, formError = FormErrorNone
, loading = False
, deleteConfirm = Comp.YesNoDimmer.emptyModel
, sources = []
@ -103,7 +108,7 @@ update flags msg model =
model.formError
else
Nothing
FormErrorNone
}
, Cmd.map TableMsg tc
)
@ -152,7 +157,7 @@ update flags msg model =
Api.Model.SourceAndTags.empty
nm =
{ model | viewMode = Edit source, formError = Nothing }
{ model | viewMode = Edit source, formError = FormErrorNone }
in
update flags (FormMsg (Comp.SourceForm.SetSource source)) nm
@ -168,7 +173,7 @@ update flags msg model =
( { model | loading = True }, Api.postSource flags source SubmitResp )
else
( { model | formError = Just "Please correct the errors in the form." }, Cmd.none )
( { model | formError = FormErrorInvalid }, Cmd.none )
SubmitResp (Ok res) ->
if res.success then
@ -182,10 +187,10 @@ update flags msg model =
( { m3 | loading = False }, Cmd.batch [ c2, c3 ] )
else
( { model | formError = Just res.message, loading = False }, Cmd.none )
( { model | formError = FormErrorSubmit res.message, loading = False }, Cmd.none )
SubmitResp (Err err) ->
( { model | formError = Just (Util.Http.errorToString err), loading = False }, Cmd.none )
( { model | formError = FormErrorHttp err, loading = False }, Cmd.none )
RequestDelete ->
update flags (YesNoMsg Comp.YesNoDimmer.activate) model
@ -444,10 +449,21 @@ viewForm2 texts flags settings model =
, div
[ classList
[ ( S.errorMessage, True )
, ( "hidden", Util.Maybe.isEmpty model.formError )
, ( "hidden", model.formError == FormErrorNone )
]
]
[ Maybe.withDefault "" model.formError |> text
[ case model.formError of
FormErrorNone ->
text ""
FormErrorHttp err ->
text (texts.httpError err)
FormErrorSubmit m ->
text m
FormErrorInvalid ->
text texts.correctFormErrors
]
, Html.map YesNoMsg
(Comp.YesNoDimmer.viewN True

View File

@ -22,7 +22,6 @@ import Html.Events exposing (onSubmit)
import Http
import Messages.Comp.TagManage exposing (Texts)
import Styles as S
import Util.Http
import Util.Maybe
import Util.Tag
import Util.Update
@ -32,13 +31,20 @@ type alias Model =
{ tagTableModel : Comp.TagTable.Model
, tagFormModel : Comp.TagForm.Model
, viewMode : ViewMode
, formError : Maybe String
, formError : FormError
, loading : Bool
, deleteConfirm : Comp.YesNoDimmer.Model
, query : String
}
type FormError
= FormErrorNone
| FormErrorHttp Http.Error
| FormErrorInvalid
| FormErrorSubmit String
type ViewMode
= Table
| Form
@ -49,7 +55,7 @@ emptyModel =
{ tagTableModel = Comp.TagTable.emptyModel
, tagFormModel = Comp.TagForm.emptyModel []
, viewMode = Table
, formError = Nothing
, formError = FormErrorNone
, loading = False
, deleteConfirm = Comp.YesNoDimmer.emptyModel
, query = ""
@ -84,7 +90,7 @@ update flags msg model =
, viewMode = Maybe.map (\_ -> Form) tm.selected |> Maybe.withDefault Table
, formError =
if Util.Maybe.nonEmpty tm.selected then
Nothing
FormErrorNone
else
model.formError
@ -144,7 +150,7 @@ update flags msg model =
InitNewTag ->
let
nm =
{ model | viewMode = Form, formError = Nothing }
{ model | viewMode = Form, formError = FormErrorNone }
tag =
Api.Model.Tag.empty
@ -163,7 +169,7 @@ update flags msg model =
( { model | loading = True }, Api.postTag flags tag SubmitResp )
else
( { model | formError = Just "Please correct the errors in the form." }, Cmd.none )
( { model | formError = FormErrorInvalid }, Cmd.none )
SubmitResp (Ok res) ->
if res.success then
@ -177,10 +183,10 @@ update flags msg model =
( { m3 | loading = False }, Cmd.batch [ c2, c3 ] )
else
( { model | formError = Just res.message, loading = False }, Cmd.none )
( { model | formError = FormErrorSubmit res.message, loading = False }, Cmd.none )
SubmitResp (Err err) ->
( { model | formError = Just (Util.Http.errorToString err), loading = False }, Cmd.none )
( { model | formError = FormErrorHttp err, loading = False }, Cmd.none )
RequestDelete ->
update flags (YesNoMsg Comp.YesNoDimmer.activate) model
@ -322,12 +328,23 @@ viewForm2 texts model =
}
, div
[ classList
[ ( "hidden", Util.Maybe.isEmpty model.formError )
[ ( "hidden", model.formError == FormErrorNone )
]
, class "my-2"
, class S.errorMessage
]
[ Maybe.withDefault "" model.formError |> text
[ case model.formError of
FormErrorNone ->
text ""
FormErrorHttp err ->
text (texts.httpError err)
FormErrorInvalid ->
text texts.correctFormErrors
FormErrorSubmit m ->
text m
]
, Html.map FormMsg (Comp.TagForm.view2 texts.tagForm model.tagFormModel)
, B.loadingDimmer

View File

@ -23,7 +23,6 @@ import Html.Events exposing (onSubmit)
import Http
import Messages.Comp.UserManage exposing (Texts)
import Styles as S
import Util.Http
import Util.Maybe
@ -45,6 +44,7 @@ type ViewMode
type FormError
= FormErrorNone
| FormErrorSubmit String
| FormErrorHttp Http.Error
| FormErrorInvalid
@ -183,7 +183,7 @@ update flags msg model =
SubmitResp (Err err) ->
( { model
| formError = FormErrorSubmit (Util.Http.errorToString err)
| formError = FormErrorHttp err
, loading = False
}
, Cmd.none
@ -319,6 +319,9 @@ viewForm2 texts settings model =
FormErrorSubmit err ->
text err
FormErrorHttp err ->
text (texts.httpError err)
FormErrorInvalid ->
text texts.pleaseCorrectErrors
]