+
+
+
+
-
-
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.html
index 17f5185bc6..105a3c0e8e 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.html
+++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.html
@@ -23,6 +23,16 @@
+
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.scss
index b70fe42401..3b7e7288c8 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.scss
+++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.scss
@@ -16,9 +16,3 @@
:host {
height: 100%;
}
-
-:host ::ng-deep {
- .mat-mdc-tab-body-content {
- overflow: hidden !important;
- }
-}
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.ts
index 1fca768980..aa0424da93 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.ts
+++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-basic-config/modbus-basic-config.component.ts
@@ -18,13 +18,15 @@ import { ChangeDetectionStrategy, Component, forwardRef, Input, OnDestroy, Templ
import {
ControlValueAccessor,
FormBuilder,
+ FormControl,
FormGroup,
NG_VALIDATORS,
NG_VALUE_ACCESSOR,
+ UntypedFormControl,
ValidationErrors,
Validator,
} from '@angular/forms';
-import { ConnectorType, ModbusBasicConfig } from '@home/components/widget/lib/gateway/gateway-widget.models';
+import { ModbusBasicConfig } from '@home/components/widget/lib/gateway/gateway-widget.models';
import { SharedModule } from '@shared/shared.module';
import { CommonModule } from '@angular/common';
import { takeUntil } from 'rxjs/operators';
@@ -33,6 +35,7 @@ import { Subject } from 'rxjs';
import { EllipsisChipListDirective } from '@shared/directives/ellipsis-chip-list.directive';
import { ModbusSlaveConfigComponent } from '../modbus-slave-config/modbus-slave-config.component';
import { ModbusMasterTableComponent } from '../modbus-master-table/modbus-master-table.component';
+import { isEqual } from '@core/utils';
@Component({
selector: 'tb-modbus-basic-config',
@@ -66,6 +69,7 @@ export class ModbusBasicConfigComponent implements ControlValueAccessor, Validat
@Input() generalTabContent: TemplateRef
;
basicFormGroup: FormGroup;
+ enableSlaveControl: FormControl;
onChange: (value: ModbusBasicConfig) => void;
onTouched: () => void;
@@ -77,13 +81,21 @@ export class ModbusBasicConfigComponent implements ControlValueAccessor, Validat
master: [],
slave: [],
});
+ this.enableSlaveControl = new FormControl(false);
this.basicFormGroup.valueChanges
.pipe(takeUntil(this.destroy$))
- .subscribe(value => {
- this.onChange(value);
+ .subscribe(({ master, slave }) => {
+ this.onChange({ master, slave: slave ?? {} });
this.onTouched();
});
+
+ this.enableSlaveControl.valueChanges
+ .pipe(takeUntil(this.destroy$))
+ .subscribe(enable => {
+ this.updateSlaveEnabling(enable);
+ this.basicFormGroup.get('slave').updateValueAndValidity({emitEvent: !!this.onChange});
+ });
}
ngOnDestroy(): void {
@@ -106,11 +118,25 @@ export class ModbusBasicConfigComponent implements ControlValueAccessor, Validat
};
this.basicFormGroup.setValue(editedBase, {emitEvent: false});
+ this.enableSlaveControl.setValue(!!basicConfig.slave && !isEqual(basicConfig.slave, {}));
}
- validate(): ValidationErrors | null {
- return this.basicFormGroup.valid ? null : {
- basicFormGroup: {valid: false}
- };
+ validate(basicFormControl: UntypedFormControl): ValidationErrors | null {
+ const { master, slave } = basicFormControl.value;
+ const isEmpty = !master?.slaves?.length && (isEqual(slave, {}) || !slave);
+ if (!this.basicFormGroup.valid || isEmpty) {
+ return {
+ basicFormGroup: {valid: false}
+ };
+ }
+ return null;
+ }
+
+ private updateSlaveEnabling(isEnabled: boolean): void {
+ if (isEnabled) {
+ this.basicFormGroup.get('slave').enable({emitEvent: false});
+ } else {
+ this.basicFormGroup.get('slave').disable({emitEvent: false});
+ }
}
}
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.html
index 02d2d1491d..f53e3ee277 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.html
+++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.html
@@ -26,12 +26,16 @@
-
-
- {{ keyControl.get('tag').value }}{{ '-' }}{{ keyControl.get('value').value }}
-
-
{{ keyControl.get('tag').value }}
+
+ {{ keyControl.get('tag').value }}{{ '-' }}{{ keyControl.get('value').value }}
+
+
+
{{ 'gateway.key' | translate }}: {{ keyControl.get('tag').value }}
+
{{ 'gateway.address' | translate }}: {{ keyControl.get('address').value }}
+
{{ 'gateway.type' | translate }}: {{ keyControl.get('type').value }}
+
+
@@ -98,7 +102,7 @@
name="value"
formControlName="objectsCount"
placeholder="{{ 'gateway.set' | translate }}"
- [readonly]="!editableDataTypes.includes(keyControl.get('type').value)"
+ [readonly]="!ModbusEditableDataTypes.includes(keyControl.get('type').value)"
/>
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.scss b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.scss
index 0e9f9a432f..445ac6c0ae 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.scss
+++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.scss
@@ -20,10 +20,7 @@
max-width: 700px;
.title-container {
- max-width: 11vw;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap
+ width: 180px;
}
.key-panel {
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.ts
index 5b312f52c8..93ca232e38 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.ts
+++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-data-keys-panel/modbus-data-keys-panel.component.ts
@@ -27,6 +27,7 @@ import {
import { TbPopoverComponent } from '@shared/components/popover.component';
import {
ModbusDataType,
+ ModbusEditableDataTypes,
ModbusFunctionCodeTranslationsMap,
ModbusObjectCountByDataType,
ModbusValue,
@@ -40,6 +41,7 @@ import { generateSecret } from '@core/utils';
import { coerceBoolean } from '@shared/decorators/coercion';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
+import { TruncateWithTooltipDirective } from '@shared/directives/truncate-with-tooltip.directive';
@Component({
selector: 'tb-modbus-data-keys-panel',
@@ -50,6 +52,7 @@ import { Subject } from 'rxjs';
CommonModule,
SharedModule,
GatewayHelpLinkPipe,
+ TruncateWithTooltipDirective,
]
})
export class ModbusDataKeysPanelComponent implements OnInit, OnDestroy {
@@ -72,14 +75,15 @@ export class ModbusDataKeysPanelComponent implements OnInit, OnDestroy {
functionCodesMap = new Map();
defaultFunctionCodes = [];
- readonly editableDataTypes = [ModbusDataType.BYTES, ModbusDataType.BITS, ModbusDataType.STRING];
+ readonly ModbusEditableDataTypes = ModbusEditableDataTypes;
readonly ModbusFunctionCodeTranslationsMap = ModbusFunctionCodeTranslationsMap;
private destroy$ = new Subject();
private readonly defaultReadFunctionCodes = [3, 4];
- private readonly defaultWriteFunctionCodes = [5, 6, 15, 16];
- private readonly stringAttrUpdatesWriteFunctionCodes = [6, 16];
+ private readonly bitsReadFunctionCodes = [1, 2];
+ private readonly defaultWriteFunctionCodes = [6, 16];
+ private readonly bitsWriteFunctionCodes = [5, 15];
constructor(private fb: UntypedFormBuilder) {}
@@ -161,7 +165,7 @@ export class ModbusDataKeysPanelComponent implements OnInit, OnDestroy {
private observeKeyDataType(keyFormGroup: FormGroup): void {
keyFormGroup.get('type').valueChanges.pipe(takeUntil(this.destroy$)).subscribe(dataType => {
- if (!this.editableDataTypes.includes(dataType)) {
+ if (!this.ModbusEditableDataTypes.includes(dataType)) {
keyFormGroup.get('objectsCount').patchValue(ModbusObjectCountByDataType[dataType], {emitEvent: false});
}
this.updateFunctionCodes(keyFormGroup, dataType);
@@ -177,23 +181,23 @@ export class ModbusDataKeysPanelComponent implements OnInit, OnDestroy {
}
private getFunctionCodes(dataType: ModbusDataType): number[] {
+ const writeFunctionCodes = [
+ ...(dataType === ModbusDataType.BITS ? this.bitsWriteFunctionCodes : []), ...this.defaultWriteFunctionCodes
+ ];
+
if (this.keysType === ModbusValueKey.ATTRIBUTES_UPDATES) {
- return dataType === ModbusDataType.STRING
- ? this.stringAttrUpdatesWriteFunctionCodes
- : this.defaultWriteFunctionCodes;
+ return writeFunctionCodes.sort((a, b) => a - b);
}
const functionCodes = [...this.defaultReadFunctionCodes];
if (dataType === ModbusDataType.BITS) {
- const bitsFunctionCodes = [1, 2];
- functionCodes.push(...bitsFunctionCodes);
- functionCodes.sort();
+ functionCodes.push(...this.bitsReadFunctionCodes);
}
if (this.keysType === ModbusValueKey.RPC_REQUESTS) {
- functionCodes.push(...this.defaultWriteFunctionCodes);
+ functionCodes.push(...writeFunctionCodes);
}
- return functionCodes;
+ return functionCodes.sort((a, b) => a - b);
}
private getDefaultFunctionCodes(): number[] {
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-master-table/modbus-master-table.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-master-table/modbus-master-table.component.html
index e16aa0c51f..8f8aeaeef7 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-master-table/modbus-master-table.component.html
+++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/connectors-configuration/modbus/modbus-master-table/modbus-master-table.component.html
@@ -16,9 +16,12 @@
-->