UI: Refactoring code
This commit is contained in:
		
							parent
							
								
									8092f23a3d
								
							
						
					
					
						commit
						6df7af6418
					
				@ -47,9 +47,9 @@ import { publishReplay, refCount } from 'rxjs/operators';
 | 
				
			|||||||
import { WidgetContext } from '@app/modules/home/models/widget-component.models';
 | 
					import { WidgetContext } from '@app/modules/home/models/widget-component.models';
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  AttributeData,
 | 
					  AttributeData,
 | 
				
			||||||
 | 
					  LatestTelemetry,
 | 
				
			||||||
  TelemetrySubscriber,
 | 
					  TelemetrySubscriber,
 | 
				
			||||||
  TelemetryType,
 | 
					  TelemetryType
 | 
				
			||||||
  LatestTelemetry
 | 
					 | 
				
			||||||
} from '@shared/models/telemetry/telemetry.models';
 | 
					} from '@shared/models/telemetry/telemetry.models';
 | 
				
			||||||
import { EntityId } from '@shared/models/id/entity-id';
 | 
					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};
 | 
					    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,
 | 
					  public subscribeToEntityTelemetry(ctx: WidgetContext,
 | 
				
			||||||
                                    entityId?: EntityId,
 | 
					                                    entityId?: EntityId,
 | 
				
			||||||
                                    type: TelemetryType = LatestTelemetry.LATEST_TELEMETRY,
 | 
					                                    type: TelemetryType = LatestTelemetry.LATEST_TELEMETRY,
 | 
				
			||||||
                                    keys: string[] = null): Observable<Array<AttributeData>> {
 | 
					                                    keys: string[] = null): Observable<Array<AttributeData>> {
 | 
				
			||||||
    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) {
 | 
					    if (!ctx.telemetrySubscribers) {
 | 
				
			||||||
      ctx.telemetrySubscribers = [];
 | 
					      ctx.telemetrySubscribers = [];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user