Browse Source

Merge branch 'fix/3984-data-mapping-crushing' of github.com:maxunbearable/thingsboard into improvement/gateway-dashboard

pull/11251/head
Vladyslav_Prykhodko 2 years ago
parent
commit
a1e549cd7a
  1. 4
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.ts
  2. 26
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.ts
  3. 22
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-widget.models.ts

4
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/mapping-table/mapping-table.component.ts

@ -192,7 +192,7 @@ export class MappingTableComponent implements ControlValueAccessor, Validator, A
$event.stopPropagation(); $event.stopPropagation();
} }
const value = isDefinedAndNotNull(index) ? this.mappingFormGroup.at(index).value : {}; const value = isDefinedAndNotNull(index) ? this.mappingFormGroup.at(index).value : {};
this.dialog.open<MappingDialogComponent, MappingInfo, MappingValue>(MappingDialogComponent, { this.dialog.open<MappingDialogComponent, MappingInfo, ConnectorMapping>(MappingDialogComponent, {
disableClose: true, disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: { data: {
@ -207,7 +207,7 @@ export class MappingTableComponent implements ControlValueAccessor, Validator, A
if (isDefinedAndNotNull(index)) { if (isDefinedAndNotNull(index)) {
this.mappingFormGroup.at(index).patchValue(res); this.mappingFormGroup.at(index).patchValue(res);
} else { } else {
this.mappingFormGroup.push(this.fb.group(res)); this.pushDataAsFormArrays([res]);
} }
this.mappingFormGroup.markAsDirty(); this.mappingFormGroup.markAsDirty();
} }

26
ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.ts

@ -24,9 +24,13 @@ import { Router } from '@angular/router';
import { import {
Attribute, Attribute,
AttributesUpdate, AttributesUpdate,
ConnectorMapping,
ConnectorMappingFormValue,
ConverterMappingFormValue,
ConvertorType, ConvertorType,
ConvertorTypeTranslationsMap, ConvertorTypeTranslationsMap,
DataConversionTranslationsMap, DataConversionTranslationsMap,
DeviceConnectorMapping,
DeviceInfoType, DeviceInfoType,
HelpLinkByMappingTypeMap, HelpLinkByMappingTypeMap,
MappingHintTranslationsMap, MappingHintTranslationsMap,
@ -38,11 +42,11 @@ import {
MappingKeysType, MappingKeysType,
MappingType, MappingType,
MappingTypeTranslationsMap, MappingTypeTranslationsMap,
MappingValue,
noLeadTrailSpacesRegex, noLeadTrailSpacesRegex,
OPCUaSourceTypes, OPCUaSourceTypes,
QualityTypes, QualityTypes,
QualityTypeTranslationsMap, QualityTypeTranslationsMap,
RequestMappingFormValue,
RequestType, RequestType,
RequestTypesTranslationsMap, RequestTypesTranslationsMap,
RpcMethod, RpcMethod,
@ -63,7 +67,7 @@ import { MappingDataKeysPanelComponent } from '@home/components/widget/lib/gatew
templateUrl: './mapping-dialog.component.html', templateUrl: './mapping-dialog.component.html',
styleUrls: ['./mapping-dialog.component.scss'] styleUrls: ['./mapping-dialog.component.scss']
}) })
export class MappingDialogComponent extends DialogComponent<MappingDialogComponent, MappingValue> implements OnDestroy { export class MappingDialogComponent extends DialogComponent<MappingDialogComponent, ConnectorMapping> implements OnDestroy {
mappingForm: UntypedFormGroup; mappingForm: UntypedFormGroup;
@ -107,7 +111,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
protected router: Router, protected router: Router,
@Inject(MAT_DIALOG_DATA) public data: MappingInfo, @Inject(MAT_DIALOG_DATA) public data: MappingInfo,
public dialogRef: MatDialogRef<MappingDialogComponent, MappingValue>, public dialogRef: MatDialogRef<MappingDialogComponent, ConnectorMapping>,
private fb: FormBuilder, private fb: FormBuilder,
private popoverService: TbPopoverService, private popoverService: TbPopoverService,
private renderer: Renderer2, private renderer: Renderer2,
@ -246,7 +250,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
} }
} }
private prepareMappingData(): { [key: string]: unknown } { private prepareMappingData(): ConnectorMapping {
const formValue = this.mappingForm.value; const formValue = this.mappingForm.value;
switch (this.data.mappingType) { switch (this.data.mappingType) {
case MappingType.DATA: case MappingType.DATA:
@ -269,7 +273,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
} }
} }
private prepareFormValueData(): { [key: string]: unknown } { private getFormValueData(): ConnectorMappingFormValue {
if (this.data.value && Object.keys(this.data.value).length) { if (this.data.value && Object.keys(this.data.value).length) {
switch (this.data.mappingType) { switch (this.data.mappingType) {
case MappingType.DATA: case MappingType.DATA:
@ -281,16 +285,16 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
type: converter.type, type: converter.type,
[converter.type]: {...converter} [converter.type]: {...converter}
} }
}; } as ConverterMappingFormValue;
case MappingType.REQUESTS: case MappingType.REQUESTS:
return { return {
requestType: this.data.value.requestType, requestType: this.data.value.requestType,
requestValue: { requestValue: {
[this.data.value.requestType]: this.data.value.requestValue [this.data.value.requestType]: this.data.value.requestValue
} }
}; } as RequestMappingFormValue;
default: default:
return this.data.value; return this.data.value as DeviceConnectorMapping;
} }
} }
} }
@ -316,7 +320,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
extensionConfig: [{}, []] extensionConfig: [{}, []]
}), }),
})); }));
this.mappingForm.patchValue(this.prepareFormValueData()); this.mappingForm.patchValue(this.getFormValueData());
this.mappingForm.get('converter.type').valueChanges.pipe( this.mappingForm.get('converter.type').valueChanges.pipe(
startWith(this.mappingForm.get('converter.type').value), startWith(this.mappingForm.get('converter.type').value),
takeUntil(this.destroy$) takeUntil(this.destroy$)
@ -396,7 +400,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
requestValueGroup.get('responseTimeout').enable({emitEvent: false}); requestValueGroup.get('responseTimeout').enable({emitEvent: false});
} }
}); });
this.mappingForm.patchValue(this.prepareFormValueData()); this.mappingForm.patchValue(this.getFormValueData());
} }
private createOPCUAMappingForm(): void { private createOPCUAMappingForm(): void {
@ -409,6 +413,6 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
rpc_methods: [[], []], rpc_methods: [[], []],
attributes_updates: [[], []] attributes_updates: [[], []]
}); });
this.mappingForm.patchValue(this.prepareFormValueData()); this.mappingForm.patchValue(this.getFormValueData());
} }
} }

