Added emmition of default values on Connector with basic config creation

This commit is contained in:
mpetrov 2024-07-10 18:14:38 +03:00
parent 99d4eb0d9c
commit e9967306b6
7 changed files with 53 additions and 20 deletions

View File

@ -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">
<mat-icon>autorenew</mat-icon>
</button>

View File

@ -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);
};
}

View File

@ -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)

View File

@ -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});

View File

@ -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);
};
}

View File

@ -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);
};
}

View File

@ -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();