Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
truenas-rk3588
webui
Commits
ba1d6dff
Unverified
Commit
ba1d6dff
authored
2 years ago
by
Evgeny Stepanovych
Committed by
GitHub
2 years ago
Browse files
Options
Download
Email Patches
Plain Diff
NAS-119438: Showing errors in rsync form (#7475)
parent
69dd88ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/modules/ix-forms/services/form-error-handler.service.ts
+25
-8
...p/modules/ix-forms/services/form-error-handler.service.ts
src/app/pages/data-protection/rsync-task/rsync-task-form/rsync-task-form.component.ts
+3
-1
...n/rsync-task/rsync-task-form/rsync-task-form.component.ts
with
28 additions
and
9 deletions
+28
-9
src/app/modules/ix-forms/services/form-error-handler.service.ts
View file @
ba1d6dff
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
UntypedFormGroup
}
from
'
@angular/forms
'
;
import
{
AbstractControl
,
UntypedFormGroup
}
from
'
@angular/forms
'
;
import
{
ResponseErrorType
}
from
'
app/enums/response-error-type.enum
'
;
import
{
Job
}
from
'
app/interfaces/job.interface
'
;
import
{
WebsocketError
}
from
'
app/interfaces/websocket-error.interface
'
;
...
...
@@ -12,14 +12,24 @@ export class FormErrorHandlerService {
private
dialog
:
DialogService
,
)
{}
handleWsFormError
(
error
:
WebsocketError
|
Job
,
formGroup
:
UntypedFormGroup
):
void
{
/**
* @param error
* @param formGroup
* @param fieldsMap Overrides backend field names with frontend field names.
* TODO: See if second `string` in fieldsMap can be typed to key of formGroup.
*/
handleWsFormError
(
error
:
WebsocketError
|
Job
,
formGroup
:
UntypedFormGroup
,
fieldsMap
:
Record
<
string
,
string
>
=
{},
):
void
{
if
(
'
type
'
in
error
&&
error
.
type
===
ResponseErrorType
.
Validation
&&
error
.
extra
)
{
this
.
handleValidationError
(
error
,
formGroup
);
this
.
handleValidationError
(
error
,
formGroup
,
fieldsMap
);
return
;
}
if
(
'
exc_info
'
in
error
&&
error
.
exc_info
.
type
===
ResponseErrorType
.
Validation
&&
error
.
exc_info
.
extra
)
{
this
.
handleValidationError
({
...
error
,
extra
:
error
.
exc_info
.
extra
as
Job
[
'
extra
'
]
},
formGroup
);
this
.
handleValidationError
({
...
error
,
extra
:
error
.
exc_info
.
extra
as
Job
[
'
extra
'
]
},
formGroup
,
fieldsMap
);
return
;
}
...
...
@@ -27,14 +37,16 @@ export class FormErrorHandlerService {
(
new
EntityUtils
()).
errorReport
(
error
,
this
.
dialog
);
}
// TODO: Add support for api fields having different names than formgroup fields, i.e. private_key => privateKey
// TODO: Same for nested API objects.
private
handleValidationError
(
error
:
WebsocketError
|
Job
,
formGroup
:
UntypedFormGroup
):
void
{
private
handleValidationError
(
error
:
WebsocketError
|
Job
,
formGroup
:
UntypedFormGroup
,
fieldsMap
:
Record
<
string
,
string
>
,
):
void
{
for
(
const
extraItem
of
(
error
as
WebsocketError
).
extra
)
{
const
field
=
extraItem
[
0
].
split
(
'
.
'
)[
1
];
const
errorMessage
=
extraItem
[
1
];
const
control
=
formGroup
.
get
(
field
);
const
control
=
this
.
getFormField
(
formGroup
,
field
,
field
sMap
);
if
(
!
control
)
{
console
.
error
(
`Could not find control
${
field
}
.`
);
// Fallback to default modal error message.
...
...
@@ -50,4 +62,9 @@ export class FormErrorHandlerService {
control
.
markAsTouched
();
}
}
private
getFormField
(
formGroup
:
UntypedFormGroup
,
field
:
string
,
fieldsMap
:
Record
<
string
,
string
>
):
AbstractControl
{
const
fieldName
=
fieldsMap
[
field
]
??
field
;
return
formGroup
.
get
(
fieldName
);
}
}
This diff is collapsed.
Click to expand it.
src/app/pages/data-protection/rsync-task/rsync-task-form/rsync-task-form.component.ts
View file @
ba1d6dff
...
...
@@ -212,7 +212,9 @@ export class RsyncTaskFormComponent implements OnInit {
},
error
:
(
error
)
=>
{
this
.
isLoading
=
false
;
this
.
errorHandler
.
handleWsFormError
(
error
,
this
.
form
);
this
.
errorHandler
.
handleWsFormError
(
error
,
this
.
form
,
{
remotehost
:
'
remotepath
'
,
});
this
.
cdr
.
markForCheck
();
},
});
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment