From 6df7af6418536437e9f60fa6c06059dffef4a5dd Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 3 Nov 2022 17:47:54 +0200 Subject: [PATCH] UI: Refactoring code --- ui-ngx/src/app/core/services/utils.service.ts | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/ui-ngx/src/app/core/services/utils.service.ts b/ui-ngx/src/app/core/services/utils.service.ts index c02abcdd39..66eefa9e13 100644 --- a/ui-ngx/src/app/core/services/utils.service.ts +++ b/ui-ngx/src/app/core/services/utils.service.ts @@ -47,9 +47,9 @@ import { publishReplay, refCount } from 'rxjs/operators'; import { WidgetContext } from '@app/modules/home/models/widget-component.models'; import { AttributeData, + LatestTelemetry, TelemetrySubscriber, - TelemetryType, - LatestTelemetry + TelemetryType } from '@shared/models/telemetry/telemetry.models'; import { EntityId } from '@shared/models/id/entity-id'; @@ -489,25 +489,18 @@ export class UtilsService { } } - public getEntityIdFromDatasource(dataSource: Datasource): EntityId { + private getEntityIdFromDatasource(dataSource: Datasource): EntityId { return {id: dataSource.entityId, entityType: dataSource.entityType}; } - public createTelemetrySubscriber(ctx: WidgetContext, - entityId?: EntityId, - type: TelemetryType = LatestTelemetry.LATEST_TELEMETRY, - keys: string[] = null): TelemetrySubscriber { - if (!entityId && ctx.datasources.length > 0) { - entityId = this.getEntityIdFromDatasource(ctx.datasources[0]); - } - return TelemetrySubscriber.createEntityAttributesSubscription(ctx.telemetryWsService, entityId, type, ctx.ngZone, keys); - } - public subscribeToEntityTelemetry(ctx: WidgetContext, entityId?: EntityId, type: TelemetryType = LatestTelemetry.LATEST_TELEMETRY, keys: string[] = null): Observable> { - const subscription = this.createTelemetrySubscriber(ctx, entityId, type, keys); + if (!entityId && ctx.datasources.length > 0) { + entityId = this.getEntityIdFromDatasource(ctx.datasources[0]); + } + const subscription = TelemetrySubscriber.createEntityAttributesSubscription(ctx.telemetryWsService, entityId, type, ctx.ngZone, keys); if (!ctx.telemetrySubscribers) { ctx.telemetrySubscribers = []; }