+
device-profile.lwm2m.no-config-servers
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-bootstrap-config-servers.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-bootstrap-config-servers.component.ts
index f76a1d2c6f..3b70918a1e 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-bootstrap-config-servers.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-bootstrap-config-servers.component.ts
@@ -14,7 +14,7 @@
/// limitations under the License.
///
-import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core';
+import { Component, EventEmitter, forwardRef, Input, OnDestroy, OnInit, Output } from '@angular/core';
import {
AbstractControl,
ControlValueAccessor,
@@ -24,13 +24,13 @@ import {
NG_VALIDATORS,
NG_VALUE_ACCESSOR
} from '@angular/forms';
-import { of, Subscription } from 'rxjs';
+import { of, Subject } from 'rxjs';
import { ServerSecurityConfig } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models';
import { TranslateService } from '@ngx-translate/core';
import { DialogService } from '@core/services/dialog.service';
import { MatDialog } from '@angular/material/dialog';
import { Lwm2mBootstrapAddConfigServerDialogComponent } from '@home/components/profile/device/lwm2m/lwm2m-bootstrap-add-config-server-dialog.component';
-import { mergeMap } from 'rxjs/operators';
+import { mergeMap, takeUntil } from 'rxjs/operators';
import { DeviceProfileService } from '@core/http/device-profile.service';
import { Lwm2mSecurityType } from '@shared/models/lwm2m-security-config.models';
@@ -50,7 +50,7 @@ import { Lwm2mSecurityType } from '@shared/models/lwm2m-security-config.models';
}
]
})
-export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValueAccessor {
+export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValueAccessor, OnDestroy {
bootstrapConfigServersFormGroup: UntypedFormGroup;
@@ -72,8 +72,7 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
}
}
- private valueChangeSubscription: Subscription = null;
-
+ private destroy$ = new Subject
();
private propagateChange = (v: any) => { };
constructor(public translate: TranslateService,
@@ -94,9 +93,17 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
this.bootstrapConfigServersFormGroup = this.fb.group({
serverConfigs: this.fb.array([])
});
+ this.bootstrapConfigServersFormGroup.valueChanges.pipe(
+ takeUntil(this.destroy$)
+ ).subscribe(() => this.updateModel());
+ }
+
+ ngOnDestroy() {
+ this.destroy$.next();
+ this.destroy$.complete();
}
- serverConfigsFromArray(): UntypedFormArray {
+ get serverConfigsFromArray(): UntypedFormArray {
return this.bootstrapConfigServersFormGroup.get('serverConfigs') as UntypedFormArray;
}
@@ -110,24 +117,22 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
}
writeValue(serverConfigs: Array | null): void {
- if (this.valueChangeSubscription) {
- this.valueChangeSubscription.unsubscribe();
- }
- const serverConfigsControls: Array = [];
- if (serverConfigs) {
- serverConfigs.forEach((serverConfig) => {
- serverConfigsControls.push(this.fb.control(serverConfig));
- });
- }
- this.bootstrapConfigServersFormGroup.setControl('serverConfigs', this.fb.array(serverConfigsControls));
- if (this.disabled) {
- this.bootstrapConfigServersFormGroup.disable({emitEvent: false});
+ if (serverConfigs?.length === this.serverConfigsFromArray.length) {
+ this.serverConfigsFromArray.patchValue(serverConfigs, {emitEvent: false});
} else {
- this.bootstrapConfigServersFormGroup.enable({emitEvent: false});
+ const serverConfigsControls: Array = [];
+ if (serverConfigs) {
+ serverConfigs.forEach((serverConfig) => {
+ serverConfigsControls.push(this.fb.control(serverConfig));
+ });
+ }
+ this.bootstrapConfigServersFormGroup.setControl('serverConfigs', this.fb.array(serverConfigsControls), {emitEvent: false});
+ if (this.disabled) {
+ this.bootstrapConfigServersFormGroup.disable({emitEvent: false});
+ } else {
+ this.bootstrapConfigServersFormGroup.enable({emitEvent: false});
+ }
}
- this.valueChangeSubscription = this.bootstrapConfigServersFormGroup.valueChanges.subscribe(() => {
- this.updateModel();
- });
}
trackByParams(index: number): number {
@@ -147,7 +152,7 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
true
).subscribe((result) => {
if (result) {
- this.serverConfigsFromArray().removeAt(index);
+ this.serverConfigsFromArray.removeAt(index);
}
});
}
@@ -169,7 +174,7 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
addServerConfigObs.subscribe((serverConfig) => {
if (serverConfig) {
serverConfig.securityMode = Lwm2mSecurityType.NO_SEC;
- this.serverConfigsFromArray().push(this.fb.control(serverConfig));
+ this.serverConfigsFromArray.push(this.fb.control(serverConfig));
this.updateModel();
} else {
this.isTransportWasRunWithBootstrap = false;
@@ -196,7 +201,7 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
}
private isBootstrapAdded(): boolean {
- const serverConfigsArray = this.serverConfigsFromArray().getRawValue();
+ const serverConfigsArray = this.serverConfigsFromArray.getRawValue();
for (let i = 0; i < serverConfigsArray.length; i++) {
if (serverConfigsArray[i].bootstrapServerIs) {
return true;
@@ -207,15 +212,15 @@ export class Lwm2mBootstrapConfigServersComponent implements OnInit, ControlValu
private removeBootstrapServerConfig(): void {
if (this.bootstrapConfigServersFormGroup) {
- const bootstrapServerIndex = this.serverConfigsFromArray().getRawValue().findIndex(server => server.bootstrapServerIs === true);
+ const bootstrapServerIndex = this.serverConfigsFromArray.getRawValue().findIndex(server => server.bootstrapServerIs === true);
if (bootstrapServerIndex !== -1) {
- this.serverConfigsFromArray().removeAt(bootstrapServerIndex);
+ this.serverConfigsFromArray.removeAt(bootstrapServerIndex);
}
}
}
private updateModel() {
- const serverConfigs: Array = this.serverConfigsFromArray().value;
+ const serverConfigs: Array = this.serverConfigsFromArray.value;
this.propagateChange(serverConfigs);
}
}
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-instances.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-instances.component.ts
index 6ca7b9b89f..48758531da 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-instances.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-instances.component.ts
@@ -80,6 +80,8 @@ export class Lwm2mObserveAttrTelemetryInstancesComponent implements ControlValue
this.instancesFormGroup = this.fb.group({
instances: this.fb.array([])
});
+
+ this.valueChange$ = this.instancesFormGroup.valueChanges.subscribe(value => this.updateModel(value.instances));
}
ngOnDestroy() {
@@ -122,22 +124,16 @@ export class Lwm2mObserveAttrTelemetryInstancesComponent implements ControlValue
if (instances.length === this.instancesFormArray.length) {
this.instancesFormArray.patchValue(instances, {emitEvent: false});
} else {
- if (this.valueChange$) {
- this.valueChange$.unsubscribe();
- }
const instancesControl: Array = [];
if (instances) {
instances.forEach((instance) => {
instancesControl.push(this.createInstanceFormGroup(instance));
});
}
- this.instancesFormGroup.setControl('instances', this.fb.array(instancesControl));
+ this.instancesFormGroup.setControl('instances', this.fb.array(instancesControl), {emitEvent: false});
if (this.disabled) {
this.instancesFormGroup.disable({emitEvent: false});
}
- this.valueChange$ = this.instancesFormGroup.valueChanges.subscribe(value => {
- this.updateModel(value.instances);
- });
}
}
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-resources.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-resources.component.ts
index fb4098057b..7fff3e288f 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-resources.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-resources.component.ts
@@ -29,7 +29,7 @@ import {
} from '@angular/forms';
import { ResourceLwM2M } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
-import { combineLatest, Subject, Subscription } from 'rxjs';
+import { combineLatest, Subject } from 'rxjs';
import { startWith, takeUntil } from 'rxjs/operators';
@Component({
@@ -71,19 +71,19 @@ export class Lwm2mObserveAttrTelemetryResourcesComponent implements ControlValue
}
private destroy$ = new Subject();
- private valueChange$: Subscription = null;
private propagateChange = (v: any) => { };
constructor(private fb: UntypedFormBuilder) {
this.resourcesFormGroup = this.fb.group({
resources: this.fb.array([])
});
+
+ this.resourcesFormGroup.valueChanges.pipe(
+ takeUntil(this.destroy$)
+ ).subscribe(() => this.updateModel(this.resourcesFormGroup.getRawValue().resources));
}
ngOnDestroy() {
- if (this.valueChange$) {
- this.valueChange$.unsubscribe();
- }
this.destroy$.next();
this.destroy$.complete();
}
@@ -131,24 +131,18 @@ export class Lwm2mObserveAttrTelemetryResourcesComponent implements ControlValue
private updatedResources(resources: ResourceLwM2M[]): void {
if (resources.length === this.resourcesFormArray.length) {
- this.resourcesFormArray.patchValue(resources, {onlySelf: true});
+ this.resourcesFormArray.patchValue(resources, {onlySelf: true, emitEvent: false});
} else {
- if (this.valueChange$) {
- this.valueChange$.unsubscribe();
- }
const resourcesControl: Array = [];
if (resources) {
resources.forEach((resource) => {
resourcesControl.push(this.createdResourceFormGroup(resource));
});
}
- this.resourcesFormGroup.setControl('resources', this.fb.array(resourcesControl));
+ this.resourcesFormGroup.setControl('resources', this.fb.array(resourcesControl), {emitEvent: false});
if (this.disabled) {
this.resourcesFormGroup.disable({emitEvent: false});
}
- this.valueChange$ = this.resourcesFormGroup.valueChanges.subscribe(() => {
- this.updateModel(this.resourcesFormGroup.getRawValue().resources);
- });
}
}
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts
index 5fd954f664..92662a77c2 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts
@@ -86,6 +86,8 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor,
this.modelsFormGroup = this.fb.group({
models: this.fb.array([])
});
+
+ this.valueChange$ = this.modelsFormGroup.valueChanges.subscribe(value => this.updateModel(value.models));
}
ngOnDestroy() {
@@ -130,20 +132,14 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor,
if (models.length === this.modelsFormArray.length) {
this.modelsFormArray.patchValue(models, {emitEvent: false});
} else {
- if (this.valueChange$) {
- this.valueChange$.unsubscribe();
- }
const modelControls: Array = [];
models.forEach(model => {
modelControls.push(this.createModelFormGroup(model));
});
- this.modelsFormGroup.setControl('models', this.fb.array(modelControls));
+ this.modelsFormGroup.setControl('models', this.fb.array(modelControls), {emitEvent: false});
if (this.disabled) {
this.modelsFormGroup.disable({emitEvent: false});
}
- this.valueChange$ = this.modelsFormGroup.valueChanges.subscribe(value => {
- this.updateModel(value.models);
- });
}
}
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-communication-config.component.html b/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-communication-config.component.html
index e78699d472..3f196e853d 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-communication-config.component.html
+++ b/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-communication-config.component.html
@@ -16,7 +16,7 @@
-->
-
@@ -58,7 +58,7 @@
remove_circle_outline
-
+
device-profile.snmp.please-add-communication-config
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-communication-config.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-communication-config.component.ts
index 959fc51ec5..7e0f8dd3b5 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-communication-config.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-communication-config.component.ts
@@ -27,7 +27,7 @@ import {
Validators
} from '@angular/forms';
import { SnmpCommunicationConfig, SnmpSpecType, SnmpSpecTypeTranslationMap } from '@shared/models/device.models';
-import { Subject, Subscription } from 'rxjs';
+import { Subject } from 'rxjs';
import { isUndefinedOrNull } from '@core/utils';
import { takeUntil } from 'rxjs/operators';
@@ -58,7 +58,6 @@ export class SnmpDeviceProfileCommunicationConfigComponent implements OnInit, On
disabled: boolean;
private usedSpecType: SnmpSpecType[] = [];
- private valueChange$: Subscription = null;
private destroy$ = new Subject
();
private propagateChange = (v: any) => { };
@@ -68,17 +67,17 @@ export class SnmpDeviceProfileCommunicationConfigComponent implements OnInit, On
this.deviceProfileCommunicationConfig = this.fb.group({
communicationConfig: this.fb.array([])
});
+ this.deviceProfileCommunicationConfig.valueChanges.pipe(
+ takeUntil(this.destroy$)
+ ).subscribe(() => this.updateModel());
}
ngOnDestroy() {
- if (this.valueChange$) {
- this.valueChange$.unsubscribe();
- }
this.destroy$.next();
this.destroy$.complete();
}
- communicationConfigFormArray(): UntypedFormArray {
+ get communicationConfigFormArray(): UntypedFormArray {
return this.deviceProfileCommunicationConfig.get('communicationConfig') as UntypedFormArray;
}
@@ -99,27 +98,27 @@ export class SnmpDeviceProfileCommunicationConfigComponent implements OnInit, On
}
writeValue(communicationConfig: SnmpCommunicationConfig[]) {
- if (this.valueChange$) {
- this.valueChange$.unsubscribe();
- }
- const communicationConfigControl: Array = [];
- if (communicationConfig) {
- communicationConfig.forEach((config) => {
- communicationConfigControl.push(this.createdFormGroup(config));
- });
- }
- this.deviceProfileCommunicationConfig.setControl('communicationConfig', this.fb.array(communicationConfigControl));
- if (!communicationConfig || !communicationConfig.length) {
- this.addCommunicationConfig();
- }
- if (this.disabled) {
- this.deviceProfileCommunicationConfig.disable({emitEvent: false});
+ if (communicationConfig?.length === this.communicationConfigFormArray.length) {
+ this.communicationConfigFormArray.patchValue(communicationConfig, {emitEvent: false});
} else {
- this.deviceProfileCommunicationConfig.enable({emitEvent: false});
+ const communicationConfigControl: Array = [];
+ if (communicationConfig) {
+ communicationConfig.forEach((config) => {
+ communicationConfigControl.push(this.createdFormGroup(config));
+ });
+ }
+ this.deviceProfileCommunicationConfig.setControl(
+ 'communicationConfig', this.fb.array(communicationConfigControl), {emitEvent: false}
+ );
+ if (!communicationConfig || !communicationConfig.length) {
+ this.addCommunicationConfig();
+ }
+ if (this.disabled) {
+ this.deviceProfileCommunicationConfig.disable({emitEvent: false});
+ } else {
+ this.deviceProfileCommunicationConfig.enable({emitEvent: false});
+ }
}
- this.valueChange$ = this.deviceProfileCommunicationConfig.valueChanges.subscribe(() => {
- this.updateModel();
- });
this.updateUsedSpecType();
if (!this.disabled && !this.deviceProfileCommunicationConfig.valid) {
this.updateModel();
@@ -133,16 +132,16 @@ export class SnmpDeviceProfileCommunicationConfigComponent implements OnInit, On
}
public removeCommunicationConfig(index: number) {
- this.communicationConfigFormArray().removeAt(index);
+ this.communicationConfigFormArray.removeAt(index);
}
get isAddEnabled(): boolean {
- return this.communicationConfigFormArray().length !== Object.keys(SnmpSpecType).length;
+ return this.communicationConfigFormArray.length !== Object.keys(SnmpSpecType).length;
}
public addCommunicationConfig() {
- this.communicationConfigFormArray().push(this.createdFormGroup());
+ this.communicationConfigFormArray.push(this.createdFormGroup());
this.deviceProfileCommunicationConfig.updateValueAndValidity();
if (!this.deviceProfileCommunicationConfig.valid) {
this.updateModel();
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-mapping.component.html b/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-mapping.component.html
index d1e68b60c8..94fe06137f 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-mapping.component.html
+++ b/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-mapping.component.html
@@ -25,7 +25,7 @@
-
-
+
device-profile.snmp.please-add-mapping-config
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-mapping.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-mapping.component.ts
index 5543bf6b11..428eb6b86e 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-mapping.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/device/snmp/snmp-device-profile-mapping.component.ts
@@ -18,19 +18,20 @@ import { Component, forwardRef, Input, OnDestroy, OnInit } from '@angular/core';
import {
AbstractControl,
ControlValueAccessor,
+ NG_VALIDATORS,
+ NG_VALUE_ACCESSOR,
UntypedFormArray,
UntypedFormBuilder,
UntypedFormGroup,
- NG_VALIDATORS,
- NG_VALUE_ACCESSOR,
ValidationErrors,
Validator,
Validators
} from '@angular/forms';
import { SnmpMapping } from '@shared/models/device.models';
-import { Subscription } from 'rxjs';
+import { Subject } from 'rxjs';
import { DataType, DataTypeTranslationMap } from '@shared/models/constants';
import { isUndefinedOrNull } from '@core/utils';
+import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'tb-snmp-device-profile-mapping',
@@ -60,7 +61,7 @@ export class SnmpDeviceProfileMappingComponent implements OnInit, OnDestroy, Con
private readonly oidPattern: RegExp = /^\.?([0-2])((\.0)|(\.[1-9][0-9]*))*$/;
- private valueChange$: Subscription = null;
+ private destroy$ = new Subject
();
private propagateChange = (v: any) => { };
constructor(private fb: UntypedFormBuilder) { }
@@ -69,12 +70,14 @@ export class SnmpDeviceProfileMappingComponent implements OnInit, OnDestroy, Con
this.mappingsConfigForm = this.fb.group({
mappings: this.fb.array([])
});
+ this.mappingsConfigForm.valueChanges.pipe(
+ takeUntil(this.destroy$)
+ ).subscribe(() => this.updateModel());
}
ngOnDestroy() {
- if (this.valueChange$) {
- this.valueChange$.unsubscribe();
- }
+ this.destroy$.next();
+ this.destroy$.complete();
}
registerOnChange(fn: any) {
@@ -100,38 +103,36 @@ export class SnmpDeviceProfileMappingComponent implements OnInit, OnDestroy, Con
}
writeValue(mappings: SnmpMapping[]) {
- if (this.valueChange$) {
- this.valueChange$.unsubscribe();
- }
- const mappingsControl: Array = [];
- if (mappings) {
- mappings.forEach((config) => {
- mappingsControl.push(this.createdFormGroup(config));
- });
- }
- this.mappingsConfigForm.setControl('mappings', this.fb.array(mappingsControl));
- if (!mappings || !mappings.length) {
- this.addMappingConfig();
- }
- if (this.disabled) {
- this.mappingsConfigForm.disable({emitEvent: false});
+ if (mappings?.length === this.mappingsConfigFormArray.length) {
+ this.mappingsConfigFormArray.patchValue(mappings, {emitEvent: false});
} else {
- this.mappingsConfigForm.enable({emitEvent: false});
+ const mappingsControl: Array = [];
+ if (mappings) {
+ mappings.forEach((config) => {
+ mappingsControl.push(this.createdFormGroup(config));
+ });
+ }
+ this.mappingsConfigForm.setControl('mappings', this.fb.array(mappingsControl), {emitEvent: false});
+ if (!mappings || !mappings.length) {
+ this.addMappingConfig();
+ }
+ if (this.disabled) {
+ this.mappingsConfigForm.disable({emitEvent: false});
+ } else {
+ this.mappingsConfigForm.enable({emitEvent: false});
+ }
}
- this.valueChange$ = this.mappingsConfigForm.valueChanges.subscribe(() => {
- this.updateModel();
- });
if (!this.disabled && !this.mappingsConfigForm.valid) {
this.updateModel();
}
}
- mappingsConfigFormArray(): UntypedFormArray {
+ get mappingsConfigFormArray(): UntypedFormArray {
return this.mappingsConfigForm.get('mappings') as UntypedFormArray;
}
public addMappingConfig() {
- this.mappingsConfigFormArray().push(this.createdFormGroup());
+ this.mappingsConfigFormArray.push(this.createdFormGroup());
this.mappingsConfigForm.updateValueAndValidity();
if (!this.mappingsConfigForm.valid) {
this.updateModel();
@@ -139,7 +140,7 @@ export class SnmpDeviceProfileMappingComponent implements OnInit, OnDestroy, Con
}
public removeMappingConfig(index: number) {
- this.mappingsConfigFormArray().removeAt(index);
+ this.mappingsConfigFormArray.removeAt(index);
}
private createdFormGroup(value?: SnmpMapping): UntypedFormGroup {
diff --git a/ui-ngx/src/app/modules/home/components/profile/queue/tenant-profile-queues.component.ts b/ui-ngx/src/app/modules/home/components/profile/queue/tenant-profile-queues.component.ts
index 2a29ec2e15..c3ff3ccc4c 100644
--- a/ui-ngx/src/app/modules/home/components/profile/queue/tenant-profile-queues.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/queue/tenant-profile-queues.component.ts
@@ -30,10 +30,11 @@ import {
import { Store } from '@ngrx/store';
import { AppState } from '@app/core/core.state';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
-import { Subscription } from 'rxjs';
+import { Subject } from 'rxjs';
import { QueueInfo } from '@shared/models/queue.models';
import { UtilsService } from '@core/services/utils.service';
import { guid } from '@core/utils';
+import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'tb-tenant-profile-queues',
@@ -70,8 +71,7 @@ export class TenantProfileQueuesComponent implements ControlValueAccessor, Valid
@Input()
disabled: boolean;
- private valueChangeSubscription$: Subscription = null;
-
+ private destroy$ = new Subject();
private propagateChange = (v: any) => { };
constructor(private store: Store,
@@ -83,12 +83,6 @@ export class TenantProfileQueuesComponent implements ControlValueAccessor, Valid
this.propagateChange = fn;
}
- ngOnDestroy() {
- if (this.valueChangeSubscription$) {
- this.valueChangeSubscription$.unsubscribe();
- }
- }
-
registerOnTouched(fn: any): void {
}
@@ -96,6 +90,15 @@ export class TenantProfileQueuesComponent implements ControlValueAccessor, Valid
this.tenantProfileQueuesFormGroup = this.fb.group({
queues: this.fb.array([])
});
+
+ this.tenantProfileQueuesFormGroup.valueChanges.pipe(
+ takeUntil(this.destroy$)
+ ).subscribe(() => this.updateModel());
+ }
+
+ ngOnDestroy() {
+ this.destroy$.next();
+ this.destroy$.complete();
}
get queuesFormArray(): UntypedFormArray {
@@ -112,30 +115,28 @@ export class TenantProfileQueuesComponent implements ControlValueAccessor, Valid
}
writeValue(queues: Array | null): void {
- if (this.valueChangeSubscription$) {
- this.valueChangeSubscription$.unsubscribe();
- }
- const queuesControls: Array = [];
- if (queues) {
- queues.forEach((queue, index) => {
- if (!queue.id) {
- if (!this.idMap[index]) {
- this.idMap.push(guid());
- }
- queue.id = this.idMap[index];
- }
- queuesControls.push(this.fb.control(queue, [Validators.required]));
- });
- }
- this.tenantProfileQueuesFormGroup.setControl('queues', this.fb.array(queuesControls));
- if (this.disabled) {
- this.tenantProfileQueuesFormGroup.disable({emitEvent: false});
+ if (queues.length === this.queuesFormArray.length) {
+ this.queuesFormArray.patchValue(queues, {emitEvent: false});
} else {
- this.tenantProfileQueuesFormGroup.enable({emitEvent: false});
+ const queuesControls: Array = [];
+ if (queues) {
+ queues.forEach((queue, index) => {
+ if (!queue.id) {
+ if (!this.idMap[index]) {
+ this.idMap.push(guid());
+ }
+ queue.id = this.idMap[index];
+ }
+ queuesControls.push(this.fb.control(queue, [Validators.required]));
+ });
+ }
+ this.tenantProfileQueuesFormGroup.setControl('queues', this.fb.array(queuesControls), {emitEvent: false});
+ if (this.disabled) {
+ this.tenantProfileQueuesFormGroup.disable({emitEvent: false});
+ } else {
+ this.tenantProfileQueuesFormGroup.enable({emitEvent: false});
+ }
}
- this.valueChangeSubscription$ = this.tenantProfileQueuesFormGroup.valueChanges.subscribe(() =>
- this.updateModel()
- );
}
public trackByQueue(index: number, queueControl: AbstractControl) {
diff --git a/ui-ngx/src/app/modules/home/components/relation/relation-filters.component.html b/ui-ngx/src/app/modules/home/components/relation/relation-filters.component.html
index 16222675db..f1d390bc77 100644
--- a/ui-ngx/src/app/modules/home/components/relation/relation-filters.component.html
+++ b/ui-ngx/src/app/modules/home/components/relation/relation-filters.component.html
@@ -17,17 +17,17 @@
-->