Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
8dc55b72
Commit
8dc55b72
authored
3 years ago
by
Boris Vasilenko
Browse files
Options
Download
Email Patches
Plain Diff
NAS-115593: fix 'show_if' for 'list' and 'dict' types
parent
5ab08858
NAS-115593-6
NAS-115593-5
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/app/interfaces/dynamic-form-schema.interface.ts
+1
-1
src/app/interfaces/dynamic-form-schema.interface.ts
src/app/modules/ix-forms/components/ix-dynamic-form/ix-dynamic-form-item/ix-dynamic-form-item.component.ts
+12
-14
...rm/ix-dynamic-form-item/ix-dynamic-form-item.component.ts
src/app/services/app-schema.service.ts
+51
-48
src/app/services/app-schema.service.ts
with
64 additions
and
63 deletions
+64
-63
src/app/interfaces/dynamic-form-schema.interface.ts
View file @
8dc55b72
...
...
@@ -21,7 +21,7 @@ export type DynamicFormSchemaNode =
export
interface
DynamicFormSchemaBase
{
controlName
:
string
;
dependsOn
?:
string
;
dependsOn
?:
string
[]
;
title
?:
string
;
required
?:
boolean
;
hidden
?:
boolean
;
...
...
This diff is collapsed.
Click to expand it.
src/app/modules/ix-forms/components/ix-dynamic-form/ix-dynamic-form-item/ix-dynamic-form-item.component.ts
View file @
8dc55b72
...
...
@@ -28,21 +28,19 @@ export class IxDynamicFormItemComponent implements OnInit {
)
{}
ngOnInit
():
void
{
this
.
dynamicForm
?.
valueChanges
.
pipe
(
map
((
changes
)
=>
{
const
dependsOn
=
this
.
dynamicSchema
?.
dependsOn
;
const
dependsOn
=
this
.
dynamicSchema
?.
dependsOn
;
if
(
!
dependsOn
)
{
return
null
;
}
return
changes
[
dependsOn
];
}
),
filter
((
x
)
=>
x
!=
null
),
distinctUntilChanged
(
),
untilDestroyed
(
this
),
).
subscribe
(()
=>
{
this
.
changeDetectorRef
.
markForCheck
(
);
dependsOn
?.
forEach
((
depend
)
=>
{
this
.
dynamicForm
?.
valueChanges
.
pipe
(
map
((
changes
)
=>
{
return
changes
[
depend
];
}),
filter
((
x
)
=>
x
!=
null
),
distinctUntilChanged
(
),
untilDestroyed
(
this
),
).
subscribe
(()
=>
{
this
.
changeDetectorRef
.
markForCheck
();
}
);
});
}
...
...
This diff is collapsed.
Click to expand it.
src/app/services/app-schema.service.ts
View file @
8dc55b72
...
...
@@ -148,7 +148,7 @@ export class AppSchemaService {
const
objs
=
this
.
transformNode
(
subquestion
);
objs
.
forEach
((
obj
)
=>
{
obj
.
indent
=
true
;
obj
.
dependsOn
=
chartSchemaNode
.
variable
;
obj
.
dependsOn
=
[
chartSchemaNode
.
variable
]
;
});
newSchema
=
newSchema
.
concat
(
objs
);
});
...
...
@@ -186,6 +186,7 @@ export class AppSchemaService {
items
,
itemsSchema
,
editable
:
schema
.
editable
,
dependsOn
:
schema
.
show_if
?.
map
((
conditional
)
=>
conditional
[
0
]),
});
}
else
{
console
.
error
(
'
Unsupported type =
'
,
schema
.
type
);
...
...
@@ -249,53 +250,6 @@ export class AppSchemaService {
if
(
schema
.
default
!==
undefined
)
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
setValue
(
schema
.
default
);
}
if
(
schema
.
show_if
)
{
const
relations
:
Relation
[]
=
schema
.
show_if
.
map
((
item
)
=>
({
fieldName
:
item
[
0
],
operatorName
:
item
[
1
],
operatorValue
:
item
[
2
],
}));
relations
.
forEach
((
relation
)
=>
{
if
(
!
formGroup
.
controls
[
relation
.
fieldName
])
{
formGroup
.
addControl
(
relation
.
fieldName
,
new
FormControl
());
}
switch
(
relation
.
operatorName
)
{
case
'
=
'
:
if
(
formGroup
.
controls
[
relation
.
fieldName
].
value
!==
relation
.
operatorValue
)
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
disable
();
}
subscription
.
add
(
formGroup
.
controls
[
relation
.
fieldName
].
valueChanges
.
pipe
(
untilDestroyed
(
this
))
.
subscribe
((
value
)
=>
{
if
(
formGroup
.
controls
[
chartSchemaNode
.
variable
].
parent
.
enabled
)
{
if
(
value
===
relation
.
operatorValue
)
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
enable
();
}
else
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
disable
();
}
}
}));
break
;
case
'
!=
'
:
if
(
formGroup
.
controls
[
relation
.
fieldName
].
value
===
relation
.
operatorValue
)
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
disable
();
}
subscription
.
add
(
formGroup
.
controls
[
relation
.
fieldName
].
valueChanges
.
pipe
(
untilDestroyed
(
this
))
.
subscribe
((
value
)
=>
{
if
(
formGroup
.
controls
[
chartSchemaNode
.
variable
].
parent
.
enabled
)
{
if
(
value
!==
relation
.
operatorValue
)
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
enable
();
}
else
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
disable
();
}
}
}));
break
;
}
});
}
}
else
if
(
schema
.
type
===
ChartSchemaType
.
Dict
)
{
formGroup
.
addControl
(
chartSchemaNode
.
variable
,
new
FormGroup
({}));
for
(
const
attr
of
schema
.
attrs
)
{
...
...
@@ -334,6 +288,55 @@ export class AppSchemaService {
}
}
}
if
(
schema
.
show_if
)
{
const
relations
:
Relation
[]
=
schema
.
show_if
.
map
((
item
)
=>
({
fieldName
:
item
[
0
],
operatorName
:
item
[
1
],
operatorValue
:
item
[
2
],
}));
relations
.
forEach
((
relation
)
=>
{
if
(
!
formGroup
.
controls
[
relation
.
fieldName
])
{
formGroup
.
addControl
(
relation
.
fieldName
,
new
FormControl
());
formGroup
.
controls
[
relation
.
fieldName
].
disable
();
}
switch
(
relation
.
operatorName
)
{
case
'
=
'
:
if
(
formGroup
.
controls
[
relation
.
fieldName
].
value
!==
relation
.
operatorValue
)
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
disable
();
}
subscription
.
add
(
formGroup
.
controls
[
relation
.
fieldName
].
valueChanges
.
pipe
(
untilDestroyed
(
this
))
.
subscribe
((
value
)
=>
{
if
(
value
!==
null
&&
formGroup
.
controls
[
chartSchemaNode
.
variable
].
parent
.
enabled
)
{
if
(
value
===
relation
.
operatorValue
)
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
enable
();
}
else
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
disable
();
}
}
}));
break
;
case
'
!=
'
:
if
(
formGroup
.
controls
[
relation
.
fieldName
].
value
===
relation
.
operatorValue
)
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
disable
();
}
subscription
.
add
(
formGroup
.
controls
[
relation
.
fieldName
].
valueChanges
.
pipe
(
untilDestroyed
(
this
))
.
subscribe
((
value
)
=>
{
if
(
value
!==
null
&&
formGroup
.
controls
[
chartSchemaNode
.
variable
].
parent
.
enabled
)
{
if
(
value
!==
relation
.
operatorValue
)
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
enable
();
}
else
{
formGroup
.
controls
[
chartSchemaNode
.
variable
].
disable
();
}
}
}));
break
;
}
});
}
return
subscription
;
}
...
...
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
Menu
Projects
Groups
Snippets
Help