Merge branch 'engix-ltd-telemetry_updater' into master
This commit is contained in:
commit
8092f23a3d
@ -43,6 +43,15 @@ import { WidgetInfo } from '@home/models/widget-component.models';
|
|||||||
import jsonSchemaDefaults from 'json-schema-defaults';
|
import jsonSchemaDefaults from 'json-schema-defaults';
|
||||||
import materialIconsCodepoints from '!raw-loader!./material-icons-codepoints.raw';
|
import materialIconsCodepoints from '!raw-loader!./material-icons-codepoints.raw';
|
||||||
import { Observable, of, ReplaySubject } from 'rxjs';
|
import { Observable, of, ReplaySubject } from 'rxjs';
|
||||||
|
import { publishReplay, refCount } from 'rxjs/operators';
|
||||||
|
import { WidgetContext } from '@app/modules/home/models/widget-component.models';
|
||||||
|
import {
|
||||||
|
AttributeData,
|
||||||
|
TelemetrySubscriber,
|
||||||
|
TelemetryType,
|
||||||
|
LatestTelemetry
|
||||||
|
} from '@shared/models/telemetry/telemetry.models';
|
||||||
|
import { EntityId } from '@shared/models/id/entity-id';
|
||||||
|
|
||||||
const i18nRegExp = new RegExp(`{${i18nPrefix}:[^{}]+}`, 'g');
|
const i18nRegExp = new RegExp(`{${i18nPrefix}:[^{}]+}`, 'g');
|
||||||
|
|
||||||
@ -479,4 +488,34 @@ export class UtilsService {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public 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<Array<AttributeData>> {
|
||||||
|
const subscription = this.createTelemetrySubscriber(ctx, entityId, type, keys);
|
||||||
|
if (!ctx.telemetrySubscribers) {
|
||||||
|
ctx.telemetrySubscribers = [];
|
||||||
|
}
|
||||||
|
ctx.telemetrySubscribers.push(subscription);
|
||||||
|
subscription.subscribe();
|
||||||
|
return subscription.attributeData$().pipe(
|
||||||
|
publishReplay(1),
|
||||||
|
refCount()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,7 @@ import { AuthService } from '@core/auth/auth.service';
|
|||||||
import { DialogService } from '@core/services/dialog.service';
|
import { DialogService } from '@core/services/dialog.service';
|
||||||
import { CustomDialogService } from '@home/components/widget/dialog/custom-dialog.service';
|
import { CustomDialogService } from '@home/components/widget/dialog/custom-dialog.service';
|
||||||
import { ResourceService } from '@core/http/resource.service';
|
import { ResourceService } from '@core/http/resource.service';
|
||||||
|
import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service';
|
||||||
import { DatePipe } from '@angular/common';
|
import { DatePipe } from '@angular/common';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { DomSanitizer } from '@angular/platform-browser';
|
import { DomSanitizer } from '@angular/platform-browser';
|
||||||
@ -80,6 +81,7 @@ export class DynamicWidgetComponent extends PageComponent implements IDynamicWid
|
|||||||
this.ctx.dialogs = $injector.get(DialogService);
|
this.ctx.dialogs = $injector.get(DialogService);
|
||||||
this.ctx.customDialog = $injector.get(CustomDialogService);
|
this.ctx.customDialog = $injector.get(CustomDialogService);
|
||||||
this.ctx.resourceService = $injector.get(ResourceService);
|
this.ctx.resourceService = $injector.get(ResourceService);
|
||||||
|
this.ctx.telemetryWsService = $injector.get(TelemetryWebsocketService);
|
||||||
this.ctx.date = $injector.get(DatePipe);
|
this.ctx.date = $injector.get(DatePipe);
|
||||||
this.ctx.translate = $injector.get(TranslateService);
|
this.ctx.translate = $injector.get(TranslateService);
|
||||||
this.ctx.http = $injector.get(HttpClient);
|
this.ctx.http = $injector.get(HttpClient);
|
||||||
@ -100,7 +102,9 @@ export class DynamicWidgetComponent extends PageComponent implements IDynamicWid
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
|
if (this.ctx.telemetrySubscribers) {
|
||||||
|
this.ctx.telemetrySubscribers.forEach(item => item.unsubscribe());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearRpcError() {
|
clearRpcError() {
|
||||||
|
|||||||
@ -39,6 +39,7 @@ import { OtaPackageService } from '@core/http/ota-package.service';
|
|||||||
import { AuthService } from '@core/auth/auth.service';
|
import { AuthService } from '@core/auth/auth.service';
|
||||||
import { ResourceService } from '@core/http/resource.service';
|
import { ResourceService } from '@core/http/resource.service';
|
||||||
import { TwoFactorAuthenticationService } from '@core/http/two-factor-authentication.service';
|
import { TwoFactorAuthenticationService } from '@core/http/two-factor-authentication.service';
|
||||||
|
import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service';
|
||||||
|
|
||||||
export const ServicesMap = new Map<string, Type<any>>(
|
export const ServicesMap = new Map<string, Type<any>>(
|
||||||
[
|
[
|
||||||
@ -65,6 +66,7 @@ export const ServicesMap = new Map<string, Type<any>>(
|
|||||||
['otaPackageService', OtaPackageService],
|
['otaPackageService', OtaPackageService],
|
||||||
['authService', AuthService],
|
['authService', AuthService],
|
||||||
['resourceService', ResourceService],
|
['resourceService', ResourceService],
|
||||||
['twoFactorAuthenticationService', TwoFactorAuthenticationService]
|
['twoFactorAuthenticationService', TwoFactorAuthenticationService],
|
||||||
|
['telemetryWsService', TelemetryWebsocketService]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|||||||
@ -75,6 +75,7 @@ import { DialogService } from '@core/services/dialog.service';
|
|||||||
import { CustomDialogService } from '@home/components/widget/dialog/custom-dialog.service';
|
import { CustomDialogService } from '@home/components/widget/dialog/custom-dialog.service';
|
||||||
import { AuthService } from '@core/auth/auth.service';
|
import { AuthService } from '@core/auth/auth.service';
|
||||||
import { ResourceService } from '@core/http/resource.service';
|
import { ResourceService } from '@core/http/resource.service';
|
||||||
|
import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service';
|
||||||
import { DatePipe } from '@angular/common';
|
import { DatePipe } from '@angular/common';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { PageLink, TimePageLink } from '@shared/models/page/page-link';
|
import { PageLink, TimePageLink } from '@shared/models/page/page-link';
|
||||||
@ -87,6 +88,7 @@ import * as RxJSOperators from 'rxjs/operators';
|
|||||||
import { TbPopoverComponent } from '@shared/components/popover.component';
|
import { TbPopoverComponent } from '@shared/components/popover.component';
|
||||||
import { EntityId } from '@shared/models/id/entity-id';
|
import { EntityId } from '@shared/models/id/entity-id';
|
||||||
import { AlarmQuery, AlarmSearchStatus, AlarmStatus} from '@app/shared/models/alarm.models';
|
import { AlarmQuery, AlarmSearchStatus, AlarmStatus} from '@app/shared/models/alarm.models';
|
||||||
|
import { TelemetrySubscriber } from '@app/shared/public-api';
|
||||||
|
|
||||||
export interface IWidgetAction {
|
export interface IWidgetAction {
|
||||||
name: string;
|
name: string;
|
||||||
@ -177,6 +179,8 @@ export class WidgetContext {
|
|||||||
dialogs: DialogService;
|
dialogs: DialogService;
|
||||||
customDialog: CustomDialogService;
|
customDialog: CustomDialogService;
|
||||||
resourceService: ResourceService;
|
resourceService: ResourceService;
|
||||||
|
telemetryWsService: TelemetryWebsocketService;
|
||||||
|
telemetrySubscribers?: TelemetrySubscriber[];
|
||||||
date: DatePipe;
|
date: DatePipe;
|
||||||
translate: TranslateService;
|
translate: TranslateService;
|
||||||
http: HttpClient;
|
http: HttpClient;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user