Edge Downlinks: refactored, added missing EdgeEventType
This commit is contained in:
parent
d35f9d0edf
commit
cdd9c867a0
@ -21,7 +21,8 @@ import {
|
|||||||
EntityTableConfig
|
EntityTableConfig
|
||||||
} from '@home/models/entity/entities-table-config.models';
|
} from '@home/models/entity/entities-table-config.models';
|
||||||
import {
|
import {
|
||||||
EdgeEvent, edgeEventActionTypeTranslations,
|
EdgeEvent,
|
||||||
|
edgeEventActionTypeTranslations,
|
||||||
EdgeEventStatus,
|
EdgeEventStatus,
|
||||||
edgeEventStatusColor,
|
edgeEventStatusColor,
|
||||||
EdgeEventType,
|
EdgeEventType,
|
||||||
@ -42,17 +43,13 @@ import {
|
|||||||
EventContentDialogComponent,
|
EventContentDialogComponent,
|
||||||
EventContentDialogData
|
EventContentDialogData
|
||||||
} from '@home/components/event/event-content-dialog.component';
|
} from '@home/components/event/event-content-dialog.component';
|
||||||
import { sortObjectKeys } from '@core/utils';
|
|
||||||
import { RuleChainService } from '@core/http/rule-chain.service';
|
import { RuleChainService } from '@core/http/rule-chain.service';
|
||||||
import { AttributeService } from '@core/http/attribute.service';
|
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 } from 'rxjs/operators';
|
||||||
import { AssetService } from '@core/http/asset.service';
|
import { EntityService } from "@core/http/entity.service";
|
||||||
import { DeviceService } from '@core/http/device.service';
|
|
||||||
import { EntityViewService } from '@core/http/entity-view.service';
|
|
||||||
import { EventTableHeaderComponent } from '@home/components/event/event-table-header.component';
|
|
||||||
|
|
||||||
export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePageLink> {
|
export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePageLink> {
|
||||||
|
|
||||||
@ -61,9 +58,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
|||||||
constructor(private edgeService: EdgeService,
|
constructor(private edgeService: EdgeService,
|
||||||
private dialogService: DialogService,
|
private dialogService: DialogService,
|
||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
private deviceService: DeviceService,
|
private entityService: EntityService,
|
||||||
private assetService: AssetService,
|
|
||||||
private entityViewService: EntityViewService,
|
|
||||||
private ruleChainService: RuleChainService,
|
private ruleChainService: RuleChainService,
|
||||||
private attributeService: AttributeService,
|
private attributeService: AttributeService,
|
||||||
private datePipe: DatePipe,
|
private datePipe: DatePipe,
|
||||||
@ -98,6 +93,24 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
|||||||
return this.edgeService.getEdgeEvents(this.entityId, pageLink);
|
return this.edgeService.getEdgeEvents(this.entityId, pageLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadEdgeInfo() {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateColumns(updateTableColumns: boolean = false): void {
|
updateColumns(updateTableColumns: boolean = false): void {
|
||||||
this.columns = [];
|
this.columns = [];
|
||||||
this.columns.push(
|
this.columns.push(
|
||||||
@ -132,94 +145,6 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null, sortKeys = false): void {
|
|
||||||
if ($event) {
|
|
||||||
$event.stopPropagation();
|
|
||||||
}
|
|
||||||
if (contentType === ContentType.JSON && sortKeys) {
|
|
||||||
try {
|
|
||||||
content = JSON.stringify(sortObjectKeys(JSON.parse(content)));
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, {
|
|
||||||
disableClose: true,
|
|
||||||
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
||||||
data: {
|
|
||||||
content,
|
|
||||||
title,
|
|
||||||
contentType
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
isEdgeEventHasData(edgeEventType: EdgeEventType) {
|
|
||||||
switch (edgeEventType) {
|
|
||||||
case EdgeEventType.WIDGET_TYPE:
|
|
||||||
case EdgeEventType.WIDGETS_BUNDLE:
|
|
||||||
case EdgeEventType.ADMIN_SETTINGS:
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
prepareEdgeEventContent(entity) {
|
|
||||||
// TODO: voba - extend this function with different cases based on action and entity type
|
|
||||||
switch (entity.type) {
|
|
||||||
case EdgeEventType.RELATION:
|
|
||||||
return of(JSON.stringify(entity.body));
|
|
||||||
case EdgeEventType.ASSET:
|
|
||||||
return this.assetService.getAsset(entity.entityId, null).pipe(
|
|
||||||
map((asset) => {
|
|
||||||
return JSON.stringify(asset);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
case EdgeEventType.DEVICE:
|
|
||||||
return this.deviceService.getDevice(entity.entityId, null).pipe(
|
|
||||||
map((device) => {
|
|
||||||
return JSON.stringify(device);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
case EdgeEventType.ENTITY_VIEW:
|
|
||||||
return this.entityViewService.getEntityView(entity.entityId, null).pipe(
|
|
||||||
map((entityView) => {
|
|
||||||
return JSON.stringify(entityView);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
case EdgeEventType.RULE_CHAIN_METADATA:
|
|
||||||
return this.ruleChainService.getRuleChainMetadata(entity.entityId, null).pipe(
|
|
||||||
map((ruleChainMetaData) => {
|
|
||||||
return JSON.stringify(ruleChainMetaData.nodes);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
return of(JSON.stringify(entity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
showEdgeEventContent($event: MouseEvent, content: string, title: string, sortKeys = false): void {
|
|
||||||
if ($event) {
|
|
||||||
$event.stopPropagation();
|
|
||||||
}
|
|
||||||
var contentType = ContentType.JSON;
|
|
||||||
if (contentType === ContentType.JSON && sortKeys) {
|
|
||||||
try {
|
|
||||||
content = JSON.stringify(sortObjectKeys(JSON.parse(content)));
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, {
|
|
||||||
disableClose: true,
|
|
||||||
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
||||||
data: {
|
|
||||||
content,
|
|
||||||
title,
|
|
||||||
contentType
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateEdgeEventStatus(createdTime) {
|
updateEdgeEventStatus(createdTime) {
|
||||||
if (this.queueStartTs && createdTime < this.queueStartTs) {
|
if (this.queueStartTs && createdTime < this.queueStartTs) {
|
||||||
return this.translate.instant('edge.deployed');
|
return this.translate.instant('edge.deployed');
|
||||||
@ -232,22 +157,63 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
|
|||||||
return createdTime > this.queueStartTs;
|
return createdTime > this.queueStartTs;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadEdgeInfo() {
|
isEdgeEventHasData(edgeEventType: EdgeEventType) {
|
||||||
this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs'])
|
switch (edgeEventType) {
|
||||||
.subscribe(
|
case EdgeEventType.DEVICE_PROFILE:
|
||||||
attributes => this.onUpdate(attributes)
|
case EdgeEventType.WIDGETS_BUNDLE:
|
||||||
);
|
case EdgeEventType.WIDGET_TYPE:
|
||||||
|
case EdgeEventType.ADMIN_SETTINGS:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdate(attributes) {
|
prepareEdgeEventContent(entity) {
|
||||||
this.queueStartTs = 0;
|
switch (entity.type) {
|
||||||
let edge = attributes.reduce(function (map, attribute) {
|
case EdgeEventType.DEVICE:
|
||||||
map[attribute.key] = attribute;
|
case EdgeEventType.ASSET:
|
||||||
return map;
|
case EdgeEventType.EDGE:
|
||||||
}, {});
|
case EdgeEventType.ENTITY_VIEW:
|
||||||
if (edge.queueStartTs) {
|
case EdgeEventType.TENANT:
|
||||||
this.queueStartTs = edge.queueStartTs.lastUpdateTs;
|
case EdgeEventType.CUSTOMER:
|
||||||
|
case EdgeEventType.DASHBOARD:
|
||||||
|
case EdgeEventType.USER:
|
||||||
|
case EdgeEventType.RULE_CHAIN:
|
||||||
|
case EdgeEventType.ALARM:
|
||||||
|
return this.entityService.getEntity(entity.type, entity.entityId, { ignoreLoading: true, ignoreErrors: true }).pipe(
|
||||||
|
map((entity) => {
|
||||||
|
return JSON.stringify(entity);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
case EdgeEventType.RELATION:
|
||||||
|
return of(JSON.stringify(entity.body));
|
||||||
|
case EdgeEventType.RULE_CHAIN_METADATA:
|
||||||
|
return this.ruleChainService.getRuleChainMetadata(entity.entityId, null).pipe(
|
||||||
|
map((ruleChainMetaData) => {
|
||||||
|
return JSON.stringify(ruleChainMetaData.nodes);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
case EdgeEventType.DEVICE_PROFILE:
|
||||||
|
case EdgeEventType.WIDGETS_BUNDLE:
|
||||||
|
case EdgeEventType.WIDGET_TYPE:
|
||||||
|
case EdgeEventType.ADMIN_SETTINGS:
|
||||||
|
return of(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showEdgeEventContent($event: MouseEvent, content: string, title: string): void {
|
||||||
|
if ($event) {
|
||||||
|
$event.stopPropagation();
|
||||||
|
}
|
||||||
|
this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, {
|
||||||
|
disableClose: true,
|
||||||
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
||||||
|
data: {
|
||||||
|
content,
|
||||||
|
title,
|
||||||
|
contentType: ContentType.JSON
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,9 +25,7 @@ import { DialogService } from '@core/services/dialog.service';
|
|||||||
import { RuleChainService } from '@core/http/rule-chain.service';
|
import { RuleChainService } from '@core/http/rule-chain.service';
|
||||||
import { AttributeService } from '@core/http/attribute.service';
|
import { AttributeService } from '@core/http/attribute.service';
|
||||||
import { EdgeService } from '@core/http/edge.service';
|
import { EdgeService } from '@core/http/edge.service';
|
||||||
import { DeviceService } from '@core/http/device.service';
|
import { EntityService } from "@core/http/entity.service";
|
||||||
import { AssetService } from '@core/http/asset.service';
|
|
||||||
import { EntityViewService } from '@core/http/entity-view.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-edge-downlink-table',
|
selector: 'tb-edge-downlink-table',
|
||||||
@ -71,9 +69,7 @@ export class EdgeDownlinkTableComponent implements OnInit {
|
|||||||
edgeDownlinkTableConfig: EdgeDownlinkTableConfig;
|
edgeDownlinkTableConfig: EdgeDownlinkTableConfig;
|
||||||
|
|
||||||
constructor(private edgeService: EdgeService,
|
constructor(private edgeService: EdgeService,
|
||||||
private deviceService: DeviceService,
|
private entityService: EntityService,
|
||||||
private assetService: AssetService,
|
|
||||||
private entityViewService: EntityViewService,
|
|
||||||
private dialogService: DialogService,
|
private dialogService: DialogService,
|
||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
private attributeService: AttributeService,
|
private attributeService: AttributeService,
|
||||||
@ -88,9 +84,7 @@ export class EdgeDownlinkTableComponent implements OnInit {
|
|||||||
this.edgeService,
|
this.edgeService,
|
||||||
this.dialogService,
|
this.dialogService,
|
||||||
this.translate,
|
this.translate,
|
||||||
this.deviceService,
|
this.entityService,
|
||||||
this.assetService,
|
|
||||||
this.entityViewService,
|
|
||||||
this.ruleChainService,
|
this.ruleChainService,
|
||||||
this.attributeService,
|
this.attributeService,
|
||||||
this.datePipe,
|
this.datePipe,
|
||||||
|
|||||||
@ -59,6 +59,7 @@ export enum EdgeEventType {
|
|||||||
USER = "USER",
|
USER = "USER",
|
||||||
CUSTOMER = "CUSTOMER",
|
CUSTOMER = "CUSTOMER",
|
||||||
RELATION = "RELATION",
|
RELATION = "RELATION",
|
||||||
|
TENANT = "TENANT",
|
||||||
WIDGETS_BUNDLE = "WIDGETS_BUNDLE",
|
WIDGETS_BUNDLE = "WIDGETS_BUNDLE",
|
||||||
WIDGET_TYPE = "WIDGET_TYPE",
|
WIDGET_TYPE = "WIDGET_TYPE",
|
||||||
ADMIN_SETTINGS = "ADMIN_SETTINGS"
|
ADMIN_SETTINGS = "ADMIN_SETTINGS"
|
||||||
@ -105,6 +106,7 @@ export const edgeEventTypeTranslations = new Map<EdgeEventType, string>(
|
|||||||
[EdgeEventType.USER, 'edge-event.type-user'],
|
[EdgeEventType.USER, 'edge-event.type-user'],
|
||||||
[EdgeEventType.CUSTOMER, 'edge-event.type-customer'],
|
[EdgeEventType.CUSTOMER, 'edge-event.type-customer'],
|
||||||
[EdgeEventType.RELATION, 'edge-event.type-relation'],
|
[EdgeEventType.RELATION, 'edge-event.type-relation'],
|
||||||
|
[EdgeEventType.TENANT, 'edge-event.type-tenant'],
|
||||||
[EdgeEventType.WIDGETS_BUNDLE, 'edge-event.type-widgets-bundle'],
|
[EdgeEventType.WIDGETS_BUNDLE, 'edge-event.type-widgets-bundle'],
|
||||||
[EdgeEventType.WIDGET_TYPE, 'edge-event.type-widgets-type'],
|
[EdgeEventType.WIDGET_TYPE, 'edge-event.type-widgets-type'],
|
||||||
[EdgeEventType.ADMIN_SETTINGS, 'edge-event.type-admin-settings']
|
[EdgeEventType.ADMIN_SETTINGS, 'edge-event.type-admin-settings']
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user