Browse Source

Merge pull request #78 from deaflynx/develop/3.3-edge

Develop/3.3 edge: changes in Edge Downlinks, Edge Widget, fix for edge rule chains missing tooltips
pull/3811/head
VoBa 6 years ago
committed by GitHub
parent
commit
aedebc32eb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      application/src/main/data/json/system/widget_bundles/edge_widgets.json
  2. 42
      ui-ngx/src/app/core/http/entity.service.ts
  3. 152
      ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts
  4. 21
      ui-ngx/src/app/modules/home/components/edge/edge-downlink-table.component.ts
  5. 57
      ui-ngx/src/app/modules/home/components/widget/lib/edges-overview-widget.component.ts
  6. 8
      ui-ngx/src/app/modules/home/pages/edge/edge-routing.module.ts
  7. 2
      ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html
  8. 18
      ui-ngx/src/app/modules/home/pages/edge/edge.component.ts
  9. 2
      ui-ngx/src/app/shared/models/edge.models.ts

2
application/src/main/data/json/system/widget_bundles/edge_widgets.json

@ -16,7 +16,7 @@
"templateHtml": "<tb-edges-overview-widget \n [ctx]=\"ctx\">\n</tb-edges-overview-widget>", "templateHtml": "<tb-edges-overview-widget \n [ctx]=\"ctx\">\n</tb-edges-overview-widget>",
"templateCss": "", "templateCss": "",
"controllerScript": "self.onInit = function() {\n};\n\nself.typeParameters = function() {\n return {\n maxDatasources: 1,\n dataKeysOptional: true\n };\n}\n\nself.onDestroy = function() {\n};\n", "controllerScript": "self.onInit = function() {\n};\n\nself.typeParameters = function() {\n return {\n maxDatasources: 1,\n dataKeysOptional: true\n };\n}\n\nself.onDestroy = function() {\n};\n",
"settingsSchema": "{}\n", "settingsSchema": "{\n \"schema\": {\n \"type\": \"object\",\n \"title\": \"EdgeOverviewSettings\",\n \"properties\": {\n \"enableDefaultTitle\": {\n \"title\": \"Display default title\",\n \"type\": \"boolean\",\n \"default\": true\n }\n },\n \"required\": []\n },\n \"form\": [\n \"enableDefaultTitle\"\n ]\n}",
"dataKeySettingsSchema": "{}\n", "dataKeySettingsSchema": "{}\n",
"defaultConfig": "{\"timewindow\":{\"realtime\":{\"interval\":1000,\"timewindowMs\":86400000},\"aggregation\":{\"type\":\"NONE\",\"limit\":200}},\"showTitle\":true,\"showTitleIcon\":true,\"titleIcon\":\"router\",\"backgroundColor\":\"rgb(255, 255, 255)\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"4px\",\"settings\":{},\"title\":\"Edge Quick Overview\",\"dropShadow\":true,\"enableFullscreen\":true,\"titleStyle\":{\"fontSize\":\"16px\",\"fontWeight\":400,\"padding\":\"5px 10px 5px 10px\"},\"useDashboardTimewindow\":false,\"showLegend\":false,\"datasources\":[{\"type\":\"function\",\"name\":\"Simulated\",\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Sin\",\"color\":\"#2196f3\",\"settings\":{\"columnWidth\":\"0px\",\"useCellStyleFunction\":false,\"cellStyleFunction\":\"\",\"useCellContentFunction\":false,\"cellContentFunction\":\"\"},\"_hash\":0.472295003170325,\"funcBody\":\"return Math.round(1000*Math.sin(time/5000));\"}]}],\"widgetStyle\":{},\"actions\":{}}" "defaultConfig": "{\"timewindow\":{\"realtime\":{\"interval\":1000,\"timewindowMs\":86400000},\"aggregation\":{\"type\":\"NONE\",\"limit\":200}},\"showTitle\":true,\"showTitleIcon\":true,\"titleIcon\":\"router\",\"backgroundColor\":\"rgb(255, 255, 255)\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"4px\",\"settings\":{},\"title\":\"Edge Quick Overview\",\"dropShadow\":true,\"enableFullscreen\":true,\"titleStyle\":{\"fontSize\":\"16px\",\"fontWeight\":400,\"padding\":\"5px 10px 5px 10px\"},\"useDashboardTimewindow\":false,\"showLegend\":false,\"datasources\":[{\"type\":\"function\",\"name\":\"Simulated\",\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Sin\",\"color\":\"#2196f3\",\"settings\":{\"columnWidth\":\"0px\",\"useCellStyleFunction\":false,\"cellStyleFunction\":\"\",\"useCellContentFunction\":false,\"cellContentFunction\":\"\"},\"_hash\":0.472295003170325,\"funcBody\":\"return Math.round(1000*Math.sin(time/5000));\"}]}],\"widgetStyle\":{},\"actions\":{}}"
} }

