From e9967306b67a31778312059354457bb6adf92021 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Wed, 10 Jul 2024 18:14:38 +0300 Subject: [PATCH 1/4] Added emmition of default values on Connector with basic config creation --- .../broker-config-control.component.html | 2 +- .../broker-config-control.component.ts | 18 +++++++++++++----- .../mqtt-basic-config.component.ts | 10 ++++++---- .../security-config.component.ts | 11 ++++++++++- .../server-config/server-config.component.ts | 12 ++++++++++-- .../workers-config-control.component.ts | 15 +++++++++++++-- .../gateway/gateway-connectors.component.ts | 5 ----- 7 files changed, 53 insertions(+), 20 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.html index f70ed366e1..7e25033e84 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.html @@ -74,7 +74,7 @@ aria-label="Generate" matTooltip="{{ 'gateway.generate-client-id' | translate }}" matTooltipPosition="above" - (click)="generate('clientId')" + (click)="generate()" *ngIf="!brokerConfigFormGroup.get('clientId').value"> autorenew diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts index 13f5c7c77e..449d2ad1a5 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { ChangeDetectionStrategy, Component, forwardRef, OnDestroy } from '@angular/core'; +import { AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, OnDestroy } from '@angular/core'; import { ControlValueAccessor, FormBuilder, @@ -61,7 +61,7 @@ import { Subject } from 'rxjs'; } ] }) -export class BrokerConfigControlComponent implements ControlValueAccessor, Validator, OnDestroy { +export class BrokerConfigControlComponent implements ControlValueAccessor, Validator, AfterViewInit, OnDestroy { brokerConfigFormGroup: UntypedFormGroup; mqttVersions = MqttVersions; portLimits = PortLimits; @@ -78,7 +78,7 @@ export class BrokerConfigControlComponent implements ControlValueAccessor, Valid host: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], port: [null, [Validators.required, Validators.min(PortLimits.MIN), Validators.max(PortLimits.MAX)]], version: [5, []], - clientId: ['', [Validators.pattern(noLeadTrailSpacesRegex)]], + clientId: ['tb_gw_' + generateSecret(5), [Validators.pattern(noLeadTrailSpacesRegex)]], security: [] }); @@ -101,13 +101,17 @@ export class BrokerConfigControlComponent implements ControlValueAccessor, Valid return ''; } + ngAfterViewInit(): void { + this.emitDefaultValue(); + } + ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); } - generate(formControlName: string): void { - this.brokerConfigFormGroup.get(formControlName)?.patchValue('tb_gw_' + generateSecret(5)); + generate(): void { + this.brokerConfigFormGroup.get('clientId').patchValue('tb_gw_' + generateSecret(5)); } registerOnChange(fn: (value: string) => void): void { @@ -127,4 +131,8 @@ export class BrokerConfigControlComponent implements ControlValueAccessor, Valid brokerConfigFormGroup: {valid: false} }; } + + private emitDefaultValue(): void { + this.onChange(this.brokerConfigFormGroup.value); + }; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts index 650ecef68a..57436daafd 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts @@ -114,10 +114,12 @@ export class MqttBasicConfigComponent implements ControlValueAccessor, Validator writeValue(basicConfig: ConnectorBaseConfig): void { const editedBase = { - workers: { - maxNumberOfWorkers: basicConfig.broker?.maxNumberOfWorkers, - maxMessageNumberPerWorker: basicConfig.broker?.maxMessageNumberPerWorker, - }, + workers: basicConfig.broker + ? { + maxNumberOfWorkers: basicConfig.broker.maxNumberOfWorkers, + maxMessageNumberPerWorker: basicConfig.broker.maxMessageNumberPerWorker, + } + : {}, dataMapping: basicConfig.dataMapping || [], broker: basicConfig.broker || {}, requestsMapping: Array.isArray(basicConfig.requestsMapping) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts index 38a66daafc..a6c147a3e7 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts @@ -15,6 +15,7 @@ /// import { + AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, @@ -67,7 +68,7 @@ import { CommonModule } from '@angular/common'; SharedModule, ] }) -export class SecurityConfigComponent implements ControlValueAccessor, OnInit, OnDestroy { +export class SecurityConfigComponent implements ControlValueAccessor, OnInit, AfterViewInit, OnDestroy { @Input() title = 'gateway.security'; @@ -112,6 +113,10 @@ export class SecurityConfigComponent implements ControlValueAccessor, OnInit, On ).subscribe((type) => this.updateValidators(type)); } + ngAfterViewInit(): void { + this.emitDefaultValue(); + } + ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); @@ -143,6 +148,10 @@ export class SecurityConfigComponent implements ControlValueAccessor, OnInit, On this.onTouched = fn; } + private emitDefaultValue(): void { + this.onChange(this.securityFormGroup.value); + }; + private updateValidators(type: SecurityType): void { if (type) { this.securityFormGroup.get('username').disable({emitEvent: false}); diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.ts index 98a36182a6..4f8e563d86 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { ChangeDetectionStrategy, Component, forwardRef, OnDestroy } from '@angular/core'; +import { AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, OnDestroy } from '@angular/core'; import { ControlValueAccessor, FormBuilder, @@ -61,7 +61,7 @@ import { takeUntil } from 'rxjs/operators'; SecurityConfigComponent, ] }) -export class ServerConfigComponent implements ControlValueAccessor, Validator, OnDestroy { +export class ServerConfigComponent implements ControlValueAccessor, Validator, AfterViewInit, OnDestroy { securityPolicyTypes = SecurityPolicyTypes; serverConfigFormGroup: UntypedFormGroup; @@ -92,6 +92,10 @@ export class ServerConfigComponent implements ControlValueAccessor, Validator, O }); } + ngAfterViewInit(): void { + this.emitDefaultValue(); + } + ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); @@ -114,4 +118,8 @@ export class ServerConfigComponent implements ControlValueAccessor, Validator, O writeValue(serverConfig: ServerConfig): void { this.serverConfigFormGroup.patchValue(serverConfig, {emitEvent: false}); } + + private emitDefaultValue(): void { + this.onChange(this.serverConfigFormGroup.value); + }; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts index 9a37bdb07c..be6542963f 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts @@ -15,6 +15,7 @@ /// import { + AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, @@ -25,7 +26,9 @@ import { FormBuilder, NG_VALIDATORS, NG_VALUE_ACCESSOR, - UntypedFormGroup, ValidationErrors, Validator, + UntypedFormGroup, + ValidationErrors, + Validator, Validators } from '@angular/forms'; import { SharedModule } from '@shared/shared.module'; @@ -56,7 +59,7 @@ import { takeUntil } from 'rxjs/operators'; } ] }) -export class WorkersConfigControlComponent implements OnDestroy, ControlValueAccessor, Validator { +export class WorkersConfigControlComponent implements AfterViewInit, OnDestroy, ControlValueAccessor, Validator { workersConfigFormGroup: UntypedFormGroup; @@ -77,6 +80,10 @@ export class WorkersConfigControlComponent implements OnDestroy, ControlValueAcc }); } + ngAfterViewInit(): void { + this.emitDefaultValue(); + } + ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); @@ -99,4 +106,8 @@ export class WorkersConfigControlComponent implements OnDestroy, ControlValueAcc workersConfigFormGroup: {valid: false} }; } + + private emitDefaultValue(): void { + this.onChange(this.workersConfigFormGroup.value); + }; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.ts index 14a8c15c00..5eeffd62cf 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.ts @@ -551,7 +551,6 @@ export class GatewayConnectorComponent extends PageComponent implements AfterVie } value.basicConfig = value.configurationJson; this.updateConnector(value); - this.generate('basicConfig.broker.clientId'); setTimeout(() => this.saveConnector()); } }); @@ -559,10 +558,6 @@ export class GatewayConnectorComponent extends PageComponent implements AfterVie }); } - generate(formControlName: string): void { - this.connectorForm.get(formControlName)?.patchValue('tb_gw_' + generateSecret(5)); - } - uniqNameRequired(): ValidatorFn { return (c: UntypedFormControl) => { const newName = c.value.trim().toLowerCase(); From 01fb50d73ac6592b8ff5d26c8f2d6b862511bd20 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Thu, 11 Jul 2024 11:57:41 +0300 Subject: [PATCH 2/4] Revert "Added emmition of default values on Connector with basic config creation" This reverts commit e9967306b67a31778312059354457bb6adf92021. --- .../broker-config-control.component.html | 2 +- .../broker-config-control.component.ts | 18 +++++------------- .../mqtt-basic-config.component.ts | 10 ++++------ .../security-config.component.ts | 11 +---------- .../server-config/server-config.component.ts | 12 ++---------- .../workers-config-control.component.ts | 15 ++------------- .../gateway/gateway-connectors.component.ts | 5 +++++ 7 files changed, 20 insertions(+), 53 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.html index 7e25033e84..f70ed366e1 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.html @@ -74,7 +74,7 @@ aria-label="Generate" matTooltip="{{ 'gateway.generate-client-id' | translate }}" matTooltipPosition="above" - (click)="generate()" + (click)="generate('clientId')" *ngIf="!brokerConfigFormGroup.get('clientId').value"> autorenew diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts index 449d2ad1a5..13f5c7c77e 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, OnDestroy } from '@angular/core'; +import { ChangeDetectionStrategy, Component, forwardRef, OnDestroy } from '@angular/core'; import { ControlValueAccessor, FormBuilder, @@ -61,7 +61,7 @@ import { Subject } from 'rxjs'; } ] }) -export class BrokerConfigControlComponent implements ControlValueAccessor, Validator, AfterViewInit, OnDestroy { +export class BrokerConfigControlComponent implements ControlValueAccessor, Validator, OnDestroy { brokerConfigFormGroup: UntypedFormGroup; mqttVersions = MqttVersions; portLimits = PortLimits; @@ -78,7 +78,7 @@ export class BrokerConfigControlComponent implements ControlValueAccessor, Valid host: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], port: [null, [Validators.required, Validators.min(PortLimits.MIN), Validators.max(PortLimits.MAX)]], version: [5, []], - clientId: ['tb_gw_' + generateSecret(5), [Validators.pattern(noLeadTrailSpacesRegex)]], + clientId: ['', [Validators.pattern(noLeadTrailSpacesRegex)]], security: [] }); @@ -101,17 +101,13 @@ export class BrokerConfigControlComponent implements ControlValueAccessor, Valid return ''; } - ngAfterViewInit(): void { - this.emitDefaultValue(); - } - ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); } - generate(): void { - this.brokerConfigFormGroup.get('clientId').patchValue('tb_gw_' + generateSecret(5)); + generate(formControlName: string): void { + this.brokerConfigFormGroup.get(formControlName)?.patchValue('tb_gw_' + generateSecret(5)); } registerOnChange(fn: (value: string) => void): void { @@ -131,8 +127,4 @@ export class BrokerConfigControlComponent implements ControlValueAccessor, Valid brokerConfigFormGroup: {valid: false} }; } - - private emitDefaultValue(): void { - this.onChange(this.brokerConfigFormGroup.value); - }; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts index 57436daafd..650ecef68a 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts @@ -114,12 +114,10 @@ export class MqttBasicConfigComponent implements ControlValueAccessor, Validator writeValue(basicConfig: ConnectorBaseConfig): void { const editedBase = { - workers: basicConfig.broker - ? { - maxNumberOfWorkers: basicConfig.broker.maxNumberOfWorkers, - maxMessageNumberPerWorker: basicConfig.broker.maxMessageNumberPerWorker, - } - : {}, + workers: { + maxNumberOfWorkers: basicConfig.broker?.maxNumberOfWorkers, + maxMessageNumberPerWorker: basicConfig.broker?.maxMessageNumberPerWorker, + }, dataMapping: basicConfig.dataMapping || [], broker: basicConfig.broker || {}, requestsMapping: Array.isArray(basicConfig.requestsMapping) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts index a6c147a3e7..38a66daafc 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts @@ -15,7 +15,6 @@ /// import { - AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, @@ -68,7 +67,7 @@ import { CommonModule } from '@angular/common'; SharedModule, ] }) -export class SecurityConfigComponent implements ControlValueAccessor, OnInit, AfterViewInit, OnDestroy { +export class SecurityConfigComponent implements ControlValueAccessor, OnInit, OnDestroy { @Input() title = 'gateway.security'; @@ -113,10 +112,6 @@ export class SecurityConfigComponent implements ControlValueAccessor, OnInit, Af ).subscribe((type) => this.updateValidators(type)); } - ngAfterViewInit(): void { - this.emitDefaultValue(); - } - ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); @@ -148,10 +143,6 @@ export class SecurityConfigComponent implements ControlValueAccessor, OnInit, Af this.onTouched = fn; } - private emitDefaultValue(): void { - this.onChange(this.securityFormGroup.value); - }; - private updateValidators(type: SecurityType): void { if (type) { this.securityFormGroup.get('username').disable({emitEvent: false}); diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.ts index 4f8e563d86..98a36182a6 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, OnDestroy } from '@angular/core'; +import { ChangeDetectionStrategy, Component, forwardRef, OnDestroy } from '@angular/core'; import { ControlValueAccessor, FormBuilder, @@ -61,7 +61,7 @@ import { takeUntil } from 'rxjs/operators'; SecurityConfigComponent, ] }) -export class ServerConfigComponent implements ControlValueAccessor, Validator, AfterViewInit, OnDestroy { +export class ServerConfigComponent implements ControlValueAccessor, Validator, OnDestroy { securityPolicyTypes = SecurityPolicyTypes; serverConfigFormGroup: UntypedFormGroup; @@ -92,10 +92,6 @@ export class ServerConfigComponent implements ControlValueAccessor, Validator, A }); } - ngAfterViewInit(): void { - this.emitDefaultValue(); - } - ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); @@ -118,8 +114,4 @@ export class ServerConfigComponent implements ControlValueAccessor, Validator, A writeValue(serverConfig: ServerConfig): void { this.serverConfigFormGroup.patchValue(serverConfig, {emitEvent: false}); } - - private emitDefaultValue(): void { - this.onChange(this.serverConfigFormGroup.value); - }; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts index be6542963f..9a37bdb07c 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts @@ -15,7 +15,6 @@ /// import { - AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, @@ -26,9 +25,7 @@ import { FormBuilder, NG_VALIDATORS, NG_VALUE_ACCESSOR, - UntypedFormGroup, - ValidationErrors, - Validator, + UntypedFormGroup, ValidationErrors, Validator, Validators } from '@angular/forms'; import { SharedModule } from '@shared/shared.module'; @@ -59,7 +56,7 @@ import { takeUntil } from 'rxjs/operators'; } ] }) -export class WorkersConfigControlComponent implements AfterViewInit, OnDestroy, ControlValueAccessor, Validator { +export class WorkersConfigControlComponent implements OnDestroy, ControlValueAccessor, Validator { workersConfigFormGroup: UntypedFormGroup; @@ -80,10 +77,6 @@ export class WorkersConfigControlComponent implements AfterViewInit, OnDestroy, }); } - ngAfterViewInit(): void { - this.emitDefaultValue(); - } - ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); @@ -106,8 +99,4 @@ export class WorkersConfigControlComponent implements AfterViewInit, OnDestroy, workersConfigFormGroup: {valid: false} }; } - - private emitDefaultValue(): void { - this.onChange(this.workersConfigFormGroup.value); - }; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.ts index 5eeffd62cf..14a8c15c00 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.ts @@ -551,6 +551,7 @@ export class GatewayConnectorComponent extends PageComponent implements AfterVie } value.basicConfig = value.configurationJson; this.updateConnector(value); + this.generate('basicConfig.broker.clientId'); setTimeout(() => this.saveConnector()); } }); @@ -558,6 +559,10 @@ export class GatewayConnectorComponent extends PageComponent implements AfterVie }); } + generate(formControlName: string): void { + this.connectorForm.get(formControlName)?.patchValue('tb_gw_' + generateSecret(5)); + } + uniqNameRequired(): ValidatorFn { return (c: UntypedFormControl) => { const newName = c.value.trim().toLowerCase(); From 4d69299ff619afc14493fffadb097076374714a7 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Thu, 11 Jul 2024 11:58:13 +0300 Subject: [PATCH 3/4] refactoring --- .../broker-config-control.component.ts | 2 +- .../mqtt-basic-config.component.ts | 20 ++++++++++--------- .../workers-config-control.component.ts | 4 +++- .../dialog/add-connector-dialog.component.ts | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts index 13f5c7c77e..83ece09cde 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts @@ -78,7 +78,7 @@ export class BrokerConfigControlComponent implements ControlValueAccessor, Valid host: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], port: [null, [Validators.required, Validators.min(PortLimits.MIN), Validators.max(PortLimits.MAX)]], version: [5, []], - clientId: ['', [Validators.pattern(noLeadTrailSpacesRegex)]], + clientId: ['tb_gw_' + generateSecret(5), [Validators.pattern(noLeadTrailSpacesRegex)]], security: [] }); diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts index 650ecef68a..557d218581 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts @@ -113,16 +113,18 @@ export class MqttBasicConfigComponent implements ControlValueAccessor, Validator } writeValue(basicConfig: ConnectorBaseConfig): void { + const { broker, dataMapping = [], requestsMapping } = basicConfig; + const editedBase = { - workers: { - maxNumberOfWorkers: basicConfig.broker?.maxNumberOfWorkers, - maxMessageNumberPerWorker: basicConfig.broker?.maxMessageNumberPerWorker, - }, - dataMapping: basicConfig.dataMapping || [], - broker: basicConfig.broker || {}, - requestsMapping: Array.isArray(basicConfig.requestsMapping) - ? basicConfig.requestsMapping - : this.getRequestDataArray(basicConfig.requestsMapping), + workers: broker ? { + maxNumberOfWorkers: broker.maxNumberOfWorkers, + maxMessageNumberPerWorker: broker.maxMessageNumberPerWorker, + } : {}, + dataMapping: dataMapping || [], + broker: broker || {}, + requestsMapping: Array.isArray(requestsMapping) + ? requestsMapping + : this.getRequestDataArray(requestsMapping), }; this.basicFormGroup.setValue(editedBase, {emitEvent: false}); diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts index 9a37bdb07c..988851f4d8 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts @@ -25,7 +25,9 @@ import { FormBuilder, NG_VALIDATORS, NG_VALUE_ACCESSOR, - UntypedFormGroup, ValidationErrors, Validator, + UntypedFormGroup, + ValidationErrors, + Validator, Validators } from '@angular/forms'; import { SharedModule } from '@shared/shared.module'; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/add-connector-dialog.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/add-connector-dialog.component.ts index 7cdfbf5808..5a1b5d2a1b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/add-connector-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/add-connector-dialog.component.ts @@ -33,7 +33,7 @@ import { } from '@home/components/widget/lib/gateway/gateway-widget.models'; import { Subject } from 'rxjs'; import { ResourcesService } from '@core/services/resources.service'; -import { takeUntil, tap } from "rxjs/operators"; +import { takeUntil, tap } from 'rxjs/operators'; @Component({ selector: 'tb-add-connector-dialog', From 82a6364c8be894e35d3d9bbc2426b82921fad50d Mon Sep 17 00:00:00 2001 From: mpetrov Date: Thu, 11 Jul 2024 12:04:08 +0300 Subject: [PATCH 4/4] refactoring --- .../mqtt-basic-config/mqtt-basic-config.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts index 557d218581..1b37ff5bf7 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts @@ -116,7 +116,7 @@ export class MqttBasicConfigComponent implements ControlValueAccessor, Validator const { broker, dataMapping = [], requestsMapping } = basicConfig; const editedBase = { - workers: broker ? { + workers: broker && (broker.maxNumberOfWorkers || broker.maxMessageNumberPerWorker) ? { maxNumberOfWorkers: broker.maxNumberOfWorkers, maxMessageNumberPerWorker: broker.maxMessageNumberPerWorker, } : {},