Commit 4a66a354aefbe969992a768cc14c85ad4aa7af23

Authored by Artem Babak
1 parent a8ecf68b

Edge widget: added displayDefaultTitle config

@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 "templateHtml": "<tb-edges-overview-widget \n [ctx]=\"ctx\">\n</tb-edges-overview-widget>", 16 "templateHtml": "<tb-edges-overview-widget \n [ctx]=\"ctx\">\n</tb-edges-overview-widget>",
17 "templateCss": "", 17 "templateCss": "",
18 "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", 18 "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",
19 - "settingsSchema": "{}\n", 19 + "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}",
20 "dataKeySettingsSchema": "{}\n", 20 "dataKeySettingsSchema": "{}\n",
21 "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\":{}}" 21 "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\":{}}"
22 } 22 }
@@ -41,6 +41,11 @@ import { BaseData, HasId } from '@shared/models/base-data'; @@ -41,6 +41,11 @@ import { BaseData, HasId } from '@shared/models/base-data';
41 import { EntityId } from '@shared/models/id/entity-id'; 41 import { EntityId } from '@shared/models/id/entity-id';
42 import { getCurrentAuthUser } from '@core/auth/auth.selectors'; 42 import { getCurrentAuthUser } from '@core/auth/auth.selectors';
43 import { Authority } from '@shared/models/authority.enum'; 43 import { Authority } from '@shared/models/authority.enum';
  44 +import { isDefined } from '@core/utils';
  45 +
  46 +interface EdgesOverviewWidgetSettings {
  47 + enableDefaultTitle: boolean;
  48 +}