42
ui-ngx/src/app/core/http/entity.service.ts

@ -76,8 +76,10 @@ import {
} from '@shared/models/query/query.models'; } from '@shared/models/query/query.models';
import { alarmFields } from '@shared/models/alarm.models'; import { alarmFields } from '@shared/models/alarm.models';
import { EdgeService } from "@core/http/edge.service"; import { EdgeService } from "@core/http/edge.service";
import { Edge, EdgeEventType } from '@shared/models/edge.models';
import { RuleChainType } from "@shared/models/rule-chain.models"; import { RuleChainType } from "@shared/models/rule-chain.models";
import { Edge } from '@shared/models/edge.models'; import { WidgetService } from "@core/http/widget.service";
import { DeviceProfileService } from "@core/http/device-profile.service";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -98,6 +100,8 @@ export class EntityService {
private dashboardService: DashboardService, private dashboardService: DashboardService,
private entityRelationService: EntityRelationService, private entityRelationService: EntityRelationService,
private attributeService: AttributeService, private attributeService: AttributeService,
private widgetService: WidgetService,
private deviceProfileService: DeviceProfileService,
private utils: UtilsService private utils: UtilsService
) { } ) { }
@ -1316,4 +1320,40 @@ export class EntityService {
} }
return entitiesObservable; return entitiesObservable;
} }
public getEdgeEventContentByEntityType(entity: any): Observable<any> {
let entityObservable: Observable<any>;
const entityId: string = entity.entityId;
const entityType: any = entity.type;
switch (entityType) {
case EdgeEventType.DASHBOARD:
case EdgeEventType.ALARM:
case EdgeEventType.RULE_CHAIN:
case EdgeEventType.EDGE:
case EdgeEventType.USER:
case EdgeEventType.CUSTOMER:
case EdgeEventType.TENANT:
case EdgeEventType.ASSET:
case EdgeEventType.DEVICE:
case EdgeEventType.ENTITY_VIEW:
entityObservable = this.getEntity(entityType, entityId, { ignoreLoading: true, ignoreErrors: true });
break;
case EdgeEventType.RULE_CHAIN_METADATA:
entityObservable = this.ruleChainService.getRuleChainMetadata(entityId);
break;
case EdgeEventType.WIDGET_TYPE:
entityObservable = this.widgetService.getWidgetTypeById(entityId);
break;
case EdgeEventType.WIDGETS_BUNDLE:
entityObservable = this.widgetService.getWidgetsBundle(entityId);
break;
case EdgeEventType.DEVICE_PROFILE:
entityObservable = this.deviceProfileService.getDeviceProfile(entityId);
break;
case EdgeEventType.RELATION:
entityObservable = of(entity.body);
break;
}
return entityObservable;
}
} }

152
ui-ngx/src/app/modules/home/components/edge/edge-downlink-table-config.ts

