Skip to content

Commit ab6cbf3

Browse files
committed
Fix missing RegisterType
1 parent 0b9100b commit ab6cbf3

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

src/app/select-slave/select-slave.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747

4848
<mat-select matInput formControlName="specificationid" (selectionChange)="onSpecificationChange(uislave)"
4949
[compareWith]="compareSpecificationIdentification">
50-
<ng-container *ngIf="uislave.specsObservable|async as identSpecs;else undetectedTemplate">
51-
<ng-container *ngFor="let i = index; let ispec of identSpecs">
50+
<ng-container *ngIf="uislave.specs;else undetectedTemplate">
51+
<ng-container *ngFor="let ispec of uislave.specs">
5252
<mat-option [value]="ispec">
5353
<mat-icon
5454
[matTooltip]="statusTooltip(ispec?ispec.status:3)">{{statusIcon(ispec?ispec.status:3)}}</mat-icon>
@@ -59,7 +59,7 @@
5959
</ng-container>
6060
</ng-container>
6161
<ng-template #undetectedTemplate >
62-
<ng-container *ngFor="let i = index; let ispec of preparedSpecs">
62+
<ng-container *ngFor="let ispec of preparedIdentSpecs">
6363
<mat-option [value]="ispec">
6464
<mat-icon
6565
[matTooltip]="statusTooltip(ispec?ispec.status:3)">{{statusIcon(ispec?ispec.status:3)}}</mat-icon>

src/app/select-slave/select-slave.component.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import { isUndefined } from "cypress/types/lodash";
8080
interface IuiSlave {
8181
slave: Islave;
8282
label: string;
83-
specsObservable?: Observable<IidentificationSpecification[]>;
83+
specs?: IidentificationSpecification[];
8484
specification?: Ispecification;
8585
slaveForm: FormGroup;
8686
commandEntities?: ImodbusEntity[];
@@ -119,8 +119,7 @@ interface IuiSlave {
119119
MatExpansionPanelHeader,
120120
MatExpansionPanelTitle,
121121
MatInput,
122-
MatError,
123-
AsyncPipe,
122+
MatError
124123
],
125124
})
126125
export class SelectSlaveComponent extends SessionStorage implements OnInit {
@@ -177,26 +176,14 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
177176
this.currentLanguage = getCurrentLanguage(navigator.language);
178177
this.entityApiService.getSpecifications().subscribe((specs) => {
179178
this.preparedSpecs = specs;
180-
specs.forEach((spec) => {
181-
let name = getSpecificationI18nName(spec, this.currentLanguage);
182-
183-
let entities: IidentEntity[] = spec.entities.map((e) => {
184-
return {
185-
id: e.id,
186-
name: e.name,
187-
readonly: e.readonly,
188-
mqttname: e.mqttname,
189-
};
190-
});
191-
if (name == undefined) name = "unknown";
192-
});
193179
});
194180
this.paramsSubscription = this.route.params.subscribe((params) => {
195181
let busId = +params["busid"];
196182
this.entityApiService.getBus(busId).subscribe((bus) => {
197183
this.bus = bus;
198184
if (this.bus) {
199185
this.busname = getConnectionName(this.bus.connectionData);
186+
this.getIdentSpecs(undefined).then((identSpecs)=>{this.preparedIdentSpecs = identSpecs})
200187
this.updateSlaves();
201188
}
202189
});
@@ -345,8 +332,8 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
345332
);
346333
return rc
347334
}
348-
getSpecsForConfiguredSlave(uiSlave:IuiSlave):Observable<IidentificationSpecification[]>{
349-
let rc= new Subject<IidentificationSpecification[]>()
335+
getIdentSpecs(uiSlave:IuiSlave| undefined ):Promise<IidentificationSpecification[]>{
336+
return new Promise<IidentificationSpecification[]>((resolve, reject)=>{
350337
let fct = ( specModbus:ImodbusSpecification| undefined )=>{
351338
let rci:IidentificationSpecification[]=[]
352339
this.preparedSpecs.forEach(spec=>{
@@ -356,15 +343,14 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
356343
identified: specModbus && spec.filename== specModbus.filename?specModbus.identified:IdentifiedStates.unknown,
357344
filename: spec.filename,
358345
} as IidentificationSpecification);
359-
rc.next(rci)
360346
})
347+
resolve(rci)
361348
}
362-
if( uiSlave.slave.specificationid )
349+
if( uiSlave && uiSlave.slave.specificationid )
363350
this.entityApiService.getModbusSpecification(this.bus.busId,uiSlave.slave.slaveid,uiSlave.slave.specificationid, true).subscribe(fct)
364351
else
365352
fct(undefined )
366-
367-
return rc;
353+
})
368354
}
369355
getUiSlave(slave: Islave, detectSpec: boolean | undefined): IuiSlave {
370356
let fg = this.initiateSlaveControl(slave, null);
@@ -373,8 +359,7 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
373359
label: this.getSlaveName(slave),
374360
slaveForm: fg,
375361
} as any;
376-
377-
rc.specsObservable = this.getSpecsForConfiguredSlave(rc) // getDetectedSpecs is disabled, because of performance issues
362+
this.getIdentSpecs(rc).then((identSpecs)=>{rc.specs = identSpecs}).catch(e=>{ console.log(e.message)}) // getDetectedSpecs is disabled, because of performance issues
378363
this.addSpecificationToUiSlave(rc);
379364
(rc.selectedEntitites = this.getSelectedEntites(slave)),
380365
this.fillCommandTopics(rc);
@@ -592,10 +577,13 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
592577
// Initialization of the UI
593578
// replacing this.uiSlaves with newUiSlaves will initialize and show it
594579
// Now, the new value needs to be marked as touched to enable cancel and save.
595-
let specCtrl = newUiSlave.slaveForm.get("specificationid");
580+
if( detectSpec){
581+
let specCtrl = newUiSlave.slaveForm.get("specificationid");
582+
583+
if (specCtrl && specCtrl.value != undefined)
584+
newUiSlave.slaveForm.markAllAsTouched();
596585

597-
if (specCtrl && specCtrl.value != undefined)
598-
newUiSlave.slaveForm.markAllAsTouched();
586+
}
599587
});
600588
}
601589
private static form2SlaveSetValue(uiSlave: IuiSlave, controlname: string) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export class EntityComponent
439439
this.entityFormGroup.get("readonly")!.setValue(entity.readonly);
440440
}
441441

442-
this.entityFormGroup.get("registerType")!.setValue(entity.registerType);
442+
this.entityFormGroup.get("registerType")!.setValue( { registerType: entity.registerType, name: "unknown"});
443443
converterFormControl.setValue(entity.converter);
444444
modbusAddressFormControl.setValue(
445445
entity.modbusAddress != undefined ? entity.modbusAddress : null,

0 commit comments

Comments
 (0)