From dbadab6e9bb41a4e39daa8c37a7729348e1c9882 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 3 Jun 2021 17:59:52 +0300 Subject: [PATCH] Minor refactoring for merge with PE --- ui-ngx/src/app/core/http/entity.service.ts | 2 +- .../edge/edge-downlink-table-config.ts | 38 +++++++------------ ...add-entities-to-edge-dialog.component.html | 12 +++--- .../add-entities-to-edge-dialog.component.ts | 10 ++--- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index c58e5ac909..f6277b36b4 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -1342,7 +1342,7 @@ export class EntityService { return entitiesObservable; } - public getEdgeEventContentByEntityType(entity: any): Observable { + public getEdgeEventContent(entity: any): Observable { let entityObservable: Observable; const entityId: string = entity.entityId; const entityType: any = entity.type; 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..4161527b9b 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,8 +47,8 @@ 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 { map, mergeMap } from 'rxjs/operators'; +import { EntityService } from '@core/http/entity.service'; export class EdgeDownlinkTableConfig extends EntityTableConfig { @@ -85,26 +85,13 @@ 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) - ); - } - - onUpdate(attributes) { - this.queueStartTs = 0; - let edge = attributes.reduce(function (map, attribute) { - map[attribute.key] = attribute; - return map; - }, {}); - if (edge.queueStartTs) { - this.queueStartTs = edge.queueStartTs.lastUpdateTs; - } + return this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']).pipe( + map((attributes) => { + const queueStartTs = attributes[0]; + this.queueStartTs = queueStartTs ? queueStartTs.lastUpdateTs : 0; + }), + mergeMap(() => this.edgeService.getEdgeEvents(this.entityId, pageLink)) + ); } updateColumns(updateTableColumns: boolean = false): void { @@ -129,7 +116,8 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig this.isEdgeEventHasData(entity.type), onAction: ($event, entity) => { - this.prepareEdgeEventContent(entity).subscribe((content) => { + this.prepareEdgeEventContent(entity).subscribe( + (content) => { this.showEdgeEventContent($event, content,'event.data'); }); } @@ -142,7 +130,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig { - return this.entityService.getEdgeEventContentByEntityType(entity).pipe( + return this.entityService.getEdgeEventContent(entity).pipe( map((result) => JSON.stringify(result)) ); } diff --git a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html index 82f166d71a..64aba5a711 100644 --- a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html +++ b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.html @@ -40,12 +40,6 @@
- +
diff --git a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts index 1cd9ba87ba..ec4418403a 100644 --- a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts @@ -69,7 +69,7 @@ export class AddEntitiesToEdgeDialogComponent extends public dialogRef: MatDialogRef, public fb: FormBuilder) { super(store, router, dialogRef); - this.entityType = data.entityType; + this.entityType = this.data.entityType; } ngOnInit(): void { @@ -77,7 +77,7 @@ export class AddEntitiesToEdgeDialogComponent extends entityIds: [null, [Validators.required]] }); this.subType = ''; - switch (this.data.entityType) { + switch (this.entityType) { case EntityType.DEVICE: this.assignToEdgeTitle = 'device.assign-device-to-edge-title'; this.assignToEdgeText = 'device.assign-device-to-edge-text'; @@ -118,7 +118,7 @@ export class AddEntitiesToEdgeDialogComponent extends const tasks: Observable[] = []; entityIds.forEach( (entityId) => { - tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId)); + tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId, this.entityType)); } ); forkJoin(tasks).subscribe( @@ -128,8 +128,8 @@ export class AddEntitiesToEdgeDialogComponent extends ); } - private getAssignToEdgeTask(edgeId: string, entityId: string): Observable { - switch (this.data.entityType) { + private getAssignToEdgeTask(edgeId: string, entityId: string, entityType: EntityType): Observable { + switch (entityType) { case EntityType.DEVICE: return this.deviceService.assignDeviceToEdge(edgeId, entityId); case EntityType.ASSET: