Edge Downlinks: fixed types, added error handler, refactored

This commit is contained in:
Artem Babak 2021-04-15 15:55:41 +03:00
parent a477cad1b7
commit c865db244c
5 changed files with 56 additions and 48 deletions

View File

@ -19,7 +19,7 @@ import { EMPTY, forkJoin, Observable, of, throwError } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { PageLink } from '@shared/models/page/page-link';
import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
import { BaseData } from '@shared/models/base-data';
import { BaseData, HasId } from '@shared/models/base-data';
import { EntityId } from '@shared/models/id/entity-id';
import { DeviceService } from '@core/http/device.service';
import { TenantService } from '@core/http/tenant.service';
@ -76,8 +76,8 @@ import {
} from '@shared/models/query/query.models';
import { alarmFields } from '@shared/models/alarm.models';
import { EdgeService } from "@core/http/edge.service";
import { Edge, EdgeEventType } from '@shared/models/edge.models';
import { RuleChainType } from "@shared/models/rule-chain.models";
import { Edge, EdgeEvent, EdgeEventType } from '@shared/models/edge.models';
import { RuleChainMetaData, RuleChainType } from "@shared/models/rule-chain.models";
import { WidgetService } from "@core/http/widget.service";
import { DeviceProfileService } from "@core/http/device-profile.service";
@ -1333,8 +1333,8 @@ export class EntityService {
return entitiesObservable;
}
public getEdgeEventContentByEntityType(entity: any): Observable<any> {
let entityObservable: Observable<any>;
public getEdgeEventContent(entity: EdgeEvent): Observable<BaseData<HasId> | RuleChainMetaData | string> {
let entityObservable: Observable<BaseData<HasId> | RuleChainMetaData | string>;
const entityId: string = entity.entityId;
const entityType: any = entity.type;
switch (entityType) {

View File

@ -22,6 +22,7 @@ import {
} from '@home/models/entity/entities-table-config.models';
import {
EdgeEvent,
EdgeEventActionType,
edgeEventActionTypeTranslations,
EdgeEventStatus,
edgeEventStatusColor,
@ -33,7 +34,6 @@ import { TranslateService } from '@ngx-translate/core';
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 } from 'rxjs';
import { PageData } from '@shared/models/page/page-data';
import { Direction } from '@shared/models/page/sort-order';
@ -49,18 +49,22 @@ import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-dow
import { EdgeService } from '@core/http/edge.service';
import { map } from 'rxjs/operators';
import { EntityService } from "@core/http/entity.service";
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { ActionNotificationShow } from '@core/notification/notification.actions';
export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePageLink> {
queueStartTs: number;
constructor(private edgeService: EdgeService,
private entityService: EntityService,
private dialogService: DialogService,
private translate: TranslateService,
private attributeService: AttributeService,
constructor(private attributeService: AttributeService,
private datePipe: DatePipe,
private dialogService: DialogService,
private dialog: MatDialog,
private edgeService: EdgeService,
private entityService: EntityService,
private translate: TranslateService,
private store: Store<AppState>,
public entityId: EntityId) {
super();
@ -74,12 +78,9 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
this.entitiesDeleteEnabled = false;
this.headerComponent = EdgeDownlinkTableHeaderComponent;
this.entityTranslations = {
noEntities: 'edge.no-downlinks-prompt'
};
this.entityResources = {} as EntityTypeResource<EdgeEvent>;
this.entityTranslations = { noEntities: 'edge.no-downlinks-prompt' };
this.entitiesFetchFunction = pageLink => this.fetchEvents(pageLink);
this.defaultSortOrder = {property: 'createdTime', direction: Direction.DESC};
this.defaultSortOrder = { property: 'createdTime', direction: Direction.DESC };
this.updateColumns();
}
@ -96,7 +97,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
);
}
onUpdate(attributes) {
onUpdate(attributes): void {
this.queueStartTs = 0;
let edge = attributes.reduce(function (map, attribute) {
map[attribute.key] = attribute;
@ -126,12 +127,13 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
{
name: this.translate.instant('action.view'),
icon: 'more_horiz',
isEnabled: (entity) => this.isEdgeEventHasData(entity.type),
isEnabled: (entity) => this.isEdgeEventHasData(entity),
onAction: ($event, entity) =>
{
this.prepareEdgeEventContent(entity).subscribe((content) => {
this.showEdgeEventContent($event, content,'event.data');
});
this.prepareEdgeEventContent(entity).subscribe(
(content) => this.showEdgeEventContent($event, content,'event.data'),
() => this.showEntityNotFoundError()
);
}
},
'40px'),
@ -141,7 +143,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
}
}
updateEdgeEventStatus(createdTime): string {
updateEdgeEventStatus(createdTime: number): string {
if (this.queueStartTs && createdTime < this.queueStartTs) {
return this.translate.instant('edge.deployed');
} else {
@ -149,21 +151,17 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
}
}
isPending(createdTime): boolean {
isPending(createdTime: number): boolean {
return createdTime > this.queueStartTs;
}
isEdgeEventHasData(edgeEventType: EdgeEventType): boolean {
switch (edgeEventType) {
case EdgeEventType.ADMIN_SETTINGS:
return false;
default:
return true;
}
isEdgeEventHasData(entity: EdgeEvent): boolean {
return !(entity.type === EdgeEventType.ADMIN_SETTINGS ||
entity.action === EdgeEventActionType.DELETED);
}
prepareEdgeEventContent(entity: any): Observable<string> {
return this.entityService.getEdgeEventContentByEntityType(entity).pipe(
prepareEdgeEventContent(entity: EdgeEvent): Observable<string> {
return this.entityService.getEdgeEventContent(entity).pipe(
map((result) => JSON.stringify(result))
);
}
@ -182,4 +180,15 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
}
});
}
showEntityNotFoundError(): void {
this.store.dispatch(new ActionNotificationShow(
{
message: this.translate.instant('edge.load-entity-error'),
type: 'error',
verticalPosition: 'top',
horizontalPosition: 'left'
}
));
}
}

View File

@ -35,8 +35,4 @@ export class EdgeDownlinkTableHeaderComponent extends EntityTableHeaderComponent
constructor(protected store: Store<AppState>) {
super(store);
}
eventTypeChanged() {
this.eventTableConfig.table.resetSortAndFilter(true, true);
}
}

View File

@ -25,6 +25,8 @@ import { DialogService } from '@core/services/dialog.service';
import { AttributeService } from '@core/http/attribute.service';
import { EdgeService } from '@core/http/edge.service';
import { EntityService } from "@core/http/entity.service";
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
@Component({
selector: 'tb-edge-downlink-table',
@ -64,27 +66,28 @@ export class EdgeDownlinkTableComponent implements OnInit {
edgeDownlinkTableConfig: EdgeDownlinkTableConfig;
constructor(private edgeService: EdgeService,
private entityService: EntityService,
private dialogService: DialogService,
private translate: TranslateService,
private attributeService: AttributeService,
constructor(private attributeService: AttributeService,
private datePipe: DatePipe,
private dialog: MatDialog) {
private dialogService: DialogService,
private dialog: MatDialog,
private edgeService: EdgeService,
private entityService: EntityService,
private translate: TranslateService,
protected store: Store<AppState>) {
}
ngOnInit() {
this.dirtyValue = !this.activeValue;
this.edgeDownlinkTableConfig = new EdgeDownlinkTableConfig(
this.edgeService,
this.entityService,
this.dialogService,
this.translate,
this.attributeService,
this.datePipe,
this.dialogService,
this.dialog,
this.edgeService,
this.entityService,
this.translate,
this.store,
this.entityIdValue
);
}
}

View File

@ -1300,7 +1300,7 @@
"make-private-edge-text": "After the confirmation the edge and all its data will be made private and won't be accessible by others.",
"import": "Import edge",
"label": "Label",
"load-entity-error": "Failed to load data. Entity not found or has been deleted.",
"load-entity-error": "Failed to load data. Entity has been deleted.",
"assign-new-edge": "Assign new edge",
"manage-edge-dashboards": "Edge dashboards",
"unassign-from-edge": "Unassign from edge",