diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.html b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.html index 19a43fcb30..102a55ad5e 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.html @@ -19,26 +19,55 @@ @switch (state) { @case ('confirm') {

{{ 'iot-hub.install-confirm-title' | translate:{ name: item.name } }}

- @if (item.type === ItemType.RULE_CHAIN) { -

{{ 'iot-hub.rule-chain-install-desc' | translate }}

- } @else { -

{{ 'iot-hub.install-desc' | translate }}

- } +

{{ 'iot-hub.install-desc' | translate }}

} @case ('select-entity') {

{{ 'iot-hub.install-confirm-title' | translate:{ name: item.name } }}

- @if (activeSelectEntityConfig?.promptKey) { -

+ @if (item.type === ItemType.RULE_CHAIN) { +

{{ 'iot-hub.rule-chain-install-subtitle' | translate }}

+
+
+ +
+ {{ 'iot-hub.rule-chain-set-as-profile-default-toggle' | translate }} +
+
+ @if (ruleChainInstallForm.controls.setAsDefault.value) { +
+ + + + +
+ } +
+
+ } @else { + @if (activeSelectEntityConfig?.promptKey) { +

+ } + + } - - } @case ('confirm-overwrite') {

{{ 'iot-hub.rule-chain-overwrite-title' | translate }}

@@ -59,7 +88,7 @@ @case ('error') {

{{ 'iot-hub.install-error-title' | translate }}

{{ 'iot-hub.install-error-message' | translate:{ name: item.name } }}

- @if (item?.type === ItemType.SOLUTION_TEMPLATE) { + @if (item.type === ItemType.SOLUTION_TEMPLATE) { } @else {
@@ -73,28 +102,20 @@ @switch (state) { @case ('confirm') { - @if (item.type === ItemType.RULE_CHAIN) { - - - } @else { - - } + } @case ('select-entity') { @if (item.type === ItemType.RULE_CHAIN) { - } @else { } diff --git a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.ts b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.ts index ee4565c0a8..4696f663b8 100644 --- a/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.ts @@ -14,9 +14,11 @@ /// limitations under the License. /// -import { Component, Inject } from '@angular/core'; +import { Component, DestroyRef, Inject } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; import { Router } from '@angular/router'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { DialogComponent } from '@shared/components/dialog.component'; @@ -70,15 +72,21 @@ export type InstallState = export class TbIotHubInstallDialogComponent extends DialogComponent { ItemType = ItemType; + EntityType = EntityType; item: MpItemVersionView; typeTranslations = itemTypeTranslations; - state: InstallState = 'confirm'; + state!: InstallState; errorMessage = ''; entityDetailsUrl: string | null = null; selectedEntityId: EntityId | null = null; pendingOverwrite: PendingOverwrite | null = null; + ruleChainInstallForm!: FormGroup<{ + setAsDefault: FormControl; + entityType: FormControl; + entityId: FormControl; + }>; private readonly selectEntityConfig: Partial> = { [ItemType.CALCULATED_FIELD]: { @@ -92,13 +100,7 @@ export class TbIotHubInstallDialogComponent extends DialogComponent(false), + entityType: this.fb.nonNullable.control(EntityType.DEVICE_PROFILE), + entityId: this.fb.control(null) + }); + this.ruleChainInstallForm.controls.setAsDefault.valueChanges + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe(setAsDefault => { + const entityIdCtrl = this.ruleChainInstallForm.controls.entityId; + if (setAsDefault) { + entityIdCtrl.setValidators(Validators.required); + } else { + entityIdCtrl.clearValidators(); + entityIdCtrl.setValue(null); + } + entityIdCtrl.updateValueAndValidity(); + }); + this.ruleChainInstallForm.controls.entityType.valueChanges + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe(() => { + this.ruleChainInstallForm.controls.entityId.setValue(null); + }); } getTypeLabel(): string { @@ -126,39 +165,33 @@ export class TbIotHubInstallDialogComponent extends DialogComponent { if (pending) { this.pendingOverwrite = pending; this.state = 'confirm-overwrite'; } else { this.pendingOverwrite = null; - this.doInstall(); + this.install(); } }, error: (err) => { @@ -170,7 +203,7 @@ export class TbIotHubInstallDialogComponent extends DialogComponent{{profile}} currently uses {{existing}} as its default rule chain. Installing will replace it with this rule chain.", "rule-chain-overwrite-replace": "Replace",