@ -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,
@ -33,7 +34,7 @@ import { DatePipe } from '@angular/common';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { EntityTypeResource } from '@shared/models/entity-type.models'; import { EntityTypeResource } from '@shared/models/entity-type.models';
import { Observable, of } from 'rxjs'; import { Observable } from 'rxjs';
import { PageData } from '@shared/models/page/page-data'; import { PageData } from '@shared/models/page/page-data';
import { Direction } from '@shared/models/page/sort-order'; import { Direction } from '@shared/models/page/sort-order';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.service';
@ -42,37 +43,29 @@ 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 { 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> {
queueStartTs: number; queueStartTs: number;
constructor(private edgeService: EdgeService, constructor(private edgeService: EdgeService,
private entityService: EntityService,
private dialogService: DialogService, private dialogService: DialogService,
private translate: TranslateService, private translate: TranslateService,
private deviceService: DeviceService,
private assetService: AssetService,
private entityViewService: EntityViewService,
private ruleChainService: RuleChainService,
private attributeService: AttributeService, private attributeService: AttributeService,
private datePipe: DatePipe, private datePipe: DatePipe,
private dialog: MatDialog, private dialog: MatDialog,
public entityId: EntityId, public entityId: EntityId) {
public tenantId: string) {
super(); super();
this.loadDataOnInit = false;
this.tableTitle = ''; this.tableTitle = '';
this.loadDataOnInit = false;
this.useTimePageLink = true; this.useTimePageLink = true;
this.detailsPanelEnabled = false; this.detailsPanelEnabled = false;
this.selectionEnabled = false; this.selectionEnabled = false;
@ -81,13 +74,11 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
this.entitiesDeleteEnabled = false; this.entitiesDeleteEnabled = false;
this.headerComponent = EdgeDownlinkTableHeaderComponent; this.headerComponent = EdgeDownlinkTableHeaderComponent;
this.entityTranslations = { this.entityTranslations = {
noEntities: 'edge.no-downlinks-prompt' noEntities: 'edge.no-downlinks-prompt'
}; };
this.entityResources = {} as EntityTypeResource<EdgeEvent>; this.entityResources = {} as EntityTypeResource<EdgeEvent>;
this.entitiesFetchFunction = pageLink => this.fetchEvents(pageLink); this.entitiesFetchFunction = pageLink => this.fetchEvents(pageLink);
this.defaultSortOrder = {property: 'createdTime', direction: Direction.DESC}; this.defaultSortOrder = {property: 'createdTime', direction: Direction.DESC};
this.updateColumns(); this.updateColumns();
@ -98,6 +89,24 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
return this.edgeService.getEdgeEvents(this.entityId, pageLink); 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;
}
}
updateColumns(updateTableColumns: boolean = false): void { updateColumns(updateTableColumns: boolean = false): void {
this.columns = []; this.columns = [];
this.columns.push( this.columns.push(
@ -132,31 +141,20 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
} }
} }
showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null, sortKeys = false): void { updateEdgeEventStatus(createdTime): string {
if ($event) { if (this.queueStartTs && createdTime < this.queueStartTs) {
$event.stopPropagation(); return this.translate.instant('edge.deployed');
} } else {
if (contentType === ContentType.JSON && sortKeys) { return this.translate.instant('edge.pending');
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) { isPending(createdTime): boolean {
return createdTime > this.queueStartTs;
}
isEdgeEventHasData(edgeEventType: EdgeEventType): boolean {
switch (edgeEventType) { switch (edgeEventType) {
case EdgeEventType.WIDGET_TYPE:
case EdgeEventType.WIDGETS_BUNDLE:
case EdgeEventType.ADMIN_SETTINGS: case EdgeEventType.ADMIN_SETTINGS:
return false; return false;
default: default:
@ -164,90 +162,24 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa
} }
} }
prepareEdgeEventContent(entity) { prepareEdgeEventContent(entity: any): Observable<string> {
// TODO: voba - extend this function with different cases based on action and entity type return this.entityService.getEdgeEventContentByEntityType(entity).pipe(
switch (entity.type) { map((result) => JSON.stringify(result))
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 { showEdgeEventContent($event: MouseEvent, content: string, title: string): void {
if ($event) { if ($event) {
$event.stopPropagation(); $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, { this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, {
disableClose: true, disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: { data: {
content, content,
title, title,
contentType contentType: ContentType.JSON
} }
}); });
} }
updateEdgeEventStatus(createdTime) {
if (this.queueStartTs && createdTime < this.queueStartTs) {
return this.translate.instant('edge.deployed');
} else {
return this.translate.instant('edge.pending');
}
}
isPending(createdTime) {
return createdTime > this.queueStartTs;
}
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;
}
}
} }

21
ui-ngx/src/app/modules/home/components/edge/edge-downlink-table.component.ts

@ -22,12 +22,9 @@ import { EntityId } from '@shared/models/id/entity-id';
import { EntitiesTableComponent } from '@home/components/entity/entities-table.component'; import { EntitiesTableComponent } from '@home/components/entity/entities-table.component';
import { EdgeDownlinkTableConfig } from './edge-downlink-table-config'; import { EdgeDownlinkTableConfig } from './edge-downlink-table-config';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.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',
@ -36,9 +33,6 @@ import { EntityViewService } from '@core/http/entity-view.service';
}) })
export class EdgeDownlinkTableComponent implements OnInit { export class EdgeDownlinkTableComponent implements OnInit {
@Input()
tenantId: string;
activeValue = false; activeValue = false;
dirtyValue = false; dirtyValue = false;
entityIdValue: EntityId; entityIdValue: EntityId;
@ -71,13 +65,10 @@ 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,
private ruleChainService: RuleChainService,
private datePipe: DatePipe, private datePipe: DatePipe,
private dialog: MatDialog) { private dialog: MatDialog) {
} }
@ -86,17 +77,13 @@ export class EdgeDownlinkTableComponent implements OnInit {
this.dirtyValue = !this.activeValue; this.dirtyValue = !this.activeValue;
this.edgeDownlinkTableConfig = new EdgeDownlinkTableConfig( this.edgeDownlinkTableConfig = new EdgeDownlinkTableConfig(
this.edgeService, this.edgeService,
this.entityService,
this.dialogService, this.dialogService,
this.translate, this.translate,
this.deviceService,
this.assetService,
this.entityViewService,
this.ruleChainService,
this.attributeService, this.attributeService,
this.datePipe, this.datePipe,
this.dialog, this.dialog,
this.entityIdValue, this.entityIdValue
this.tenantId
); );
} }

