mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 18:39:33 +00:00
Externalize string in ui settings form
This commit is contained in:
parent
9ccc3ce438
commit
c0ba211fe7
@ -23,10 +23,18 @@ import Styles as S
|
||||
type alias Model =
|
||||
{ formModel : Comp.UiSettingsForm.Model
|
||||
, settings : Maybe UiSettings
|
||||
, message : Maybe BasicResult
|
||||
, formResult : FormResult
|
||||
}
|
||||
|
||||
|
||||
type FormResult
|
||||
= FormInit
|
||||
| FormUnchanged
|
||||
| FormSaved
|
||||
| FormHttpError Http.Error
|
||||
| FormUnknownError
|
||||
|
||||
|
||||
type Msg
|
||||
= UiSettingsFormMsg Comp.UiSettingsForm.Msg
|
||||
| Submit
|
||||
@ -42,7 +50,7 @@ init flags settings =
|
||||
in
|
||||
( { formModel = fm
|
||||
, settings = Nothing
|
||||
, message = Nothing
|
||||
, formResult = FormInit
|
||||
}
|
||||
, Cmd.map UiSettingsFormMsg fc
|
||||
)
|
||||
@ -79,12 +87,12 @@ update flags settings msg model =
|
||||
|
||||
else
|
||||
sett
|
||||
, message =
|
||||
, formResult =
|
||||
if sett /= Nothing then
|
||||
Nothing
|
||||
FormInit
|
||||
|
||||
else
|
||||
model.message
|
||||
model.formResult
|
||||
}
|
||||
, cmd = Cmd.none
|
||||
, newSettings = Nothing
|
||||
@ -93,25 +101,32 @@ update flags settings msg model =
|
||||
Submit ->
|
||||
case model.settings of
|
||||
Just s ->
|
||||
{ model = { model | message = Nothing }
|
||||
{ model = { model | formResult = FormInit }
|
||||
, cmd = Api.saveClientSettings flags s (SaveSettingsResp s)
|
||||
, newSettings = Nothing
|
||||
}
|
||||
|
||||
Nothing ->
|
||||
{ model = { model | message = Just (BasicResult False "Settings unchanged or invalid.") }
|
||||
{ model = { model | formResult = FormUnchanged }
|
||||
, cmd = Cmd.none
|
||||
, newSettings = Nothing
|
||||
}
|
||||
|
||||
SaveSettingsResp newSettings (Ok res) ->
|
||||
{ model = { model | message = Just res }
|
||||
, cmd = Cmd.none
|
||||
, newSettings = Just newSettings
|
||||
}
|
||||
if res.success then
|
||||
{ model = { model | formResult = FormSaved }
|
||||
, cmd = Cmd.none
|
||||
, newSettings = Just newSettings
|
||||
}
|
||||
|
||||
else
|
||||
{ model = { model | formResult = FormUnknownError }
|
||||
, cmd = Cmd.none
|
||||
, newSettings = Nothing
|
||||
}
|
||||
|
||||
SaveSettingsResp _ (Err err) ->
|
||||
UpdateResult model Cmd.none Nothing
|
||||
UpdateResult { model | formResult = FormHttpError err } Cmd.none Nothing
|
||||
|
||||
UpdateSettings ->
|
||||
let
|
||||
@ -130,12 +145,26 @@ update flags settings msg model =
|
||||
|
||||
isError : Model -> Bool
|
||||
isError model =
|
||||
Maybe.map .success model.message == Just False
|
||||
case model.formResult of
|
||||
FormSaved ->
|
||||
False
|
||||
|
||||
FormInit ->
|
||||
False
|
||||
|
||||
FormUnchanged ->
|
||||
True
|
||||
|
||||
FormHttpError _ ->
|
||||
True
|
||||
|
||||
FormUnknownError ->
|
||||
True
|
||||
|
||||
|
||||
isSuccess : Model -> Bool
|
||||
isSuccess model =
|
||||
Maybe.map .success model.message == Just True
|
||||
not (isError model)
|
||||
|
||||
|
||||
view2 : Texts -> Flags -> UiSettings -> String -> Model -> Html Msg
|
||||
@ -157,12 +186,24 @@ view2 texts flags settings classes model =
|
||||
[ classList
|
||||
[ ( S.successMessage, isSuccess model )
|
||||
, ( S.errorMessage, isError model )
|
||||
, ( "hidden", model.message == Nothing )
|
||||
, ( "hidden", model.formResult == FormInit )
|
||||
]
|
||||
]
|
||||
[ Maybe.map .message model.message
|
||||
|> Maybe.withDefault ""
|
||||
|> text
|
||||
[ case model.formResult of
|
||||
FormInit ->
|
||||
text ""
|
||||
|
||||
FormUnchanged ->
|
||||
text texts.settingsUnchanged
|
||||
|
||||
FormHttpError err ->
|
||||
text (texts.httpError err)
|
||||
|
||||
FormSaved ->
|
||||
text texts.settingsSaved
|
||||
|
||||
FormUnknownError ->
|
||||
text texts.unknownSaveError
|
||||
]
|
||||
, Html.map UiSettingsFormMsg
|
||||
(Comp.UiSettingsForm.view2
|
||||
|
@ -1,6 +1,8 @@
|
||||
module Messages.Comp.UiSettingsManage exposing (Texts, gb)
|
||||
|
||||
import Http
|
||||
import Messages.Basics
|
||||
import Messages.Comp.HttpError
|
||||
import Messages.Comp.UiSettingsForm
|
||||
|
||||
|
||||
@ -8,6 +10,10 @@ type alias Texts =
|
||||
{ basics : Messages.Basics.Texts
|
||||
, uiSettingsForm : Messages.Comp.UiSettingsForm.Texts
|
||||
, saveSettings : String
|
||||
, settingsUnchanged : String
|
||||
, settingsSaved : String
|
||||
, unknownSaveError : String
|
||||
, httpError : Http.Error -> String
|
||||
}
|
||||
|
||||
|
||||
@ -16,4 +22,8 @@ gb =
|
||||
{ basics = Messages.Basics.gb
|
||||
, uiSettingsForm = Messages.Comp.UiSettingsForm.gb
|
||||
, saveSettings = "Save settings"
|
||||
, settingsUnchanged = "Settings unchanged or invalid."
|
||||
, settingsSaved = "Settings saved."
|
||||
, unknownSaveError = "Unknown error while trying to save settings."
|
||||
, httpError = Messages.Comp.HttpError.gb
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user