Commit 4a66a354aefbe969992a768cc14c85ad4aa7af23
1 parent
a8ecf68b
Edge widget: added displayDefaultTitle config
Showing
2 changed files
with
33 additions
and
26 deletions
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | "templateHtml": "<tb-edges-overview-widget \n [ctx]=\"ctx\">\n</tb-edges-overview-widget>", |
17 | 17 | "templateCss": "", |
18 | 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 | 20 | "dataKeySettingsSchema": "{}\n", |
21 | 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 | 41 | import { EntityId } from '@shared/models/id/entity-id'; |
42 | 42 | import { getCurrentAuthUser } from '@core/auth/auth.selectors'; |
43 | 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 | 50 | @Component({ |
46 | 51 | selector: 'tb-edges-overview-widget', |
... | ... | @@ -59,12 +64,10 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni |
59 | 64 | private widgetConfig: WidgetConfig; |
60 | 65 | private subscription: IWidgetSubscription; |
61 | 66 | private datasources: Array<EntityNodeDatasource>; |
67 | + private settings: EdgesOverviewWidgetSettings; | |
62 | 68 | |
63 | 69 | private nodeIdCounter = 0; |
64 | 70 | |
65 | - private entityNodesMap: {[parentNodeId: string]: {[edgeId: string]: string}} = {}; | |
66 | - private entityGroupsNodesMap: {[edgeNodeId: string]: {[groupType: string]: string}} = {}; | |
67 | - | |
68 | 71 | constructor(protected store: Store<AppState>, |
69 | 72 | private edgeService: EdgeService, |
70 | 73 | private entityService: EntityService, |
... | ... | @@ -78,6 +81,8 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni |
78 | 81 | this.widgetConfig = this.ctx.widgetConfig; |
79 | 82 | this.subscription = this.ctx.defaultSubscription; |
80 | 83 | this.datasources = this.subscription.datasources as Array<EntityNodeDatasource>; |
84 | + this.settings = this.ctx.settings; | |
85 | + this.initializeConfig(); | |
81 | 86 | this.ctx.updateWidgetParams(); |
82 | 87 | } |
83 | 88 | |
... | ... | @@ -86,11 +91,11 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni |
86 | 91 | if (node.id === '#' && datasource) { |
87 | 92 | if (datasource.type === DatasourceType.entity && datasource.entity.id.entityType === EntityType.EDGE) { |
88 | 93 | var selectedEdge: BaseData<EntityId> = datasource.entity; |
94 | + this.updateTitle(selectedEdge); | |
89 | 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 | 97 | } else if (datasource.type === DatasourceType.function) { |
93 | - cb(this.loadNodesForEdge(datasource.entityId, datasource.entity)); | |
98 | + cb(this.loadNodesForEdge(datasource.entity)); | |
94 | 99 | } else { |
95 | 100 | this.edgeIsDatasource = false; |
96 | 101 | cb([]); |
... | ... | @@ -103,21 +108,19 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni |
103 | 108 | this.entityService.getAssignedToEdgeEntitiesByType(edgeId, entityType, pageLink).subscribe( |
104 | 109 | (entities) => { |
105 | 110 | if (entities.data.length > 0) { |
106 | - cb(this.entitiesToNodes(node.id, entities.data)); | |
111 | + cb(this.entitiesToNodes(entities.data)); | |
107 | 112 | } else { |
108 | 113 | cb([]); |
109 | 114 | } |
110 | 115 | } |
111 | - ) | |
116 | + ); | |
112 | 117 | } else { |
113 | 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 | 123 | const nodes: EdgeOverviewNode[] = []; |
119 | - const nodesMap = {}; | |
120 | - this.entityGroupsNodesMap[parentNodeId] = nodesMap; | |
121 | 124 | const authUser = getCurrentAuthUser(this.store); |
122 | 125 | var allowedGroupTypes: EntityType[] = edgeGroupsTypes; |
123 | 126 | if (authUser.authority === Authority.CUSTOMER_USER) { |
... | ... | @@ -136,18 +139,12 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni |
136 | 139 | } as EdgeGroupNodeData |
137 | 140 | }; |
138 | 141 | nodes.push(node); |
139 | - nodesMap[entityType] = node.id; | |
140 | 142 | }); |
141 | 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 | 148 | id: (++this.nodeIdCounter)+'', |
152 | 149 | icon: false, |
153 | 150 | text: entityNodeText(entity), |
... | ... | @@ -159,17 +156,14 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni |
159 | 156 | entity: entity, |
160 | 157 | internalId: entity.id.id |
161 | 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 | 163 | const nodes: EdgeOverviewNode[] = []; |
169 | - this.entityNodesMap[parentNodeId] = {}; | |
170 | 164 | if (entities) { |
171 | 165 | entities.forEach((entity) => { |
172 | - const node = this.createEntityNode(parentNodeId, entity); | |
166 | + const node = this.createEntityNode(entity); | |
173 | 167 | nodes.push(node); |
174 | 168 | }); |
175 | 169 | } |
... | ... | @@ -187,4 +181,17 @@ export class EdgesOverviewWidgetComponent extends PageComponent implements OnIni |
187 | 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 | } | ... | ... |