57
ui-ngx/src/app/modules/home/components/widget/lib/edges-overview-widget.component.ts

@ -41,6 +41,11 @@ import { BaseData, HasId } from '@shared/models/base-data';
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { getCurrentAuthUser } from '@core/auth/auth.selectors'; import { getCurrentAuthUser } from '@core/auth/auth.selectors';
import { Authority } from '@shared/models/authority.enum'; import { Authority } from '@shared/models/authority.enum';
import { isDefined } from '@core/utils';
interface EdgesOverviewWidgetSettings {
enableDefaultTitle: boolean;
}
@Component({ @Component({
selector: 'tb-edges-overview-widget', selector: 'tb-edges-overview-widget',
@ -59,12 +64,10 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
private widgetConfig: WidgetConfig; private widgetConfig: WidgetConfig;
private subscription: IWidgetSubscription; private subscription: IWidgetSubscription;
private datasources: Array<EntityNodeDatasource>; private datasources: Array<EntityNodeDatasource>;
private settings: EdgesOverviewWidgetSettings;
private nodeIdCounter = 0; private nodeIdCounter = 0;
private entityNodesMap: {[parentNodeId: string]: {[edgeId: string]: string}} = {};
private entityGroupsNodesMap: {[edgeNodeId: string]: {[groupType: string]: string}} = {};
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
private edgeService: EdgeService, private edgeService: EdgeService,
private entityService: EntityService, private entityService: EntityService,
@ -78,6 +81,8 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
this.widgetConfig = this.ctx.widgetConfig; this.widgetConfig = this.ctx.widgetConfig;
this.subscription = this.ctx.defaultSubscription; this.subscription = this.ctx.defaultSubscription;
this.datasources = this.subscription.datasources as Array<EntityNodeDatasource>; this.datasources = this.subscription.datasources as Array<EntityNodeDatasource>;
this.settings = this.ctx.settings;
this.initializeConfig();
this.ctx.updateWidgetParams(); this.ctx.updateWidgetParams();
} }
@ -86,11 +91,11 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
if (node.id === '#' && datasource) { if (node.id === '#' && datasource) {
if (datasource.type === DatasourceType.entity && datasource.entity.id.entityType === EntityType.EDGE) { if (datasource.type === DatasourceType.entity && datasource.entity.id.entityType === EntityType.EDGE) {
var selectedEdge: BaseData<EntityId> = datasource.entity; var selectedEdge: BaseData<EntityId> = datasource.entity;
this.updateTitle(selectedEdge);
this.getCustomerTitle(selectedEdge.id.id); this.getCustomerTitle(selectedEdge.id.id);
this.ctx.widgetTitle = `${selectedEdge.name} Quick Overview`; cb(this.loadNodesForEdge(selectedEdge));
cb(this.loadNodesForEdge(selectedEdge.id.id, selectedEdge));
} else if (datasource.type === DatasourceType.function) { } else if (datasource.type === DatasourceType.function) {
cb(this.loadNodesForEdge(datasource.entityId, datasource.entity)); cb(this.loadNodesForEdge(datasource.entity));
} else { } else {
this.edgeIsDatasource = false; this.edgeIsDatasource = false;
cb([]); cb([]);
@ -103,21 +108,19 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
this.entityService.getAssignedToEdgeEntitiesByType(edgeId, entityType, pageLink).subscribe( this.entityService.getAssignedToEdgeEntitiesByType(edgeId, entityType, pageLink).subscribe(
(entities) => { (entities) => {
if (entities.data.length > 0) { if (entities.data.length > 0) {
cb(this.entitiesToNodes(node.id, entities.data)); cb(this.entitiesToNodes(entities.data));
} else { } else {
cb([]); cb([]);
} }
} }
) );
} else { } else {
cb([]); cb([]);
} }
} }
private loadNodesForEdge(parentNodeId: string, entity: BaseData<HasId>): EdgeOverviewNode[] { private loadNodesForEdge(entity: BaseData<HasId>): EdgeOverviewNode[] {
const nodes: EdgeOverviewNode[] = []; const nodes: EdgeOverviewNode[] = [];
const nodesMap = {};
this.entityGroupsNodesMap[parentNodeId] = nodesMap;
const authUser = getCurrentAuthUser(this.store); const authUser = getCurrentAuthUser(this.store);
var allowedGroupTypes: EntityType[] = edgeGroupsTypes; var allowedGroupTypes: EntityType[] = edgeGroupsTypes;
if (authUser.authority === Authority.CUSTOMER_USER) { if (authUser.authority === Authority.CUSTOMER_USER) {
@ -136,18 +139,12 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
} as EdgeGroupNodeData } as EdgeGroupNodeData
}; };
nodes.push(node); nodes.push(node);
nodesMap[entityType] = node.id;
}); });
return nodes; return nodes;
} }
private createEntityNode(parentNodeId: string, entity: BaseData<HasId>): EdgeOverviewNode { private createEntityNode(entity: BaseData<HasId>): EdgeOverviewNode {
let nodesMap = this.entityNodesMap[parentNodeId]; return {
if (!nodesMap) {
nodesMap = {};
this.entityNodesMap[parentNodeId] = nodesMap;
}
const node: EdgeOverviewNode = {
id: (++this.nodeIdCounter)+'', id: (++this.nodeIdCounter)+'',
icon: false, icon: false,
text: entityNodeText(entity), text: entityNodeText(entity),
@ -159,17 +156,14 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
entity: entity, entity: entity,
internalId: entity.id.id internalId: entity.id.id
} as EntityNodeData } as EntityNodeData
}; } as EdgeOverviewNode;
nodesMap[entity.id.id] = node.id;
return node;
} }
private entitiesToNodes(parentNodeId: string, entities: BaseData<HasId>[]): EdgeOverviewNode[] { private entitiesToNodes(entities: BaseData<HasId>[]): EdgeOverviewNode[] {
const nodes: EdgeOverviewNode[] = []; const nodes: EdgeOverviewNode[] = [];
this.entityNodesMap[parentNodeId] = {};
if (entities) { if (entities) {
entities.forEach((entity) => { entities.forEach((entity) => {
const node = this.createEntityNode(parentNodeId, entity); const node = this.createEntityNode(entity);
nodes.push(node); nodes.push(node);
}); });
} }
@ -187,4 +181,17 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
this.cd.detectChanges(); this.cd.detectChanges();
}); });
} }
private initializeConfig(): void {
const edgeIsDatasource: boolean = this.datasources[0] && this.datasources[0].type === DatasourceType.entity && this.datasources[0].entity.id.entityType === EntityType.EDGE;
if (edgeIsDatasource) {
const edge = this.datasources[0].entity;
this.updateTitle(edge);
}
}
private updateTitle(edge: BaseData<EntityId>): void {
const displayDefaultTitle: boolean = isDefined(this.settings.enableDefaultTitle) ? this.settings.enableDefaultTitle : false;
this.ctx.widgetTitle = displayDefaultTitle ? `${edge.name} Quick Overview` : this.widgetConfig.title;
}
} }

