From c865db244c028a824c33cf00748162147bae7ea4 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 15 Apr 2021 15:55:41 +0300 Subject: [PATCH] Edge Downlinks: fixed types, added error handler, refactored --- ui-ngx/src/app/core/http/entity.service.ts | 10 +-- .../edge/edge-downlink-table-config.ts | 63 +++++++++++-------- .../edge-downlink-table-header.component.ts | 4 -- .../edge/edge-downlink-table.component.ts | 25 ++++---- .../assets/locale/locale.constant-en_US.json | 2 +- 5 files changed, 56 insertions(+), 48 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 90275f1016..592dbc9bca 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -19,7 +19,7 @@ import { EMPTY, forkJoin, Observable, of, throwError } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { PageLink } from '@shared/models/page/page-link'; import { AliasEntityType, EntityType } from '@shared/models/entity-type.models'; -import { BaseData } from '@shared/models/base-data'; +import { BaseData, HasId } from '@shared/models/base-data'; import { EntityId } from '@shared/models/id/entity-id'; import { DeviceService } from '@core/http/device.service'; import { TenantService } from '@core/http/tenant.service'; @@ -76,8 +76,8 @@ import { } from '@shared/models/query/query.models'; import { alarmFields } from '@shared/models/alarm.models'; import { EdgeService } from "@core/http/edge.service"; -import { Edge, EdgeEventType } from '@shared/models/edge.models'; -import { RuleChainType } from "@shared/models/rule-chain.models"; +import { Edge, EdgeEvent, 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"; @@ -1333,8 +1333,8 @@ export class EntityService { return entitiesObservable; } - public getEdgeEventContentByEntityType(entity: any): Observable { - let entityObservable: Observable; + public getEdgeEventContent(entity: EdgeEvent): Observable | RuleChainMetaData | string> { + let entityObservable: Observable | RuleChainMetaData | string>; const entityId: string = entity.entityId; const entityType: any = entity.type; switch (entityType) { 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 8f2f9a776d..517415a68a 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 @@ -22,6 +22,7 @@ import { } from '@home/models/entity/entities-table-config.models'; import { EdgeEvent, + EdgeEventActionType, edgeEventActionTypeTranslations, EdgeEventStatus, edgeEventStatusColor, @@ -33,7 +34,6 @@ import { TranslateService } from '@ngx-translate/core'; import { DatePipe } from '@angular/common'; import { MatDialog } from '@angular/material/dialog'; import { EntityId } from '@shared/models/id/entity-id'; -import { EntityTypeResource } from '@shared/models/entity-type.models'; import { Observable } from 'rxjs'; import { PageData } from '@shared/models/page/page-data'; import { Direction } from '@shared/models/page/sort-order'; @@ -49,18 +49,22 @@ import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-dow import { EdgeService } from '@core/http/edge.service'; import { map } from 'rxjs/operators'; import { EntityService } from "@core/http/entity.service"; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { ActionNotificationShow } from '@core/notification/notification.actions'; export class EdgeDownlinkTableConfig extends EntityTableConfig { queueStartTs: number; - constructor(private edgeService: EdgeService, - private entityService: EntityService, - private dialogService: DialogService, - private translate: TranslateService, - private attributeService: AttributeService, + constructor(private attributeService: AttributeService, private datePipe: DatePipe, + private dialogService: DialogService, private dialog: MatDialog, + private edgeService: EdgeService, + private entityService: EntityService, + private translate: TranslateService, + private store: Store, public entityId: EntityId) { super(); @@ -74,12 +78,9 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig; + this.entityTranslations = { noEntities: 'edge.no-downlinks-prompt' }; this.entitiesFetchFunction = pageLink => this.fetchEvents(pageLink); - this.defaultSortOrder = {property: 'createdTime', direction: Direction.DESC}; + this.defaultSortOrder = { property: 'createdTime', direction: Direction.DESC }; this.updateColumns(); } @@ -96,7 +97,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig this.isEdgeEventHasData(entity.type), + isEnabled: (entity) => this.isEdgeEventHasData(entity), onAction: ($event, entity) => { - this.prepareEdgeEventContent(entity).subscribe((content) => { - this.showEdgeEventContent($event, content,'event.data'); - }); + this.prepareEdgeEventContent(entity).subscribe( + (content) => this.showEdgeEventContent($event, content,'event.data'), + () => this.showEntityNotFoundError() + ); } }, '40px'), @@ -141,7 +143,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig this.queueStartTs; } - isEdgeEventHasData(edgeEventType: EdgeEventType): boolean { - switch (edgeEventType) { - case EdgeEventType.ADMIN_SETTINGS: - return false; - default: - return true; - } + isEdgeEventHasData(entity: EdgeEvent): boolean { + return !(entity.type === EdgeEventType.ADMIN_SETTINGS || + entity.action === EdgeEventActionType.DELETED); } - prepareEdgeEventContent(entity: any): Observable { - return this.entityService.getEdgeEventContentByEntityType(entity).pipe( + prepareEdgeEventContent(entity: EdgeEvent): Observable { + return this.entityService.getEdgeEventContent(entity).pipe( map((result) => JSON.stringify(result)) ); } @@ -182,4 +180,15 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig) { super(store); } - - eventTypeChanged() { - this.eventTableConfig.table.resetSortAndFilter(true, true); - } } diff --git a/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table.component.ts b/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table.component.ts index 3b5fca1c7a..cac27c55de 100644 --- a/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/edge/edge-downlink-table.component.ts @@ -25,6 +25,8 @@ import { DialogService } from '@core/services/dialog.service'; import { AttributeService } from '@core/http/attribute.service'; import { EdgeService } from '@core/http/edge.service'; import { EntityService } from "@core/http/entity.service"; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; @Component({ selector: 'tb-edge-downlink-table', @@ -64,27 +66,28 @@ export class EdgeDownlinkTableComponent implements OnInit { edgeDownlinkTableConfig: EdgeDownlinkTableConfig; - constructor(private edgeService: EdgeService, - private entityService: EntityService, - private dialogService: DialogService, - private translate: TranslateService, - private attributeService: AttributeService, + constructor(private attributeService: AttributeService, private datePipe: DatePipe, - private dialog: MatDialog) { + private dialogService: DialogService, + private dialog: MatDialog, + private edgeService: EdgeService, + private entityService: EntityService, + private translate: TranslateService, + protected store: Store) { } ngOnInit() { this.dirtyValue = !this.activeValue; this.edgeDownlinkTableConfig = new EdgeDownlinkTableConfig( - this.edgeService, - this.entityService, - this.dialogService, - this.translate, this.attributeService, this.datePipe, + this.dialogService, this.dialog, + this.edgeService, + this.entityService, + this.translate, + this.store, this.entityIdValue ); } - } diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 5ee15c371d..1149dcd84d 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1300,7 +1300,7 @@ "make-private-edge-text": "After the confirmation the edge and all its data will be made private and won't be accessible by others.", "import": "Import edge", "label": "Label", - "load-entity-error": "Failed to load data. Entity not found or has been deleted.", + "load-entity-error": "Failed to load data. Entity has been deleted.", "assign-new-edge": "Assign new edge", "manage-edge-dashboards": "Edge dashboards", "unassign-from-edge": "Unassign from edge",