Browse Source

UI: Refactoring gateway connectors configuration

pull/11101/head
Vladyslav_Prykhodko 2 years ago
parent
commit
bbb2b1683e
  1. 2
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.html
  2. 16
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.ts
  3. 50
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/dialog/mapping-dialog.component.ts
  4. 8
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-widget.models.ts

2
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.html

@ -32,7 +32,7 @@
<div class="fixed-title-width tb-required" translate>gateway.type</div> <div class="fixed-title-width tb-required" translate>gateway.type</div>
<div class="tb-flex no-gap"> <div class="tb-flex no-gap">
<mat-form-field class="tb-flex no-gap fill-width" appearance="outline" subscriptSizing="dynamic"> <mat-form-field class="tb-flex no-gap fill-width" appearance="outline" subscriptSizing="dynamic">
<mat-select name="valueType" formControlName="type"> <mat-select formControlName="type">
<mat-select-trigger> <mat-select-trigger>
<div class="tb-flex align-center"> <div class="tb-flex align-center">
<mat-icon class="tb-mat-18" [svgIcon]="valueTypes.get(keyControl.get('type').value)?.icon"> <mat-icon class="tb-mat-18" [svgIcon]="valueTypes.get(keyControl.get('type').value)?.icon">

16
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/type-value-panel/type-value-panel.component.ts

@ -14,12 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { import { Component, forwardRef, OnDestroy, OnInit } from '@angular/core';
Component,
forwardRef,
OnDestroy,
OnInit,
} from '@angular/core';
import { import {
AbstractControl, AbstractControl,
ControlValueAccessor, ControlValueAccessor,
@ -31,7 +26,6 @@ import {
Validator, Validator,
Validators Validators
} from '@angular/forms'; } from '@angular/forms';
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
import { isDefinedAndNotNull } from '@core/utils'; import { isDefinedAndNotNull } from '@core/utils';
import { import {
MappingDataKey, MappingDataKey,
@ -60,12 +54,10 @@ import { Subject } from 'rxjs';
] ]
}) })
export class TypeValuePanelComponent implements ControlValueAccessor, Validator, OnInit, OnDestroy { export class TypeValuePanelComponent implements ControlValueAccessor, Validator, OnInit, OnDestroy {
valueTypeKeys = Object.values(MappingValueType);
valueTypeEnum = MappingValueType; valueTypeKeys: MappingValueType[] = Object.values(MappingValueType);
valueTypes = mappingValueTypesMap; valueTypes = mappingValueTypesMap;
dataKeyType: DataKeyType;
valueListFormArray: UntypedFormArray; valueListFormArray: UntypedFormArray;
errorText = '';
private destroy$ = new Subject<void>(); private destroy$ = new Subject<void>();
private propagateChange = (v: any) => {}; private propagateChange = (v: any) => {};
@ -138,7 +130,7 @@ export class TypeValuePanelComponent implements ControlValueAccessor, Validator,
}; };
} }
updateView(value: any): void { private updateView(value: any): void {
this.propagateChange(value); this.propagateChange(value);
} }
} }

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

