mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-24 11:28:25 +00:00
Externalize error messages
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
module Page.CollectiveSettings.Data exposing
|
||||
( Model
|
||||
( FormState(..)
|
||||
, Model
|
||||
, Msg(..)
|
||||
, Tab(..)
|
||||
, init
|
||||
@ -21,10 +22,17 @@ type alias Model =
|
||||
, userModel : Comp.UserManage.Model
|
||||
, settingsModel : Comp.CollectiveSettingsForm.Model
|
||||
, insights : ItemInsights
|
||||
, submitResult : Maybe BasicResult
|
||||
, formState : FormState
|
||||
}
|
||||
|
||||
|
||||
type FormState
|
||||
= InitialState
|
||||
| SubmitSuccessful
|
||||
| SubmitFailed String
|
||||
| SubmitError Http.Error
|
||||
|
||||
|
||||
init : Flags -> ( Model, Cmd Msg )
|
||||
init flags =
|
||||
let
|
||||
@ -39,7 +47,7 @@ init flags =
|
||||
, userModel = Comp.UserManage.emptyModel
|
||||
, settingsModel = cm
|
||||
, insights = Api.Model.ItemInsights.empty
|
||||
, submitResult = Nothing
|
||||
, formState = InitialState
|
||||
}
|
||||
, Cmd.batch
|
||||
[ Cmd.map SourceMsg sc
|
||||
|
@ -1,13 +1,11 @@
|
||||
module Page.CollectiveSettings.Update exposing (update)
|
||||
|
||||
import Api
|
||||
import Api.Model.BasicResult exposing (BasicResult)
|
||||
import Comp.CollectiveSettingsForm
|
||||
import Comp.SourceManage
|
||||
import Comp.UserManage
|
||||
import Data.Flags exposing (Flags)
|
||||
import Page.CollectiveSettings.Data exposing (..)
|
||||
import Util.Http
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
@ -58,12 +56,12 @@ update flags msg model =
|
||||
Just sett ->
|
||||
Api.setCollectiveSettings flags sett SubmitResp
|
||||
in
|
||||
( { model | settingsModel = m2, submitResult = Nothing }
|
||||
( { model | settingsModel = m2, formState = InitialState }
|
||||
, Cmd.batch [ cmd, Cmd.map SettingsFormMsg c2 ]
|
||||
)
|
||||
|
||||
Init ->
|
||||
( { model | submitResult = Nothing }
|
||||
( { model | formState = InitialState }
|
||||
, Cmd.batch
|
||||
[ Api.getInsights flags GetInsightsResp
|
||||
, Api.getCollectiveSettings flags CollectiveSettingsResp
|
||||
@ -89,11 +87,16 @@ update flags msg model =
|
||||
( model, Cmd.none )
|
||||
|
||||
SubmitResp (Ok res) ->
|
||||
( { model | submitResult = Just res }, Cmd.none )
|
||||
( { model
|
||||
| formState =
|
||||
if res.success then
|
||||
SubmitSuccessful
|
||||
|
||||
else
|
||||
SubmitFailed res.message
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
SubmitResp (Err err) ->
|
||||
let
|
||||
res =
|
||||
BasicResult False (Util.Http.errorToString err)
|
||||
in
|
||||
( { model | submitResult = Just res }, Cmd.none )
|
||||
( { model | formState = SubmitError err }, Cmd.none )
|
||||
|
@ -14,7 +14,6 @@ import Html.Events exposing (onClick)
|
||||
import Messages.Page.CollectiveSettings exposing (Texts)
|
||||
import Page.CollectiveSettings.Data exposing (..)
|
||||
import Styles as S
|
||||
import Util.Maybe
|
||||
import Util.Size
|
||||
|
||||
|
||||
@ -249,6 +248,27 @@ viewSettings texts flags settings model =
|
||||
[ text texts.collectiveSettings
|
||||
]
|
||||
]
|
||||
, div
|
||||
[ classList
|
||||
[ ( "hidden", model.formState == InitialState )
|
||||
, ( S.successMessage, model.formState == SubmitSuccessful )
|
||||
, ( S.errorMessage, model.formState /= SubmitSuccessful )
|
||||
]
|
||||
, class "mb-2"
|
||||
]
|
||||
[ case model.formState of
|
||||
SubmitSuccessful ->
|
||||
text texts.submitSuccessful
|
||||
|
||||
SubmitError err ->
|
||||
text (texts.httpError err)
|
||||
|
||||
SubmitFailed m ->
|
||||
text m
|
||||
|
||||
InitialState ->
|
||||
text ""
|
||||
]
|
||||
, Html.map SettingsFormMsg
|
||||
(Comp.CollectiveSettingsForm.view2
|
||||
flags
|
||||
@ -256,23 +276,4 @@ viewSettings texts flags settings model =
|
||||
settings
|
||||
model.settingsModel
|
||||
)
|
||||
, div
|
||||
[ classList
|
||||
[ ( "hidden", Util.Maybe.isEmpty model.submitResult )
|
||||
, ( S.successMessage
|
||||
, Maybe.map .success model.submitResult
|
||||
|> Maybe.withDefault False
|
||||
)
|
||||
, ( S.errorMessage
|
||||
, Maybe.map .success model.submitResult
|
||||
|> Maybe.map not
|
||||
|> Maybe.withDefault False
|
||||
)
|
||||
]
|
||||
, class "mt-2"
|
||||
]
|
||||
[ Maybe.map .message model.submitResult
|
||||
|> Maybe.withDefault ""
|
||||
|> text
|
||||
]
|
||||
]
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Page.Login.Data exposing
|
||||
( Model
|
||||
( FormState(..)
|
||||
, Model
|
||||
, Msg(..)
|
||||
, emptyModel
|
||||
)
|
||||
@ -13,16 +14,23 @@ type alias Model =
|
||||
{ username : String
|
||||
, password : String
|
||||
, rememberMe : Bool
|
||||
, result : Maybe AuthResult
|
||||
, formState : FormState
|
||||
}
|
||||
|
||||
|
||||
type FormState
|
||||
= AuthSuccess AuthResult
|
||||
| AuthFailed AuthResult
|
||||
| HttpError Http.Error
|
||||
| FormInitial
|
||||
|
||||
|
||||
emptyModel : Model
|
||||
emptyModel =
|
||||
{ username = ""
|
||||
, password = ""
|
||||
, rememberMe = False
|
||||
, result = Nothing
|
||||
, formState = FormInitial
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,7 +6,6 @@ import Data.Flags exposing (Flags)
|
||||
import Page exposing (Page(..))
|
||||
import Page.Login.Data exposing (..)
|
||||
import Ports
|
||||
import Util.Http
|
||||
|
||||
|
||||
update : Maybe Page -> Flags -> Msg -> Model -> ( Model, Cmd Msg, Maybe AuthResult )
|
||||
@ -37,13 +36,13 @@ update referrer flags msg model =
|
||||
Maybe.withDefault HomePage referrer |> Page.goto
|
||||
in
|
||||
if lr.success then
|
||||
( { model | result = Just lr, password = "" }
|
||||
( { model | formState = AuthSuccess lr, password = "" }
|
||||
, Cmd.batch [ setAccount lr, gotoRef ]
|
||||
, Just lr
|
||||
)
|
||||
|
||||
else
|
||||
( { model | result = Just lr, password = "" }
|
||||
( { model | formState = AuthFailed lr, password = "" }
|
||||
, Ports.removeAccount ()
|
||||
, Just lr
|
||||
)
|
||||
@ -52,11 +51,11 @@ update referrer flags msg model =
|
||||
let
|
||||
empty =
|
||||
Api.Model.AuthResult.empty
|
||||
|
||||
lr =
|
||||
{ empty | message = Util.Http.errorToString err }
|
||||
in
|
||||
( { model | password = "", result = Just lr }, Ports.removeAccount (), Just empty )
|
||||
( { model | password = "", formState = HttpError err }
|
||||
, Ports.removeAccount ()
|
||||
, Just empty
|
||||
)
|
||||
|
||||
|
||||
setAccount : AuthResult -> Cmd msg
|
||||
|
@ -158,17 +158,21 @@ viewContent texts flags versionInfo _ model =
|
||||
|
||||
resultMessage : Texts -> Model -> Html Msg
|
||||
resultMessage texts model =
|
||||
case model.result of
|
||||
Just r ->
|
||||
if r.success then
|
||||
div [ class ("my-2" ++ S.successMessage) ]
|
||||
[ text texts.loginSuccessful
|
||||
]
|
||||
case model.formState of
|
||||
AuthSuccess _ ->
|
||||
div [ class ("my-2" ++ S.successMessage) ]
|
||||
[ text texts.loginSuccessful
|
||||
]
|
||||
|
||||
else
|
||||
div [ class ("my-2" ++ S.errorMessage) ]
|
||||
[ text r.message
|
||||
]
|
||||
AuthFailed r ->
|
||||
div [ class ("my-2" ++ S.errorMessage) ]
|
||||
[ text r.message
|
||||
]
|
||||
|
||||
Nothing ->
|
||||
HttpError err ->
|
||||
div [ class ("my-2" ++ S.errorMessage) ]
|
||||
[ text (texts.httpError err)
|
||||
]
|
||||
|
||||
FormInitial ->
|
||||
span [ class "hidden" ] []
|
||||
|
@ -19,7 +19,8 @@ type alias Model =
|
||||
|
||||
type State
|
||||
= Empty
|
||||
| Failed String
|
||||
| Failed Http.Error
|
||||
| GenericFail String
|
||||
| Success InviteResult
|
||||
|
||||
|
||||
@ -29,6 +30,9 @@ isFailed state =
|
||||
Failed _ ->
|
||||
True
|
||||
|
||||
GenericFail _ ->
|
||||
True
|
||||
|
||||
_ ->
|
||||
False
|
||||
|
||||
|
@ -4,7 +4,6 @@ import Api
|
||||
import Api.Model.GenInvite exposing (GenInvite)
|
||||
import Data.Flags exposing (Flags)
|
||||
import Page.NewInvite.Data exposing (..)
|
||||
import Util.Http
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
@ -24,7 +23,7 @@ update flags msg model =
|
||||
( { model | result = Success res }, Cmd.none )
|
||||
|
||||
else
|
||||
( { model | result = Failed res.message }, Cmd.none )
|
||||
( { model | result = GenericFail res.message }, Cmd.none )
|
||||
|
||||
InviteResp (Err err) ->
|
||||
( { model | result = Failed (Util.Http.errorToString err) }, Cmd.none )
|
||||
( { model | result = Failed err }, Cmd.none )
|
||||
|
@ -43,7 +43,11 @@ viewContent texts flags _ model =
|
||||
[ text texts.invitationKey
|
||||
]
|
||||
, div [ class "relative" ]
|
||||
[ div [ class "inline-flex items-center justify-center absolute left-0 top-0 h-full w-10 text-gray-400 dark:text-bluegray-400 " ]
|
||||
[ div
|
||||
[ class "inline-flex items-center justify-center"
|
||||
, class "absolute left-0 top-0 h-full w-10"
|
||||
, class "text-gray-400 dark:text-bluegray-400"
|
||||
]
|
||||
[ i [ class "fa fa-key" ] []
|
||||
]
|
||||
, input
|
||||
@ -93,13 +97,16 @@ resultMessage texts model =
|
||||
]
|
||||
]
|
||||
[ case model.result of
|
||||
Failed m ->
|
||||
p [] [ text m ]
|
||||
Failed err ->
|
||||
text (texts.httpError err)
|
||||
|
||||
GenericFail m ->
|
||||
text m
|
||||
|
||||
Success r ->
|
||||
div [ class "" ]
|
||||
[ p []
|
||||
[ text r.message
|
||||
[ text texts.newInvitationCreated
|
||||
, text (" " ++ texts.invitationKey ++ ":")
|
||||
]
|
||||
, pre [ class "text-center font-mono mt-4" ]
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Page.Queue.Data exposing
|
||||
( Model
|
||||
( FormState(..)
|
||||
, Model
|
||||
, Msg(..)
|
||||
, QueueView(..)
|
||||
, emptyModel
|
||||
@ -20,7 +21,7 @@ import Util.Maybe
|
||||
|
||||
type alias Model =
|
||||
{ state : JobQueueState
|
||||
, error : String
|
||||
, formState : FormState
|
||||
, pollingInterval : Float
|
||||
, init : Bool
|
||||
, stopRefresh : Bool
|
||||
@ -32,6 +33,11 @@ type alias Model =
|
||||
}
|
||||
|
||||
|
||||
type FormState
|
||||
= InitialForm
|
||||
| HttpError Http.Error
|
||||
|
||||
|
||||
type QueueView
|
||||
= CurrentJobs
|
||||
| QueueAll
|
||||
@ -44,7 +50,7 @@ type QueueView
|
||||
emptyModel : Model
|
||||
emptyModel =
|
||||
{ state = Api.Model.JobQueueState.empty
|
||||
, error = ""
|
||||
, formState = InitialForm
|
||||
, pollingInterval = 1200
|
||||
, init = False
|
||||
, stopRefresh = False
|
||||
|
@ -4,10 +4,8 @@ import Api
|
||||
import Comp.YesNoDimmer
|
||||
import Data.Flags exposing (Flags)
|
||||
import Page.Queue.Data exposing (..)
|
||||
import Ports
|
||||
import Task
|
||||
import Time
|
||||
import Util.Http
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
@ -42,7 +40,7 @@ update flags msg model =
|
||||
( { model | state = s, stopRefresh = False }, refresh )
|
||||
|
||||
StateResp (Err err) ->
|
||||
( { model | error = Util.Http.errorToString err }, Cmd.none )
|
||||
( { model | formState = HttpError err }, Cmd.none )
|
||||
|
||||
StopRefresh ->
|
||||
( { model | stopRefresh = True, init = False }, Cmd.none )
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Page.Register.Data exposing
|
||||
( Model
|
||||
( FormState(..)
|
||||
, Model
|
||||
, Msg(..)
|
||||
, emptyModel
|
||||
)
|
||||
@ -9,31 +10,36 @@ import Http
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ result : Maybe BasicResult
|
||||
, collId : String
|
||||
{ collId : String
|
||||
, login : String
|
||||
, pass1 : String
|
||||
, pass2 : String
|
||||
, showPass1 : Bool
|
||||
, showPass2 : Bool
|
||||
, errorMsg : List String
|
||||
, formState : FormState
|
||||
, loading : Bool
|
||||
, successMsg : String
|
||||
, invite : Maybe String
|
||||
}
|
||||
|
||||
|
||||
type FormState
|
||||
= HttpError Http.Error
|
||||
| GenericError String
|
||||
| RegistrationSuccessful
|
||||
| PasswordMismatch
|
||||
| InputValid
|
||||
| FormEmpty
|
||||
|
||||
|
||||
emptyModel : Model
|
||||
emptyModel =
|
||||
{ result = Nothing
|
||||
, collId = ""
|
||||
{ collId = ""
|
||||
, login = ""
|
||||
, pass1 = ""
|
||||
, pass2 = ""
|
||||
, showPass1 = False
|
||||
, showPass2 = False
|
||||
, errorMsg = []
|
||||
, successMsg = ""
|
||||
, formState = FormEmpty
|
||||
, loading = False
|
||||
, invite = Nothing
|
||||
}
|
||||
|
@ -1,19 +1,17 @@
|
||||
module Page.Register.Update exposing (update)
|
||||
|
||||
import Api
|
||||
import Api.Model.BasicResult exposing (BasicResult)
|
||||
import Data.Flags exposing (Flags)
|
||||
import Page exposing (Page(..))
|
||||
import Page.Register.Data exposing (..)
|
||||
import Util.Http
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update flags msg model =
|
||||
case msg of
|
||||
RegisterSubmit ->
|
||||
case model.errorMsg of
|
||||
[] ->
|
||||
case model.formState of
|
||||
InputValid ->
|
||||
let
|
||||
reg =
|
||||
{ collectiveName = model.collId
|
||||
@ -35,7 +33,7 @@ update flags msg model =
|
||||
err =
|
||||
validateForm m
|
||||
in
|
||||
( { m | errorMsg = err }, Cmd.none )
|
||||
( { m | formState = err }, Cmd.none )
|
||||
|
||||
SetLogin str ->
|
||||
let
|
||||
@ -45,7 +43,7 @@ update flags msg model =
|
||||
err =
|
||||
validateForm m
|
||||
in
|
||||
( { m | errorMsg = err }, Cmd.none )
|
||||
( { m | formState = err }, Cmd.none )
|
||||
|
||||
SetPass1 str ->
|
||||
let
|
||||
@ -55,7 +53,7 @@ update flags msg model =
|
||||
err =
|
||||
validateForm m
|
||||
in
|
||||
( { m | errorMsg = err }, Cmd.none )
|
||||
( { m | formState = err }, Cmd.none )
|
||||
|
||||
SetPass2 str ->
|
||||
let
|
||||
@ -65,7 +63,7 @@ update flags msg model =
|
||||
err =
|
||||
validateForm m
|
||||
in
|
||||
( { m | errorMsg = err }, Cmd.none )
|
||||
( { m | formState = err }, Cmd.none )
|
||||
|
||||
SetInvite str ->
|
||||
( { model
|
||||
@ -98,29 +96,21 @@ update flags msg model =
|
||||
Cmd.none
|
||||
in
|
||||
( { m
|
||||
| result =
|
||||
| formState =
|
||||
if r.success then
|
||||
Nothing
|
||||
RegistrationSuccessful
|
||||
|
||||
else
|
||||
Just r
|
||||
GenericError r.message
|
||||
}
|
||||
, cmd
|
||||
)
|
||||
|
||||
SubmitResp (Err err) ->
|
||||
let
|
||||
errMsg =
|
||||
Util.Http.errorToString err
|
||||
|
||||
res =
|
||||
BasicResult False
|
||||
(errMsg ++ " Please check the form and try again.")
|
||||
in
|
||||
( { model | result = Just res }, Cmd.none )
|
||||
( { model | formState = HttpError err }, Cmd.none )
|
||||
|
||||
|
||||
validateForm : Model -> List String
|
||||
validateForm : Model -> FormState
|
||||
validateForm model =
|
||||
if
|
||||
model.collId
|
||||
@ -132,10 +122,10 @@ validateForm model =
|
||||
|| model.pass2
|
||||
== ""
|
||||
then
|
||||
[ "All fields are required!" ]
|
||||
FormEmpty
|
||||
|
||||
else if model.pass1 /= model.pass2 then
|
||||
[ "The passwords do not match." ]
|
||||
PasswordMismatch
|
||||
|
||||
else
|
||||
[]
|
||||
InputValid
|
||||
|
@ -239,22 +239,32 @@ viewContent texts flags _ model =
|
||||
|
||||
resultMessage : Texts -> Model -> Html Msg
|
||||
resultMessage texts model =
|
||||
case model.result of
|
||||
Just r ->
|
||||
if r.success then
|
||||
div [ class S.successMessage ]
|
||||
[ text texts.registrationSuccessful
|
||||
]
|
||||
case model.formState of
|
||||
InputValid ->
|
||||
div [ class "hidden" ]
|
||||
[]
|
||||
|
||||
else
|
||||
div [ class S.errorMessage ]
|
||||
[ text r.message
|
||||
]
|
||||
RegistrationSuccessful ->
|
||||
div [ class S.successMessage ]
|
||||
[ text texts.registrationSuccessful
|
||||
]
|
||||
|
||||
Nothing ->
|
||||
if List.isEmpty model.errorMsg then
|
||||
span [ class "hidden" ] []
|
||||
PasswordMismatch ->
|
||||
div [ class S.errorMessage ]
|
||||
[ text texts.passwordsDontMatch
|
||||
]
|
||||
|
||||
else
|
||||
div [ class S.errorMessage ]
|
||||
(List.map (\s -> div [] [ text s ]) model.errorMsg)
|
||||
GenericError m ->
|
||||
div [ class S.errorMessage ]
|
||||
[ text m
|
||||
]
|
||||
|
||||
FormEmpty ->
|
||||
div [ class S.errorMessage ]
|
||||
[ text texts.allFieldsRequired
|
||||
]
|
||||
|
||||
HttpError err ->
|
||||
div [ class S.errorMessage ]
|
||||
[ text (texts.httpError err)
|
||||
]
|
||||
|
Reference in New Issue
Block a user