Browse Source

[4114] fixed number version bug, added hide new field for opc and refactoring

pull/11516/head
mpetrov 2 years ago
parent
commit
148108006c
  1. 16
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/abstract/gateway-connector-version-processor.abstract.ts
  2. 8
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/abstract/modbus-version-processor.abstract.ts
  3. 8
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/abstract/mqtt-version-processor.abstract.ts
  4. 8
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/abstract/opc-version-processor.abstract.ts
  5. 2
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-server-config/opc-server-config.component.html
  6. 15
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-server-config/opc-server-config.component.ts
  7. 2
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-ua-basic-config/opc-ua-basic-config.component.html
  8. 1
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-ua-basic-config/opc-ua-basic-config.component.ts
  9. 1
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-ua-basic-config/opc-ua-legacy-basic-config.component.ts
  10. 8
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-widget.models.ts
  11. 2
      ui-ngx/src/assets/metadata/connector-default-configs/modbus.json
  12. 2
      ui-ngx/src/assets/metadata/connector-default-configs/mqtt.json
  13. 2
      ui-ngx/src/assets/metadata/connector-default-configs/opcua.json

16
ui-ngx/src/app/modules/home/components/widget/lib/gateway/abstract/gateway-connector-version-processor.abstract.ts

@ -15,14 +15,14 @@
/// ///
import { GatewayConnector, GatewayVersion } from '@home/components/widget/lib/gateway/gateway-widget.models'; import { GatewayConnector, GatewayVersion } from '@home/components/widget/lib/gateway/gateway-widget.models';
import { isString } from '@core/utils'; import { isNumber, isString } from '@core/utils';
export abstract class GatewayConnectorVersionProcessor<BasicConfig> { export abstract class GatewayConnectorVersionProcessor<BasicConfig> {
gatewayVersion: number; gatewayVersion: number;
configVersion: number; configVersion: number;
protected constructor(protected gatewayVersionStr: string, protected connector: GatewayConnector<BasicConfig>) { protected constructor(protected gatewayVersionIn: string | number, protected connector: GatewayConnector<BasicConfig>) {
this.gatewayVersion = this.parseVersion(this.gatewayVersionStr); this.gatewayVersion = this.parseVersion(this.gatewayVersionIn);
this.configVersion = this.parseVersion(connector.configVersion); this.configVersion = this.parseVersion(connector.configVersion);
} }
@ -45,11 +45,15 @@ export abstract class GatewayConnectorVersionProcessor<BasicConfig> {
} }
private isVersionUpgradeNeeded(): boolean { private isVersionUpgradeNeeded(): boolean {
return this.gatewayVersionStr === GatewayVersion.Current && (!this.configVersion || this.configVersion < this.gatewayVersion); return this.gatewayVersionIn === GatewayVersion.Current && (!this.configVersion || this.configVersion < this.gatewayVersion);
} }
private parseVersion(version: string): number { private parseVersion(version: string | number): number {
return isString(version) ? Number(version.replace(/\./g, '')) : 0; if (isNumber(version)) {
return version as number;
}
return isString(version) ? parseFloat((version as string).replace(/\./g, '').slice(0, 3)) / 100 : 0;
} }
protected abstract getDowngradedVersion(): GatewayConnector<BasicConfig>; protected abstract getDowngradedVersion(): GatewayConnector<BasicConfig>;

8
ui-ngx/src/app/modules/home/components/widget/lib/gateway/abstract/modbus-version-processor.abstract.ts

@ -29,10 +29,10 @@ import { ModbusVersionMappingUtil } from '@home/components/widget/lib/gateway/ut
export class ModbusVersionProcessor extends GatewayConnectorVersionProcessor<any> { export class ModbusVersionProcessor extends GatewayConnectorVersionProcessor<any> {
constructor( constructor(
protected gatewayVersionStr: string, protected gatewayVersionIn: string,
protected connector: GatewayConnector<ModbusBasicConfig> protected connector: GatewayConnector<ModbusBasicConfig>
) { ) {
super(gatewayVersionStr, connector); super(gatewayVersionIn, connector);
} }
getUpgradedVersion(): GatewayConnector<ModbusBasicConfig_v3_5_2> { getUpgradedVersion(): GatewayConnector<ModbusBasicConfig_v3_5_2> {
@ -47,7 +47,7 @@ export class ModbusVersionProcessor extends GatewayConnectorVersionProcessor<any
? ModbusVersionMappingUtil.mapSlaveToUpgradedVersion(configurationJson.slave as ModbusLegacySlave) ? ModbusVersionMappingUtil.mapSlaveToUpgradedVersion(configurationJson.slave as ModbusLegacySlave)
: {} as ModbusSlave, : {} as ModbusSlave,
}, },
configVersion: this.gatewayVersionStr configVersion: this.gatewayVersionIn
} as GatewayConnector<ModbusBasicConfig_v3_5_2>; } as GatewayConnector<ModbusBasicConfig_v3_5_2>;
} }
@ -62,7 +62,7 @@ export class ModbusVersionProcessor extends GatewayConnectorVersionProcessor<any
: {} as ModbusLegacySlave, : {} as ModbusLegacySlave,
master: configurationJson.master, master: configurationJson.master,
}, },
configVersion: this.gatewayVersionStr configVersion: this.gatewayVersionIn
} as GatewayConnector<ModbusLegacyBasicConfig>; } as GatewayConnector<ModbusLegacyBasicConfig>;
} }
} }

