Minor refactoring for merge with PE
This commit is contained in:
parent
633131574a
commit
dbadab6e9b
@ -1342,7 +1342,7 @@ export class EntityService {
|
||||
return entitiesObservable;
|
||||
}
|
||||
|
||||
public getEdgeEventContentByEntityType(entity: any): Observable<any> {
|
||||
public getEdgeEventContent(entity: any): Observable<any> {
|
||||
let entityObservable: Observable<any>;
|
||||
const entityId: string = entity.entityId;
|
||||
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 { 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<EdgeEvent, TimePageLink> {
|
||||
|
||||
@ -85,26 +85,13 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
||||
}
|
||||
|
||||
fetchEvents(pageLink: TimePageLink): Observable<PageData<EdgeEvent>> {
|
||||
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<EdgeEvent, TimePa
|
||||
isEnabled: (entity) => 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<EdgeEvent, TimePa
|
||||
}
|
||||
|
||||
updateEdgeEventStatus(createdTime): string {
|
||||
if (this.queueStartTs && createdTime < this.queueStartTs) {
|
||||
if (createdTime < this.queueStartTs) {
|
||||
return this.translate.instant('edge.deployed');
|
||||
} else {
|
||||
return this.translate.instant('edge.pending');
|
||||
@ -163,7 +151,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
||||
}
|
||||
|
||||
prepareEdgeEventContent(entity: any): Observable<string> {
|
||||
return this.entityService.getEdgeEventContentByEntityType(entity).pipe(
|
||||
return this.entityService.getEdgeEventContent(entity).pipe(
|
||||
map((result) => JSON.stringify(result))
|
||||
);
|
||||
}
|
||||
|
||||
@ -40,12 +40,6 @@
|
||||
</fieldset>
|
||||
</div>
|
||||
<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"
|
||||
style="margin-right: 20px;"
|
||||
type="button"
|
||||
@ -53,5 +47,11 @@
|
||||
(click)="cancel()">
|
||||
{{ 'action.cancel' | translate }}
|
||||
</button>
|
||||
<button mat-raised-button color="primary"
|
||||
type="submit"
|
||||
[disabled]="(isLoading$ | async) || addEntitiesToEdgeFormGroup.invalid
|
||||
|| !addEntitiesToEdgeFormGroup.dirty">
|
||||
{{ 'action.assign' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -69,7 +69,7 @@ export class AddEntitiesToEdgeDialogComponent extends
|
||||
public dialogRef: MatDialogRef<AddEntitiesToEdgeDialogComponent, boolean>,
|
||||
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<any>[] = [];
|
||||
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<any> {
|
||||
switch (this.data.entityType) {
|
||||
private getAssignToEdgeTask(edgeId: string, entityId: string, entityType: EntityType): Observable<any> {
|
||||
switch (entityType) {
|
||||
case EntityType.DEVICE:
|
||||
return this.deviceService.assignDeviceToEdge(edgeId, entityId);
|
||||
case EntityType.ASSET:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user