From 4981db7aeb5c0a304305fa435c35796480560efa Mon Sep 17 00:00:00 2001 From: deaflynx Date: Tue, 21 Sep 2021 07:28:22 +0300 Subject: [PATCH 1/4] Edge downlinks fixes: - show entity.body for POST_ATTRIBUTES, ATTRIBUTES_UPDATED, ATTRIBUTES_DELETED, TIMESERIES_UPDATED; - update status pending/deployed color without refresh page; - for RELATION type show empty 'entityId'; --- ui-ngx/src/app/core/http/entity.service.ts | 13 ++++++- .../edge/edge-downlink-table-config.ts | 37 ++++++++----------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 6665beb3b3..37e7b91206 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -83,7 +83,7 @@ import { import { alarmFields } from '@shared/models/alarm.models'; import { OtaPackageService } from '@core/http/ota-package.service'; import { EdgeService } from '@core/http/edge.service'; -import { Edge, EdgeEvent, EdgeEventType } from '@shared/models/edge.models'; +import { Edge, EdgeEvent, EdgeEventActionType, EdgeEventType } from '@shared/models/edge.models'; import { RuleChainMetaData, RuleChainType } from '@shared/models/rule-chain.models'; import { WidgetService } from '@core/http/widget.service'; import { DeviceProfileService } from '@core/http/device-profile.service'; @@ -1391,6 +1391,7 @@ export class EntityService { let entityObservable: Observable | RuleChainMetaData | string>; const entityId: string = entity.entityId; const entityType: any = entity.type; + const entityAction: EdgeEventActionType = entity.action; switch (entityType) { case EdgeEventType.DASHBOARD: case EdgeEventType.ALARM: @@ -1402,7 +1403,15 @@ export class EntityService { case EdgeEventType.ASSET: case EdgeEventType.DEVICE: case EdgeEventType.ENTITY_VIEW: - entityObservable = this.getEntity(entityType, entityId, { ignoreLoading: true, ignoreErrors: true }); + if (entityAction === EdgeEventActionType.POST_ATTRIBUTES || + entityAction === EdgeEventActionType.ATTRIBUTES_UPDATED || + entityAction === EdgeEventActionType.ATTRIBUTES_DELETED || + entityAction === EdgeEventActionType.TIMESERIES_UPDATED || + entityAction === EdgeEventActionType.RPC_CALL) { + return of(entity.body); + } else { + entityObservable = this.getEntity(entityType, entityId, { ignoreLoading: true, ignoreErrors: true }); + } break; case EdgeEventType.RULE_CHAIN_METADATA: entityObservable = this.ruleChainService.getRuleChainMetadata(entityId); diff --git a/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts b/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts index 517415a68a..38c3317ff0 100644 --- a/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts @@ -47,7 +47,7 @@ import { AttributeService } from '@core/http/attribute.service'; import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component'; import { EdgeService } from '@core/http/edge.service'; -import { map } from 'rxjs/operators'; +import { concatMap, map } from 'rxjs/operators'; import { EntityService } from "@core/http/entity.service"; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; @@ -55,7 +55,7 @@ import { ActionNotificationShow } from '@core/notification/notification.actions' export class EdgeDownlinkTableConfig extends EntityTableConfig { - queueStartTs: number; + private queueStartTs: number; constructor(private attributeService: AttributeService, private datePipe: DatePipe, @@ -85,19 +85,14 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig> { - this.loadEdgeInfo(); - return this.edgeService.getEdgeEvents(this.entityId, pageLink); - } - - loadEdgeInfo(): void { - this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']) - .subscribe( - attributes => this.onUpdate(attributes) - ); + private fetchEvents(pageLink: TimePageLink): Observable> { + return this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']).pipe( + map((attributes) => this.onUpdate(attributes)), + concatMap(() => this.edgeService.getEdgeEvents(this.entityId, pageLink)) + ); } - onUpdate(attributes): void { + private onUpdate(attributes: any): void { this.queueStartTs = 0; let edge = attributes.reduce(function (map, attribute) { map[attribute.key] = attribute; @@ -108,7 +103,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig('createdTime', 'event.event-time', this.datePipe, '120px'), @@ -117,7 +112,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig('action', 'edge.event-action', '25%', entity => this.translate.instant(edgeEventActionTypeTranslations.get(entity.action)), entity => ({}), false), new EntityTableColumn('entityId', 'edge.entity-id', '40%', - (entity) => entity.entityId, entity => ({}), false), + (entity) => entity.entityId ? entity.entityId : '', () => ({}), false), new EntityTableColumn('status', 'event.status', '10%', (entity) => this.updateEdgeEventStatus(entity.createdTime), entity => ({ @@ -143,7 +138,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig this.queueStartTs; } - isEdgeEventHasData(entity: EdgeEvent): boolean { + private isEdgeEventHasData(entity: EdgeEvent): boolean { return !(entity.type === EdgeEventType.ADMIN_SETTINGS || entity.action === EdgeEventActionType.DELETED); } - prepareEdgeEventContent(entity: EdgeEvent): Observable { + private prepareEdgeEventContent(entity: EdgeEvent): Observable { return this.entityService.getEdgeEventContent(entity).pipe( map((result) => JSON.stringify(result)) ); } - showEdgeEventContent($event: MouseEvent, content: string, title: string): void { + private showEdgeEventContent($event: MouseEvent, content: string, title: string): void { if ($event) { $event.stopPropagation(); } @@ -181,7 +176,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig Date: Tue, 21 Sep 2021 13:16:13 +0300 Subject: [PATCH 2/4] getEdgeEventContent() refactored --- ui-ngx/src/app/core/http/entity.service.ts | 16 ++++++++-------- ui-ngx/src/app/shared/models/edge.models.ts | 8 ++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 37e7b91206..015ba6ec88 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -83,7 +83,12 @@ import { import { alarmFields } from '@shared/models/alarm.models'; import { OtaPackageService } from '@core/http/ota-package.service'; import { EdgeService } from '@core/http/edge.service'; -import { Edge, EdgeEvent, EdgeEventActionType, EdgeEventType } from '@shared/models/edge.models'; +import { + Edge, + EdgeEvent, + EdgeEventType, + bodyContentEdgeEventActionTypes +} from '@shared/models/edge.models'; import { RuleChainMetaData, RuleChainType } from '@shared/models/rule-chain.models'; import { WidgetService } from '@core/http/widget.service'; import { DeviceProfileService } from '@core/http/device-profile.service'; @@ -1391,7 +1396,6 @@ export class EntityService { let entityObservable: Observable | RuleChainMetaData | string>; const entityId: string = entity.entityId; const entityType: any = entity.type; - const entityAction: EdgeEventActionType = entity.action; switch (entityType) { case EdgeEventType.DASHBOARD: case EdgeEventType.ALARM: @@ -1403,12 +1407,8 @@ export class EntityService { case EdgeEventType.ASSET: case EdgeEventType.DEVICE: case EdgeEventType.ENTITY_VIEW: - if (entityAction === EdgeEventActionType.POST_ATTRIBUTES || - entityAction === EdgeEventActionType.ATTRIBUTES_UPDATED || - entityAction === EdgeEventActionType.ATTRIBUTES_DELETED || - entityAction === EdgeEventActionType.TIMESERIES_UPDATED || - entityAction === EdgeEventActionType.RPC_CALL) { - return of(entity.body); + if (bodyContentEdgeEventActionTypes.indexOf(entity.action) > -1) { + entityObservable = of(entity.body); } else { entityObservable = this.getEntity(entityType, entityId, { ignoreLoading: true, ignoreErrors: true }); } diff --git a/ui-ngx/src/app/shared/models/edge.models.ts b/ui-ngx/src/app/shared/models/edge.models.ts index fd7cb57706..5cc1c7b23c 100644 --- a/ui-ngx/src/app/shared/models/edge.models.ts +++ b/ui-ngx/src/app/shared/models/edge.models.ts @@ -137,6 +137,14 @@ export const edgeEventActionTypeTranslations = new Map( [ [EdgeEventStatus.DEPLOYED, '#000000'], From cafba9226a31103a86c9e52b67ddf39b1768b1e6 Mon Sep 17 00:00:00 2001 From: deaflynx Date: Tue, 21 Sep 2021 13:19:19 +0300 Subject: [PATCH 3/4] Added type definition for edge const --- ui-ngx/src/app/shared/models/edge.models.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/shared/models/edge.models.ts b/ui-ngx/src/app/shared/models/edge.models.ts index 5cc1c7b23c..25d3305b83 100644 --- a/ui-ngx/src/app/shared/models/edge.models.ts +++ b/ui-ngx/src/app/shared/models/edge.models.ts @@ -137,7 +137,7 @@ export const edgeEventActionTypeTranslations = new Map Date: Tue, 21 Sep 2021 15:35:52 +0300 Subject: [PATCH 4/4] Changed indexOf -> includes in getEdgeEventContent --- ui-ngx/src/app/core/http/entity.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 015ba6ec88..3346d5ce83 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -1407,7 +1407,7 @@ export class EntityService { case EdgeEventType.ASSET: case EdgeEventType.DEVICE: case EdgeEventType.ENTITY_VIEW: - if (bodyContentEdgeEventActionTypes.indexOf(entity.action) > -1) { + if (bodyContentEdgeEventActionTypes.includes(entity.action)) { entityObservable = of(entity.body); } else { entityObservable = this.getEntity(entityType, entityId, { ignoreLoading: true, ignoreErrors: true });