Commit dbadab6e9bb41a4e39daa8c37a7729348e1c9882
1 parent
63313157
Minor refactoring for merge with PE
Showing
4 changed files
with
25 additions
and
37 deletions
... | ... | @@ -1342,7 +1342,7 @@ export class EntityService { |
1342 | 1342 | return entitiesObservable; |
1343 | 1343 | } |
1344 | 1344 | |
1345 | - public getEdgeEventContentByEntityType(entity: any): Observable<any> { | |
1345 | + public getEdgeEventContent(entity: any): Observable<any> { | |
1346 | 1346 | let entityObservable: Observable<any>; |
1347 | 1347 | const entityId: string = entity.entityId; |
1348 | 1348 | const entityType: any = entity.type; | ... | ... |
... | ... | @@ -47,8 +47,8 @@ import { AttributeService } from '@core/http/attribute.service'; |
47 | 47 | import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; |
48 | 48 | import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component'; |
49 | 49 | import { EdgeService } from '@core/http/edge.service'; |
50 | -import { map } from 'rxjs/operators'; | |
51 | -import { EntityService } from "@core/http/entity.service"; | |
50 | +import { map, mergeMap } from 'rxjs/operators'; | |
51 | +import { EntityService } from '@core/http/entity.service'; | |
52 | 52 | |
53 | 53 | export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePageLink> { |
54 | 54 | |
... | ... | @@ -85,26 +85,13 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa |
85 | 85 | } |
86 | 86 | |
87 | 87 | fetchEvents(pageLink: TimePageLink): Observable<PageData<EdgeEvent>> { |
88 | - this.loadEdgeInfo(); | |
89 | - return this.edgeService.getEdgeEvents(this.entityId, pageLink); | |
90 | - } | |
91 | - | |
92 | - loadEdgeInfo(): void { | |
93 | - this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']) | |
94 | - .subscribe( | |
95 | - attributes => this.onUpdate(attributes) | |
96 | - ); | |
97 | - } | |
98 | - | |
99 | - onUpdate(attributes) { | |
100 | - this.queueStartTs = 0; | |
101 | - let edge = attributes.reduce(function (map, attribute) { | |
102 | - map[attribute.key] = attribute; | |
103 | - return map; | |
104 | - }, {}); | |
105 | - if (edge.queueStartTs) { | |
106 | - this.queueStartTs = edge.queueStartTs.lastUpdateTs; | |
107 | - } | |
88 | + return this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']).pipe( | |
89 | + map((attributes) => { | |
90 | + const queueStartTs = attributes[0]; | |
91 | + this.queueStartTs = queueStartTs ? queueStartTs.lastUpdateTs : 0; | |
92 | + }), | |
93 | + mergeMap(() => this.edgeService.getEdgeEvents(this.entityId, pageLink)) | |
94 | + ); | |
108 | 95 | } |
109 | 96 | |
110 | 97 | updateColumns(updateTableColumns: boolean = false): void { |
... | ... | @@ -129,7 +116,8 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa |
129 | 116 | isEnabled: (entity) => this.isEdgeEventHasData(entity.type), |
130 | 117 | onAction: ($event, entity) => |
131 | 118 | { |
132 | - this.prepareEdgeEventContent(entity).subscribe((content) => { | |
119 | + this.prepareEdgeEventContent(entity).subscribe( | |
120 | + (content) => { | |
133 | 121 | this.showEdgeEventContent($event, content,'event.data'); |
134 | 122 | }); |
135 | 123 | } |
... | ... | @@ -142,7 +130,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa |
142 | 130 | } |
143 | 131 | |
144 | 132 | updateEdgeEventStatus(createdTime): string { |
145 | - if (this.queueStartTs && createdTime < this.queueStartTs) { | |
133 | + if (createdTime < this.queueStartTs) { | |
146 | 134 | return this.translate.instant('edge.deployed'); |
147 | 135 | } else { |
148 | 136 | return this.translate.instant('edge.pending'); |
... | ... | @@ -163,7 +151,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa |
163 | 151 | } |
164 | 152 | |
165 | 153 | prepareEdgeEventContent(entity: any): Observable<string> { |
166 | - return this.entityService.getEdgeEventContentByEntityType(entity).pipe( | |
154 | + return this.entityService.getEdgeEventContent(entity).pipe( | |
167 | 155 | map((result) => JSON.stringify(result)) |
168 | 156 | ); |
169 | 157 | } | ... | ... |
... | ... | @@ -40,12 +40,6 @@ |
40 | 40 | </fieldset> |
41 | 41 | </div> |
42 | 42 | <div mat-dialog-actions fxLayoutAlign="end center"> |
43 | - <button mat-raised-button color="primary" | |
44 | - type="submit" | |
45 | - [disabled]="(isLoading$ | async) || addEntitiesToEdgeFormGroup.invalid | |
46 | - || !addEntitiesToEdgeFormGroup.dirty"> | |
47 | - {{ 'action.assign' | translate }} | |
48 | - </button> | |
49 | 43 | <button mat-button color="primary" |
50 | 44 | style="margin-right: 20px;" |
51 | 45 | type="button" |
... | ... | @@ -53,5 +47,11 @@ |
53 | 47 | (click)="cancel()"> |
54 | 48 | {{ 'action.cancel' | translate }} |
55 | 49 | </button> |
50 | + <button mat-raised-button color="primary" | |
51 | + type="submit" | |
52 | + [disabled]="(isLoading$ | async) || addEntitiesToEdgeFormGroup.invalid | |
53 | + || !addEntitiesToEdgeFormGroup.dirty"> | |
54 | + {{ 'action.assign' | translate }} | |
55 | + </button> | |
56 | 56 | </div> |
57 | 57 | </form> | ... | ... |
... | ... | @@ -69,7 +69,7 @@ export class AddEntitiesToEdgeDialogComponent extends |
69 | 69 | public dialogRef: MatDialogRef<AddEntitiesToEdgeDialogComponent, boolean>, |
70 | 70 | public fb: FormBuilder) { |
71 | 71 | super(store, router, dialogRef); |
72 | - this.entityType = data.entityType; | |
72 | + this.entityType = this.data.entityType; | |
73 | 73 | } |
74 | 74 | |
75 | 75 | ngOnInit(): void { |
... | ... | @@ -77,7 +77,7 @@ export class AddEntitiesToEdgeDialogComponent extends |
77 | 77 | entityIds: [null, [Validators.required]] |
78 | 78 | }); |
79 | 79 | this.subType = ''; |
80 | - switch (this.data.entityType) { | |
80 | + switch (this.entityType) { | |
81 | 81 | case EntityType.DEVICE: |
82 | 82 | this.assignToEdgeTitle = 'device.assign-device-to-edge-title'; |
83 | 83 | this.assignToEdgeText = 'device.assign-device-to-edge-text'; |
... | ... | @@ -118,7 +118,7 @@ export class AddEntitiesToEdgeDialogComponent extends |
118 | 118 | const tasks: Observable<any>[] = []; |
119 | 119 | entityIds.forEach( |
120 | 120 | (entityId) => { |
121 | - tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId)); | |
121 | + tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId, this.entityType)); | |
122 | 122 | } |
123 | 123 | ); |
124 | 124 | forkJoin(tasks).subscribe( |
... | ... | @@ -128,8 +128,8 @@ export class AddEntitiesToEdgeDialogComponent extends |
128 | 128 | ); |
129 | 129 | } |
130 | 130 | |
131 | - private getAssignToEdgeTask(edgeId: string, entityId: string): Observable<any> { | |
132 | - switch (this.data.entityType) { | |
131 | + private getAssignToEdgeTask(edgeId: string, entityId: string, entityType: EntityType): Observable<any> { | |
132 | + switch (entityType) { | |
133 | 133 | case EntityType.DEVICE: |
134 | 134 | return this.deviceService.assignDeviceToEdge(edgeId, entityId); |
135 | 135 | case EntityType.ASSET: | ... | ... |