8
ui-ngx/src/app/modules/home/components/widget/lib/gateway/abstract/mqtt-version-processor.abstract.ts

@ -31,10 +31,10 @@ export class MqttVersionProcessor extends GatewayConnectorVersionProcessor<MQTTB
private readonly mqttRequestTypeKeys = Object.values(RequestType); private readonly mqttRequestTypeKeys = Object.values(RequestType);
constructor( constructor(
protected gatewayVersionStr: string, protected gatewayVersionIn: string,
protected connector: GatewayConnector<MQTTBasicConfig> protected connector: GatewayConnector<MQTTBasicConfig>
) { ) {
super(gatewayVersionStr, connector); super(gatewayVersionIn, connector);
} }
getUpgradedVersion(): GatewayConnector<MQTTBasicConfig_v3_5_2> { getUpgradedVersion(): GatewayConnector<MQTTBasicConfig_v3_5_2> {
@ -67,7 +67,7 @@ export class MqttVersionProcessor extends GatewayConnectorVersionProcessor<MQTTB
return { return {
...this.connector, ...this.connector,
configurationJson, configurationJson,
configVersion: this.gatewayVersionStr configVersion: this.gatewayVersionIn
} as GatewayConnector<MQTTBasicConfig_v3_5_2>; } as GatewayConnector<MQTTBasicConfig_v3_5_2>;
} }
@ -85,7 +85,7 @@ export class MqttVersionProcessor extends GatewayConnectorVersionProcessor<MQTTB
...updatedRequestsMapping, ...updatedRequestsMapping,
mapping: updatedMapping, mapping: updatedMapping,
}, },
configVersion: this.gatewayVersionStr configVersion: this.gatewayVersionIn
} as GatewayConnector<MQTTLegacyBasicConfig>; } as GatewayConnector<MQTTLegacyBasicConfig>;
} }

8
ui-ngx/src/app/modules/home/components/widget/lib/gateway/abstract/opc-version-processor.abstract.ts

@ -26,10 +26,10 @@ import { OpcVersionMappingUtil } from '@home/components/widget/lib/gateway/utils
export class OpcVersionProcessor extends GatewayConnectorVersionProcessor<OPCBasicConfig> { export class OpcVersionProcessor extends GatewayConnectorVersionProcessor<OPCBasicConfig> {
constructor( constructor(
protected gatewayVersionStr: string, protected gatewayVersionIn: string,
protected connector: GatewayConnector<OPCBasicConfig> protected connector: GatewayConnector<OPCBasicConfig>
) { ) {
super(gatewayVersionStr, connector); super(gatewayVersionIn, connector);
} }
getUpgradedVersion(): GatewayConnector<OPCBasicConfig_v3_5_2> { getUpgradedVersion(): GatewayConnector<OPCBasicConfig_v3_5_2> {
@ -40,7 +40,7 @@ export class OpcVersionProcessor extends GatewayConnectorVersionProcessor<OPCBas
server: server ? OpcVersionMappingUtil.mapServerToUpgradedVersion(server) : {}, server: server ? OpcVersionMappingUtil.mapServerToUpgradedVersion(server) : {},
mapping: server.mapping ? OpcVersionMappingUtil.mapMappingToUpgradedVersion(server.mapping) : [], mapping: server.mapping ? OpcVersionMappingUtil.mapMappingToUpgradedVersion(server.mapping) : [],
}, },
configVersion: this.gatewayVersionStr configVersion: this.gatewayVersionIn
} as GatewayConnector<OPCBasicConfig_v3_5_2>; } as GatewayConnector<OPCBasicConfig_v3_5_2>;
} }
@ -50,7 +50,7 @@ export class OpcVersionProcessor extends GatewayConnectorVersionProcessor<OPCBas
configurationJson: { configurationJson: {
server: OpcVersionMappingUtil.mapServerToDowngradedVersion(this.connector.configurationJson as OPCBasicConfig_v3_5_2) server: OpcVersionMappingUtil.mapServerToDowngradedVersion(this.connector.configurationJson as OPCBasicConfig_v3_5_2)
}, },
configVersion: this.gatewayVersionStr configVersion: this.gatewayVersionIn
} as GatewayConnector<OPCLegacyBasicConfig>; } as GatewayConnector<OPCLegacyBasicConfig>;
} }
} }

