From bf41bc5f092c6c246aea505396dd0c24261b2999 Mon Sep 17 00:00:00 2001 From: deaflynx Date: Wed, 3 Mar 2021 14:30:02 +0200 Subject: [PATCH] Edge Downlinks refactor, prepareEdgeEventContent moved to Entity Service --- ui-ngx/src/app/core/http/entity.service.ts | 40 ++++++++++++- .../edge/edge-downlink-table-config.ts | 58 ++++--------------- .../edge/edge-downlink-table.component.ts | 9 --- .../home/pages/edge/edge-tabs.component.html | 2 +- 4 files changed, 50 insertions(+), 59 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 2a334d7050..58cd3225ab 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -76,8 +76,10 @@ import { } from '@shared/models/query/query.models'; import { alarmFields } from '@shared/models/alarm.models'; import { EdgeService } from "@core/http/edge.service"; -import { Edge } from '@shared/models/edge.models'; +import { Edge, EdgeEventType } from '@shared/models/edge.models'; import { RuleChainType } from "@shared/models/rule-chain.models"; +import { WidgetService } from "@core/http/widget.service"; +import { DeviceProfileService } from "@core/http/device-profile.service"; @Injectable({ providedIn: 'root' @@ -98,6 +100,8 @@ export class EntityService { private dashboardService: DashboardService, private entityRelationService: EntityRelationService, private attributeService: AttributeService, + private widgetService: WidgetService, + private deviceProfileService: DeviceProfileService, private utils: UtilsService ) { } @@ -1316,4 +1320,38 @@ export class EntityService { } return entitiesObservable; } + + public getEdgeEventContentByEntityType(entity: any) { + let entityObservable: Observable; + switch (entity.type) { + case EdgeEventType.DASHBOARD: + case EdgeEventType.ALARM: + case EdgeEventType.RULE_CHAIN: + case EdgeEventType.EDGE: + case EdgeEventType.USER: + case EdgeEventType.CUSTOMER: + case EdgeEventType.TENANT: + case EdgeEventType.ASSET: + case EdgeEventType.DEVICE: + case EdgeEventType.ENTITY_VIEW: + entityObservable = this.getEntity(entity.type, entity.entityId, { ignoreLoading: true, ignoreErrors: true }); + break; + case EdgeEventType.RULE_CHAIN_METADATA: + entityObservable = this.ruleChainService.getRuleChainMetadata(entity.entityId); + break; + case EdgeEventType.WIDGET_TYPE: + entityObservable = this.widgetService.getWidgetTypeById(entity.entityId); + break; + case EdgeEventType.WIDGETS_BUNDLE: + entityObservable = this.widgetService.getWidgetsBundle(entity.entityId); + break; + case EdgeEventType.DEVICE_PROFILE: + entityObservable = this.deviceProfileService.getDeviceProfile(entity.entityId); + break; + case EdgeEventType.RELATION: + entityObservable = of(entity.body); + break; + } + return entityObservable; + } } 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 2fc307ebd1..8f2f9a776d 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 @@ -34,7 +34,7 @@ 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, of } from 'rxjs'; +import { Observable } from 'rxjs'; import { PageData } from '@shared/models/page/page-data'; import { Direction } from '@shared/models/page/sort-order'; import { DialogService } from '@core/services/dialog.service'; @@ -43,15 +43,12 @@ import { EventContentDialogComponent, EventContentDialogData } from '@home/components/event/event-content-dialog.component'; -import { RuleChainService } from '@core/http/rule-chain.service'; 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 { EntityService } from "@core/http/entity.service"; -import { WidgetService } from "@core/http/widget.service"; -import { DeviceProfileService } from "@core/http/device-profile.service"; export class EdgeDownlinkTableConfig extends EntityTableConfig { @@ -62,16 +59,13 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig this.onUpdate(attributes) @@ -147,7 +141,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig this.queueStartTs; } - isEdgeEventHasData(edgeEventType: EdgeEventType) { + isEdgeEventHasData(edgeEventType: EdgeEventType): boolean { switch (edgeEventType) { case EdgeEventType.ADMIN_SETTINGS: return false; @@ -168,42 +162,10 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig JSON.stringify(entity)) - ); - case EdgeEventType.RELATION: - return of(JSON.stringify(entity.body)); - case EdgeEventType.RULE_CHAIN_METADATA: - return this.ruleChainService.getRuleChainMetadata(entity.entityId).pipe( - map((ruleChainMetaData) => JSON.stringify(ruleChainMetaData.nodes)) - ); - case EdgeEventType.WIDGET_TYPE: - return this.widgetService.getWidgetTypeById(entity.entityId).pipe( - map((widgetType) => JSON.stringify(widgetType)) - ); - case EdgeEventType.WIDGETS_BUNDLE: - return this.widgetService.getWidgetsBundle(entity.entityId).pipe( - map((widgetBundles) => JSON.stringify(widgetBundles)) - ); - case EdgeEventType.DEVICE_PROFILE: - return this.deviceProfileService.getDeviceProfile(entity.entityId).pipe( - map((deviceProfile) => JSON.stringify(deviceProfile)) - ); - case EdgeEventType.ADMIN_SETTINGS: - return of(null); - } + prepareEdgeEventContent(entity: any): Observable { + return this.entityService.getEdgeEventContentByEntityType(entity).pipe( + map((result) => JSON.stringify(result)) + ); } showEdgeEventContent($event: MouseEvent, content: string, title: string): void { 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 50cedbe426..3b5fca1c7a 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 @@ -22,12 +22,9 @@ import { EntityId } from '@shared/models/id/entity-id'; import { EntitiesTableComponent } from '@home/components/entity/entities-table.component'; import { EdgeDownlinkTableConfig } from './edge-downlink-table-config'; import { DialogService } from '@core/services/dialog.service'; -import { RuleChainService } from '@core/http/rule-chain.service'; import { AttributeService } from '@core/http/attribute.service'; import { EdgeService } from '@core/http/edge.service'; import { EntityService } from "@core/http/entity.service"; -import { WidgetService } from "@core/http/widget.service"; -import { DeviceProfileService } from "@core/http/device-profile.service"; @Component({ selector: 'tb-edge-downlink-table', @@ -72,9 +69,6 @@ export class EdgeDownlinkTableComponent implements OnInit { private dialogService: DialogService, private translate: TranslateService, private attributeService: AttributeService, - private deviceProfileService: DeviceProfileService, - private ruleChainService: RuleChainService, - private widgetService: WidgetService, private datePipe: DatePipe, private dialog: MatDialog) { } @@ -87,9 +81,6 @@ export class EdgeDownlinkTableComponent implements OnInit { this.dialogService, this.translate, this.attributeService, - this.deviceProfileService, - this.ruleChainService, - this.widgetService, this.datePipe, this.dialog, this.entityIdValue diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html index 3058522130..615ee09ee1 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html @@ -43,7 +43,7 @@ -