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();
}
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,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
@ -207,7 +207,7 @@ export class MappingTableComponent implements ControlValueAccessor, Validator, A
if (isDefinedAndNotNull(index)) {
this.mappingFormGroup.at(index).patchValue(res);
} else {
this.mappingFormGroup.push(this.fb.group(res));
this.pushDataAsFormArrays([res]);
}
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 {
Attribute,
AttributesUpdate,
ConnectorMapping,
ConnectorMappingFormValue,
ConverterMappingFormValue,
ConvertorType,
ConvertorTypeTranslationsMap,
DataConversionTranslationsMap,
DeviceConnectorMapping,
DeviceInfoType,
HelpLinkByMappingTypeMap,
MappingHintTranslationsMap,
@ -38,11 +42,11 @@ import {
MappingKeysType,
MappingType,
MappingTypeTranslationsMap,
MappingValue,
noLeadTrailSpacesRegex,
OPCUaSourceTypes,
QualityTypes,
QualityTypeTranslationsMap,
RequestMappingFormValue,
RequestType,
RequestTypesTranslationsMap,
RpcMethod,
@ -63,7 +67,7 @@ import { MappingDataKeysPanelComponent } from '@home/components/widget/lib/gatew
templateUrl: './mapping-dialog.component.html',
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;
@ -107,7 +111,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
constructor(protected store: Store<AppState>,
protected router: Router,
@Inject(MAT_DIALOG_DATA) public data: MappingInfo,
public dialogRef: MatDialogRef<MappingDialogComponent, MappingValue>,
public dialogRef: MatDialogRef<MappingDialogComponent, ConnectorMapping>,
private fb: FormBuilder,
private popoverService: TbPopoverService,
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;
switch (this.data.mappingType) {
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) {
switch (this.data.mappingType) {
case MappingType.DATA:
@ -281,16 +285,16 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
type: converter.type,
[converter.type]: {...converter}
}
};
} as ConverterMappingFormValue;
case MappingType.REQUESTS:
return {
requestType: this.data.value.requestType,
requestValue: {
[this.data.value.requestType]: this.data.value.requestValue
}
};
} as RequestMappingFormValue;
default:
return this.data.value;
return this.data.value as DeviceConnectorMapping;
}
}
}
@ -316,7 +320,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
extensionConfig: [{}, []]
}),
}));
this.mappingForm.patchValue(this.prepareFormValueData());
this.mappingForm.patchValue(this.getFormValueData());
this.mappingForm.get('converter.type').valueChanges.pipe(
startWith(this.mappingForm.get('converter.type').value),
takeUntil(this.destroy$)
@ -396,7 +400,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
requestValueGroup.get('responseTimeout').enable({emitEvent: false});
}
});
this.mappingForm.patchValue(this.prepareFormValueData());
this.mappingForm.patchValue(this.getFormValueData());
}
private createOPCUAMappingForm(): void {
@ -409,6 +413,6 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
rpc_methods: [[], []],
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 ConnectorMappingFormValue = DeviceConnectorMapping | RequestMappingFormValue | ConverterMappingFormValue;
export interface ConnectorBaseConfig {
mapping?: DeviceConnectorMapping[];
dataMapping?: ConverterConnectorMapping[];
@ -223,7 +225,7 @@ export interface AttributesUpdate {
value: string;
}
interface Converter {
export interface Converter {
type: ConvertorType;
deviceNameJsonExpression: string;
deviceTypeJsonExpression: string;
@ -239,14 +241,20 @@ export interface ConverterConnectorMapping {
converter: Converter;
}
export type ConverterMappingFormValue = Omit<ConverterConnectorMapping, 'converter'> & {
converter: {
type: ConvertorType;
} & Record<ConvertorType, Converter>;
};
export interface DeviceConnectorMapping {
deviceNodePattern: string;
deviceNodeSource: string;
deviceInfo: DeviceInfo;
attributes: Attribute[];
timeseries: Timeseries[];
rpc_methods: RpcMethod[];
attributes_updates: AttributesUpdate[];
attributes?: Attribute[];
timeseries?: Timeseries[];
rpc_methods?: RpcMethod[];
attributes_updates?: AttributesUpdate[];
}
export enum ConnectorType {
@ -605,6 +613,10 @@ export interface RequestMappingData {
requestValue: RequestDataItem;
}
export type RequestMappingFormValue = Omit<RequestMappingData, 'requestValue'> & {
requestValue: Record<RequestType, RequestDataItem>;
};
export interface RequestDataItem {
type: string;
details: string;

Loading…
Cancel
Save