8
ui-ngx/src/app/modules/home/pages/edge/edge-routing.module.ts

@ -34,7 +34,7 @@ import {
importRuleChainBreadcumbLabelFunction, importRuleChainBreadcumbLabelFunction,
ResolvedRuleChainMetaDataResolver, ResolvedRuleChainMetaDataResolver,
ruleChainBreadcumbLabelFunction, RuleChainImportGuard, ruleChainBreadcumbLabelFunction, RuleChainImportGuard,
RuleChainResolver, RuleNodeComponentsResolver RuleChainResolver, RuleNodeComponentsResolver, TooltipsterResolver
} from '@home/pages/rulechain/rulechain-routing.module'; } from '@home/pages/rulechain/rulechain-routing.module';
const routes: Routes = [ const routes: Routes = [
@ -194,7 +194,8 @@ const routes: Routes = [
resolve: { resolve: {
ruleChain: RuleChainResolver, ruleChain: RuleChainResolver,
ruleChainMetaData: ResolvedRuleChainMetaDataResolver, ruleChainMetaData: ResolvedRuleChainMetaDataResolver,
ruleNodeComponents: RuleNodeComponentsResolver ruleNodeComponents: RuleNodeComponentsResolver,
tooltipster: TooltipsterResolver
} }
}, },
{ {
@ -213,7 +214,8 @@ const routes: Routes = [
ruleChainType: RuleChainType.EDGE ruleChainType: RuleChainType.EDGE
}, },
resolve: { resolve: {
ruleNodeComponents: RuleNodeComponentsResolver ruleNodeComponents: RuleNodeComponentsResolver,
tooltipster: TooltipsterResolver
} }
} }
] ]