@ -22,6 +22,8 @@ import { FormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { DialogComponent } from '@shared/components/dialog.component'; import { DialogComponent } from '@shared/components/dialog.component';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { import {
Attribute,
AttributesUpdate,
ConvertorType, ConvertorType,
ConvertorTypeTranslationsMap, ConvertorTypeTranslationsMap,
DataConversionTranslationsMap, DataConversionTranslationsMap,
@ -34,16 +36,19 @@ import {
MappingKeysPanelTitleTranslationsMap, MappingKeysPanelTitleTranslationsMap,
MappingKeysType, MappingKeysType,
MappingType, MappingType,
MappingTypeTranslationsMap, MappingValue, MappingTypeTranslationsMap,
MappingValue,
noLeadTrailSpacesRegex, noLeadTrailSpacesRegex,
OPCUaSourceTypes, OPCUaSourceTypes,
QualityTypes, QualityTypes,
QualityTypeTranslationsMap, QualityTypeTranslationsMap,
RequestType, RequestType,
RequestTypesTranslationsMap, RequestTypesTranslationsMap,
RpcMethod,
ServerSideRPCType, ServerSideRPCType,
SourceTypes, SourceTypes,
SourceTypeTranslationsMap SourceTypeTranslationsMap,
Timeseries
} from '@home/components/widget/lib/gateway/gateway-widget.models'; } from '@home/components/widget/lib/gateway/gateway-widget.models';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { startWith, takeUntil } from 'rxjs/operators'; import { startWith, takeUntil } from 'rxjs/operators';
@ -66,17 +71,17 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
qualityTypes = QualityTypes; qualityTypes = QualityTypes;
QualityTranslationsMap = QualityTypeTranslationsMap; QualityTranslationsMap = QualityTypeTranslationsMap;
convertorTypes = Object.values(ConvertorType); convertorTypes: ConvertorType[] = Object.values(ConvertorType);
ConvertorTypeEnum = ConvertorType; ConvertorTypeEnum = ConvertorType;
ConvertorTypeTranslationsMap = ConvertorTypeTranslationsMap; ConvertorTypeTranslationsMap = ConvertorTypeTranslationsMap;
sourceTypes = Object.values(SourceTypes); sourceTypes: SourceTypes[] = Object.values(SourceTypes);
OPCUaSourceTypes = Object.values(OPCUaSourceTypes) as Array<OPCUaSourceTypes>; OPCUaSourceTypes = Object.values(OPCUaSourceTypes) as Array<OPCUaSourceTypes>;
OPCUaSourceTypesEnum = OPCUaSourceTypes; OPCUaSourceTypesEnum = OPCUaSourceTypes;
sourceTypesEnum = SourceTypes; sourceTypesEnum = SourceTypes;
SourceTypeTranslationsMap = SourceTypeTranslationsMap; SourceTypeTranslationsMap = SourceTypeTranslationsMap;
requestTypes = Object.values(RequestType); requestTypes: RequestType[] = Object.values(RequestType);
RequestTypeEnum = RequestType; RequestTypeEnum = RequestType;
RequestTypesTranslationsMap = RequestTypesTranslationsMap; RequestTypesTranslationsMap = RequestTypesTranslationsMap;
@ -92,12 +97,8 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
DataConversionTranslationsMap = DataConversionTranslationsMap; DataConversionTranslationsMap = DataConversionTranslationsMap;
hiddenAttributesCount = 0;
keysPopupClosed = true; keysPopupClosed = true;
submitted = false;
private destroy$ = new Subject<void>(); private destroy$ = new Subject<void>();
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
@ -116,30 +117,30 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
get converterAttributes(): Array<string> { get converterAttributes(): Array<string> {
if (this.converterType) { if (this.converterType) {
return this.mappingForm.get('converter').get(this.converterType).value.attributes.map(value => value.key); return this.mappingForm.get('converter').get(this.converterType).value.attributes.map((value: Attribute) => value.key);
} }
} }
get converterTelemetry(): Array<string> { get converterTelemetry(): Array<string> {
if (this.converterType) { if (this.converterType) {
return this.mappingForm.get('converter').get(this.converterType).value.timeseries.map(value => value.key); return this.mappingForm.get('converter').get(this.converterType).value.timeseries.map((value: Timeseries) => value.key);
} }
} }
get opcAttributes(): Array<string> { get opcAttributes(): Array<string> {
return this.mappingForm.get('attributes').value?.map(value => value.key) || []; return this.mappingForm.get('attributes').value?.map((value: Attribute) => value.key) || [];
} }
get opcTelemetry(): Array<string> { get opcTelemetry(): Array<string> {
return this.mappingForm.get('timeseries').value?.map(value => value.key) || []; return this.mappingForm.get('timeseries').value?.map((value: Timeseries) => value.key) || [];
} }
get opcRpcMethods(): Array<string> { get opcRpcMethods(): Array<string> {
return this.mappingForm.get('rpc_methods').value?.map(value => value.method) || []; return this.mappingForm.get('rpc_methods').value?.map((value: RpcMethod) => value.method) || [];
} }
get opcAttributesUpdates(): Array<string> { get opcAttributesUpdates(): Array<string> {
return this.mappingForm.get('attributes_updates')?.value?.map(value => value.key) || []; return this.mappingForm.get('attributes_updates')?.value?.map((value: AttributesUpdate) => value.key) || [];
} }
get converterType(): ConvertorType { get converterType(): ConvertorType {
@ -197,7 +198,6 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
} }
add(): void { add(): void {
this.submitted = true;
if (this.mappingForm.valid) { if (this.mappingForm.valid) {
this.dialogRef.close(this.prepareMappingData()); this.dialogRef.close(this.prepareMappingData());
} }
@ -215,9 +215,9 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
: this.mappingForm; : this.mappingForm;
const keysControl = group.get(keysType); const keysControl = group.get(keysType);
const ctx: {[key: string]: any} = { const ctx: { [key: string]: any } = {
keys: keysControl.value, keys: keysControl.value,
keysType: keysType, keysType,
rawData: this.mappingForm.get('converter.type')?.value === ConvertorType.BYTES, rawData: this.mappingForm.get('converter.type')?.value === ConvertorType.BYTES,
panelTitle: MappingKeysPanelTitleTranslationsMap.get(keysType), panelTitle: MappingKeysPanelTitleTranslationsMap.get(keysType),
addKeyTitle: MappingKeysAddKeyTranslationsMap.get(keysType), addKeyTitle: MappingKeysAddKeyTranslationsMap.get(keysType),
@ -247,11 +247,11 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
} }
} }
private prepareMappingData(): {[key: string]: unknown} { private prepareMappingData(): { [key: string]: unknown } {
const formValue = this.mappingForm.value; const formValue = this.mappingForm.value;
switch (this.data.mappingType) { switch (this.data.mappingType) {
case MappingType.DATA: case MappingType.DATA:
const { converter, topicFilter, subscriptionQos } = formValue; const {converter, topicFilter, subscriptionQos} = formValue;
return { return {
topicFilter, topicFilter,
subscriptionQos, subscriptionQos,
@ -270,17 +270,17 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
} }
} }
private prepareFormValueData(): {[key: string]: unknown} { private prepareFormValueData(): { [key: string]: unknown } {
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:
const { converter, topicFilter, subscriptionQos } = this.data.value; const {converter, topicFilter, subscriptionQos} = this.data.value;
return { return {
topicFilter, topicFilter,
subscriptionQos, subscriptionQos,
converter: { converter: {
type: converter.type, type: converter.type,
[converter.type]: { ...converter } [converter.type]: {...converter}
} }
}; };
case MappingType.REQUESTS: case MappingType.REQUESTS:
@ -327,7 +327,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
converterGroup.get('bytes').disable({emitEvent: false}); converterGroup.get('bytes').disable({emitEvent: false});
converterGroup.get('custom').disable({emitEvent: false}); converterGroup.get('custom').disable({emitEvent: false});
converterGroup.get(value).enable({emitEvent: false}); converterGroup.get(value).enable({emitEvent: false});
}) });
} }
private createRequestMappingForm(): void { private createRequestMappingForm(): void {
@ -343,7 +343,7 @@ export class MappingDialogComponent extends DialogComponent<MappingDialogCompone
}), }),
attributeRequests: this.fb.group({ attributeRequests: this.fb.group({
topicFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], topicFilter: ['', [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
deviceInfo: this.fb.group({ deviceInfo: this.fb.group({
deviceNameExpressionSource: [SourceTypes.MSG, []], deviceNameExpressionSource: [SourceTypes.MSG, []],
deviceNameExpression: ['', [Validators.required]], deviceNameExpression: ['', [Validators.required]],
}), }),

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

@ -195,13 +195,13 @@ interface DeviceInfo {
deviceProfileExpressionSource: string; deviceProfileExpressionSource: string;
} }
interface Attribute { export interface Attribute {
key: string; key: string;
type: string; type: string;
value: string; value: string;
} }
interface Timeseries { export interface Timeseries {
key: string; key: string;
type: string; type: string;
value: string; value: string;
@ -212,12 +212,12 @@ interface RpcArgument {
value: number; value: number;
} }
interface RpcMethod { export interface RpcMethod {
method: string; method: string;
arguments: RpcArgument[]; arguments: RpcArgument[];
} }
interface AttributesUpdate { export interface AttributesUpdate {
key: string; key: string;
type: string; type: string;
value: string; value: string;

Loading…
Cancel
Save