Minor refactoring for merge with PE
This commit is contained in:
parent
633131574a
commit
dbadab6e9b
@ -1342,7 +1342,7 @@ export class EntityService {
|
|||||||
return entitiesObservable;
|
return entitiesObservable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getEdgeEventContentByEntityType(entity: any): Observable<any> {
|
public getEdgeEventContent(entity: any): Observable<any> {
|
||||||
let entityObservable: Observable<any>;
|
let entityObservable: Observable<any>;
|
||||||
const entityId: string = entity.entityId;
|
const entityId: string = entity.entityId;
|
||||||
const entityType: any = entity.type;
|
const entityType: any = entity.type;
|
||||||
|
|||||||
@ -47,8 +47,8 @@ import { AttributeService } from '@core/http/attribute.service';
|
|||||||
import { AttributeScope } from '@shared/models/telemetry/telemetry.models';
|
import { AttributeScope } from '@shared/models/telemetry/telemetry.models';
|
||||||
import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component';
|
import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component';
|
||||||
import { EdgeService } from '@core/http/edge.service';
|
import { EdgeService } from '@core/http/edge.service';
|
||||||
import { map } from 'rxjs/operators';
|
import { map, mergeMap } from 'rxjs/operators';
|
||||||
import { EntityService } from "@core/http/entity.service";
|
import { EntityService } from '@core/http/entity.service';
|
||||||
|
|
||||||
export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePageLink> {
|
export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePageLink> {
|
||||||
|
|
||||||
@ -85,26 +85,13 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchEvents(pageLink: TimePageLink): Observable<PageData<EdgeEvent>> {
|
fetchEvents(pageLink: TimePageLink): Observable<PageData<EdgeEvent>> {
|
||||||
this.loadEdgeInfo();
|
return this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']).pipe(
|
||||||
return this.edgeService.getEdgeEvents(this.entityId, pageLink);
|
map((attributes) => {
|
||||||
}
|
const queueStartTs = attributes[0];
|
||||||
|
this.queueStartTs = queueStartTs ? queueStartTs.lastUpdateTs : 0;
|
||||||
loadEdgeInfo(): void {
|
}),
|
||||||
this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs'])
|
mergeMap(() => this.edgeService.getEdgeEvents(this.entityId, pageLink))
|
||||||
.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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateColumns(updateTableColumns: boolean = false): void {
|
updateColumns(updateTableColumns: boolean = false): void {
|
||||||
@ -129,7 +116,8 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
|||||||
isEnabled: (entity) => this.isEdgeEventHasData(entity.type),
|
isEnabled: (entity) => this.isEdgeEventHasData(entity.type),
|
||||||
onAction: ($event, entity) =>
|
onAction: ($event, entity) =>
|
||||||
{
|
{
|
||||||
this.prepareEdgeEventContent(entity).subscribe((content) => {
|
this.prepareEdgeEventContent(entity).subscribe(
|
||||||
|
(content) => {
|
||||||
this.showEdgeEventContent($event, content,'event.data');
|
this.showEdgeEventContent($event, content,'event.data');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -142,7 +130,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateEdgeEventStatus(createdTime): string {
|
updateEdgeEventStatus(createdTime): string {
|
||||||
if (this.queueStartTs && createdTime < this.queueStartTs) {
|
if (createdTime < this.queueStartTs) {
|
||||||
return this.translate.instant('edge.deployed');
|
return this.translate.instant('edge.deployed');
|
||||||
} else {
|
} else {
|
||||||
return this.translate.instant('edge.pending');
|
return this.translate.instant('edge.pending');
|
||||||
@ -163,7 +151,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
|||||||
}
|
}
|
||||||
|
|
||||||
prepareEdgeEventContent(entity: any): Observable<string> {
|
prepareEdgeEventContent(entity: any): Observable<string> {
|
||||||
return this.entityService.getEdgeEventContentByEntityType(entity).pipe(
|
return this.entityService.getEdgeEventContent(entity).pipe(
|
||||||
map((result) => JSON.stringify(result))
|
map((result) => JSON.stringify(result))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,12 +40,6 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div mat-dialog-actions fxLayoutAlign="end center">
|
<div mat-dialog-actions fxLayoutAlign="end center">
|
||||||
<button mat-raised-button color="primary"
|
|
||||||
type="submit"
|
|
||||||
[disabled]="(isLoading$ | async) || addEntitiesToEdgeFormGroup.invalid
|
|
||||||
|| !addEntitiesToEdgeFormGroup.dirty">
|
|
||||||
{{ 'action.assign' | translate }}
|
|
||||||
</button>
|
|
||||||
<button mat-button color="primary"
|
<button mat-button color="primary"
|
||||||
style="margin-right: 20px;"
|
style="margin-right: 20px;"
|
||||||
type="button"
|
type="button"
|
||||||
@ -53,5 +47,11 @@
|
|||||||
(click)="cancel()">
|
(click)="cancel()">
|
||||||
{{ 'action.cancel' | translate }}
|
{{ 'action.cancel' | translate }}
|
||||||
</button>
|
</button>
|
||||||
|
<button mat-raised-button color="primary"
|
||||||
|
type="submit"
|
||||||
|
[disabled]="(isLoading$ | async) || addEntitiesToEdgeFormGroup.invalid
|
||||||
|
|| !addEntitiesToEdgeFormGroup.dirty">
|
||||||
|
{{ 'action.assign' | translate }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@ -69,7 +69,7 @@ export class AddEntitiesToEdgeDialogComponent extends
|
|||||||
public dialogRef: MatDialogRef<AddEntitiesToEdgeDialogComponent, boolean>,
|
public dialogRef: MatDialogRef<AddEntitiesToEdgeDialogComponent, boolean>,
|
||||||
public fb: FormBuilder) {
|
public fb: FormBuilder) {
|
||||||
super(store, router, dialogRef);
|
super(store, router, dialogRef);
|
||||||
this.entityType = data.entityType;
|
this.entityType = this.data.entityType;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@ -77,7 +77,7 @@ export class AddEntitiesToEdgeDialogComponent extends
|
|||||||
entityIds: [null, [Validators.required]]
|
entityIds: [null, [Validators.required]]
|
||||||
});
|
});
|
||||||
this.subType = '';
|
this.subType = '';
|
||||||
switch (this.data.entityType) {
|
switch (this.entityType) {
|
||||||
case EntityType.DEVICE:
|
case EntityType.DEVICE:
|
||||||
this.assignToEdgeTitle = 'device.assign-device-to-edge-title';
|
this.assignToEdgeTitle = 'device.assign-device-to-edge-title';
|
||||||
this.assignToEdgeText = 'device.assign-device-to-edge-text';
|
this.assignToEdgeText = 'device.assign-device-to-edge-text';
|
||||||
@ -118,7 +118,7 @@ export class AddEntitiesToEdgeDialogComponent extends
|
|||||||
const tasks: Observable<any>[] = [];
|
const tasks: Observable<any>[] = [];
|
||||||
entityIds.forEach(
|
entityIds.forEach(
|
||||||
(entityId) => {
|
(entityId) => {
|
||||||
tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId));
|
tasks.push(this.getAssignToEdgeTask(this.data.edgeId, entityId, this.entityType));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
forkJoin(tasks).subscribe(
|
forkJoin(tasks).subscribe(
|
||||||
@ -128,8 +128,8 @@ export class AddEntitiesToEdgeDialogComponent extends
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getAssignToEdgeTask(edgeId: string, entityId: string): Observable<any> {
|
private getAssignToEdgeTask(edgeId: string, entityId: string, entityType: EntityType): Observable<any> {
|
||||||
switch (this.data.entityType) {
|
switch (entityType) {
|
||||||
case EntityType.DEVICE:
|
case EntityType.DEVICE:
|
||||||
return this.deviceService.assignDeviceToEdge(edgeId, entityId);
|
return this.deviceService.assignDeviceToEdge(edgeId, entityId);
|
||||||
case EntityType.ASSET:
|
case EntityType.ASSET:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user