diff --git a/application/src/main/data/json/system/widget_bundles/edge_widgets.json b/application/src/main/data/json/system/widget_bundles/edge_widgets.json
index 6412ff9d99..8b64885d80 100644
--- a/application/src/main/data/json/system/widget_bundles/edge_widgets.json
+++ b/application/src/main/data/json/system/widget_bundles/edge_widgets.json
@@ -16,7 +16,7 @@
"templateHtml": "\n",
"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",
- "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",
"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\":{}}"
}
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/edges-overview-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/edges-overview-widget.component.ts
index 657cc92efe..0b15def29f 100644
--- a/ui-ngx/src/app/modules/home/components/widget/lib/edges-overview-widget.component.ts
+++ b/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 { getCurrentAuthUser } from '@core/auth/auth.selectors';
import { Authority } from '@shared/models/authority.enum';
+import { isDefined } from '@core/utils';
+
+interface EdgesOverviewWidgetSettings {
+ enableDefaultTitle: boolean;
+}
@Component({
selector: 'tb-edges-overview-widget',
@@ -59,12 +64,10 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
private widgetConfig: WidgetConfig;
private subscription: IWidgetSubscription;
private datasources: Array;
+ private settings: EdgesOverviewWidgetSettings;
private nodeIdCounter = 0;
- private entityNodesMap: {[parentNodeId: string]: {[edgeId: string]: string}} = {};
- private entityGroupsNodesMap: {[edgeNodeId: string]: {[groupType: string]: string}} = {};
-
constructor(protected store: Store,
private edgeService: EdgeService,
private entityService: EntityService,
@@ -78,6 +81,8 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
this.widgetConfig = this.ctx.widgetConfig;
this.subscription = this.ctx.defaultSubscription;
this.datasources = this.subscription.datasources as Array;
+ this.settings = this.ctx.settings;
+ this.initializeConfig();
this.ctx.updateWidgetParams();
}
@@ -86,11 +91,11 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
if (node.id === '#' && datasource) {
if (datasource.type === DatasourceType.entity && datasource.entity.id.entityType === EntityType.EDGE) {
var selectedEdge: BaseData = datasource.entity;
+ this.updateTitle(selectedEdge);
this.getCustomerTitle(selectedEdge.id.id);
- this.ctx.widgetTitle = `${selectedEdge.name} Quick Overview`;
- cb(this.loadNodesForEdge(selectedEdge.id.id, selectedEdge));
+ cb(this.loadNodesForEdge(selectedEdge));
} else if (datasource.type === DatasourceType.function) {
- cb(this.loadNodesForEdge(datasource.entityId, datasource.entity));
+ cb(this.loadNodesForEdge(datasource.entity));
} else {
this.edgeIsDatasource = false;
cb([]);
@@ -103,21 +108,19 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
this.entityService.getAssignedToEdgeEntitiesByType(edgeId, entityType, pageLink).subscribe(
(entities) => {
if (entities.data.length > 0) {
- cb(this.entitiesToNodes(node.id, entities.data));
+ cb(this.entitiesToNodes(entities.data));
} else {
cb([]);
}
}
- )
+ );
} else {
cb([]);
}
}
- private loadNodesForEdge(parentNodeId: string, entity: BaseData): EdgeOverviewNode[] {
+ private loadNodesForEdge(entity: BaseData): EdgeOverviewNode[] {
const nodes: EdgeOverviewNode[] = [];
- const nodesMap = {};
- this.entityGroupsNodesMap[parentNodeId] = nodesMap;
const authUser = getCurrentAuthUser(this.store);
var allowedGroupTypes: EntityType[] = edgeGroupsTypes;
if (authUser.authority === Authority.CUSTOMER_USER) {
@@ -136,18 +139,12 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
} as EdgeGroupNodeData
};
nodes.push(node);
- nodesMap[entityType] = node.id;
});
return nodes;
}
- private createEntityNode(parentNodeId: string, entity: BaseData): EdgeOverviewNode {
- let nodesMap = this.entityNodesMap[parentNodeId];
- if (!nodesMap) {
- nodesMap = {};
- this.entityNodesMap[parentNodeId] = nodesMap;
- }
- const node: EdgeOverviewNode = {
+ private createEntityNode(entity: BaseData): EdgeOverviewNode {
+ return {
id: (++this.nodeIdCounter)+'',
icon: false,
text: entityNodeText(entity),
@@ -159,17 +156,14 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
entity: entity,
internalId: entity.id.id
} as EntityNodeData
- };
- nodesMap[entity.id.id] = node.id;
- return node;
+ } as EdgeOverviewNode;
}
- private entitiesToNodes(parentNodeId: string, entities: BaseData[]): EdgeOverviewNode[] {
+ private entitiesToNodes(entities: BaseData[]): EdgeOverviewNode[] {
const nodes: EdgeOverviewNode[] = [];
- this.entityNodesMap[parentNodeId] = {};
if (entities) {
entities.forEach((entity) => {
- const node = this.createEntityNode(parentNodeId, entity);
+ const node = this.createEntityNode(entity);
nodes.push(node);
});
}
@@ -187,4 +181,17 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
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): void {
+ const displayDefaultTitle: boolean = isDefined(this.settings.enableDefaultTitle) ? this.settings.enableDefaultTitle : false;
+ this.ctx.widgetTitle = displayDefaultTitle ? `${edge.name} Quick Overview` : this.widgetConfig.title;
+ }
}