Skip to content

Commit 5fcb6f1

Browse files
committed
Added Decimal places to numbers
1 parent c75937c commit 5fcb6f1

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/app/specification/entity/entity.component.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,23 @@
183183
</mat-form-field>
184184
</div>
185185
<div class="flexrows">
186-
<mat-form-field class="smallfield width150pt">
186+
<mat-form-field class="smallfield width100pt">
187187
<mat-label>Multiplier</mat-label>
188188
<input #propMultiplier matInput type="number" formControlName="multiplier"
189189
(change)="onConverterValueChange()">
190190
<mat-error *ngIf="numberPropertiesFormGroup.get('multiplier')!.hasError('required')">
191191
This field is required
192192
</mat-error>
193193
</mat-form-field>
194-
<mat-form-field class="smallfield width100pt">
194+
<mat-form-field class="smallfield width80pt">
195195
<mat-label>Offset</mat-label>
196196
<input #propOffset matInput type="number" formControlName="offset"
197197
(change)="onConverterValueChange()">
198198
<mat-error *ngIf="numberPropertiesFormGroup.get('offset')!.hasError('required')">
199199
This field is required
200200
</mat-error>
201201
</mat-form-field>
202-
<mat-form-field class="smallfield width150pt">
202+
<mat-form-field class="smallfield width130pt">
203203
<mat-label>Number Format</mat-label>
204204
<mat-select matInput formControlName="numberFormat" [errorStateMatcher]="errorStateMatcher"
205205
(selectionChange)="onConverterValueChange()" [compareWith]="compareNumber">
@@ -211,6 +211,18 @@
211211
This field is required
212212
</mat-error>
213213
</mat-form-field>
214+
<mat-form-field class="smallfield width100pt">
215+
<mat-label>Decimals</mat-label>
216+
<mat-select matInput formControlName="decimals"
217+
(selectionChange)="onConverterValueChange()" [compareWith]="compareNumber">
218+
<mat-option [value]="-1"></mat-option>
219+
<mat-option [value]="0">0</mat-option>
220+
<mat-option [value]="1">1</mat-option>
221+
<mat-option [value]="2">2</mat-option>
222+
<mat-option [value]="3">3</mat-option>
223+
<mat-option [value]="4">4</mat-option>
224+
</mat-select>
225+
</mat-form-field>
214226

215227
</div>
216228
<h3 class="smallfield width150pt"> Identification{{entity.readonly?"":"/step"}}</h3>

src/app/specification/entity/entity.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export class EntityComponent
242242
stateClass: [null as EnumStateClasses | null],
243243
multiplier: [1, Validators.required],
244244
offset: [0, Validators.required],
245+
decimals:[2],
245246
numberFormat: [EnumNumberFormat.default, Validators.required],
246247
uom: [null as string | null],
247248
min: [null as string | null],
@@ -438,6 +439,9 @@ export class EntityComponent
438439
this.numberPropertiesFormGroup
439440
.get("offset")!
440441
.setValue(np.offset ? np.offset : 0);
442+
this.numberPropertiesFormGroup
443+
.get("decimals")!
444+
.setValue(np.decimals != undefined ? np.decimals : -1);
441445
let dc = this.getDeviceClass(np.device_class)
442446
this.numberPropertiesFormGroup
443447
.get("deviceClass")!
@@ -730,6 +734,10 @@ export class EntityComponent
730734
enumber.offset =
731735
this.numberPropertiesFormGroup.get("offset")!.value;
732736
else enumber.offset = 0;
737+
if (this.numberPropertiesFormGroup.get("decimals")!.value != null)
738+
enumber.decimals =
739+
this.numberPropertiesFormGroup.get("decimals")!.value;
740+
else enumber.decimals = 2;
733741
if (this.numberPropertiesFormGroup.get("numberFormat")!.value != null)
734742
enumber.numberFormat =
735743
this.numberPropertiesFormGroup.get("numberFormat")!.value;
@@ -998,7 +1006,7 @@ export class EntityComponent
9981006
}
9991007
getMqttValue(rc: ImodbusEntity): string {
10001008
if (rc)
1001-
if (rc.converter.name === "number" && rc.mqttValue) {
1009+
if (rc.converter.name === "number" && rc.mqttValue!= undefined) {
10021010
return (rc.mqttValue as number).toString();
10031011
} else return rc.mqttValue as string;
10041012
return "N/A";

0 commit comments

Comments
 (0)