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 new file mode 100644 index 0000000000..a6c3a620dd --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.html @@ -0,0 +1,86 @@ + +
+
+
gateway.host
+
+ + + + warning + + +
+
+
+
gateway.port
+
+ + + + warning + + +
+
+
+
gateway.mqtt-version
+
+ + + {{ version.name }} + + +
+
+
+
gateway.client-id
+
+ + + + +
+
+ + +
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 new file mode 100644 index 0000000000..893fb30fde --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-config-control/broker-config-control.component.ts @@ -0,0 +1,136 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + ChangeDetectionStrategy, + Component, + forwardRef, + inject, + OnDestroy, +} from '@angular/core'; +import { + ControlValueAccessor, + FormBuilder, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + UntypedFormGroup, + ValidationErrors, + Validator, + Validators +} from '@angular/forms'; +import { + BrokerConfig, + MqttVersions, + noLeadTrailSpacesRegex, + PortLimits, +} from '@home/components/widget/lib/gateway/gateway-widget.models'; +import { SharedModule } from '@shared/shared.module'; +import { CommonModule } from '@angular/common'; +import { TranslateService } from '@ngx-translate/core'; +import { generateSecret } from '@core/utils'; +import { SecurityConfigComponent } from '@home/components/widget/lib/gateway/connectors-configuration/public-api'; +import { Subject } from 'rxjs'; + +@Component({ + selector: 'tb-broker-config-control', + templateUrl: './broker-config-control.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [ + CommonModule, + SharedModule, + SecurityConfigComponent, + ], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => BrokerConfigControlComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => BrokerConfigControlComponent), + multi: true + } + ] +}) +export class BrokerConfigControlComponent implements ControlValueAccessor, Validator, OnDestroy { + brokerConfigFormGroup: UntypedFormGroup; + mqttVersions = MqttVersions; + portLimits = PortLimits; + + onChange!: (value: string) => void; + onTouched!: () => void; + + private translate = inject(TranslateService); + private destroy$ = new Subject(); + + constructor(private fb: FormBuilder) { + this.brokerConfigFormGroup = this.fb.group({ + name: ['', []], + host: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + port: [null, [Validators.required, Validators.min(PortLimits.MIN), Validators.max(PortLimits.MAX)]], + version: [5, []], + clientId: ['', [Validators.pattern(noLeadTrailSpacesRegex)]], + security: [] + }); + + this.brokerConfigFormGroup.valueChanges.subscribe(value => { + this.onChange(value); + this.onTouched(); + }); + } + + get portErrorTooltip(): string { + if (this.brokerConfigFormGroup.get('port').hasError('required')) { + return this.translate.instant('gateway.port-required'); + } else if ( + this.brokerConfigFormGroup.get('port').hasError('min') || + this.brokerConfigFormGroup.get('port').hasError('max') + ) { + return this.translate.instant('gateway.port-limits-error', + {min: PortLimits.MIN, max: PortLimits.MAX}); + } + return ''; + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + generate(formControlName: string): void { + this.brokerConfigFormGroup.get(formControlName)?.patchValue('tb_gw_' + generateSecret(5)); + } + + registerOnChange(fn: (value: string) => void): void { + this.onChange = fn; + } + + registerOnTouched(fn: () => void): void { + this.onTouched = fn; + } + + writeValue(brokerConfig: BrokerConfig): void { + this.brokerConfigFormGroup.patchValue(brokerConfig, {emitEvent: false}); + } + + validate(): ValidationErrors | null { + return this.brokerConfigFormGroup.valid ? null : { + brokerConfigFormGroup: {valid: false} + }; + } +} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table/device-info-table.component.html similarity index 88% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table.component.html rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table/device-info-table.component.html index c3fe478ef2..bbaf616471 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table/device-info-table.component.html @@ -50,9 +50,10 @@ class="tb-error"> warning -
@@ -83,9 +84,10 @@ class="tb-error"> warning -
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table/device-info-table.component.scss similarity index 100% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table.component.scss rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table/device-info-table.component.scss diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table/device-info-table.component.ts similarity index 83% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table.component.ts rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table/device-info-table.component.ts index 8a40f25430..569f40b185 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/device-info-table/device-info-table.component.ts @@ -16,27 +16,19 @@ import { ChangeDetectionStrategy, - ChangeDetectorRef, Component, - ElementRef, forwardRef, Input, - NgZone, OnDestroy, OnInit, - ViewContainerRef } from '@angular/core'; import { PageComponent } from '@shared/components/page.component'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { TranslateService } from '@ngx-translate/core'; import { MatDialog } from '@angular/material/dialog'; -import { DialogService } from '@core/services/dialog.service'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; -import { Overlay } from '@angular/cdk/overlay'; -import { UtilsService } from '@core/services/utils.service'; -import { EntityService } from '@core/http/entity.service'; import { ControlValueAccessor, FormBuilder, @@ -50,6 +42,7 @@ import { import { DeviceInfoType, noLeadTrailSpacesRegex, + OPCUaSourceTypes, SourceTypes, SourceTypeTranslationsMap } from '@home/components/widget/lib/gateway/gateway-widget.models'; @@ -88,7 +81,7 @@ export class DeviceInfoTableComponent extends PageComponent implements ControlVa required = false; @Input() - sourceTypes: Array = Object.values(SourceTypes); + sourceTypes: Array = Object.values(SourceTypes); deviceInfoTypeValue: any; @@ -111,14 +104,6 @@ export class DeviceInfoTableComponent extends PageComponent implements ControlVa constructor(protected store: Store, public translate: TranslateService, public dialog: MatDialog, - private overlay: Overlay, - private viewContainerRef: ViewContainerRef, - private dialogService: DialogService, - private entityService: EntityService, - private utils: UtilsService, - private zone: NgZone, - private cd: ChangeDetectorRef, - private elementRef: ElementRef, private fb: FormBuilder) { super(store); } @@ -131,13 +116,13 @@ export class DeviceInfoTableComponent extends PageComponent implements ControlVa if (this.useSource) { this.mappingFormGroup.addControl('deviceNameExpressionSource', - this.fb.control(SourceTypes.MSG, [])); + this.fb.control(this.sourceTypes[0], [])); } if (this.deviceInfoType === DeviceInfoType.FULL) { if (this.useSource) { this.mappingFormGroup.addControl('deviceProfileExpressionSource', - this.fb.control(SourceTypes.MSG, [])); + this.fb.control(this.sourceTypes[0], [])); } this.mappingFormGroup.addControl('deviceProfileExpression', this.fb.control('', this.required ? @@ -154,6 +139,7 @@ export class DeviceInfoTableComponent extends PageComponent implements ControlVa ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); + super.ngOnDestroy(); } registerOnChange(fn: any): void { @@ -175,5 +161,4 @@ export class DeviceInfoTableComponent extends PageComponent implements ControlVa updateView(value: any) { this.propagateChange(value); } - } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/general-config/general-config.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/general-config/general-config.component.html new file mode 100644 index 0000000000..9c5ee12e6c --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/general-config/general-config.component.html @@ -0,0 +1,80 @@ + +
+
+
gateway.name
+
+ + + + warning + + +
+
+
+
gateway.connectors-table-class
+
+ + + +
+
+
+
gateway.connectors-table-key
+
+ + + +
+
+
+
gateway.logs-configuration
+
+ + + {{ 'gateway.enable-remote-logging' | translate }} + + +
+
+
gateway.remote-logging-level
+
+ + + {{ logLevel }} + + +
+
+
+
+ + + {{ 'gateway.send-change-data' | translate }} + + +
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/general-config/general-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/general-config/general-config.component.ts new file mode 100644 index 0000000000..320031a9fe --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/general-config/general-config.component.ts @@ -0,0 +1,52 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + ChangeDetectionStrategy, + Component, + inject, +} from '@angular/core'; +import { + ControlContainer, + FormGroup, +} from '@angular/forms'; +import { + ConnectorType, + GatewayLogLevel, +} from '@home/components/widget/lib/gateway/gateway-widget.models'; +import { SharedModule } from '@shared/shared.module'; +import { CommonModule } from '@angular/common'; + +@Component({ + selector: 'tb-general-config', + templateUrl: './general-config.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [ + CommonModule, + SharedModule, + ], +}) +export class GeneralConfigComponent { + gatewayLogLevel = Object.values(GatewayLogLevel); + connectorType = ConnectorType; + + get parentFormGroup(): FormGroup { + return this.parentContainer.control as FormGroup; + } + + private parentContainer = inject(ControlContainer); +} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel/mapping-data-keys-panel.component.html similarity index 71% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel.component.html rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel/mapping-data-keys-panel.component.html index 4c3a6434fd..8b95c0bd3a 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel/mapping-data-keys-panel.component.html @@ -26,14 +26,15 @@ -
{{ keyControl.get('key').value }}
- {{ '-' }} -
{{ valueTitle(keyControl.get('value').value) }}
+
+ {{ keyControl.get('key').value }}{{ '-' }} +
+
{{ valueTitle(keyControl) }}
+ *ngIf="keysType !== MappingKeysType.CUSTOM && keysType !== MappingKeysType.RPC_METHODS">
gateway.platform-side
@@ -53,12 +54,6 @@ class="tb-error"> warning -
-
@@ -71,18 +66,25 @@
- + - - {{ (rawData ? 'gateway.raw' : valueTypes.get(keyControl.get('type').value)?.name) | translate}} + + {{ (valueTypes.get(keyControl.get('type').value)?.name || valueTypes.get(keyControl.get('type').value)) | translate }} + + {{ 'gateway.raw' | translate }} +
- + - {{ valueTypes.get(valueType).name | translate }} + + {{ valueTypes.get(valueType).name || valueTypes.get(valueType) | translate }} + @@ -112,7 +114,8 @@
@@ -120,7 +123,7 @@
- +
gateway.key
@@ -152,7 +155,41 @@
- +
+
+
+
+ gateway.method-name +
+
+ + + + warning + + +
+
+
+ + + +
+ {{ 'gateway.arguments' | translate }}{{' (' + keyControl.get('arguments').value?.length + ')'}} +
+
+
+ + + +
+
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel/mapping-data-keys-panel.component.scss similarity index 100% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel.component.scss rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel/mapping-data-keys-panel.component.scss diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel/mapping-data-keys-panel.component.ts similarity index 64% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel.component.ts rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel/mapping-data-keys-panel.component.ts index 40ee2728bd..7867a7213f 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel/mapping-data-keys-panel.component.ts @@ -23,6 +23,8 @@ import { } from '@angular/core'; import { AbstractControl, + FormControl, + FormGroup, UntypedFormArray, UntypedFormBuilder, Validators @@ -39,7 +41,9 @@ import { MappingKeysType, MappingValueType, mappingValueTypesMap, - noLeadTrailSpacesRegex + noLeadTrailSpacesRegex, + OPCUaSourceTypes, + RpcMethodsMapping, } from '@home/components/widget/lib/gateway/gateway-widget.models'; @Component({ @@ -66,7 +70,16 @@ export class MappingDataKeysPanelComponent extends PageComponent implements OnIn keys: Array | {[key: string]: any}; @Input() - keysType: string; + keysType: MappingKeysType; + + @Input() + valueTypeKeys: Array = Object.values(MappingValueType); + + @Input() + valueTypeEnum = MappingValueType; + + @Input() + valueTypes: Map = mappingValueTypesMap; @Input() @coerceBoolean() @@ -76,16 +89,10 @@ export class MappingDataKeysPanelComponent extends PageComponent implements OnIn popover: TbPopoverComponent; @Output() - keysDataApplied = new EventEmitter | {[key: string]: any}>(); - - valueTypeKeys = Object.values(MappingValueType); + keysDataApplied = new EventEmitter | {[key: string]: unknown}>(); MappingKeysType = MappingKeysType; - valueTypeEnum = MappingValueType; - - valueTypes = mappingValueTypesMap; - dataKeyType: DataKeyType; keysListFormArray: UntypedFormArray; @@ -97,8 +104,8 @@ export class MappingDataKeysPanelComponent extends PageComponent implements OnIn super(store); } - ngOnInit() { - this.keysListFormArray = this.prepareKeysFormArray(this.keys) + ngOnInit(): void { + this.keysListFormArray = this.prepareKeysFormArray(this.keys); } trackByKey(index: number, keyControl: AbstractControl): any { @@ -106,12 +113,21 @@ export class MappingDataKeysPanelComponent extends PageComponent implements OnIn } addKey(): void { - const dataKeyFormGroup = this.fb.group({ - key: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - value: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]] - }); - if (this.keysType !== MappingKeysType.CUSTOM) { - dataKeyFormGroup.addControl('type', this.fb.control(this.rawData ? 'raw' : MappingValueType.STRING)); + let dataKeyFormGroup: FormGroup; + if (this.keysType === MappingKeysType.RPC_METHODS) { + dataKeyFormGroup = this.fb.group({ + method: ['', [Validators.required]], + arguments: [[], []] + }); + } else { + dataKeyFormGroup = this.fb.group({ + key: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + value: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]] + }); + } + if (this.keysType !== MappingKeysType.CUSTOM && this.keysType !== MappingKeysType.RPC_METHODS) { + const controlValue = this.rawData ? 'raw' : this.valueTypeKeys[0]; + dataKeyFormGroup.addControl('type', this.fb.control(controlValue)); } this.keysListFormArray.push(dataKeyFormGroup); } @@ -124,11 +140,11 @@ export class MappingDataKeysPanelComponent extends PageComponent implements OnIn this.keysListFormArray.markAsDirty(); } - cancel() { + cancel(): void { this.popover?.hide(); } - applyKeysData() { + applyKeysData(): void { let keys = this.keysListFormArray.value; if (this.keysType === MappingKeysType.CUSTOM) { keys = {}; @@ -139,7 +155,7 @@ export class MappingDataKeysPanelComponent extends PageComponent implements OnIn this.keysDataApplied.emit(keys); } - private prepareKeysFormArray(keys: Array | {[key: string]: any}): UntypedFormArray { + private prepareKeysFormArray(keys: Array | {[key: string]: any}): UntypedFormArray { const keysControlGroups: Array = []; if (keys) { if (this.keysType === MappingKeysType.CUSTOM) { @@ -148,19 +164,28 @@ export class MappingDataKeysPanelComponent extends PageComponent implements OnIn }); } keys.forEach((keyData) => { - const { key, value, type } = keyData; - const dataKeyFormGroup = this.fb.group({ - key: [key, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - value: [value, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - type: [type, []] - }); + let dataKeyFormGroup: FormGroup; + if (this.keysType === MappingKeysType.RPC_METHODS) { + dataKeyFormGroup = this.fb.group({ + method: [keyData.method, [Validators.required]], + arguments: [[...keyData.arguments], []] + }); + } else { + const { key, value, type } = keyData; + dataKeyFormGroup = this.fb.group({ + key: [key, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + value: [value, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + type: [type, []] + }); + } keysControlGroups.push(dataKeyFormGroup); }); } return this.fb.array(keysControlGroups); } - valueTitle(value: any): string { + valueTitle(keyControl: FormControl): string { + const value = keyControl.get(this.keysType === MappingKeysType.RPC_METHODS ? 'method' : 'value').value; if (isDefinedAndNotNull(value)) { if (typeof value === 'object') { return JSON.stringify(value); @@ -169,5 +194,4 @@ export class MappingDataKeysPanelComponent extends PageComponent implements OnIn } return ''; } - } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.html similarity index 96% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table.component.html rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.html index e5c703d8d0..48e280bc67 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.html @@ -60,10 +60,12 @@
- + {{ column.title | translate }} - + {{ mapping[column.def] }} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.scss similarity index 100% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table.component.scss rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.scss diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.ts similarity index 57% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table.component.ts rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.ts index 4ef9695c65..02fcfac1a0 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.ts @@ -17,41 +17,49 @@ import { AfterViewInit, ChangeDetectionStrategy, - ChangeDetectorRef, Component, ElementRef, forwardRef, Input, - NgZone, OnDestroy, OnInit, ViewChild, - ViewContainerRef } from '@angular/core'; -import { PageComponent } from '@shared/components/page.component'; import { PageLink } from '@shared/models/page/page-link'; -import { Store } from '@ngrx/store'; -import { AppState } from '@core/core.state'; import { TranslateService } from '@ngx-translate/core'; import { MatDialog } from '@angular/material/dialog'; import { DialogService } from '@core/services/dialog.service'; import { BehaviorSubject, Observable, Subject } from 'rxjs'; -import { debounceTime, distinctUntilChanged, map, takeUntil } from 'rxjs/operators'; -import { Overlay } from '@angular/cdk/overlay'; -import { UtilsService } from '@core/services/utils.service'; -import { EntityService } from '@core/http/entity.service'; -import { ControlValueAccessor, FormBuilder, NG_VALUE_ACCESSOR, UntypedFormArray } from '@angular/forms'; +import { debounceTime, distinctUntilChanged, map, take, takeUntil } from 'rxjs/operators'; import { + ControlValueAccessor, + FormArray, + FormBuilder, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + UntypedFormArray, + ValidationErrors, + Validator, +} from '@angular/forms'; +import { + ConnectorMapping, + ConverterConnectorMapping, ConvertorTypeTranslationsMap, + DeviceConnectorMapping, MappingInfo, MappingType, MappingTypeTranslationsMap, + MappingValue, + RequestMappingData, RequestType, RequestTypesTranslationsMap } from '@home/components/widget/lib/gateway/gateway-widget.models'; import { CollectionViewer, DataSource } from '@angular/cdk/collections'; import { MappingDialogComponent } from '@home/components/widget/lib/gateway/dialog/mapping-dialog.component'; import { isDefinedAndNotNull, isUndefinedOrNull } from '@core/utils'; +import { coerceBoolean } from '@shared/decorators/coercion'; +import { SharedModule } from '@shared/shared.module'; +import { CommonModule } from '@angular/common'; @Component({ selector: 'tb-mapping-table', @@ -63,10 +71,28 @@ import { isDefinedAndNotNull, isUndefinedOrNull } from '@core/utils'; provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => MappingTableComponent), multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => MappingTableComponent), + multi: true } - ] + ], + standalone: true, + imports: [CommonModule, SharedModule] }) -export class MappingTableComponent extends PageComponent implements ControlValueAccessor, AfterViewInit, OnInit, OnDestroy { +export class MappingTableComponent implements ControlValueAccessor, Validator, AfterViewInit, OnInit, OnDestroy { + @coerceBoolean() + @Input() required = false; + + @Input() + set mappingType(value: MappingType) { + if (this.mappingTypeValue !== value) { + this.mappingTypeValue = value; + } + } + + @ViewChild('searchInput') searchInputField: ElementRef; mappingTypeTranslationsMap = MappingTypeTranslationsMap; mappingTypeEnum = MappingType; @@ -75,79 +101,48 @@ export class MappingTableComponent extends PageComponent implements ControlValue textSearchMode = false; dataSource: MappingDatasource; hidePageSize = false; - activeValue = false; dirtyValue = false; - - viewsInited = false; - mappingTypeValue: MappingType; + mappingFormGroup: UntypedFormArray; + textSearch = this.fb.control('', {nonNullable: true}); get mappingType(): MappingType { return this.mappingTypeValue; } - @Input() - set mappingType(value: MappingType) { - if (this.mappingTypeValue !== value) { - this.mappingTypeValue = value; - } - } - - @ViewChild('searchInput') searchInputField: ElementRef; - - mappingFormGroup: UntypedFormArray; - textSearch = this.fb.control('', {nonNullable: true}); + onChange: (value: string) => void = () => {}; + onTouched: () => void = () => {}; private destroy$ = new Subject(); - private propagateChange = (v: any) => {}; - constructor(protected store: Store, - public translate: TranslateService, + constructor(public translate: TranslateService, public dialog: MatDialog, - private overlay: Overlay, - private viewContainerRef: ViewContainerRef, private dialogService: DialogService, - private entityService: EntityService, - private utils: UtilsService, - private zone: NgZone, - private cd: ChangeDetectorRef, - private elementRef: ElementRef, private fb: FormBuilder) { - super(store); this.mappingFormGroup = this.fb.array([]); this.dirtyValue = !this.activeValue; this.dataSource = new MappingDatasource(); } - ngOnInit() { - if (this.mappingType === MappingType.DATA) { - this.mappingColumns.push( - {def: 'topicFilter', title: 'gateway.topic-filter'}, - {def: 'QoS', title: 'gateway.mqtt-qos'}, - {def: 'converter', title: 'gateway.payload-type'} - ) - } else { - this.mappingColumns.push( - {def: 'type', title: 'gateway.type'}, - {def: 'details', title: 'gateway.details'} - ); - } + ngOnInit(): void { + this.setMappingColumns(); this.displayedColumns.push(...this.mappingColumns.map(column => column.def), 'actions'); this.mappingFormGroup.valueChanges.pipe( takeUntil(this.destroy$) ).subscribe((value) => { this.updateTableData(value); - this.updateView(value); + this.onChange(value); + this.onTouched(); }); } - ngOnDestroy() { + ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); } - ngAfterViewInit() { + ngAfterViewInit(): void { this.textSearch.valueChanges.pipe( debounceTime(150), distinctUntilChanged((prev, current) => (prev ?? '') === current.trim()), @@ -158,55 +153,26 @@ export class MappingTableComponent extends PageComponent implements ControlValue }); } - registerOnChange(fn: any): void { - this.propagateChange = fn; + registerOnChange(fn: (value: string) => void): void { + this.onChange = fn; } - registerOnTouched(fn: any): void {} - - writeValue(config: any) { - if (isUndefinedOrNull(config)) { - config = this.mappingType === MappingType.REQUESTS ? {} : []; - } - let mappingConfigs = config; - if (this.mappingType === MappingType.REQUESTS) { - mappingConfigs = []; - - Object.keys(config).forEach((configKey) => { - for (let mapping of config[configKey]) { - mappingConfigs.push({ - requestType: configKey, - requestValue: mapping - }); - } - }); - } - this.mappingFormGroup.clear({emitEvent: false}); - for (let mapping of mappingConfigs) { - this.mappingFormGroup.push(this.fb.group(mapping), {emitEvent: false}); - } - this.updateTableData(mappingConfigs); + registerOnTouched(fn: () => void): void { + this.onTouched = fn; } - updateView(mappingConfigs: Array<{[key: string]: any}>) { - let config; - if (this.mappingType === MappingType.REQUESTS) { - config = {}; - for (let mappingConfig of mappingConfigs) { - if (config[mappingConfig.requestType]) { - config[mappingConfig.requestType].push(mappingConfig.requestValue); - } else { - config[mappingConfig.requestType] = [mappingConfig.requestValue]; - } - } - } else { - config = mappingConfigs; - } + writeValue(connectorMappings: ConnectorMapping[]): void { + (this.mappingFormGroup as FormArray).clear(); + this.pushDataAsFormArrays(connectorMappings) + } - this.propagateChange(config); + validate(): ValidationErrors | null { + return !this.required || this.mappingFormGroup.controls.length ? null : { + mappingFormGroup: {valid: false} + }; } - enterFilterMode() { + enterFilterMode(): void { this.textSearchMode = true; setTimeout(() => { this.searchInputField.nativeElement.focus(); @@ -214,18 +180,18 @@ export class MappingTableComponent extends PageComponent implements ControlValue }, 10); } - exitFilterMode() { + exitFilterMode(): void { this.updateTableData(this.mappingFormGroup.value); this.textSearchMode = false; this.textSearch.reset(); } - manageMapping($event: Event, index?: number) { + manageMapping($event: Event, index?: number): void { if ($event) { $event.stopPropagation(); } const value = isDefinedAndNotNull(index) ? this.mappingFormGroup.at(index).value : {}; - this.dialog.open(MappingDialogComponent, { + this.dialog.open(MappingDialogComponent, { disableClose: true, panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], data: { @@ -233,45 +199,23 @@ export class MappingTableComponent extends PageComponent implements ControlValue value, buttonTitle: isUndefinedOrNull(index) ? 'action.add' : 'action.apply' } - }).afterClosed().subscribe( - (res) => { + }).afterClosed() + .pipe(take(1), takeUntil(this.destroy$)) + .subscribe(res => { if (res) { if (isDefinedAndNotNull(index)) { this.mappingFormGroup.at(index).patchValue(res); } else { this.mappingFormGroup.push(this.fb.group(res)); } + this.mappingFormGroup.markAsDirty(); } - } - ); + }); } - updateTableData(value: Array<{[key: string]: any}>, textSearch?: string): void { - let tableValue = value; - if (this.mappingType === MappingType.DATA) { - tableValue = tableValue.map((value) => { - return { - topicFilter: value.topicFilter, - QoS: value.subscriptionQos, - converter: this.translate.instant(ConvertorTypeTranslationsMap.get(value.converter.type)) - }; - }); - } else { - tableValue = tableValue.map((value) => { - let details; - if (value.requestType === RequestType.ATTRIBUTE_UPDATE) { - details = value.requestValue.attributeFilter; - } else if (value.requestType === RequestType.SERVER_SIDE_RPC) { - details = value.requestValue.methodFilter; - } else { - details = value.requestValue.topicFilter; - } - return { - type: this.translate.instant(RequestTypesTranslationsMap.get(value.requestType)), - details - }; - }); - } + updateTableData(value: ConnectorMapping[], textSearch?: string): void { + let tableValue = + value.map((value: ConnectorMapping) => this.getMappingValue(value)); if (textSearch) { tableValue = tableValue.filter(value => Object.values(value).some(val => @@ -282,7 +226,7 @@ export class MappingTableComponent extends PageComponent implements ControlValue this.dataSource.loadMappings(tableValue); } - deleteMapping($event: Event, index: number) { + deleteMapping($event: Event, index: number): void { if ($event) { $event.stopPropagation(); } @@ -295,10 +239,76 @@ export class MappingTableComponent extends PageComponent implements ControlValue ).subscribe((result) => { if (result) { this.mappingFormGroup.removeAt(index); + this.mappingFormGroup.markAsDirty(); } }); } + private pushDataAsFormArrays(data: ConnectorMapping[]): void { + if (data?.length) { + data.forEach((mapping: ConnectorMapping) => this.mappingFormGroup.push(this.fb.control(mapping))); + } + } + + private getMappingValue(value: ConnectorMapping): MappingValue { + switch (this.mappingType) { + case MappingType.DATA: + return { + topicFilter: (value as ConverterConnectorMapping).topicFilter, + QoS: (value as ConverterConnectorMapping).subscriptionQos, + converter: this.translate.instant(ConvertorTypeTranslationsMap.get((value as ConverterConnectorMapping).converter?.type) || '') + }; + case MappingType.REQUESTS: + let details; + if ((value as RequestMappingData).requestType === RequestType.ATTRIBUTE_UPDATE) { + details = (value as RequestMappingData).requestValue.attributeFilter; + } else if ((value as RequestMappingData).requestType === RequestType.SERVER_SIDE_RPC) { + details = (value as RequestMappingData).requestValue.methodFilter; + } else { + details = (value as RequestMappingData).requestValue.topicFilter; + } + return { + requestType: (value as RequestMappingData).requestType, + type: this.translate.instant(RequestTypesTranslationsMap.get((value as RequestMappingData).requestType)), + details + }; + case MappingType.OPCUA: + const deviceNamePattern = (value as DeviceConnectorMapping).deviceInfo?.deviceNameExpression; + const deviceProfileExpression = (value as DeviceConnectorMapping).deviceInfo?.deviceProfileExpression; + const { deviceNodePattern } = value as DeviceConnectorMapping; + return { + deviceNodePattern, + deviceNamePattern, + deviceProfileExpression + }; + default: + return {} as MappingValue; + } + } + + private setMappingColumns(): void { + switch (this.mappingType) { + case MappingType.DATA: + this.mappingColumns.push( + { def: 'topicFilter', title: 'gateway.topic-filter' }, + { def: 'QoS', title: 'gateway.mqtt-qos' }, + { def: 'converter', title: 'gateway.payload-type' } + ); + break; + case MappingType.REQUESTS: + this.mappingColumns.push( + { def: 'type', title: 'gateway.type' }, + { def: 'details', title: 'gateway.details' } + ); + break; + case MappingType.OPCUA: + this.mappingColumns.push( + { def: 'deviceNodePattern', title: 'gateway.device-node' }, + { def: 'deviceNamePattern', title: 'gateway.device-name' }, + { def: 'deviceProfileExpression', title: 'gateway.device-profile' } + ); + } + } } export class MappingDatasource implements DataSource<{[key: string]: any}> { @@ -335,5 +345,4 @@ export class MappingDatasource implements DataSource<{[key: string]: any}> { map((mappings) => mappings.length) ); } - } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.html new file mode 100644 index 0000000000..8fecdd8618 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.html @@ -0,0 +1,24 @@ + + + + + + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+ 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 new file mode 100644 index 0000000000..a46d55fed4 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mqtt-basic-config/mqtt-basic-config.component.ts @@ -0,0 +1,170 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + ChangeDetectionStrategy, + Component, + forwardRef, + Input, + OnDestroy, + TemplateRef, +} from '@angular/core'; +import { + ControlValueAccessor, + FormBuilder, + FormGroup, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + ValidationErrors, + Validator, +} from '@angular/forms'; +import { + ConnectorBaseConfig, + ConnectorType, + MappingType, + RequestMappingData, + RequestType, +} from '@home/components/widget/lib/gateway/gateway-widget.models'; +import { SharedModule } from '@shared/shared.module'; +import { CommonModule } from '@angular/common'; +import { + BrokerConfigControlComponent, + MappingTableComponent, + SecurityConfigComponent, + WorkersConfigControlComponent, + GeneralConfigComponent +} from '@home/components/widget/lib/gateway/connectors-configuration/public-api'; +import { takeUntil } from 'rxjs/operators'; +import { Subject } from 'rxjs'; +import { isObject } from 'lodash'; + +@Component({ + selector: 'tb-mqtt-basic-config', + templateUrl: './mqtt-basic-config.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => MqttBasicConfigComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => MqttBasicConfigComponent), + multi: true + } + ], + standalone: true, + imports: [ + CommonModule, + SharedModule, + SecurityConfigComponent, + WorkersConfigControlComponent, + BrokerConfigControlComponent, + MappingTableComponent, + GeneralConfigComponent, + ], + styles: [` + :host { + height: 100%; + } + :host ::ng-deep { + .mat-mdc-tab-group, .mat-mdc-tab-body-wrapper { + height: 100%; + } + } + `], +}) + +export class MqttBasicConfigComponent implements ControlValueAccessor, Validator, OnDestroy { + @Input() generalTabContent: TemplateRef; + + mappingTypes = MappingType; + basicFormGroup: FormGroup; + + onChange!: (value: string) => void; + onTouched!: () => void; + + protected readonly connectorType = ConnectorType; + private destroy$ = new Subject(); + + constructor(private fb: FormBuilder) { + this.basicFormGroup = this.fb.group({ + dataMapping: [], + requestsMapping: [], + broker: [], + workers: [], + }); + + this.basicFormGroup.valueChanges + .pipe(takeUntil(this.destroy$)) + .subscribe(value => { + this.onChange(value); + this.onTouched(); + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + registerOnChange(fn: (value: string) => void): void { + this.onChange = fn; + } + + registerOnTouched(fn: () => void): void { + this.onTouched = fn; + } + + writeValue(basicConfig: ConnectorBaseConfig): void { + const editedBase = { + ...basicConfig, + workers: { + maxNumberOfWorkers: basicConfig.broker?.maxNumberOfWorkers, + maxMessageNumberPerWorker: basicConfig.broker?.maxMessageNumberPerWorker, + }, + requestsMapping: Array.isArray(basicConfig.requestsMapping) + ? basicConfig.requestsMapping + : this.getRequestDataArray(basicConfig.requestsMapping), + }; + + this.basicFormGroup.patchValue(editedBase, {emitEvent: false}); + } + + validate(): ValidationErrors | null { + return this.basicFormGroup.valid ? null : { + basicFormGroup: {valid: false} + }; + } + + private getRequestDataArray(value: Record): RequestMappingData[] { + const mappingConfigs = []; + + if (isObject(value)) { + Object.keys(value).forEach((configKey: string) => { + for (let mapping of value[configKey]) { + mappingConfigs.push({ + requestType: configKey, + requestValue: mapping + }); + } + }); + } + + return mappingConfigs; + } +} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc-ua-basic-config/opc-ua-basic-config.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc-ua-basic-config/opc-ua-basic-config.component.html new file mode 100644 index 0000000000..75c2b76f69 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc-ua-basic-config/opc-ua-basic-config.component.html @@ -0,0 +1,13 @@ + + + + + + + + +
+ +
+
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc-ua-basic-config/opc-ua-basic-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc-ua-basic-config/opc-ua-basic-config.component.ts new file mode 100644 index 0000000000..f32dbff598 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc-ua-basic-config/opc-ua-basic-config.component.ts @@ -0,0 +1,139 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + ChangeDetectionStrategy, + Component, + forwardRef, + Input, + OnDestroy, + TemplateRef, +} from '@angular/core'; +import { + ControlValueAccessor, + FormBuilder, + FormGroup, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + ValidationErrors, + Validator, +} from '@angular/forms'; +import { + ConnectorBaseConfig, + ConnectorType, + MappingType, +} from '@home/components/widget/lib/gateway/gateway-widget.models'; +import { SharedModule } from '@shared/shared.module'; +import { CommonModule } from '@angular/common'; +import { + BrokerConfigControlComponent, + MappingTableComponent, + SecurityConfigComponent, + ServerConfigComponent, + WorkersConfigControlComponent, + GeneralConfigComponent +} from '@home/components/widget/lib/gateway/connectors-configuration/public-api'; +import { takeUntil } from 'rxjs/operators'; +import { Subject } from 'rxjs'; + +@Component({ + selector: 'tb-opc-ua-basic-config', + templateUrl: './opc-ua-basic-config.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => OpcUaBasicConfigComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => OpcUaBasicConfigComponent), + multi: true + } + ], + standalone: true, + imports: [ + CommonModule, + SharedModule, + SecurityConfigComponent, + WorkersConfigControlComponent, + BrokerConfigControlComponent, + MappingTableComponent, + GeneralConfigComponent, + ServerConfigComponent, + ], + styles: [` + :host { + height: 100%; + } + :host ::ng-deep { + .mat-mdc-tab-group, .mat-mdc-tab-body-wrapper { + height: 100%; + } + } + `], +}) + +export class OpcUaBasicConfigComponent implements ControlValueAccessor, Validator, OnDestroy { + @Input() generalTabContent: TemplateRef; + + mappingTypes = MappingType; + basicFormGroup: FormGroup; + + onChange!: (value: string) => void; + onTouched!: () => void; + + protected readonly connectorType = ConnectorType; + private destroy$ = new Subject(); + + constructor(private fb: FormBuilder) { + this.basicFormGroup = this.fb.group({ + mapping: [], + server: [], + }); + + this.basicFormGroup.valueChanges + .pipe(takeUntil(this.destroy$)) + .subscribe(value => { + this.onChange(value); + this.onTouched(); + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + registerOnChange(fn: (value: string) => void): void { + this.onChange = fn; + } + + registerOnTouched(fn: () => void): void { + this.onTouched = fn; + } + + writeValue(basicConfig: ConnectorBaseConfig): void { + this.basicFormGroup.patchValue(basicConfig, {emitEvent: false}); + } + + validate(): ValidationErrors | null { + return this.basicFormGroup.valid ? null : { + basicFormGroup: {valid: false} + }; + } +} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/public-api.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/public-api.ts new file mode 100644 index 0000000000..93776a85fc --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/public-api.ts @@ -0,0 +1,27 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +export * from './mapping-table/mapping-table.component'; +export * from './device-info-table/device-info-table.component'; +export * from './security-config/security-config.component'; +export * from './server-config/server-config.component'; +export * from './mapping-data-keys-panel/mapping-data-keys-panel.component'; +export * from './type-value-panel/type-value-panel.component'; +export * from './broker-config-control/broker-config-control.component'; +export * from './workers-config-control/workers-config-control.component'; +export * from './opc-ua-basic-config/opc-ua-basic-config.component'; +export * from './mqtt-basic-config/mqtt-basic-config.component'; +export * from './general-config/general-config.component'; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-security.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.html similarity index 65% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-security.component.html rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.html index 319b10f0b2..87976abf08 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-security.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.html @@ -17,7 +17,7 @@ -->
-
gateway.security
+
{{ title | translate }}
{{ SecurityTypeTranslationsMap.get(type) | translate }} @@ -81,6 +81,48 @@
+ +
+
gateway.mode
+
+ + + + {{ type }} + + + +
+
+
+
gateway.username
+
+ + + + warning + + +
+
+
+
gateway.password
+
+ + +
+ +
+
+
+
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-security.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.scss similarity index 100% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-security.component.scss rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.scss diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-security.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts similarity index 51% rename from ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-security.component.ts rename to ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts index 655545e5fb..73095927b7 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/broker-security.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component.ts @@ -16,24 +16,13 @@ import { ChangeDetectionStrategy, - ChangeDetectorRef, Component, - ElementRef, forwardRef, - NgZone, + Input, OnDestroy, - ViewContainerRef + OnInit, } from '@angular/core'; -import { PageComponent } from '@shared/components/page.component'; -import { Store } from '@ngrx/store'; -import { AppState } from '@core/core.state'; -import { TranslateService } from '@ngx-translate/core'; -import { MatDialog } from '@angular/material/dialog'; -import { DialogService } from '@core/services/dialog.service'; import { Subject } from 'rxjs'; -import { Overlay } from '@angular/cdk/overlay'; -import { UtilsService } from '@core/services/utils.service'; -import { EntityService } from '@core/http/entity.service'; import { ControlValueAccessor, FormBuilder, @@ -41,124 +30,143 @@ import { NG_VALUE_ACCESSOR, UntypedFormGroup, ValidationErrors, - Validator, Validators } from '@angular/forms'; import { - BrokerSecurityType, - BrokerSecurityTypeTranslationsMap, - noLeadTrailSpacesRegex + SecurityType, + SecurityTypeTranslationsMap, + ModeType, + noLeadTrailSpacesRegex, + ConnectorSecurity } from '@home/components/widget/lib/gateway/gateway-widget.models'; import { takeUntil } from 'rxjs/operators'; +import { coerceBoolean } from '@shared/decorators/coercion'; +import { SharedModule } from '@shared/shared.module'; +import { CommonModule } from '@angular/common'; @Component({ - selector: 'tb-broker-security', - templateUrl: './broker-security.component.html', - styleUrls: ['./broker-security.component.scss'], + selector: 'tb-security-config', + templateUrl: './security-config.component.html', + styleUrls: ['./security-config.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, providers: [ { provide: NG_VALUE_ACCESSOR, - useExisting: forwardRef(() => BrokerSecurityComponent), + useExisting: forwardRef(() => SecurityConfigComponent), multi: true }, { provide: NG_VALIDATORS, - useExisting: forwardRef(() => BrokerSecurityComponent), + useExisting: forwardRef(() => SecurityConfigComponent), multi: true } + ], + standalone: true, + imports:[ + CommonModule, + SharedModule, ] }) -export class BrokerSecurityComponent extends PageComponent implements ControlValueAccessor, Validator, OnDestroy { +export class SecurityConfigComponent implements ControlValueAccessor, OnInit, OnDestroy { + @Input() + title: string = 'gateway.security'; - BrokerSecurityType = BrokerSecurityType; - - securityTypes = Object.values(BrokerSecurityType); - - SecurityTypeTranslationsMap = BrokerSecurityTypeTranslationsMap; + @Input() + @coerceBoolean() + extendCertificatesModel = false; + BrokerSecurityType = SecurityType; + securityTypes = Object.values(SecurityType); + modeTypes = Object.values(ModeType); + SecurityTypeTranslationsMap = SecurityTypeTranslationsMap; securityFormGroup: UntypedFormGroup; + onChange!: (value: string) => void; + onTouched!: () => void; + private destroy$ = new Subject(); - private propagateChange = (v: any) => {}; - constructor(protected store: Store, - public translate: TranslateService, - public dialog: MatDialog, - private overlay: Overlay, - private viewContainerRef: ViewContainerRef, - private dialogService: DialogService, - private entityService: EntityService, - private utils: UtilsService, - private zone: NgZone, - private cd: ChangeDetectorRef, - private elementRef: ElementRef, - private fb: FormBuilder) { - super(store); + constructor(private fb: FormBuilder) {} + + ngOnInit(): void { this.securityFormGroup = this.fb.group({ - type: [BrokerSecurityType.ANONYMOUS, []], + type: [SecurityType.ANONYMOUS, []], username: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], password: ['', [Validators.pattern(noLeadTrailSpacesRegex)]], pathToCACert: ['', [Validators.pattern(noLeadTrailSpacesRegex)]], pathToPrivateKey: ['', [Validators.pattern(noLeadTrailSpacesRegex)]], pathToClientCert: ['', [Validators.pattern(noLeadTrailSpacesRegex)]] }); + if (this.extendCertificatesModel) { + this.securityFormGroup.addControl('mode', this.fb.control(ModeType.NONE, [])); + } this.securityFormGroup.valueChanges.pipe( takeUntil(this.destroy$) ).subscribe((value) => { - this.updateView(value); + this.onChange(value); + this.onTouched(); }); this.securityFormGroup.get('type').valueChanges.pipe( takeUntil(this.destroy$) - ).subscribe((type) => { - this.updateValidators(type); - }); + ).subscribe((type) => this.updateValidators(type)); } - ngOnDestroy() { + ngOnDestroy(): void { this.destroy$.next(); this.destroy$.complete(); - super.ngOnDestroy(); } - registerOnChange(fn: any): void { - this.propagateChange = fn; - } - - registerOnTouched(fn: any): void {} - - writeValue(deviceInfo: any) { - if (!deviceInfo.type) { - deviceInfo.type = BrokerSecurityType.ANONYMOUS; + writeValue(securityInfo: ConnectorSecurity): void { + if (!securityInfo) { + const defaultSecurity = {type: SecurityType.ANONYMOUS}; + this.securityFormGroup.reset(defaultSecurity, {emitEvent: false}); + } else { + if (!securityInfo.type) { + securityInfo.type = SecurityType.ANONYMOUS; + } + this.securityFormGroup.reset(securityInfo, {emitEvent: false}); } - this.securityFormGroup.reset(deviceInfo); - this.updateView(deviceInfo); } validate(): ValidationErrors | null { - return this.securityFormGroup.valid ? null : { + return this.securityFormGroup.get('type').value !== SecurityType.BASIC || this.securityFormGroup.valid ? null : { securityForm: { valid: false } }; } - updateView(value: any) { - this.propagateChange(value); + registerOnChange(fn: (value: string) => void): void { + this.onChange = fn; } - private updateValidators(type) { + registerOnTouched(fn: () => void): void { + this.onTouched = fn; + } + + private updateValidators(type: SecurityType): void { if (type) { this.securityFormGroup.get('username').disable({emitEvent: false}); this.securityFormGroup.get('password').disable({emitEvent: false}); this.securityFormGroup.get('pathToCACert').disable({emitEvent: false}); this.securityFormGroup.get('pathToPrivateKey').disable({emitEvent: false}); this.securityFormGroup.get('pathToClientCert').disable({emitEvent: false}); - if (type === BrokerSecurityType.BASIC) { + this.securityFormGroup.get('mode')?.disable({emitEvent: false}); + if (type === SecurityType.BASIC) { this.securityFormGroup.get('username').enable({emitEvent: false}); this.securityFormGroup.get('password').enable({emitEvent: false}); - } else if (type === BrokerSecurityType.CERTIFICATES) { + } else if (type === SecurityType.CERTIFICATES) { this.securityFormGroup.get('pathToCACert').enable({emitEvent: false}); this.securityFormGroup.get('pathToPrivateKey').enable({emitEvent: false}); this.securityFormGroup.get('pathToClientCert').enable({emitEvent: false}); + if (this.extendCertificatesModel) { + const modeControl = this.securityFormGroup.get('mode'); + if (modeControl && !modeControl.value) { + modeControl.setValue(ModeType.NONE, {emitEvent: false}); + } + + modeControl?.enable({emitEvent: false}); + this.securityFormGroup.get('username').enable({emitEvent: false}); + this.securityFormGroup.get('password').enable({emitEvent: false}); + } } } } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.html new file mode 100644 index 0000000000..ee097ae642 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.html @@ -0,0 +1,125 @@ + +
+
+
gateway.server-url
+
+ + + + warning + + +
+
+
+
+ gateway.timeout +
+
+ + + + warning + + +
+
+
+
gateway.security
+
+ + + {{ version.name }} + + +
+
+
+
+ gateway.scan-period +
+
+ + + + warning + + +
+
+
+
+ gateway.sub-check-period +
+
+ + + + warning + + +
+
+
+ + + {{ 'gateway.enable-subscription' | translate }} + + +
+
+ + + {{ 'gateway.show-map' | translate }} + + +
+ + +
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.scss new file mode 100644 index 0000000000..416f368279 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.scss @@ -0,0 +1,20 @@ +/** + * Copyright © 2016-2024 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +:host { + width: 100%; + height: 100%; + display: block; +} 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 new file mode 100644 index 0000000000..5954918f4f --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/server-config/server-config.component.ts @@ -0,0 +1,121 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + ChangeDetectionStrategy, + Component, + forwardRef, + OnDestroy +} from '@angular/core'; +import { + ControlValueAccessor, + FormBuilder, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + UntypedFormGroup, + ValidationErrors, + Validator, + Validators +} from '@angular/forms'; +import { + noLeadTrailSpacesRegex, + SecurityType, + ServerConfig, + ServerSecurityTypes +} from '@home/components/widget/lib/gateway/gateway-widget.models'; +import { SharedModule } from '@shared/shared.module'; +import { CommonModule } from '@angular/common'; +import { SecurityConfigComponent } from '@home/components/widget/lib/gateway/connectors-configuration/public-api'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; + +@Component({ + selector: 'tb-server-config', + templateUrl: './server-config.component.html', + styleUrls: ['./server-config.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => ServerConfigComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => ServerConfigComponent), + multi: true + } + ], + standalone: true, + imports: [ + CommonModule, + SharedModule, + SecurityConfigComponent, + ] +}) +export class ServerConfigComponent implements ControlValueAccessor, Validator, OnDestroy { + serverSecurityTypes = ServerSecurityTypes; + serverConfigFormGroup: UntypedFormGroup; + + onChange!: (value: string) => void; + onTouched!: () => void; + + private destroy$ = new Subject(); + + constructor(private fb: FormBuilder) { + this.serverConfigFormGroup = this.fb.group({ + name: ['', []], + url: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + timeoutInMillis: [1000, [Validators.required, Validators.min(1000)]], + scanPeriodInMillis: [1000, [Validators.required, Validators.min(1000)]], + enableSubscriptions: [true, []], + subCheckPeriodInMillis: [10, [Validators.required, Validators.min(10)]], + showMap: [false, []], + security: [SecurityType.BASIC128, []], + identity: [{}, [Validators.required]] + }); + + this.serverConfigFormGroup.valueChanges.pipe( + takeUntil(this.destroy$) + ).subscribe((value) => { + this.onChange(value); + this.onTouched(); + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + registerOnChange(fn: (value: string) => void): void { + this.onChange = fn; + } + + registerOnTouched(fn: () => void): void { + this.onTouched = fn; + } + + validate(): ValidationErrors | null { + return this.serverConfigFormGroup.valid ? null : { + serverConfigFormGroup: { valid: false } + }; + } + + writeValue(serverConfig: ServerConfig): void { + this.serverConfigFormGroup.patchValue(serverConfig, {emitEvent: false}); + } +} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.html new file mode 100644 index 0000000000..7ce7fb94f0 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.html @@ -0,0 +1,92 @@ + +
+
+
+
+ + + + +
{{ valueTitle(keyControl.get('value').value) }}
+
+
+ +
+
gateway.type
+
+ + + +
+ + + + {{ valueTypes.get(keyControl.get('type').value)?.name | translate}} + +
+
+ + + + {{ valueTypes.get(valueType).name | translate }} + +
+
+
+
+
+
gateway.value
+ + + + warning + + +
+
+
+
+
+ +
+
+
+ +
+
+ +
+ {{ 'gateway.no-value' }} +
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.scss new file mode 100644 index 0000000000..687025e729 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.scss @@ -0,0 +1,52 @@ +/** + * Copyright © 2016-2024 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +:host { + + .title-container { + max-width: 11vw; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap + } + + .key-panel { + height: 250px; + overflow: auto; + } + + .tb-form-panel { + .mat-mdc-icon-button { + width: 56px; + height: 56px; + padding: 16px; + color: rgba(0, 0, 0, 0.54); + } + } + + .see-example { + width: 32px; + height: 32px; + margin: 4px; + } +} + +:host ::ng-deep { + .mat-mdc-form-field-icon-suffix { + display: flex; + } +} + diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.ts new file mode 100644 index 0000000000..e163d463ed --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.ts @@ -0,0 +1,144 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + Component, + forwardRef, + OnDestroy, + OnInit, +} from '@angular/core'; +import { + AbstractControl, + ControlValueAccessor, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + UntypedFormArray, + UntypedFormBuilder, + ValidationErrors, + Validator, + Validators +} from '@angular/forms'; +import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; +import { isDefinedAndNotNull } from '@core/utils'; +import { + MappingDataKey, + MappingValueType, + mappingValueTypesMap, + noLeadTrailSpacesRegex +} from '@home/components/widget/lib/gateway/gateway-widget.models'; +import { takeUntil } from 'rxjs/operators'; +import { Subject } from 'rxjs'; + +@Component({ + selector: 'tb-type-value-panel', + templateUrl: './type-value-panel.component.html', + styleUrls: ['./type-value-panel.component.scss'], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => TypeValuePanelComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => TypeValuePanelComponent), + multi: true + } + ] +}) +export class TypeValuePanelComponent implements ControlValueAccessor, Validator, OnInit, OnDestroy { + valueTypeKeys = Object.values(MappingValueType); + valueTypeEnum = MappingValueType; + valueTypes = mappingValueTypesMap; + dataKeyType: DataKeyType; + valueListFormArray: UntypedFormArray; + errorText = ''; + + private destroy$ = new Subject(); + private propagateChange = (v: any) => {}; + + constructor(private fb: UntypedFormBuilder) {} + + ngOnInit(): void { + this.valueListFormArray = this.fb.array([]); + this.valueListFormArray.valueChanges.pipe( + takeUntil(this.destroy$) + ).subscribe((value) => { + this.updateView(value); + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + trackByKey(_: number, keyControl: AbstractControl): any { + return keyControl; + } + + addKey(): void { + const dataKeyFormGroup = this.fb.group({ + type: [MappingValueType.STRING, []], + value: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]] + }); + this.valueListFormArray.push(dataKeyFormGroup); + } + + deleteKey($event: Event, index: number): void { + if ($event) { + $event.stopPropagation(); + } + this.valueListFormArray.removeAt(index); + this.valueListFormArray.markAsDirty(); + } + + valueTitle(value: any): string { + if (isDefinedAndNotNull(value)) { + if (typeof value === 'object') { + return JSON.stringify(value); + } + return value; + } + return ''; + } + + registerOnChange(fn: any): void { + this.propagateChange = fn; + } + + registerOnTouched(fn: any): void {} + + writeValue(deviceInfoArray: Array): void { + for (const deviceInfo of deviceInfoArray) { + const dataKeyFormGroup = this.fb.group({ + type: [deviceInfo.type, []], + value: [deviceInfo.value, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]] + }); + this.valueListFormArray.push(dataKeyFormGroup); + } + } + + validate(): ValidationErrors | null { + return this.valueListFormArray.valid ? null : { + valueListForm: { valid: false } + }; + } + + updateView(value: any): void { + this.propagateChange(value); + } +} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.html new file mode 100644 index 0000000000..37f7b1422e --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.html @@ -0,0 +1,63 @@ + +
+
+
+ gateway.max-number-of-workers +
+
+ + + + warning + + +
+
+
+
+ gateway.max-messages-queue-for-worker +
+
+ + + + warning + + +
+
+
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 new file mode 100644 index 0000000000..f858328d5e --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/workers-config-control/workers-config-control.component.ts @@ -0,0 +1,101 @@ +/// +/// Copyright © 2016-2024 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { + ChangeDetectionStrategy, + Component, + forwardRef, + OnDestroy, +} from '@angular/core'; +import { + ControlValueAccessor, + FormBuilder, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + UntypedFormGroup, ValidationErrors, Validator, + Validators +} from '@angular/forms'; +import { SharedModule } from '@shared/shared.module'; +import { CommonModule } from '@angular/common'; +import { WorkersConfig } from '@home/components/widget/lib/gateway/gateway-widget.models'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; + +@Component({ + selector: 'tb-workers-config-control', + templateUrl: './workers-config-control.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [ + CommonModule, + SharedModule, + ], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => WorkersConfigControlComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => WorkersConfigControlComponent), + multi: true + } + ] +}) +export class WorkersConfigControlComponent implements OnDestroy, ControlValueAccessor, Validator { + workersConfigFormGroup: UntypedFormGroup; + + onChange!: (value: string) => void; + onTouched!: () => void; + + private destroy$ = new Subject(); + + constructor(private fb: FormBuilder) { + this.workersConfigFormGroup = this.fb.group({ + maxNumberOfWorkers: [100, [Validators.required, Validators.min(1)]], + maxMessageNumberPerWorker: [10, [Validators.required, Validators.min(1)]], + }); + + this.workersConfigFormGroup.valueChanges.pipe(takeUntil(this.destroy$)).subscribe(value => { + this.onChange(value); + this.onTouched(); + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + registerOnChange(fn: (value: string) => void): void { + this.onChange = fn; + } + + registerOnTouched(fn: () => void): void { + this.onTouched = fn; + } + + writeValue(workersConfig: WorkersConfig): void { + this.workersConfigFormGroup.patchValue(workersConfig, {emitEvent: false}); + } + + validate(): ValidationErrors | null { + return this.workersConfigFormGroup.valid ? null : { + workersConfigFormGroup: {valid: false} + }; + } +} diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.html index 78ceaa566f..a202c85fcb 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.html @@ -615,6 +615,124 @@ + +
+
+
+ gateway.device-node +
+
+
+ + + + {{ SourceTypeTranslationsMap.get(type) | translate }} + + + + + + + warning + +
+
+
+
+
+ + +
+
gateway.attributes
+
+ + + {{ attribute }} + + + + + + +
+
+
+
gateway.timeseries
+
+ + + {{ telemetry }} + + + + + + +
+
+
+
gateway.attribute-updates
+
+ + + {{ attribute }} + + + + + + +
+
+
+
gateway.rpc-methods
+
+ + + {{ attribute }} + + + + + + +
+
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.scss index d002a0fc87..147dcd51da 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.scss +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.scss @@ -72,4 +72,8 @@ .mat-mdc-form-field-icon-suffix { display: flex; } + + .device-config { + padding-left: 10px; + } } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.ts index d01050b52e..a2b6a67490 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.ts @@ -19,7 +19,6 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { FormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; -import { BaseData, HasId } from '@shared/models/base-data'; import { DialogComponent } from '@shared/components/dialog.component'; import { Router } from '@angular/router'; import { @@ -35,8 +34,9 @@ import { MappingKeysPanelTitleTranslationsMap, MappingKeysType, MappingType, - MappingTypeTranslationsMap, + MappingTypeTranslationsMap, MappingValue, noLeadTrailSpacesRegex, + OPCUaSourceTypes, QualityTypes, QualityTypeTranslationsMap, RequestType, @@ -49,16 +49,15 @@ import { Subject } from 'rxjs'; import { startWith, takeUntil } from 'rxjs/operators'; import { MatButton } from '@angular/material/button'; import { TbPopoverService } from '@shared/components/popover.service'; -import { MappingDataKeysPanelComponent } from '@home/components/widget/lib/gateway/connectors-configuration/mapping-data-keys-panel.component'; import { TranslateService } from '@ngx-translate/core'; +import { MappingDataKeysPanelComponent } from '@home/components/widget/lib/gateway/connectors-configuration/public-api'; @Component({ selector: 'tb-mapping-dialog', templateUrl: './mapping-dialog.component.html', - styleUrls: ['./mapping-dialog.component.scss'], - providers: [], + styleUrls: ['./mapping-dialog.component.scss'] }) -export class MappingDialogComponent extends DialogComponent> implements OnDestroy { +export class MappingDialogComponent extends DialogComponent implements OnDestroy { mappingForm: UntypedFormGroup; @@ -72,6 +71,8 @@ export class MappingDialogComponent extends DialogComponent; + OPCUaSourceTypesEnum = OPCUaSourceTypes; sourceTypesEnum = SourceTypes; SourceTypeTranslationsMap = SourceTypeTranslationsMap; @@ -102,7 +103,7 @@ export class MappingDialogComponent extends DialogComponent, protected router: Router, @Inject(MAT_DIALOG_DATA) public data: MappingInfo, - public dialogRef: MatDialogRef, + public dialogRef: MatDialogRef, private fb: FormBuilder, private popoverService: TbPopoverService, private renderer: Renderer2, @@ -125,6 +126,22 @@ export class MappingDialogComponent extends DialogComponent { + return this.mappingForm.get('attributes').value?.map(value => value.key) || []; + } + + get opcTelemetry(): Array { + return this.mappingForm.get('timeseries').value?.map(value => value.key) || []; + } + + get opcRpcMethods(): Array { + return this.mappingForm.get('rpc_methods').value?.map(value => value.method) || []; + } + + get opcAttributesUpdates(): Array { + return this.mappingForm.get('attributes_updates')?.value?.map(value => value.key) || []; + } + get converterType(): ConvertorType { return this.mappingForm.get('converter').get('type').value; } @@ -155,109 +172,17 @@ export class MappingDialogComponent extends DialogComponent { - const converterGroup = this.mappingForm.get('converter'); - converterGroup.get('json').disable({emitEvent: false}); - converterGroup.get('bytes').disable({emitEvent: false}); - converterGroup.get('custom').disable({emitEvent: false}); - converterGroup.get(value).enable({emitEvent: false}); - }) - } - - if (this.data.mappingType === MappingType.REQUESTS) { - this.mappingForm.addControl('requestType', this.fb.control(RequestType.CONNECT_REQUEST, [])); - this.mappingForm.addControl('requestValue', this.fb.group({ - connectRequests: this.fb.group({ - topicFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - deviceInfo: [{}, []] - }), - disconnectRequests: this.fb.group({ - topicFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - deviceInfo: [{}, []] - }), - attributeRequests: this.fb.group({ - topicFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - deviceInfo: this.fb.group({ - deviceNameExpressionSource: [SourceTypes.MSG, []], - deviceNameExpression: ['', [Validators.required]], - }), - attributeNameExpressionSource: [SourceTypes.MSG, []], - attributeNameExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - topicExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - valueExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - retain: [false, []] - }), - attributeUpdates: this.fb.group({ - deviceNameFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - attributeFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - topicExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - valueExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - retain: [true, []] - }), - serverSideRpc: this.fb.group({ - type: [ServerSideRPCType.TWO_WAY, []], - deviceNameFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - methodFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - requestTopicExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - responseTopicExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - valueExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], - responseTopicQoS: [0, []], - responseTimeout: [10000, [Validators.required, Validators.min(1)]], - }) - })); - this.mappingForm.get('requestType').valueChanges.pipe( - startWith(this.mappingForm.get('requestType').value), - takeUntil(this.destroy$) - ).subscribe((value) => { - const requestValueGroup = this.mappingForm.get('requestValue'); - requestValueGroup.get('connectRequests').disable({emitEvent: false}); - requestValueGroup.get('disconnectRequests').disable({emitEvent: false}); - requestValueGroup.get('attributeRequests').disable({emitEvent: false}); - requestValueGroup.get('attributeUpdates').disable({emitEvent: false}); - requestValueGroup.get('serverSideRpc').disable({emitEvent: false}); - requestValueGroup.get(value).enable(); - }); - this.mappingForm.get('requestValue.serverSideRpc.type').valueChanges.pipe( - takeUntil(this.destroy$) - ).subscribe((value) => { - const requestValueGroup = this.mappingForm.get('requestValue.serverSideRpc'); - if (value === ServerSideRPCType.ONE_WAY) { - requestValueGroup.get('responseTopicExpression').disable({emitEvent: false}); - requestValueGroup.get('responseTopicQoS').disable({emitEvent: false}); - requestValueGroup.get('responseTimeout').disable({emitEvent: false}); - } else { - requestValueGroup.get('responseTopicExpression').enable({emitEvent: false}); - requestValueGroup.get('responseTopicQoS').enable({emitEvent: false}); - requestValueGroup.get('responseTimeout').enable({emitEvent: false}); - } - }); - this.mappingForm.patchValue(this.prepareFormValueData()); + switch (this.data.mappingType) { + case MappingType.DATA: + this.mappingForm = this.fb.group({}); + this.createDataMappingForm(); + break; + case MappingType.REQUESTS: + this.mappingForm = this.fb.group({}); + this.createRequestMappingForm(); + break; + case MappingType.OPCUA: + this.createOPCUAMappingForm(); } } @@ -278,7 +203,7 @@ export class MappingDialogComponent extends DialogComponent { + dataKeysPanelPopover.tbComponentRef.instance.keysDataApplied.pipe(takeUntil(this.destroy$)).subscribe((keysData) => { dataKeysPanelPopover.hide(); keysControl.patchValue(keysData); keysControl.markAsDirty(); }); - dataKeysPanelPopover.tbHideStart.subscribe(() => { + dataKeysPanelPopover.tbHideStart.pipe(takeUntil(this.destroy$)).subscribe(() => { this.keysPopupClosed = true; }); } } - private prepareMappingData(): {[key: string]: any} { + private prepareMappingData(): {[key: string]: unknown} { const formValue = this.mappingForm.value; - if (this.data.mappingType === MappingType.DATA) { - const { converter, topicFilter, subscriptionQos } = formValue; - return { - topicFilter, - subscriptionQos, - converter: { - type: converter.type, - ...converter[converter.type] - } - }; - } else { - return { - requestType: formValue.requestType, - requestValue: formValue.requestValue[formValue.requestType] - }; - } - } - - private prepareFormValueData(): {[key: string]: any} { - if (this.data.value && Object.keys(this.data.value).length) { - if (this.data.mappingType === MappingType.DATA) { - const { converter, topicFilter, subscriptionQos } = this.data.value; + switch (this.data.mappingType) { + case MappingType.DATA: + const { converter, topicFilter, subscriptionQos } = formValue; return { topicFilter, subscriptionQos, converter: { type: converter.type, - [converter.type]: { ...converter } + ...converter[converter.type] } }; - } else { + case MappingType.REQUESTS: return { - requestType: this.data.value.requestType, - requestValue: { - [this.data.value.requestType]: this.data.value.requestValue - } + requestType: formValue.requestType, + requestValue: formValue.requestValue[formValue.requestType] }; + default: + return formValue; + } + } + + private prepareFormValueData(): {[key: string]: unknown} { + if (this.data.value && Object.keys(this.data.value).length) { + switch (this.data.mappingType) { + case MappingType.DATA: + const { converter, topicFilter, subscriptionQos } = this.data.value; + return { + topicFilter, + subscriptionQos, + converter: { + type: converter.type, + [converter.type]: { ...converter } + } + }; + case MappingType.REQUESTS: + return { + requestType: this.data.value.requestType, + requestValue: { + [this.data.value.requestType]: this.data.value.requestValue + } + }; + default: + return this.data.value; } } - return this.data.value; + } + + private createDataMappingForm(): void { + this.mappingForm.addControl('topicFilter', + this.fb.control('', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)])); + this.mappingForm.addControl('subscriptionQos', this.fb.control(0)); + this.mappingForm.addControl('converter', this.fb.group({ + type: [ConvertorType.JSON, []], + json: this.fb.group({ + deviceInfo: [{}, []], + attributes: [[], []], + timeseries: [[], []] + }), + bytes: this.fb.group({ + deviceInfo: [{}, []], + attributes: [[], []], + timeseries: [[], []] + }), + custom: this.fb.group({ + extension: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + extensionConfig: [{}, []] + }), + })); + this.mappingForm.patchValue(this.prepareFormValueData()); + this.mappingForm.get('converter.type').valueChanges.pipe( + startWith(this.mappingForm.get('converter.type').value), + takeUntil(this.destroy$) + ).subscribe((value) => { + const converterGroup = this.mappingForm.get('converter'); + converterGroup.get('json').disable({emitEvent: false}); + converterGroup.get('bytes').disable({emitEvent: false}); + converterGroup.get('custom').disable({emitEvent: false}); + converterGroup.get(value).enable({emitEvent: false}); + }) + } + + private createRequestMappingForm(): void { + this.mappingForm.addControl('requestType', this.fb.control(RequestType.CONNECT_REQUEST, [])); + this.mappingForm.addControl('requestValue', this.fb.group({ + connectRequests: this.fb.group({ + topicFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + deviceInfo: [{}, []] + }), + disconnectRequests: this.fb.group({ + topicFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + deviceInfo: [{}, []] + }), + attributeRequests: this.fb.group({ + topicFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + deviceInfo: this.fb.group({ + deviceNameExpressionSource: [SourceTypes.MSG, []], + deviceNameExpression: ['', [Validators.required]], + }), + attributeNameExpressionSource: [SourceTypes.MSG, []], + attributeNameExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + topicExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + valueExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + retain: [false, []] + }), + attributeUpdates: this.fb.group({ + deviceNameFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + attributeFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + topicExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + valueExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + retain: [true, []] + }), + serverSideRpc: this.fb.group({ + type: [ServerSideRPCType.TWO_WAY, []], + deviceNameFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + methodFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + requestTopicExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + responseTopicExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + valueExpression: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], + responseTopicQoS: [0, []], + responseTimeout: [10000, [Validators.required, Validators.min(1)]], + }) + })); + this.mappingForm.get('requestType').valueChanges.pipe( + startWith(this.mappingForm.get('requestType').value), + takeUntil(this.destroy$) + ).subscribe((value) => { + const requestValueGroup = this.mappingForm.get('requestValue'); + requestValueGroup.get('connectRequests').disable({emitEvent: false}); + requestValueGroup.get('disconnectRequests').disable({emitEvent: false}); + requestValueGroup.get('attributeRequests').disable({emitEvent: false}); + requestValueGroup.get('attributeUpdates').disable({emitEvent: false}); + requestValueGroup.get('serverSideRpc').disable({emitEvent: false}); + requestValueGroup.get(value).enable(); + }); + this.mappingForm.get('requestValue.serverSideRpc.type').valueChanges.pipe( + takeUntil(this.destroy$) + ).subscribe((value) => { + const requestValueGroup = this.mappingForm.get('requestValue.serverSideRpc'); + if (value === ServerSideRPCType.ONE_WAY) { + requestValueGroup.get('responseTopicExpression').disable({emitEvent: false}); + requestValueGroup.get('responseTopicQoS').disable({emitEvent: false}); + requestValueGroup.get('responseTimeout').disable({emitEvent: false}); + } else { + requestValueGroup.get('responseTopicExpression').enable({emitEvent: false}); + requestValueGroup.get('responseTopicQoS').enable({emitEvent: false}); + requestValueGroup.get('responseTimeout').enable({emitEvent: false}); + } + }); + this.mappingForm.patchValue(this.prepareFormValueData()); + } + + private createOPCUAMappingForm(): void { + this.mappingForm = this.fb.group({ + deviceNodeSource: [OPCUaSourceTypes.PATH, []], + deviceNodePattern: ['', [Validators.required]], + deviceInfo: [{}, []], + attributes: [[], []], + timeseries: [[], []], + rpc_methods: [[], []], + attributes_updates: [[], []] + }); + this.mappingForm.patchValue(this.prepareFormValueData()); } } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.html index eb7afe0cc5..cafb8d159b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-connectors.component.html @@ -156,7 +156,10 @@ {{ initialConnector?.type ? gatewayConnectorDefaultTypes.get(initialConnector.type) : '' }} {{ 'gateway.configuration' | translate }} - + {{ 'gateway.basic' | translate }} @@ -170,213 +173,25 @@ class="no-data-found" translate> gateway.select-connector + + +
- - -
-
-
gateway.name
-
- - - - warning - - -
-
-
-
gateway.connectors-table-class
-
- - - -
-
-
-
gateway.connectors-table-key
-
- - - -
-
-
-
gateway.logs-configuration
-
- - - {{ 'gateway.enable-remote-logging' | translate }} - - -
-
-
gateway.remote-logging-level
-
- - - {{ logLevel }} - - -
-
-
-
- - - {{ 'gateway.send-change-data' | translate }} - - -
-
-
- - - -
-
-
gateway.host
-
- - - - warning - - -
-
-
-
gateway.port
-
- - - - warning - - -
-
-
-
gateway.mqtt-version
-
- - - {{ version.name }} - - -
-
-
-
gateway.client-id
-
- - - - -
-
- - -
-
+ + + + + + + + + + - -
- -
-
- -
- -
-
- -
- -
-
-
- gateway.max-number-of-workers -
-
- - - - warning - - -
-
-
-
- gateway.max-messages-queue-for-worker -
-
- - - - warning - - -
-
-
-
-
-
-
- - -
+ +