2
ui-ngx/src/app/modules/home/pages/edge/edge-tabs.component.html

@ -43,7 +43,7 @@
</mat-tab> </mat-tab>
<mat-tab *ngIf="entity && authUser.authority === authorities.TENANT_ADMIN" <mat-tab *ngIf="entity && authUser.authority === authorities.TENANT_ADMIN"
label="{{ 'edge.downlinks' | translate }}" #downLinksTab="matTab"> label="{{ 'edge.downlinks' | translate }}" #downLinksTab="matTab">
<tb-edge-downlink-table [active]="downLinksTab.isActive" [tenantId]="entity.tenantId.id" <tb-edge-downlink-table [active]="downLinksTab.isActive"
[entityId]="entity.id"></tb-edge-downlink-table> [entityId]="entity.id"></tb-edge-downlink-table>
</mat-tab> </mat-tab>
<mat-tab *ngIf="entity" <mat-tab *ngIf="entity"

18
ui-ngx/src/app/modules/home/pages/edge/edge.component.ts

@ -83,7 +83,7 @@ export class EdgeComponent extends EntityComponent<EdgeInfo> {
) )
} }
); );
this.checkIsNewEdge(entity, form); this.generateRoutingKeyAndSecret(entity, form);
return form; return form;
} }
@ -100,7 +100,7 @@ export class EdgeComponent extends EntityComponent<EdgeInfo> {
description: entity.additionalInfo ? entity.additionalInfo.description : '' description: entity.additionalInfo ? entity.additionalInfo.description : ''
} }
}); });
this.checkIsNewEdge(entity, this.entityForm); this.generateRoutingKeyAndSecret(entity, this.entityForm);
} }
updateFormState() { updateFormState() {
@ -109,13 +109,6 @@ export class EdgeComponent extends EntityComponent<EdgeInfo> {
this.entityForm.get('secret').disable({emitEvent: false}); this.entityForm.get('secret').disable({emitEvent: false});
} }
private checkIsNewEdge(entity: EdgeInfo, form: FormGroup) {
if (entity && !entity.id) {
form.get('routingKey').patchValue(guid(), {emitEvent: false});
form.get('secret').patchValue(generateSecret(20), {emitEvent: false});
}
}
onEdgeIdCopied($event) { onEdgeIdCopied($event) {
this.store.dispatch(new ActionNotificationShow( this.store.dispatch(new ActionNotificationShow(
{ {
@ -139,4 +132,11 @@ export class EdgeComponent extends EntityComponent<EdgeInfo> {
horizontalPosition: 'right' horizontalPosition: 'right'
})); }));
} }
private generateRoutingKeyAndSecret(entity: EdgeInfo, form: FormGroup) {
if (entity && !entity.id) {
form.get('routingKey').patchValue(guid(), {emitEvent: false});
form.get('secret').patchValue(generateSecret(20), {emitEvent: false});
}
}
} }

2
ui-ngx/src/app/shared/models/edge.models.ts

@ -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…
Cancel
Save