UI: liquid level widget added additional checkup for datasources

This commit is contained in:
Dmitriymush 2023-11-10 14:55:07 +02:00
parent f1195c16da
commit 8dce7dcad2

View File

@ -160,26 +160,30 @@ export class LiquidLevelWidgetComponent implements OnInit {
}
private getData(): Observable<{ svg: string; volume: number; units: string }> {
const entityId: EntityId = {
entityType: this.ctx.datasources[0].entityType,
id: this.ctx.datasources[0].entityId
};
if (this.ctx.datasources?.length) {
const entityId: EntityId = {
entityType: this.ctx.datasources[0].entityType,
id: this.ctx.datasources[0].entityId
};
return this.getShape(entityId).pipe(
switchMap(shape => {
this.shape = shape;
this.svgParams = svgMapping.get(shape);
if (this.svgParams) {
return forkJoin([
this.resourcesService.loadJsonResource<string>(this.svgParams.svg),
this.getTankersParams(entityId)
]).pipe(
map(params => ({svg: params[0], ...params[1]}))
);
}
return of(null);
})
);
return this.getShape(entityId).pipe(
switchMap(shape => {
this.shape = shape;
this.svgParams = svgMapping.get(shape);
if (this.svgParams) {
return forkJoin([
this.resourcesService.loadJsonResource<string>(this.svgParams.svg),
this.getTankersParams(entityId)
]).pipe(
map(params => ({svg: params[0], ...params[1]}))
);
}
return of(null);
})
);
}
return of(null);
}
public onInit() {