From 74277323bd3a46701e45a9a99c68565ec0867fc8 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Fri, 23 Oct 2020 15:18:34 +0300 Subject: [PATCH] EdgeEvents with Status --- .../components/event/event-table-config.ts | 57 ++++++++++++++++++- .../components/event/event-table.component.ts | 3 + .../entity/entities-table-config.models.ts | 9 +++ ui-ngx/src/app/shared/models/event.models.ts | 13 ++++- 4 files changed, 79 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts index ceb5acca7b..02ee8ea578 100644 --- a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts @@ -20,7 +20,14 @@ import { EntityTableColumn, EntityTableConfig } from '@home/models/entity/entities-table-config.models'; -import {DebugEventType, EdgeEventType, Event, EventType} from '@shared/models/event.models'; +import { + DebugEventType, + EdgeEventType, + EdgeEventStatusColor, + edgeEventStatusColor, + Event, + EventType +} from '@shared/models/event.models'; import {TimePageLink} from '@shared/models/page/page-link'; import {TranslateService} from '@ngx-translate/core'; import {DatePipe} from '@angular/common'; @@ -40,6 +47,8 @@ import { } from '@home/components/event/event-content-dialog.component'; import {sortObjectKeys} from '@core/utils'; import {RuleChainService} from "@core/http/rule-chain.service"; +import {AttributeService} from "@core/http/attribute.service"; +import {AttributeScope} from "@shared/models/telemetry/telemetry.models"; export class EventTableConfig extends EntityTableConfig { @@ -57,11 +66,13 @@ export class EventTableConfig extends EntityTableConfig { } eventTypes: Array; + queueStartTs: any; constructor(private eventService: EventService, private dialogService: DialogService, private translate: TranslateService, private ruleChainService: RuleChainService, + private attributeService: AttributeService, private datePipe: DatePipe, private dialog: MatDialog, public entityId: EntityId, @@ -111,6 +122,7 @@ export class EventTableConfig extends EntityTableConfig { fetchEvents(pageLink: TimePageLink): Observable> { if (this.eventTypeValue === EventType.EDGE_EVENT) { + this.loadEdgeInfo(); return this.eventService.getEdgeEvents(this.entityId, pageLink); } else { return this.eventService.getEvents(this.entityId, this.eventType, this.tenantId, pageLink); @@ -182,6 +194,11 @@ export class EventTableConfig extends EntityTableConfig { (entity) => entity.action, entity => ({}), false), new EntityTableColumn('entityId', 'event.entityId', '100%', (entity) => entity.id.id, entity => ({}), false), //TODO: replace this to entity.entityId because of conflict wiht entityId model + new EntityTableColumn('status', 'event.status', '100%', + (entity) => this.updateEdgeEventStatus(entity.createdTime), + entity => ({ + color: this.isPending(entity.createdTime) ? edgeEventStatusColor.get(EdgeEventStatusColor.PENDING) : edgeEventStatusColor.get(EdgeEventStatusColor.DEPLOYED) + }), false), new EntityActionTableColumn('data', 'event.data', { name: this.translate.instant('action.view'), @@ -291,7 +308,7 @@ export class EventTableConfig extends EntityTableConfig { } manageEdgeEventContent(entity) { - var content = ''; + var content: string; switch (entity.type) { case EdgeEventType.RELATION: content = entity.body; @@ -328,4 +345,40 @@ export class EventTableConfig extends EntityTableConfig { } }); } + + updateEdgeEventStatus(createdTime) { + if (this.queueStartTs) { + var status: string; + if (createdTime < this.queueStartTs) { + status = this.translate.instant('edge.success'); + } else { + status = this.translate.instant('edge.failed'); + } + return status; + } + } + + isPending(createdTime) { + return createdTime > this.queueStartTs; + } + + loadEdgeInfo() { + this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE,["queueStartTs"]) + .subscribe( + attributes => this.onUpdate(attributes) + ); + } + + onUpdate(attributes) { + let edge = attributes.reduce(function (map, attribute) { + map[attribute.key] = attribute; + return map; + }, {}); + if (edge.queueStartTs) { + this.queueStartTs = edge.queueStartTs.lastUpdateTs; + } + } + + } + diff --git a/ui-ngx/src/app/modules/home/components/event/event-table.component.ts b/ui-ngx/src/app/modules/home/components/event/event-table.component.ts index 06ed3141a1..6aa96c83da 100644 --- a/ui-ngx/src/app/modules/home/components/event/event-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/event/event-table.component.ts @@ -25,6 +25,7 @@ import { EventService } from '@core/http/event.service'; import { DialogService } from '@core/services/dialog.service'; import { DebugEventType, EventType } from '@shared/models/event.models'; import { RuleChainService } from "@core/http/rule-chain.service"; +import {AttributeService} from "@core/http/attribute.service"; @Component({ selector: 'tb-event-table', @@ -80,6 +81,7 @@ export class EventTableComponent implements OnInit { constructor(private eventService: EventService, private dialogService: DialogService, private translate: TranslateService, + private attributeService: AttributeService, private ruleChainService: RuleChainService, private datePipe: DatePipe, private dialog: MatDialog) { @@ -92,6 +94,7 @@ export class EventTableComponent implements OnInit { this.dialogService, this.translate, this.ruleChainService, + this.attributeService, this.datePipe, this.dialog, this.entityIdValue, diff --git a/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts b/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts index 4fbbd32900..c53f9d5a42 100644 --- a/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts +++ b/ui-ngx/src/app/modules/home/models/entity/entities-table-config.models.ts @@ -108,6 +108,15 @@ export class EntityActionTableColumn> extends BaseEnti } } +export class EdgeStatusTableColumn> extends BaseEntityTableColumn { + constructor(public key: string, + public title: string, + public actionDescriptor: CellActionDescriptor, + public width: string = '0px') { + super('action', key, title, width, false); + } +} + export class DateEntityTableColumn> extends EntityTableColumn { constructor(key: string, title: string, diff --git a/ui-ngx/src/app/shared/models/event.models.ts b/ui-ngx/src/app/shared/models/event.models.ts index 73c62f1e74..3f101f4e24 100644 --- a/ui-ngx/src/app/shared/models/event.models.ts +++ b/ui-ngx/src/app/shared/models/event.models.ts @@ -19,7 +19,6 @@ import { TenantId } from '@shared/models/id/tenant-id'; import { EntityId } from '@shared/models/id/entity-id'; import { EventId } from './id/event-id'; import { ContentType } from '@shared/models/constants'; -import { EntityType } from '@shared/models/entity-type.models' export enum EventType { ERROR = 'ERROR', @@ -55,6 +54,18 @@ export enum EdgeEventType { ADMIN_SETTINGS = "ADMIN_SETTINGS" } +export enum EdgeEventStatusColor { + DEPLOYED = "DEPLOYED", + PENDING = "PENDING" +} + +export const edgeEventStatusColor = new Map ( + [ + [EdgeEventStatusColor.DEPLOYED, '#000000'], + [EdgeEventStatusColor.PENDING, '#9e9e9e'] + ] +); + export const eventTypeTranslations = new Map( [ [EventType.ERROR, 'event.type-error'],