44 49
45 @Component({ 50 @Component({
46 selector: 'tb-edges-overview-widget', 51 selector: 'tb-edges-overview-widget',
@@ -59,12 +64,10 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni @@ -59,12 +64,10 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
59 private widgetConfig: WidgetConfig; 64 private widgetConfig: WidgetConfig;
60 private subscription: IWidgetSubscription; 65 private subscription: IWidgetSubscription;
61 private datasources: Array<EntityNodeDatasource>; 66 private datasources: Array<EntityNodeDatasource>;
  67 + private settings: EdgesOverviewWidgetSettings;
62 68
63 private nodeIdCounter = 0; 69 private nodeIdCounter = 0;
64 70
65 - private entityNodesMap: {[parentNodeId: string]: {[edgeId: string]: string}} = {};  
66 - private entityGroupsNodesMap: {[edgeNodeId: string]: {[groupType: string]: string}} = {};  
67 -  
68 constructor(protected store: Store<AppState>, 71 constructor(protected store: Store<AppState>,
69 private edgeService: EdgeService, 72 private edgeService: EdgeService,
70 private entityService: EntityService, 73 private entityService: EntityService,
@@ -78,6 +81,8 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni @@ -78,6 +81,8 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
78 this.widgetConfig = this.ctx.widgetConfig; 81 this.widgetConfig = this.ctx.widgetConfig;
79 this.subscription = this.ctx.defaultSubscription; 82 this.subscription = this.ctx.defaultSubscription;
80 this.datasources = this.subscription.datasources as Array<EntityNodeDatasource>; 83 this.datasources = this.subscription.datasources as Array<EntityNodeDatasource>;
  84 + this.settings = this.ctx.settings;
  85 + this.initializeConfig();
81 this.ctx.updateWidgetParams(); 86 this.ctx.updateWidgetParams();
82 } 87 }
83 88
@@ -86,11 +91,11 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni @@ -86,11 +91,11 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
86 if (node.id === '#' && datasource) { 91 if (node.id === '#' && datasource) {
87 if (datasource.type === DatasourceType.entity && datasource.entity.id.entityType === EntityType.EDGE) { 92 if (datasource.type === DatasourceType.entity && datasource.entity.id.entityType === EntityType.EDGE) {
88 var selectedEdge: BaseData<EntityId> = datasource.entity; 93 var selectedEdge: BaseData<EntityId> = datasource.entity;
  94 + this.updateTitle(selectedEdge);
89 this.getCustomerTitle(selectedEdge.id.id); 95 this.getCustomerTitle(selectedEdge.id.id);
90 - this.ctx.widgetTitle = `${selectedEdge.name} Quick Overview`;  
91 - cb(this.loadNodesForEdge(selectedEdge.id.id, selectedEdge)); 96 + cb(this.loadNodesForEdge(selectedEdge));
92 } else if (datasource.type === DatasourceType.function) { 97 } else if (datasource.type === DatasourceType.function) {
93 - cb(this.loadNodesForEdge(datasource.entityId, datasource.entity)); 98 + cb(this.loadNodesForEdge(datasource.entity));
94 } else { 99 } else {
95 this.edgeIsDatasource = false; 100 this.edgeIsDatasource = false;
96 cb([]); 101 cb([]);
@@ -103,21 +108,19 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni @@ -103,21 +108,19 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
103 this.entityService.getAssignedToEdgeEntitiesByType(edgeId, entityType, pageLink).subscribe( 108 this.entityService.getAssignedToEdgeEntitiesByType(edgeId, entityType, pageLink).subscribe(
104 (entities) => { 109 (entities) => {
105 if (entities.data.length > 0) { 110 if (entities.data.length > 0) {
106 - cb(this.entitiesToNodes(node.id, entities.data)); 111 + cb(this.entitiesToNodes(entities.data));
107 } else { 112 } else {
108 cb([]); 113 cb([]);
109 } 114 }
110 } 115 }
111 - ) 116 + );
112 } else { 117 } else {
113 cb([]); 118 cb([]);
114 } 119 }
115 } 120 }
116 121
117 - private loadNodesForEdge(parentNodeId: string, entity: BaseData<HasId>): EdgeOverviewNode[] { 122 + private loadNodesForEdge(entity: BaseData<HasId>): EdgeOverviewNode[] {
118 const nodes: EdgeOverviewNode[] = []; 123 const nodes: EdgeOverviewNode[] = [];
119 - const nodesMap = {};  
120 - this.entityGroupsNodesMap[parentNodeId] = nodesMap;  
121 const authUser = getCurrentAuthUser(this.store); 124 const authUser = getCurrentAuthUser(this.store);
122 var allowedGroupTypes: EntityType[] = edgeGroupsTypes; 125 var allowedGroupTypes: EntityType[] = edgeGroupsTypes;
123 if (authUser.authority === Authority.CUSTOMER_USER) { 126 if (authUser.authority === Authority.CUSTOMER_USER) {
@@ -136,18 +139,12 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni @@ -136,18 +139,12 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
136 } as EdgeGroupNodeData 139 } as EdgeGroupNodeData
137 }; 140 };
138 nodes.push(node); 141 nodes.push(node);
139 - nodesMap[entityType] = node.id;  
140 }); 142 });
141 return nodes; 143 return nodes;
142 } 144 }
143 145
144 - private createEntityNode(parentNodeId: string, entity: BaseData<HasId>): EdgeOverviewNode {  
145 - let nodesMap = this.entityNodesMap[parentNodeId];  
146 - if (!nodesMap) {  
147 - nodesMap = {};  
148 - this.entityNodesMap[parentNodeId] = nodesMap;  
149 - }  
150 - const node: EdgeOverviewNode = { 146 + private createEntityNode(entity: BaseData<HasId>): EdgeOverviewNode {
  147 + return {
151 id: (++this.nodeIdCounter)+'', 148 id: (++this.nodeIdCounter)+'',
152 icon: false, 149 icon: false,
153 text: entityNodeText(entity), 150 text: entityNodeText(entity),
@@ -159,17 +156,14 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni @@ -159,17 +156,14 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
159 entity: entity, 156 entity: entity,
160 internalId: entity.id.id 157 internalId: entity.id.id
161 } as EntityNodeData 158 } as EntityNodeData
162 - };  
163 - nodesMap[entity.id.id] = node.id;  
164 - return node; 159 + } as EdgeOverviewNode;
165 } 160 }
166 161
167 - private entitiesToNodes(parentNodeId: string, entities: BaseData<HasId>[]): EdgeOverviewNode[] { 162 + private entitiesToNodes(entities: BaseData<HasId>[]): EdgeOverviewNode[] {
168 const nodes: EdgeOverviewNode[] = []; 163 const nodes: EdgeOverviewNode[] = [];
169 - this.entityNodesMap[parentNodeId] = {};  
170 if (entities) { 164 if (entities) {
171 entities.forEach((entity) => { 165 entities.forEach((entity) => {
172 - const node = this.createEntityNode(parentNodeId, entity); 166 + const node = this.createEntityNode(entity);
173 nodes.push(node); 167 nodes.push(node);
174 }); 168 });
175 } 169 }
@@ -187,4 +181,17 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni @@ -187,4 +181,17 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni
187 this.cd.detectChanges(); 181 this.cd.detectChanges();
188 }); 182 });
189 } 183 }
  184 +
  185 + private initializeConfig(): void {
  186 + const edgeIsDatasource: boolean = this.datasources[0] && this.datasources[0].type === DatasourceType.entity && this.datasources[0].entity.id.entityType === EntityType.EDGE;
  187 + if (edgeIsDatasource) {
  188 + const edge = this.datasources[0].entity;
  189 + this.updateTitle(edge);
  190 + }
  191 + }
  192 +
  193 + private updateTitle(edge: BaseData<EntityId>): void {
  194 + const displayDefaultTitle: boolean = isDefined(this.settings.enableDefaultTitle) ? this.settings.enableDefaultTitle : false;
  195 + this.ctx.widgetTitle = displayDefaultTitle ? `${edge.name} Quick Overview` : this.widgetConfig.title;
  196 + }
190 } 197 }