22
ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-widget.models.ts

@ -174,6 +174,8 @@ export interface ConnectorSecurity {
export type ConnectorMapping = DeviceConnectorMapping | RequestMappingData | ConverterConnectorMapping; export type ConnectorMapping = DeviceConnectorMapping | RequestMappingData | ConverterConnectorMapping;
export type ConnectorMappingFormValue = DeviceConnectorMapping | RequestMappingFormValue | ConverterMappingFormValue;
export interface ConnectorBaseConfig { export interface ConnectorBaseConfig {
mapping?: DeviceConnectorMapping[]; mapping?: DeviceConnectorMapping[];
dataMapping?: ConverterConnectorMapping[]; dataMapping?: ConverterConnectorMapping[];
@ -223,7 +225,7 @@ export interface AttributesUpdate {
value: string; value: string;
} }
interface Converter { export interface Converter {
type: ConvertorType; type: ConvertorType;
deviceNameJsonExpression: string; deviceNameJsonExpression: string;
deviceTypeJsonExpression: string; deviceTypeJsonExpression: string;
@ -239,14 +241,20 @@ export interface ConverterConnectorMapping {
converter: Converter; converter: Converter;
} }
export type ConverterMappingFormValue = Omit<ConverterConnectorMapping, 'converter'> & {
converter: {
type: ConvertorType;
} & Record<ConvertorType, Converter>;
};
export interface DeviceConnectorMapping { export interface DeviceConnectorMapping {
deviceNodePattern: string; deviceNodePattern: string;
deviceNodeSource: string; deviceNodeSource: string;
deviceInfo: DeviceInfo; deviceInfo: DeviceInfo;
attributes: Attribute[]; attributes?: Attribute[];
timeseries: Timeseries[]; timeseries?: Timeseries[];
rpc_methods: RpcMethod[]; rpc_methods?: RpcMethod[];
attributes_updates: AttributesUpdate[]; attributes_updates?: AttributesUpdate[];
} }
export enum ConnectorType { export enum ConnectorType {
@ -605,6 +613,10 @@ export interface RequestMappingData {
requestValue: RequestDataItem; requestValue: RequestDataItem;
} }
export type RequestMappingFormValue = Omit<RequestMappingData, 'requestValue'> & {
requestValue: Record<RequestType, RequestDataItem>;
};
export interface RequestDataItem { export interface RequestDataItem {
type: string; type: string;
details: string; details: string;

Loading…
Cancel
Save