2
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-server-config/opc-server-config.component.html

@ -84,7 +84,7 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div class="tb-form-row column-xs" fxLayoutAlign="space-between center"> <div *ngIf="!hideNewFields" class="tb-form-row column-xs" fxLayoutAlign="space-between center">
<div class="fixed-title-width" tb-hint-tooltip-icon="{{ 'gateway.hints.poll-period' | translate }}"> <div class="fixed-title-width" tb-hint-tooltip-icon="{{ 'gateway.hints.poll-period' | translate }}">
<div tbTruncateWithTooltip>{{ 'gateway.poll-period' | translate }}</div> <div tbTruncateWithTooltip>{{ 'gateway.poll-period' | translate }}</div>
</div> </div>

15
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-server-config/opc-server-config.component.ts

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { ChangeDetectionStrategy, Component, forwardRef, OnDestroy } from '@angular/core'; import { AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, Input, OnDestroy } from '@angular/core';
import { import {
ControlValueAccessor, ControlValueAccessor,
FormBuilder, FormBuilder,
@ -39,6 +39,7 @@ import {
SecurityConfigComponent SecurityConfigComponent
} from '@home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component'; } from '@home/components/widget/lib/gateway/connectors-configuration/security-config/security-config.component';
import { HOUR } from '@shared/models/time/time.models'; import { HOUR } from '@shared/models/time/time.models';
import { coerceBoolean } from '@shared/decorators/coercion';
@Component({ @Component({
selector: 'tb-opc-server-config', selector: 'tb-opc-server-config',
@ -64,7 +65,11 @@ import { HOUR } from '@shared/models/time/time.models';
SecurityConfigComponent, SecurityConfigComponent,
] ]
}) })
export class OpcServerConfigComponent implements ControlValueAccessor, Validator, OnDestroy { export class OpcServerConfigComponent implements ControlValueAccessor, Validator, AfterViewInit, OnDestroy {
@Input()
@coerceBoolean()
hideNewFields: boolean = false;
securityPolicyTypes = SecurityPolicyTypes; securityPolicyTypes = SecurityPolicyTypes;
serverConfigFormGroup: UntypedFormGroup; serverConfigFormGroup: UntypedFormGroup;
@ -95,6 +100,12 @@ export class OpcServerConfigComponent implements ControlValueAccessor, Validator
}); });
} }
ngAfterViewInit(): void {
if (this.hideNewFields) {
this.serverConfigFormGroup.get('pollPeriodInMillis').disable({emitEvent: false});
}
}
ngOnDestroy(): void { ngOnDestroy(): void {
this.destroy$.next(); this.destroy$.next();
this.destroy$.complete(); this.destroy$.complete();

2
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-ua-basic-config/opc-ua-basic-config.component.html

@ -20,7 +20,7 @@
<ng-container [ngTemplateOutlet]="generalTabContent"></ng-container> <ng-container [ngTemplateOutlet]="generalTabContent"></ng-container>
</mat-tab> </mat-tab>
<mat-tab label="{{ 'gateway.server' | translate }}*"> <mat-tab label="{{ 'gateway.server' | translate }}*">
<tb-opc-server-config formControlName="server"></tb-opc-server-config> <tb-opc-server-config formControlName="server" [hideNewFields]="isLegacy"></tb-opc-server-config>
</mat-tab> </mat-tab>
<mat-tab label="{{ 'gateway.data-mapping' | translate }}*"> <mat-tab label="{{ 'gateway.data-mapping' | translate }}*">
<div class="tb-form-panel no-border no-padding padding-top tb-flex fill-height"> <div class="tb-form-panel no-border no-padding padding-top tb-flex fill-height">

1
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-ua-basic-config/opc-ua-basic-config.component.ts

@ -63,6 +63,7 @@ import {
export class OpcUaBasicConfigComponent extends GatewayConnectorBasicConfigDirective<OPCBasicConfig_v3_5_2, OPCBasicConfig_v3_5_2> { export class OpcUaBasicConfigComponent extends GatewayConnectorBasicConfigDirective<OPCBasicConfig_v3_5_2, OPCBasicConfig_v3_5_2> {
mappingTypes = MappingType; mappingTypes = MappingType;
isLegacy = false;
protected override initBasicFormGroup(): FormGroup { protected override initBasicFormGroup(): FormGroup {
return this.fb.group({ return this.fb.group({

1
ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/opc/opc-ua-basic-config/opc-ua-legacy-basic-config.component.ts

@ -64,6 +64,7 @@ import { OpcVersionMappingUtil } from '@home/components/widget/lib/gateway/utils
export class OpcUaLegacyBasicConfigComponent extends GatewayConnectorBasicConfigDirective<OPCBasicConfig_v3_5_2, OPCLegacyBasicConfig> { export class OpcUaLegacyBasicConfigComponent extends GatewayConnectorBasicConfigDirective<OPCBasicConfig_v3_5_2, OPCLegacyBasicConfig> {
mappingTypes = MappingType; mappingTypes = MappingType;
isLegacy = true;
protected override initBasicFormGroup(): FormGroup { protected override initBasicFormGroup(): FormGroup {
return this.fb.group({ return this.fb.group({

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

@ -131,7 +131,7 @@ export interface GatewayConnector<BaseConfig = ConnectorBaseConfig> extends Gate
export interface GatewayVersionedDefaultConfig { export interface GatewayVersionedDefaultConfig {
legacy: GatewayConnector<ConnectorLegacyConfig>; legacy: GatewayConnector<ConnectorLegacyConfig>;
'3.5.1': GatewayConnector<ConnectorBaseConfig_v_3_5_2>; '3.5.2': GatewayConnector<ConnectorBaseConfig_v3_5_2>;
} }
export interface DataMapping { export interface DataMapping {
@ -189,7 +189,7 @@ export interface ConnectorSecurity {
} }
export enum GatewayVersion { export enum GatewayVersion {
Current = '3.5.1', Current = '3.5.2',
Legacy = 'legacy' Legacy = 'legacy'
} }
@ -197,11 +197,11 @@ export type ConnectorMapping = DeviceConnectorMapping | RequestMappingValue | Co
export type ConnectorMappingFormValue = DeviceConnectorMapping | RequestMappingFormValue | ConverterMappingFormValue; export type ConnectorMappingFormValue = DeviceConnectorMapping | RequestMappingFormValue | ConverterMappingFormValue;
export type ConnectorBaseConfig = ConnectorBaseConfig_v_3_5_2 | ConnectorLegacyConfig; export type ConnectorBaseConfig = ConnectorBaseConfig_v3_5_2 | ConnectorLegacyConfig;
export type ConnectorLegacyConfig = ConnectorBaseInfo | MQTTLegacyBasicConfig | OPCLegacyBasicConfig | ModbusBasicConfig; export type ConnectorLegacyConfig = ConnectorBaseInfo | MQTTLegacyBasicConfig | OPCLegacyBasicConfig | ModbusBasicConfig;
export type ConnectorBaseConfig_v_3_5_2 = ConnectorBaseInfo | MQTTBasicConfig_v3_5_2 | OPCBasicConfig_v3_5_2; export type ConnectorBaseConfig_v3_5_2 = ConnectorBaseInfo | MQTTBasicConfig_v3_5_2 | OPCBasicConfig_v3_5_2;
export interface ConnectorBaseInfo { export interface ConnectorBaseInfo {
name: string; name: string;

2
ui-ngx/src/assets/metadata/connector-default-configs/modbus.json

@ -1,5 +1,5 @@
{ {
"3.5.1": { "3.5.2": {
"master": { "master": {
"slaves": [ "slaves": [
{ {

2
ui-ngx/src/assets/metadata/connector-default-configs/mqtt.json

@ -1,5 +1,5 @@
{ {
"3.5.1": { "3.5.2": {
"broker": { "broker": {
"host": "127.0.0.1", "host": "127.0.0.1",
"port": 1883, "port": 1883,

2
ui-ngx/src/assets/metadata/connector-default-configs/opcua.json

@ -1,5 +1,5 @@
{ {
"3.5.1": { "3.5.2": {
"server": { "server": {
"url": "localhost:4840/freeopcua/server/", "url": "localhost:4840/freeopcua/server/",
"timeoutInMillis": 5000, "timeoutInMillis": 5000,

Loading…
Cancel
Save